Line data Source code
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 0 : NS_IMPL_NS_NEW_HTML_ELEMENT(Audio)
24 :
25 : namespace mozilla {
26 : namespace dom {
27 :
28 0 : NS_IMPL_ELEMENT_CLONE(HTMLAudioElement)
29 :
30 0 : HTMLAudioElement::HTMLAudioElement(already_AddRefed<NodeInfo>& aNodeInfo)
31 0 : : HTMLMediaElement(aNodeInfo)
32 : {
33 0 : }
34 :
35 0 : HTMLAudioElement::~HTMLAudioElement()
36 : {
37 0 : }
38 :
39 : bool
40 0 : HTMLAudioElement::IsInteractiveHTMLContent(bool aIgnoreTabindex) const
41 : {
42 0 : return HasAttr(kNameSpaceID_None, nsGkAtoms::controls) ||
43 0 : HTMLMediaElement::IsInteractiveHTMLContent(aIgnoreTabindex);
44 : }
45 :
46 : already_AddRefed<HTMLAudioElement>
47 0 : HTMLAudioElement::Audio(const GlobalObject& aGlobal,
48 : const Optional<nsAString>& aSrc,
49 : ErrorResult& aRv)
50 : {
51 0 : nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(aGlobal.GetAsSupports());
52 : nsIDocument* doc;
53 0 : if (!win || !(doc = win->GetExtantDoc())) {
54 0 : aRv.Throw(NS_ERROR_FAILURE);
55 0 : return nullptr;
56 : }
57 :
58 : already_AddRefed<mozilla::dom::NodeInfo> nodeInfo =
59 : doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::audio, nullptr,
60 : kNameSpaceID_XHTML,
61 0 : nsIDOMNode::ELEMENT_NODE);
62 :
63 0 : RefPtr<HTMLAudioElement> audio = new HTMLAudioElement(nodeInfo);
64 0 : audio->SetHTMLAttr(nsGkAtoms::preload, NS_LITERAL_STRING("auto"), aRv);
65 0 : if (aRv.Failed()) {
66 0 : return nullptr;
67 : }
68 :
69 0 : if (aSrc.WasPassed()) {
70 0 : aRv = audio->SetSrc(aSrc.Value());
71 : }
72 :
73 0 : return audio.forget();
74 : }
75 :
76 0 : nsresult HTMLAudioElement::SetAcceptHeader(nsIHttpChannel* aChannel)
77 : {
78 : nsAutoCString value(
79 : "audio/webm,"
80 : "audio/ogg,"
81 : "audio/wav,"
82 : "audio/*;q=0.9,"
83 : "application/ogg;q=0.7,"
84 0 : "video/*;q=0.6,*/*;q=0.5");
85 :
86 0 : return aChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
87 : value,
88 0 : false);
89 : }
90 :
91 : JSObject*
92 0 : HTMLAudioElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
93 : {
94 0 : return HTMLAudioElementBinding::Wrap(aCx, this, aGivenProto);
95 : }
96 :
97 : } // namespace dom
98 : } // namespace mozilla
|