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-03 21:42:39 +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/HTMLStyleElement.h"
|
2013-02-03 21:42:40 +04:00
|
|
|
#include "mozilla/dom/HTMLStyleElementBinding.h"
|
2013-02-03 21:42:39 +04:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsStyleConsts.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2013-02-03 21:42:39 +04:00
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsStubMutationObserver.h"
|
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Style)
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom {
|
2013-02-03 21:42:39 +04:00
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
HTMLStyleElement::HTMLStyleElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: nsGenericHTMLElement(std::move(aNodeInfo)) {
|
2013-02-03 21:42:39 +04:00
|
|
|
AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
2020-02-20 19:19:15 +03:00
|
|
|
HTMLStyleElement::~HTMLStyleElement() = default;
|
2013-02-03 21:42:39 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLStyleElement)
|
|
|
|
|
2013-02-03 21:42:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLStyleElement,
|
|
|
|
nsGenericHTMLElement)
|
2020-05-21 06:07:16 +03:00
|
|
|
tmp->LinkStyle::Traverse(cb);
|
2013-02-03 21:42:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2013-02-03 21:42:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLStyleElement,
|
|
|
|
nsGenericHTMLElement)
|
2020-05-21 06:07:16 +03:00
|
|
|
tmp->LinkStyle::Unlink();
|
2013-02-03 21:42:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2017-09-01 02:29:22 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLStyleElement,
|
|
|
|
nsGenericHTMLElement,
|
|
|
|
nsIMutationObserver)
|
2013-02-03 21:42:39 +04:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLStyleElement)
|
|
|
|
|
2019-04-19 16:31:05 +03:00
|
|
|
bool HTMLStyleElement::Disabled() const {
|
2016-10-14 14:25:38 +03:00
|
|
|
StyleSheet* ss = GetSheet();
|
2013-03-17 18:42:59 +04:00
|
|
|
return ss && ss->Disabled();
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-17 18:42:59 +04:00
|
|
|
void HTMLStyleElement::SetDisabled(bool aDisabled) {
|
2016-10-14 14:25:38 +03:00
|
|
|
if (StyleSheet* ss = GetSheet()) {
|
2013-03-17 18:42:59 +04:00
|
|
|
ss->SetDisabled(aDisabled);
|
2013-02-03 21:42:40 +04:00
|
|
|
}
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void HTMLStyleElement::CharacterDataChanged(nsIContent* aContent,
|
2018-02-27 17:30:27 +03:00
|
|
|
const CharacterDataChangeInfo&) {
|
2013-02-03 21:42:39 +04:00
|
|
|
ContentChanged(aContent);
|
|
|
|
}
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void HTMLStyleElement::ContentAppended(nsIContent* aFirstNewContent) {
|
|
|
|
ContentChanged(aFirstNewContent->GetParent());
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void HTMLStyleElement::ContentInserted(nsIContent* aChild) {
|
2013-02-03 21:42:39 +04:00
|
|
|
ContentChanged(aChild);
|
|
|
|
}
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void HTMLStyleElement::ContentRemoved(nsIContent* aChild,
|
2013-02-03 21:42:39 +04:00
|
|
|
nsIContent* aPreviousSibling) {
|
|
|
|
ContentChanged(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLStyleElement::ContentChanged(nsIContent* aContent) {
|
2017-11-08 01:25:45 +03:00
|
|
|
mTriggeringPrincipal = nullptr;
|
2013-02-03 21:42:39 +04:00
|
|
|
if (nsContentUtils::IsInSameAnonymousTree(this, aContent)) {
|
2018-04-24 13:50:35 +03:00
|
|
|
Unused << UpdateStyleSheetInternal(nullptr, nullptr);
|
2013-02-03 21:42:39 +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 HTMLStyleElement::BindToTree(BindContext& aContext, nsINode& aParent) {
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aContext, aParent);
|
2013-02-03 21:42:39 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
void (HTMLStyleElement::*update)() =
|
|
|
|
&HTMLStyleElement::UpdateStyleSheetInternal;
|
2017-06-12 22:34:10 +03:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
NewRunnableMethod("dom::HTMLStyleElement::BindToTree", this, update));
|
2013-02-03 21:42:39 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-05-29 01:47:08 +03:00
|
|
|
void HTMLStyleElement::UnbindFromTree(bool aNullParent) {
|
2021-01-18 14:09:55 +03:00
|
|
|
RefPtr<Document> oldDoc = GetUncomposedDoc();
|
2013-12-02 14:26:12 +04:00
|
|
|
ShadowRoot* oldShadow = GetContainingShadow();
|
2014-09-27 02:07:40 +04:00
|
|
|
|
2019-05-29 01:47:08 +03:00
|
|
|
nsGenericHTMLElement::UnbindFromTree(aNullParent);
|
2014-09-27 02:07:40 +04:00
|
|
|
|
2018-04-24 13:50:35 +03:00
|
|
|
Unused << UpdateStyleSheetInternal(oldDoc, oldShadow);
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult HTMLStyleElement::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) {
|
2015-09-23 04:19:49 +03:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
2013-02-03 21:42:39 +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-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-23 04:19:49 +03:00
|
|
|
return nsGenericHTMLElement::AfterSetAttr(
|
2017-10-10 00:33:38 +03:00
|
|
|
aNameSpaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
2018-03-26 23:41:43 +03:00
|
|
|
void HTMLStyleElement::GetInnerHTML(nsAString& aInnerHTML,
|
|
|
|
OOMReporter& aError) {
|
2015-05-22 21:16:20 +03:00
|
|
|
if (!nsContentUtils::GetNodeTextContent(this, false, aInnerHTML, fallible)) {
|
2018-03-26 23:41:43 +03:00
|
|
|
aError.ReportOOM();
|
2014-03-19 21:05:03 +04:00
|
|
|
}
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLStyleElement::SetInnerHTML(const nsAString& aInnerHTML,
|
2017-12-21 01:43:18 +03:00
|
|
|
nsIPrincipal* aScriptedPrincipal,
|
2013-02-03 21:42:39 +04:00
|
|
|
ErrorResult& aError) {
|
2017-12-21 01:43:18 +03:00
|
|
|
SetTextContentInternal(aInnerHTML, aScriptedPrincipal, aError);
|
2017-11-08 01:25:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLStyleElement::SetTextContentInternal(const nsAString& aTextContent,
|
|
|
|
nsIPrincipal* aScriptedPrincipal,
|
|
|
|
ErrorResult& aError) {
|
2018-04-10 21:06:26 +03:00
|
|
|
// Per spec, if we're setting text content to an empty string and don't
|
|
|
|
// already have any children, we should not trigger any mutation observers, or
|
|
|
|
// re-parse the stylesheet.
|
|
|
|
if (aTextContent.IsEmpty() && !GetFirstChild()) {
|
|
|
|
nsIPrincipal* principal =
|
|
|
|
mTriggeringPrincipal ? mTriggeringPrincipal.get() : NodePrincipal();
|
|
|
|
if (principal == aScriptedPrincipal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:39 +04:00
|
|
|
SetEnableUpdates(false);
|
|
|
|
|
2017-11-08 01:25:45 +03:00
|
|
|
aError = nsContentUtils::SetNodeTextContent(this, aTextContent, true);
|
2013-02-03 21:42:39 +04:00
|
|
|
|
|
|
|
SetEnableUpdates(true);
|
|
|
|
|
2017-11-08 01:25:45 +03:00
|
|
|
mTriggeringPrincipal = aScriptedPrincipal;
|
|
|
|
|
2018-04-24 13:50:35 +03:00
|
|
|
Unused << UpdateStyleSheetInternal(nullptr, nullptr);
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
2020-07-28 18:45:35 +03:00
|
|
|
void HTMLStyleElement::SetDevtoolsAsTriggeringPrincipal() {
|
|
|
|
mTriggeringPrincipal = CreateDevtoolsPrincipal();
|
|
|
|
}
|
|
|
|
|
2020-05-21 06:07:16 +03:00
|
|
|
Maybe<LinkStyle::SheetInfo> HTMLStyleElement::GetStyleSheetInfo() {
|
2020-02-11 22:38:26 +03:00
|
|
|
if (!IsCSSMimeTypeAttributeForStyleElement(*this)) {
|
2018-05-06 14:20:03 +03:00
|
|
|
return Nothing();
|
2013-02-03 21:42:39 +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,
|
2020-01-13 14:47:25 +03:00
|
|
|
do_AddRef(mTriggeringPrincipal),
|
2020-05-04 21:50:20 +03:00
|
|
|
MakeAndAddRef<ReferrerInfo>(*this),
|
2018-05-06 14:20:03 +03:00
|
|
|
CORS_NONE,
|
|
|
|
title,
|
|
|
|
media,
|
2020-09-23 18:17:15 +03:00
|
|
|
/* integrity = */ u""_ns,
|
2020-01-13 14:47:25 +03:00
|
|
|
/* nsStyleUtil::CSPAllowsInlineStyle takes care of nonce checking for
|
|
|
|
inline styles. Bug 1607011 */
|
2020-09-23 18:17:15 +03:00
|
|
|
/* nonce = */ u""_ns,
|
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-02-03 21:42:39 +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
|
|
|
JSObject* HTMLStyleElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return HTMLStyleElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-03 21:42:40 +04:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom
|