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)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLStyleElement::~HTMLStyleElement() {}
|
|
|
|
|
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)
|
|
|
|
tmp->nsStyleLinkElement::Traverse(cb);
|
|
|
|
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)
|
|
|
|
tmp->nsStyleLinkElement::Unlink();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2017-09-01 02:29:22 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLStyleElement,
|
|
|
|
nsGenericHTMLElement,
|
|
|
|
nsIStyleSheetLinkingElement,
|
|
|
|
nsIMutationObserver)
|
2013-02-03 21:42:39 +04:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLStyleElement)
|
|
|
|
|
2013-02-03 21:42:40 +04:00
|
|
|
bool HTMLStyleElement::Disabled() {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult HTMLStyleElement::BindToTree(Document* aDocument, nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent) {
|
2013-02-03 21:42:39 +04:00
|
|
|
nsresult rv =
|
|
|
|
nsGenericHTMLElement::BindToTree(aDocument, aParent, aBindingParent);
|
|
|
|
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
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
return rv;
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLStyleElement::UnbindFromTree(bool aDeep, bool aNullParent) {
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> oldDoc = GetUncomposedDoc();
|
2013-12-02 14:26:12 +04:00
|
|
|
ShadowRoot* oldShadow = GetContainingShadow();
|
2014-09-27 02:07:40 +04:00
|
|
|
|
2013-02-03 21:42:39 +04:00
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
2014-09-27 02:07:40 +04:00
|
|
|
|
2015-02-09 21:01:23 +03:00
|
|
|
if (oldShadow && GetContainingShadow()) {
|
|
|
|
// The style is in a shadow tree and is still in the
|
|
|
|
// shadow tree. Thus the sheets in the shadow DOM
|
|
|
|
// do not need to be updated.
|
2014-09-27 02:07:40 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-05-06 14:20:03 +03:00
|
|
|
Maybe<nsStyleLinkElement::SheetInfo> HTMLStyleElement::GetStyleSheetInfo() {
|
2018-05-08 07:51:34 +03:00
|
|
|
if (!IsCSSMimeTypeAttribute(*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-06 14:20:03 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;
|
2018-05-08 07:11:56 +03:00
|
|
|
return Some(SheetInfo{
|
2018-05-06 14:20:03 +03:00
|
|
|
*OwnerDoc(),
|
|
|
|
this,
|
|
|
|
nullptr,
|
|
|
|
prin.forget(),
|
|
|
|
net::ReferrerPolicy::RP_Unset,
|
|
|
|
CORS_NONE,
|
|
|
|
title,
|
|
|
|
media,
|
2018-05-06 16:06:52 +03:00
|
|
|
HasAlternateRel::No,
|
2018-05-06 14:20:03 +03:00
|
|
|
IsInline::Yes,
|
|
|
|
});
|
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
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:39 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|