/src/mozilla-central/dom/html/HTMLAudioElement.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "mozilla/dom/HTMLAudioElement.h" |
8 | | #include "mozilla/dom/HTMLAudioElementBinding.h" |
9 | | #include "nsError.h" |
10 | | #include "nsGenericHTMLElement.h" |
11 | | #include "nsGkAtoms.h" |
12 | | #include "nsIDocument.h" |
13 | | #include "jsfriendapi.h" |
14 | | #include "nsContentUtils.h" |
15 | | #include "nsJSUtils.h" |
16 | | #include "AudioSampleFormat.h" |
17 | | #include <algorithm> |
18 | | #include "nsComponentManagerUtils.h" |
19 | | #include "nsIHttpChannel.h" |
20 | | #include "mozilla/dom/TimeRanges.h" |
21 | | #include "AudioStream.h" |
22 | | |
23 | | NS_IMPL_NS_NEW_HTML_ELEMENT(Audio) |
24 | | |
25 | | namespace mozilla { |
26 | | namespace dom { |
27 | | |
28 | | NS_IMPL_ELEMENT_CLONE(HTMLAudioElement) |
29 | | |
30 | | HTMLAudioElement::HTMLAudioElement(already_AddRefed<NodeInfo>&& aNodeInfo) |
31 | | : HTMLMediaElement(std::move(aNodeInfo)) |
32 | 0 | { |
33 | 0 | DecoderDoctorLogger::LogConstruction(this); |
34 | 0 | } |
35 | | |
36 | | HTMLAudioElement::~HTMLAudioElement() |
37 | 0 | { |
38 | 0 | DecoderDoctorLogger::LogDestruction(this); |
39 | 0 | } |
40 | | |
41 | | bool |
42 | | HTMLAudioElement::IsInteractiveHTMLContent(bool aIgnoreTabindex) const |
43 | 0 | { |
44 | 0 | return HasAttr(kNameSpaceID_None, nsGkAtoms::controls) || |
45 | 0 | HTMLMediaElement::IsInteractiveHTMLContent(aIgnoreTabindex); |
46 | 0 | } |
47 | | |
48 | | already_AddRefed<HTMLAudioElement> |
49 | | HTMLAudioElement::Audio(const GlobalObject& aGlobal, |
50 | | const Optional<nsAString>& aSrc, |
51 | | ErrorResult& aRv) |
52 | 0 | { |
53 | 0 | nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(aGlobal.GetAsSupports()); |
54 | 0 | nsIDocument* doc; |
55 | 0 | if (!win || !(doc = win->GetExtantDoc())) { |
56 | 0 | aRv.Throw(NS_ERROR_FAILURE); |
57 | 0 | return nullptr; |
58 | 0 | } |
59 | 0 | |
60 | 0 | RefPtr<mozilla::dom::NodeInfo> nodeInfo = |
61 | 0 | doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::audio, nullptr, |
62 | 0 | kNameSpaceID_XHTML, |
63 | 0 | ELEMENT_NODE); |
64 | 0 |
|
65 | 0 | RefPtr<HTMLAudioElement> audio = new HTMLAudioElement(nodeInfo.forget()); |
66 | 0 | audio->SetHTMLAttr(nsGkAtoms::preload, NS_LITERAL_STRING("auto"), aRv); |
67 | 0 | if (aRv.Failed()) { |
68 | 0 | return nullptr; |
69 | 0 | } |
70 | 0 | |
71 | 0 | if (aSrc.WasPassed()) { |
72 | 0 | audio->SetSrc(aSrc.Value(), aRv); |
73 | 0 | } |
74 | 0 |
|
75 | 0 | return audio.forget(); |
76 | 0 | } |
77 | | |
78 | | nsresult HTMLAudioElement::SetAcceptHeader(nsIHttpChannel* aChannel) |
79 | 0 | { |
80 | 0 | nsAutoCString value( |
81 | 0 | "audio/webm," |
82 | 0 | "audio/ogg," |
83 | 0 | "audio/wav," |
84 | 0 | "audio/*;q=0.9," |
85 | 0 | "application/ogg;q=0.7," |
86 | 0 | "video/*;q=0.6,*/*;q=0.5"); |
87 | 0 |
|
88 | 0 | return aChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"), |
89 | 0 | value, |
90 | 0 | false); |
91 | 0 | } |
92 | | |
93 | | JSObject* |
94 | | HTMLAudioElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
95 | 0 | { |
96 | 0 | return HTMLAudioElement_Binding::Wrap(aCx, this, aGivenProto); |
97 | 0 | } |
98 | | |
99 | | } // namespace dom |
100 | | } // namespace mozilla |