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 05:50:21 +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/SVGStyleElement.h"
|
2018-12-28 05:47:10 +03:00
|
|
|
|
|
|
|
#include "mozilla/dom/Element.h"
|
2013-01-05 05:50:21 +04:00
|
|
|
#include "mozilla/dom/SVGStyleElementBinding.h"
|
2019-01-25 02:40:25 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsContentUtils.h"
|
2013-01-05 05:50:21 +04:00
|
|
|
|
2018-12-21 14:43:29 +03:00
|
|
|
NS_IMPL_NS_NEW_SVG_ELEMENT(Style)
|
2013-01-05 05:50:21 +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* SVGStyleElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return SVGStyleElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2017-09-01 02:29:22 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(SVGStyleElement,
|
|
|
|
SVGStyleElementBase,
|
|
|
|
nsIStyleSheetLinkingElement,
|
|
|
|
nsIMutationObserver)
|
2013-01-05 05:50:21 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(SVGStyleElement)
|
|
|
|
|
2013-01-05 05:50:21 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGStyleElement,
|
|
|
|
SVGStyleElementBase)
|
|
|
|
tmp->nsStyleLinkElement::Traverse(cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2013-01-05 05:50:21 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGStyleElement,
|
|
|
|
SVGStyleElementBase)
|
|
|
|
tmp->nsStyleLinkElement::Unlink();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
SVGStyleElement::SVGStyleElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: SVGStyleElementBase(std::move(aNodeInfo)) {
|
2013-01-05 05:50:21 +04:00
|
|
|
AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-05-30 05:58:49 +03:00
|
|
|
// nsINode methods
|
2013-01-05 05:50:21 +04:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGStyleElement)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult SVGStyleElement::BindToTree(Document* aDocument, nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent) {
|
2013-01-05 05:50:21 +04:00
|
|
|
nsresult rv =
|
|
|
|
SVGStyleElementBase::BindToTree(aDocument, aParent, aBindingParent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
void (SVGStyleElement::*update)() =
|
|
|
|
&SVGStyleElement::UpdateStyleSheetInternal;
|
2017-06-12 22:34:10 +03:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
NewRunnableMethod("dom::SVGStyleElement::BindToTree", this, update));
|
2013-01-05 05:50:21 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVGStyleElement::UnbindFromTree(bool aDeep, bool aNullParent) {
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> oldDoc = GetUncomposedDoc();
|
2014-06-12 05:15:22 +04:00
|
|
|
ShadowRoot* oldShadow = GetContainingShadow();
|
2013-01-05 05:50:21 +04:00
|
|
|
SVGStyleElementBase::UnbindFromTree(aDeep, aNullParent);
|
2018-04-24 13:50:35 +03:00
|
|
|
Unused << UpdateStyleSheetInternal(oldDoc, oldShadow);
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
|
2018-01-03 22:21:23 +03:00
|
|
|
nsresult SVGStyleElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
|
|
bool aNotify) {
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
2013-01-09 03:25:48 +04:00
|
|
|
if (aName == nsGkAtoms::title || aName == nsGkAtoms::media ||
|
|
|
|
aName == nsGkAtoms::type) {
|
2018-04-24 13:50:35 +03:00
|
|
|
Unused << UpdateStyleSheetInternal(nullptr, nullptr, ForceUpdate::Yes);
|
2013-01-09 03:25:48 +04:00
|
|
|
}
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
|
2018-01-03 22:21:23 +03:00
|
|
|
return SVGStyleElementBase::AfterSetAttr(
|
|
|
|
aNameSpaceID, aName, aValue, aOldValue, aMaybeScriptedPrincipal, aNotify);
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SVGStyleElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2013-01-05 05:50:21 +04:00
|
|
|
nsAttrValue& aResult) {
|
|
|
|
if (aNamespaceID == kNameSpaceID_None &&
|
|
|
|
aAttribute == nsGkAtoms::crossorigin) {
|
|
|
|
ParseCORSValue(aValue, aResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SVGStyleElementBase::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIMutationObserver methods
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void SVGStyleElement::CharacterDataChanged(nsIContent* aContent,
|
2018-02-27 17:30:27 +03:00
|
|
|
const CharacterDataChangeInfo&) {
|
2013-01-05 05:50:21 +04:00
|
|
|
ContentChanged(aContent);
|
|
|
|
}
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void SVGStyleElement::ContentAppended(nsIContent* aFirstNewContent) {
|
|
|
|
ContentChanged(aFirstNewContent->GetParent());
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void SVGStyleElement::ContentInserted(nsIContent* aChild) {
|
2013-01-05 05:50:21 +04:00
|
|
|
ContentChanged(aChild);
|
|
|
|
}
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void SVGStyleElement::ContentRemoved(nsIContent* aChild,
|
2013-01-05 05:50:21 +04:00
|
|
|
nsIContent* aPreviousSibling) {
|
|
|
|
ContentChanged(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVGStyleElement::ContentChanged(nsIContent* aContent) {
|
|
|
|
if (nsContentUtils::IsInSameAnonymousTree(this, aContent)) {
|
2018-04-24 13:50:35 +03:00
|
|
|
Unused << UpdateStyleSheetInternal(nullptr, nullptr);
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2013-02-03 00:23:19 +04:00
|
|
|
void SVGStyleElement::GetXmlspace(nsAString& aXmlspace) {
|
2013-01-05 05:50:21 +04:00
|
|
|
GetAttr(kNameSpaceID_XML, nsGkAtoms::space, aXmlspace);
|
|
|
|
}
|
2013-02-03 00:23:19 +04:00
|
|
|
|
2013-01-05 05:50:21 +04:00
|
|
|
void SVGStyleElement::SetXmlspace(const nsAString& aXmlspace, ErrorResult& rv) {
|
|
|
|
rv = SetAttr(kNameSpaceID_XML, nsGkAtoms::space, aXmlspace, true);
|
|
|
|
}
|
|
|
|
|
2013-02-03 00:23:19 +04:00
|
|
|
void SVGStyleElement::GetMedia(nsAString& aMedia) {
|
2018-04-04 06:58:49 +03:00
|
|
|
GetAttr(nsGkAtoms::media, aMedia);
|
2013-02-03 00:23:19 +04:00
|
|
|
}
|
|
|
|
|
2013-01-09 03:25:48 +04:00
|
|
|
void SVGStyleElement::SetMedia(const nsAString& aMedia, ErrorResult& rv) {
|
2018-04-04 06:58:49 +03:00
|
|
|
SetAttr(nsGkAtoms::media, aMedia, rv);
|
2013-01-08 12:36:21 +04:00
|
|
|
}
|
|
|
|
|
2013-02-03 00:23:19 +04:00
|
|
|
void SVGStyleElement::GetType(nsAString& aType) {
|
2018-04-04 06:58:49 +03:00
|
|
|
GetAttr(nsGkAtoms::type, aType);
|
2013-02-03 00:23:19 +04:00
|
|
|
}
|
|
|
|
|
2013-01-09 03:25:48 +04:00
|
|
|
void SVGStyleElement::SetType(const nsAString& aType, ErrorResult& rv) {
|
2018-04-04 06:58:49 +03:00
|
|
|
SetAttr(nsGkAtoms::type, aType, rv);
|
2013-01-08 12:36:21 +04:00
|
|
|
}
|
|
|
|
|
2013-02-03 00:23:19 +04:00
|
|
|
void SVGStyleElement::GetTitle(nsAString& aTitle) {
|
2018-04-04 06:58:49 +03:00
|
|
|
GetAttr(nsGkAtoms::title, aTitle);
|
2013-02-03 00:23:19 +04:00
|
|
|
}
|
|
|
|
|
2013-01-09 03:25:48 +04:00
|
|
|
void SVGStyleElement::SetTitle(const nsAString& aTitle, ErrorResult& rv) {
|
2018-04-04 06:58:49 +03:00
|
|
|
SetAttr(nsGkAtoms::title, aTitle, rv);
|
2013-01-08 12:36:21 +04:00
|
|
|
}
|
2013-01-05 05:50:21 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsStyleLinkElement methods
|
|
|
|
|
2018-05-06 14:20:03 +03:00
|
|
|
Maybe<nsStyleLinkElement::SheetInfo> SVGStyleElement::GetStyleSheetInfo() {
|
2018-05-08 07:51:34 +03:00
|
|
|
if (!IsCSSMimeTypeAttribute(*this)) {
|
2018-05-06 14:20:03 +03:00
|
|
|
return Nothing();
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
|
2018-05-08 07:51:34 +03:00
|
|
|
nsAutoString title;
|
|
|
|
nsAutoString media;
|
|
|
|
GetTitleAndMediaForElement(*this, title, media);
|
|
|
|
|
2018-05-08 07:11:56 +03:00
|
|
|
return Some(SheetInfo{
|
2018-05-06 14:20:03 +03:00
|
|
|
*OwnerDoc(),
|
|
|
|
this,
|
|
|
|
nullptr,
|
2018-05-08 07:51:34 +03:00
|
|
|
// FIXME(bug 1459822): Why doesn't this need a principal, but
|
|
|
|
// HTMLStyleElement does?
|
2018-05-06 14:20:03 +03:00
|
|
|
nullptr,
|
|
|
|
net::ReferrerPolicy::RP_Unset,
|
2018-05-08 07:51:34 +03:00
|
|
|
// FIXME(bug 1459822): Why does this need a crossorigin attribute, but
|
|
|
|
// HTMLStyleElement doesn't?
|
2018-05-06 14:20:03 +03:00
|
|
|
AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin)),
|
|
|
|
title,
|
|
|
|
media,
|
2018-05-06 16:06:52 +03:00
|
|
|
HasAlternateRel::No,
|
2018-05-06 14:20:03 +03:00
|
|
|
IsInline::Yes,
|
2019-04-19 16:31:05 +03:00
|
|
|
IsExplicitlyEnabled::No,
|
2018-05-06 14:20:03 +03:00
|
|
|
});
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|