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