2015-05-03 22:32:37 +03: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 15:12:37 +04: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 16:26:39 +04:00
|
|
|
|
|
|
|
#include "mozilla/dom/HTMLAudioElement.h"
|
|
|
|
#include "mozilla/dom/HTMLAudioElementBinding.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2008-07-09 12:22:20 +04:00
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIDocument.h"
|
2011-10-04 18:06:54 +04:00
|
|
|
#include "jsfriendapi.h"
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-09-24 07:47:30 +04:00
|
|
|
#include "nsJSUtils.h"
|
2012-10-25 14:09:40 +04:00
|
|
|
#include "AudioSampleFormat.h"
|
2012-11-16 07:25:26 +04:00
|
|
|
#include "AudioChannelCommon.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2013-09-06 21:50:24 +04:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2013-10-22 01:23:33 +04:00
|
|
|
#include "nsIHttpChannel.h"
|
|
|
|
#include "mozilla/dom/TimeRanges.h"
|
|
|
|
#include "AudioStream.h"
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2013-04-04 11:04:29 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Audio)
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2013-03-19 16:25:46 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2013-10-18 06:10:56 +04:00
|
|
|
extern bool IsAudioAPIEnabled();
|
|
|
|
|
2013-03-19 16:25:46 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLAudioElement)
|
2008-07-09 12:22:20 +04:00
|
|
|
|
|
|
|
|
2014-07-13 06:20:42 +04:00
|
|
|
HTMLAudioElement::HTMLAudioElement(already_AddRefed<NodeInfo>& aNodeInfo)
|
2014-04-03 01:53:39 +04:00
|
|
|
: HTMLMediaElement(aNodeInfo)
|
2008-07-09 12:22:20 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-19 16:25:46 +04:00
|
|
|
HTMLAudioElement::~HTMLAudioElement()
|
2008-07-09 12:22:20 +04:00
|
|
|
{
|
|
|
|
}
|
2009-05-19 09:18:41 +04:00
|
|
|
|
2015-01-20 23:39:28 +03:00
|
|
|
bool
|
2015-03-17 23:42:14 +03:00
|
|
|
HTMLAudioElement::IsInteractiveHTMLContent(bool aIgnoreTabindex) const
|
2015-01-20 23:39:28 +03:00
|
|
|
{
|
2015-03-23 12:02:33 +03:00
|
|
|
return HasAttr(kNameSpaceID_None, nsGkAtoms::controls) ||
|
|
|
|
HTMLMediaElement::IsInteractiveHTMLContent(aIgnoreTabindex);
|
2015-01-20 23:39:28 +03:00
|
|
|
}
|
|
|
|
|
2013-03-19 16:26:39 +04:00
|
|
|
already_AddRefed<HTMLAudioElement>
|
2013-04-12 23:35:46 +04:00
|
|
|
HTMLAudioElement::Audio(const GlobalObject& aGlobal,
|
|
|
|
const Optional<nsAString>& aSrc,
|
|
|
|
ErrorResult& aRv)
|
2013-03-19 16:26:39 +04:00
|
|
|
{
|
2013-08-23 09:17:08 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.GetAsSupports());
|
2013-03-19 16:26:39 +04:00
|
|
|
nsIDocument* doc;
|
|
|
|
if (!win || !(doc = win->GetExtantDoc())) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo> nodeInfo =
|
2013-03-19 16:26:39 +04:00
|
|
|
doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::audio, nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
|
2014-03-15 23:00:17 +04:00
|
|
|
nsRefPtr<HTMLAudioElement> audio = new HTMLAudioElement(nodeInfo);
|
2013-03-19 16:26:39 +04:00
|
|
|
audio->SetHTMLAttr(nsGkAtoms::preload, NS_LITERAL_STRING("auto"), aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-04-12 23:35:46 +04:00
|
|
|
if (aSrc.WasPassed()) {
|
|
|
|
aRv = audio->SetSrc(aSrc.Value());
|
2013-03-19 16:26:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return audio.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-19 16:25:46 +04:00
|
|
|
nsresult HTMLAudioElement::SetAcceptHeader(nsIHttpChannel* aChannel)
|
2010-07-29 08:58:07 +04:00
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString value(
|
2010-07-29 08:58:07 +04: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-30 03:34:37 +04:00
|
|
|
false);
|
2010-07-29 08:58:07 +04:00
|
|
|
}
|
2013-03-19 16:25:46 +04:00
|
|
|
|
2013-03-19 16:26:39 +04: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 17:13:33 +03:00
|
|
|
HTMLAudioElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-03-19 16:26:39 +04: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 17:13:33 +03:00
|
|
|
return HTMLAudioElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-03-19 16:26:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-19 16:25:46 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|