2015-05-03 19:32:37 +00: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-01-05 09:41:28 +00: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/. */
|
|
|
|
|
2018-12-28 02:47:10 +00:00
|
|
|
#include "mozilla/dom/SVGScriptElement.h"
|
|
|
|
|
2013-01-05 09:41:28 +00:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "mozilla/dom/SVGScriptElementBinding.h"
|
2017-03-09 16:54:26 +00:00
|
|
|
#include "nsIScriptError.h"
|
2013-01-05 09:41:28 +00:00
|
|
|
|
2018-12-21 11:43:29 +00:00
|
|
|
NS_IMPL_NS_NEW_SVG_ELEMENT_CHECK_PARSER(Script)
|
2013-01-05 09:41:28 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
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 14:13:33 +00:00
|
|
|
JSObject* SVGScriptElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-25 21:20:54 +00:00
|
|
|
return SVGScriptElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-01-05 09:41:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 08:58:14 +00:00
|
|
|
SVGElement::StringInfo SVGScriptElement::sStringInfo[2] = {
|
2018-03-29 09:45:24 +00:00
|
|
|
{nsGkAtoms::href, kNameSpaceID_None, false},
|
|
|
|
{nsGkAtoms::href, kNameSpaceID_XLink, false}};
|
2013-01-05 09:41:28 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(SVGScriptElement, SVGScriptElementBase,
|
|
|
|
nsIScriptLoaderObserver, nsIScriptElement,
|
|
|
|
nsIMutationObserver)
|
2013-01-05 09:41:28 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2018-09-21 20:45:49 +00:00
|
|
|
SVGScriptElement::SVGScriptElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2013-01-05 09:41:28 +00:00
|
|
|
FromParser aFromParser)
|
2018-09-21 20:45:49 +00:00
|
|
|
: SVGScriptElementBase(std::move(aNodeInfo)), ScriptElement(aFromParser) {
|
2013-01-05 09:41:28 +00:00
|
|
|
AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-05-30 02:58:49 +00:00
|
|
|
// nsINode methods
|
2013-01-05 09:41:28 +00:00
|
|
|
|
2018-08-08 23:58:44 +00:00
|
|
|
nsresult SVGScriptElement::Clone(dom::NodeInfo* aNodeInfo,
|
|
|
|
nsINode** aResult) const {
|
2013-01-05 09:41:28 +00:00
|
|
|
*aResult = nullptr;
|
|
|
|
|
2020-03-17 14:53:16 +00:00
|
|
|
SVGScriptElement* it = new (aNodeInfo->NodeInfoManager())
|
|
|
|
SVGScriptElement(do_AddRef(aNodeInfo), NOT_FROM_PARSER);
|
2013-01-05 09:41:28 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsINode> kungFuDeathGrip = it;
|
|
|
|
nsresult rv1 = it->Init();
|
2018-08-08 23:58:44 +00:00
|
|
|
nsresult rv2 = const_cast<SVGScriptElement*>(this)->CopyInnerTo(it);
|
2013-01-05 09:41:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv1, rv1);
|
|
|
|
NS_ENSURE_SUCCESS(rv2, rv2);
|
|
|
|
|
|
|
|
// The clone should be marked evaluated if we are.
|
|
|
|
it->mAlreadyStarted = mAlreadyStarted;
|
|
|
|
it->mLineNumber = mLineNumber;
|
|
|
|
it->mMalformed = mMalformed;
|
|
|
|
|
|
|
|
kungFuDeathGrip.swap(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2013-02-02 20:23:18 +00:00
|
|
|
void SVGScriptElement::GetType(nsAString& aType) { GetScriptType(aType); }
|
|
|
|
|
|
|
|
void SVGScriptElement::SetType(const nsAString& aType, ErrorResult& rv) {
|
|
|
|
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::type, aType, true);
|
|
|
|
}
|
|
|
|
|
2014-09-06 02:42:33 +00:00
|
|
|
void SVGScriptElement::GetCrossOrigin(nsAString& aCrossOrigin) {
|
|
|
|
// Null for both missing and invalid defaults is ok, since we
|
|
|
|
// always parse to an enum value, so we don't need an invalid
|
|
|
|
// default, and we _want_ the missing default to be null.
|
|
|
|
GetEnumAttr(nsGkAtoms::crossorigin, nullptr, aCrossOrigin);
|
2013-02-02 20:23:18 +00:00
|
|
|
}
|
2013-01-05 09:41:28 +00:00
|
|
|
|
2014-09-06 02:42:33 +00:00
|
|
|
void SVGScriptElement::SetCrossOrigin(const nsAString& aCrossOrigin,
|
|
|
|
ErrorResult& aError) {
|
|
|
|
SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin, aCrossOrigin, aError);
|
2013-02-02 20:23:18 +00:00
|
|
|
}
|
2013-01-05 09:41:28 +00:00
|
|
|
|
2019-03-19 00:01:03 +00:00
|
|
|
already_AddRefed<DOMSVGAnimatedString> SVGScriptElement::Href() {
|
2016-08-26 10:06:04 +00:00
|
|
|
return mStringAttributes[HREF].IsExplicitlySet()
|
|
|
|
? mStringAttributes[HREF].ToDOMAnimatedString(this)
|
|
|
|
: mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this);
|
2013-01-05 09:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIScriptElement methods
|
|
|
|
|
|
|
|
bool SVGScriptElement::GetScriptType(nsAString& type) {
|
2016-07-13 16:10:13 +00:00
|
|
|
return GetAttr(kNameSpaceID_None, nsGkAtoms::type, type);
|
2013-01-05 09:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SVGScriptElement::GetScriptText(nsAString& text) {
|
2015-05-22 18:16:20 +00:00
|
|
|
nsContentUtils::GetNodeTextContent(this, false, text);
|
2013-01-05 09:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SVGScriptElement::GetScriptCharset(nsAString& charset) {
|
|
|
|
charset.Truncate();
|
|
|
|
}
|
|
|
|
|
2019-01-02 13:05:23 +00:00
|
|
|
void SVGScriptElement::FreezeExecutionAttrs(Document* aOwnerDoc) {
|
2013-01-05 09:41:28 +00:00
|
|
|
if (mFrozen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-26 10:06:04 +00:00
|
|
|
if (mStringAttributes[HREF].IsExplicitlySet() ||
|
|
|
|
mStringAttributes[XLINK_HREF].IsExplicitlySet()) {
|
2013-01-05 09:41:28 +00:00
|
|
|
// variation of this code in nsHTMLScriptElement - check if changes
|
2018-03-18 18:09:51 +00:00
|
|
|
// need to be transferred when modifying
|
2017-03-09 16:54:26 +00:00
|
|
|
bool isHref = false;
|
2013-01-05 09:41:28 +00:00
|
|
|
nsAutoString src;
|
2016-08-26 10:06:04 +00:00
|
|
|
if (mStringAttributes[HREF].IsExplicitlySet()) {
|
|
|
|
mStringAttributes[HREF].GetAnimValue(src, this);
|
2017-03-09 16:54:26 +00:00
|
|
|
isHref = true;
|
2016-08-26 10:06:04 +00:00
|
|
|
} else {
|
|
|
|
mStringAttributes[XLINK_HREF].GetAnimValue(src, this);
|
|
|
|
}
|
2013-01-05 09:41:28 +00:00
|
|
|
|
2016-09-07 18:21:36 +00:00
|
|
|
// Empty src should be treated as invalid URL.
|
|
|
|
if (!src.IsEmpty()) {
|
2019-07-15 18:29:05 +00:00
|
|
|
NS_NewURI(getter_AddRefs(mUri), src, nullptr, GetBaseURI());
|
2017-03-09 16:54:26 +00:00
|
|
|
|
|
|
|
if (!mUri) {
|
2020-07-01 08:29:29 +00:00
|
|
|
AutoTArray<nsString, 2> params = {
|
|
|
|
isHref ? u"href"_ns : u"xlink:href"_ns, src};
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2017-03-09 16:54:26 +00:00
|
|
|
nsContentUtils::ReportToConsole(
|
2020-07-01 08:29:29 +00:00
|
|
|
nsIScriptError::warningFlag, "SVG"_ns, OwnerDoc(),
|
2017-03-09 16:54:26 +00:00
|
|
|
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceInvalidUri", params,
|
2019-06-08 21:26:12 +00:00
|
|
|
nullptr, EmptyString(), GetScriptLineNumber(),
|
2018-07-05 06:21:04 +00:00
|
|
|
GetScriptColumnNumber());
|
2017-03-09 16:54:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-07-01 08:29:29 +00:00
|
|
|
AutoTArray<nsString, 1> params = {isHref ? u"href"_ns : u"xlink:href"_ns};
|
2017-03-09 16:54:26 +00:00
|
|
|
|
|
|
|
nsContentUtils::ReportToConsole(
|
2020-07-01 08:29:29 +00:00
|
|
|
nsIScriptError::warningFlag, "SVG"_ns, OwnerDoc(),
|
2019-06-08 21:26:12 +00:00
|
|
|
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceEmpty", params, nullptr,
|
|
|
|
EmptyString(), GetScriptLineNumber(), GetScriptColumnNumber());
|
2016-09-07 18:21:36 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 09:41:28 +00:00
|
|
|
// At this point mUri will be null for invalid URLs.
|
|
|
|
mExternal = true;
|
|
|
|
}
|
2016-08-26 10:06:04 +00:00
|
|
|
|
2013-01-05 09:41:28 +00:00
|
|
|
mFrozen = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-05-08 06:24:22 +00:00
|
|
|
// ScriptElement methods
|
2013-01-05 09:41:28 +00:00
|
|
|
|
|
|
|
bool SVGScriptElement::HasScriptContent() {
|
2016-08-26 10:06:04 +00:00
|
|
|
return (mFrozen ? mExternal
|
|
|
|
: mStringAttributes[HREF].IsExplicitlySet() ||
|
|
|
|
mStringAttributes[XLINK_HREF].IsExplicitlySet()) ||
|
2013-01-05 09:41:28 +00:00
|
|
|
nsContentUtils::HasNonEmptyTextContent(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-21 08:58:14 +00:00
|
|
|
// SVGElement methods
|
2013-01-05 09:41:28 +00:00
|
|
|
|
2018-12-21 08:58:14 +00:00
|
|
|
SVGElement::StringAttributesInfo SVGScriptElement::GetStringInfo() {
|
2013-01-05 09:41:28 +00:00
|
|
|
return StringAttributesInfo(mStringAttributes, sStringInfo,
|
|
|
|
ArrayLength(sStringInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
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 04:27:04 +00:00
|
|
|
nsresult SVGScriptElement::BindToTree(BindContext& aContext, nsINode& aParent) {
|
|
|
|
nsresult rv = SVGScriptElementBase::BindToTree(aContext, aParent);
|
2013-01-05 09:41:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2019-06-17 16:02:59 +00:00
|
|
|
if (IsInComposedDoc()) {
|
2013-01-05 09:41:28 +00:00
|
|
|
MaybeProcessScript();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
nsresult SVGScriptElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-05-18 21:09:01 +00:00
|
|
|
const nsAttrValue* aValue,
|
2017-10-09 21:33:38 +00:00
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
|
|
|
bool aNotify) {
|
2016-08-26 10:06:04 +00:00
|
|
|
if ((aNamespaceID == kNameSpaceID_XLink ||
|
|
|
|
aNamespaceID == kNameSpaceID_None) &&
|
|
|
|
aName == nsGkAtoms::href) {
|
2013-01-05 09:41:28 +00:00
|
|
|
MaybeProcessScript();
|
|
|
|
}
|
|
|
|
return SVGScriptElementBase::AfterSetAttr(
|
2017-10-09 21:33:38 +00:00
|
|
|
aNamespaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
|
2013-01-05 09:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SVGScriptElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 03:35:52 +00:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2013-01-05 09:41:28 +00:00
|
|
|
nsAttrValue& aResult) {
|
|
|
|
if (aNamespaceID == kNameSpaceID_None &&
|
|
|
|
aAttribute == nsGkAtoms::crossorigin) {
|
|
|
|
ParseCORSValue(aValue, aResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SVGScriptElementBase::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2017-11-02 03:35:52 +00:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
2013-01-05 09:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CORSMode SVGScriptElement::GetCORSMode() const {
|
|
|
|
return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|