2015-05-03 12:32:37 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-03-19 05:26:39 -07:00
|
|
|
|
|
|
|
#include "mozilla/dom/HTMLAudioElement.h"
|
|
|
|
#include "mozilla/dom/HTMLAudioElementBinding.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2008-07-09 01:22:20 -07:00
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIDocument.h"
|
2011-10-04 07:06:54 -07:00
|
|
|
#include "jsfriendapi.h"
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "nsContentUtils.h"
|
2012-09-23 20:47:30 -07:00
|
|
|
#include "nsJSUtils.h"
|
2012-10-25 03:09:40 -07:00
|
|
|
#include "AudioSampleFormat.h"
|
2012-11-15 19:25:26 -08:00
|
|
|
#include "AudioChannelCommon.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2013-09-06 10:50:24 -07:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2013-10-21 14:23:33 -07:00
|
|
|
#include "nsIHttpChannel.h"
|
|
|
|
#include "mozilla/dom/TimeRanges.h"
|
|
|
|
#include "AudioStream.h"
|
2008-07-09 01:22:20 -07:00
|
|
|
|
2013-04-04 00:04:29 -07:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Audio)
|
2008-07-09 01:22:20 -07:00
|
|
|
|
2013-03-19 05:25:46 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2008-07-09 01:22:20 -07:00
|
|
|
|
2013-10-17 19:10:56 -07:00
|
|
|
extern bool IsAudioAPIEnabled();
|
|
|
|
|
2013-03-19 05:25:46 -07:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLAudioElement)
|
2008-07-09 01:22:20 -07:00
|
|
|
|
|
|
|
|
2014-07-12 19:20:42 -07:00
|
|
|
HTMLAudioElement::HTMLAudioElement(already_AddRefed<NodeInfo>& aNodeInfo)
|
2014-04-02 14:53:39 -07:00
|
|
|
: HTMLMediaElement(aNodeInfo)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-19 05:25:46 -07:00
|
|
|
HTMLAudioElement::~HTMLAudioElement()
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
|
|
|
}
|
2009-05-18 22:18:41 -07:00
|
|
|
|
2015-01-20 12:39:28 -08:00
|
|
|
bool
|
2015-03-17 13:42:14 -07:00
|
|
|
HTMLAudioElement::IsInteractiveHTMLContent(bool aIgnoreTabindex) const
|
2015-01-20 12:39:28 -08:00
|
|
|
{
|
2015-03-23 02:02:33 -07:00
|
|
|
return HasAttr(kNameSpaceID_None, nsGkAtoms::controls) ||
|
|
|
|
HTMLMediaElement::IsInteractiveHTMLContent(aIgnoreTabindex);
|
2015-01-20 12:39:28 -08:00
|
|
|
}
|
|
|
|
|
2013-03-19 05:26:39 -07:00
|
|
|
already_AddRefed<HTMLAudioElement>
|
2013-04-12 12:35:46 -07:00
|
|
|
HTMLAudioElement::Audio(const GlobalObject& aGlobal,
|
|
|
|
const Optional<nsAString>& aSrc,
|
|
|
|
ErrorResult& aRv)
|
2013-03-19 05:26:39 -07:00
|
|
|
{
|
2013-08-22 22:17:08 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.GetAsSupports());
|
2013-03-19 05:26:39 -07:00
|
|
|
nsIDocument* doc;
|
|
|
|
if (!win || !(doc = win->GetExtantDoc())) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo> nodeInfo =
|
2013-03-19 05:26:39 -07:00
|
|
|
doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::audio, nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
|
2014-03-15 12:00:17 -07:00
|
|
|
nsRefPtr<HTMLAudioElement> audio = new HTMLAudioElement(nodeInfo);
|
2013-03-19 05:26:39 -07:00
|
|
|
audio->SetHTMLAttr(nsGkAtoms::preload, NS_LITERAL_STRING("auto"), aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-04-12 12:35:46 -07:00
|
|
|
if (aSrc.WasPassed()) {
|
|
|
|
aRv = audio->SetSrc(aSrc.Value());
|
2013-03-19 05:26:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return audio.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-19 05:25:46 -07:00
|
|
|
nsresult HTMLAudioElement::SetAcceptHeader(nsIHttpChannel* aChannel)
|
2010-07-28 21:58:07 -07:00
|
|
|
{
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString value(
|
2010-07-28 21:58:07 -07:00
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
"audio/webm,"
|
|
|
|
#endif
|
|
|
|
"audio/ogg,"
|
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
"audio/wav,"
|
|
|
|
#endif
|
|
|
|
"audio/*;q=0.9,"
|
|
|
|
"application/ogg;q=0.7,"
|
|
|
|
"video/*;q=0.6,*/*;q=0.5");
|
|
|
|
|
|
|
|
return aChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
|
|
|
|
value,
|
2011-09-29 16:34:37 -07:00
|
|
|
false);
|
2010-07-28 21:58:07 -07:00
|
|
|
}
|
2013-03-19 05:25:46 -07:00
|
|
|
|
2013-03-19 05:26:39 -07:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
HTMLAudioElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-03-19 05:26:39 -07:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return HTMLAudioElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-03-19 05:26:39 -07:00
|
|
|
}
|
|
|
|
|
2013-03-19 05:25:46 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|