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: */
|
2013-02-07 19:38:26 +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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/HTMLSourceElement.h"
|
2013-02-07 19:39:10 +04:00
|
|
|
#include "mozilla/dom/HTMLSourceElementBinding.h"
|
2013-02-07 19:38:26 +04:00
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
#include "mozilla/dom/HTMLImageElement.h"
|
2018-04-15 13:29:46 +03:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2014-05-03 01:32:20 +04:00
|
|
|
#include "mozilla/dom/ResponsiveImageSelector.h"
|
2017-04-10 05:25:33 +03:00
|
|
|
#include "mozilla/dom/MediaList.h"
|
2015-05-26 14:01:14 +03:00
|
|
|
#include "mozilla/dom/MediaSource.h"
|
2014-05-03 01:32:20 +04:00
|
|
|
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
|
2018-06-02 16:51:42 +03:00
|
|
|
#include "mozilla/dom/BlobURLProtocolHandler.h"
|
2014-05-03 01:32:20 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2013-02-07 19:38:26 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Source)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLSourceElement::HTMLSourceElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-02-07 19:38:26 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLSourceElement::~HTMLSourceElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-26 14:01:14 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLSourceElement, nsGenericHTMLElement,
|
|
|
|
mSrcMediaSource)
|
|
|
|
|
2017-10-28 01:00:42 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLSourceElement, nsGenericHTMLElement)
|
2013-02-07 19:38:26 +04:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLSourceElement)
|
|
|
|
|
2014-04-18 01:38:18 +04:00
|
|
|
bool
|
|
|
|
HTMLSourceElement::MatchesCurrentMedia()
|
|
|
|
{
|
|
|
|
if (mMediaList) {
|
2018-02-21 01:00:10 +03:00
|
|
|
nsPresContext* pctx = OwnerDoc()->GetPresContext();
|
2017-04-14 04:39:53 +03:00
|
|
|
return pctx && mMediaList->Matches(pctx);
|
2014-04-18 01:38:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// No media specified
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-11 02:53:00 +03:00
|
|
|
/* static */ bool
|
|
|
|
HTMLSourceElement::WouldMatchMediaForDocument(const nsAString& aMedia,
|
|
|
|
const nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
if (aMedia.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-21 01:00:10 +03:00
|
|
|
nsPresContext* pctx = aDocument->GetPresContext();
|
2014-12-11 02:53:00 +03:00
|
|
|
|
2018-03-28 18:31:46 +03:00
|
|
|
RefPtr<MediaList> mediaList = MediaList::Create(aMedia);
|
2017-04-14 04:39:53 +03:00
|
|
|
return pctx && mediaList->Matches(pctx);
|
2014-12-11 02:53:00 +03:00
|
|
|
}
|
|
|
|
|
2016-02-03 04:53:00 +03:00
|
|
|
void
|
|
|
|
HTMLSourceElement::UpdateMediaList(const nsAttrValue* aValue)
|
|
|
|
{
|
|
|
|
mMediaList = nullptr;
|
|
|
|
nsString mediaStr;
|
|
|
|
if (!aValue || (mediaStr = aValue->GetStringValue()).IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-28 18:31:46 +03:00
|
|
|
mMediaList = MediaList::Create(mediaStr);
|
2016-02-03 04:53:00 +03:00
|
|
|
}
|
|
|
|
|
2014-04-18 01:38:18 +04:00
|
|
|
nsresult
|
2017-10-03 01:05:19 +03:00
|
|
|
HTMLSourceElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
|
|
bool aNotify)
|
2014-04-18 01:38:18 +04:00
|
|
|
{
|
2017-10-06 01:59:15 +03:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::srcset) {
|
|
|
|
mSrcsetTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
|
|
|
|
this, aValue ? aValue->GetStringValue() : EmptyString(),
|
|
|
|
aMaybeScriptedPrincipal);
|
|
|
|
}
|
2014-05-03 01:32:20 +04:00
|
|
|
// If we are associated with a <picture> with a valid <img>, notify it of
|
|
|
|
// responsive parameter changes
|
2015-03-10 17:23:14 +03:00
|
|
|
Element *parent = nsINode::GetParentElement();
|
2014-05-03 01:32:20 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
2014-10-02 07:30:49 +04:00
|
|
|
(aName == nsGkAtoms::srcset ||
|
|
|
|
aName == nsGkAtoms::sizes ||
|
2014-10-09 01:01:19 +04:00
|
|
|
aName == nsGkAtoms::media ||
|
|
|
|
aName == nsGkAtoms::type) &&
|
2015-03-03 14:09:00 +03:00
|
|
|
parent && parent->IsHTMLElement(nsGkAtoms::picture)) {
|
2014-05-03 01:32:20 +04:00
|
|
|
nsString strVal = aValue ? aValue->GetStringValue() : EmptyString();
|
|
|
|
// Find all img siblings after this <source> and notify them of the change
|
2015-03-10 17:23:14 +03:00
|
|
|
nsCOMPtr<nsIContent> sibling = AsContent();
|
2014-05-03 01:32:20 +04:00
|
|
|
while ( (sibling = sibling->GetNextSibling()) ) {
|
2015-03-03 14:09:00 +03:00
|
|
|
if (sibling->IsHTMLElement(nsGkAtoms::img)) {
|
2014-05-03 01:32:20 +04:00
|
|
|
HTMLImageElement *img = static_cast<HTMLImageElement*>(sibling.get());
|
|
|
|
if (aName == nsGkAtoms::srcset) {
|
|
|
|
img->PictureSourceSrcsetChanged(AsContent(), strVal, aNotify);
|
|
|
|
} else if (aName == nsGkAtoms::sizes) {
|
|
|
|
img->PictureSourceSizesChanged(AsContent(), strVal, aNotify);
|
2016-02-03 04:53:00 +03:00
|
|
|
} else if (aName == nsGkAtoms::media) {
|
|
|
|
UpdateMediaList(aValue);
|
|
|
|
img->PictureSourceMediaOrTypeChanged(AsContent(), aNotify);
|
|
|
|
} else if (aName == nsGkAtoms::type) {
|
2014-10-09 01:01:19 +04:00
|
|
|
img->PictureSourceMediaOrTypeChanged(AsContent(), aNotify);
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::media) {
|
2016-02-03 04:53:00 +03:00
|
|
|
UpdateMediaList(aValue);
|
2015-05-26 14:01:14 +03:00
|
|
|
} else if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {
|
2017-10-06 01:28:22 +03:00
|
|
|
mSrcTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
|
|
|
|
this, aValue ? aValue->GetStringValue() : EmptyString(),
|
|
|
|
aMaybeScriptedPrincipal);
|
2015-05-26 14:01:14 +03:00
|
|
|
mSrcMediaSource = nullptr;
|
|
|
|
if (aValue) {
|
|
|
|
nsString srcStr = aValue->GetStringValue();
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NewURIFromString(srcStr, getter_AddRefs(uri));
|
|
|
|
if (uri && IsMediaSourceURI(uri)) {
|
|
|
|
NS_GetSourceForMediaSourceURI(uri, getter_AddRefs(mSrcMediaSource));
|
|
|
|
}
|
|
|
|
}
|
2014-04-18 01:38:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
|
2017-10-10 00:33:38 +03:00
|
|
|
aValue, aOldValue,
|
|
|
|
aMaybeScriptedPrincipal,
|
|
|
|
aNotify);
|
2014-04-18 01:38:18 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 19:38:26 +04:00
|
|
|
nsresult
|
|
|
|
HTMLSourceElement::BindToTree(nsIDocument *aDocument,
|
|
|
|
nsIContent *aParent,
|
|
|
|
nsIContent *aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument,
|
|
|
|
aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2018-04-15 13:29:46 +03:00
|
|
|
if (auto* media = HTMLMediaElement::FromNodeOrNull(aParent)) {
|
2014-05-03 01:32:20 +04:00
|
|
|
media->NotifyAddedSource();
|
|
|
|
}
|
2013-02-07 19:38:26 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-07 19:39:10 +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
|
|
|
HTMLSourceElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-07 19:39:10 +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 HTMLSourceElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-07 19:39:10 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 19:38:26 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|