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
|
|
|
|
2019-03-29 18:11:04 +03:00
|
|
|
#include "mozilla/dom/DocumentInlines.h"
|
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 {
|
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
HTMLSourceElement::HTMLSourceElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: nsGenericHTMLElement(std::move(aNodeInfo)) {}
|
2013-02-07 19:38:26 +04:00
|
|
|
|
|
|
|
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) {
|
2019-04-04 14:25:31 +03:00
|
|
|
return mMediaList->Matches(*OwnerDoc());
|
2014-04-18 01:38:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// No media specified
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
bool HTMLSourceElement::WouldMatchMediaForDocument(const nsAString& aMedia,
|
|
|
|
const Document* aDocument) {
|
2014-12-11 02:53:00 +03:00
|
|
|
if (aMedia.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-28 18:31:46 +03:00
|
|
|
RefPtr<MediaList> mediaList = MediaList::Create(aMedia);
|
2019-04-04 14:25:31 +03:00
|
|
|
return mediaList->Matches(*aDocument);
|
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
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult 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) {
|
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)) {
|
2019-02-01 18:20:15 +03:00
|
|
|
if (aName == nsGkAtoms::media) {
|
|
|
|
UpdateMediaList(aValue);
|
|
|
|
}
|
|
|
|
|
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())) {
|
2019-02-01 18:20:15 +03:00
|
|
|
if (auto* img = HTMLImageElement::FromNode(sibling)) {
|
2014-05-03 01:32:20 +04:00
|
|
|
if (aName == nsGkAtoms::srcset) {
|
2019-02-01 18:20:15 +03:00
|
|
|
img->PictureSourceSrcsetChanged(this, strVal, aNotify);
|
2014-05-03 01:32:20 +04:00
|
|
|
} else if (aName == nsGkAtoms::sizes) {
|
2019-02-01 18:20:15 +03:00
|
|
|
img->PictureSourceSizesChanged(this, strVal, aNotify);
|
|
|
|
} else if (aName == nsGkAtoms::media || aName == nsGkAtoms::type) {
|
|
|
|
img->PictureSourceMediaOrTypeChanged(this, 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(
|
2017-10-10 00:33:38 +03:00
|
|
|
aNameSpaceID, aName, aValue, aOldValue, aMaybeScriptedPrincipal, aNotify);
|
2014-04-18 01:38:18 +04:00
|
|
|
}
|
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
nsresult HTMLSourceElement::BindToTree(BindContext& aContext,
|
|
|
|
nsINode& aParent) {
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aContext, aParent);
|
2013-02-07 19:38:26 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
if (auto* media = HTMLMediaElement::FromNode(aParent)) {
|
2014-05-03 01:32:20 +04:00
|
|
|
media->NotifyAddedSource();
|
|
|
|
}
|
2013-02-07 19:38:26 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
JSObject* HTMLSourceElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return HTMLSourceElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-07 19:39:10 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 19:38:26 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|