mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 13:23:07 +00:00
10160cd03d
- Bug 1240749 - Fixes for DPI support in Gtk widget interface: remove incorrect Get[Avail]RectDisplayPix overrides, as desktop pixels == device pixels for the Gtk widget backend, and implement nsScreenGtk::GetDefaultCSSScaleFactor, required by nsGlobalWindow since per-monitor DPI patches in bug 890156. r=karlt (9975cac985)
- Bug 1033488 - Part 2. Make PuppetBidiKeyboard correctly on content process. r=masayuki (3a91ce60a8)
- Bug 1257067 - modified XF86XK_ keysyms to GDK_ ones r=masayuki (4b922f9365)
- Bug 1251984 - allow gfx.xrender.enabled pref to work for compositing even if content backend is not Cairo. r=jrmuizel (257a163074)
- Bug 1235941 - Detect DPI change for GTK3. r=karlt (f8ca209d4b)
- Bug 1256728: Add environment variable to disable force present from bug 1232042. r=BenWa (c3b12a085b)
- Bug 1257124: Add null check for IDWriteFactory in gfxDWriteFontFileLoader::CreateCustomFontFile. r=bas (d33af4b9e1)
- Bug 1266209 - log failure reason when PathBuilderD2D::Finish fails. r=bas.schouten (360d7c2ada)
- Bug 1256552 - Disable C4577 to unblock compilation on VS2015; r=jrmuizel (7375fbf42a)
- Bug 1265960 - Remove gfxReusable* r=Bas (ed0b3aca14)
- Bug 1246290 - Refactoring to get rid of SampleContentTransformForFrame from AsyncPanZoomController. r=botond (3be6b4c1f9)
- Bug 1246290 - Add the ability for APZCs to not expose async transforms. r=botond (48942ceddf)
- Bug 1259296 - Scroll snap in the compositor in response to wheel events. r=kats (5fc694c804)
- Bug 1249040 - Allow wheel scrolls to accumulate in the presence of scroll snapping. r=kats (7514e3f6d6)
- Bug 1237343 - Replace uses of mozilla::Vector with nsTArray. r=botond (b721de19cd)
- Bug 1236046 - Don't use a stupidly small time delta to compute a velocity. r=botond (6c8f298ab6)
- Bug 1257959 - Dynamic toolbar transition seems to slow down flings r=kats (47ec4d0d54)
- Bug 1265513 - Do a fuzzy match when checking to see if a scroll will result in overscroll. r=botond (03ee304916)
- Bug 1254252 - Have Axis::ClampOriginToScrollableRect just return the original value if it falls with in the page bounds. r=kats (f88c0b4d7d)
- Bug 1261373 - Record how long it takes for content response notifications to be delivered to APZ. r=botond f=bsmedberg (b4b24d7602)
- Bug 1265515 - Update nsAutoPtr.h includes in gfx/layers/apz to RefPtr.h. r=kats (48bbc2cda8)
- Bug 1259296 - Make sure APZ smooth scroll animations end at their exact destination scroll offset. r=kats (36cace259b)
- Bug 1251837, part 1 - Use pushPrefEnv in setDeltaMultiplierSettings in window_wheel_default_action.html. r=masayuki (d673d55f02)
- Bug 1251837, part 2 - Use pushPrefEnv in doTestActionOverride in window_wheel_default_action.html. r=masayuki (f0375a3820)
- Bug 1251837, part 3 - Use pushPrefEnv in doTestWholeScroll in window_wheel_default_action.html. r=masayuki (0a7af4e103)
- Bug 1251837, part 4 - Use pushPrefEnv in doTestActionOverride in window_wheel_default_action.html. r=masayuki (51bd9cd1e2)
- Bug 1251837, part 5 - Make prepare() in doTestScroll take a callback, and use pushPrefEnv. r=masayuki (856056a947)
- Bug 1251837, part 6 - Make cleanup() in doTestScroll take a callback, and use pushPrefEnv. r=masayuki (34aa62b7f3)
- Bug 1255173 - Fix onZoomReset() in test_wheel_default_action.html to work with e10s. r=masayuki, r=jmaher (0c248c7587)
- Bug 1255178 - Part 1: Remove a leftover use of clearUserPref. r=masayuki Also, remove some trailing whitespace. (c067affdba)
- Bug 1255178 - Part 2: Remove extraneous argument to sendWheelAndWait. r=masayuki (80ce47c89b)
- Bug 1255634 - APZ should scroll by more than a page with large values of mousewheel.default.delta_multiplier_{x,y}. r=masayuki,kats (d72f77daed)
- Bug 1251638 - Don't clamp the displayport to the scrollable rect on the compositor side. r=botond (5dae2ba82e)
- Bug 1251638 - Do a bit of cleanup on the displayport margin computation in APZC; no functional changes. r=botond (575453b538)
- Bug 1266154 - Don't start a scroll snap animation if we're already at the destination. r=kats (2926d33a07)
- Bug 1258851 - Update HitTestingTreeNode::IsScrollbarNode to include the scrollbar track layers. r=rbarker (1e68081a6a)
- Bug 1265806 - Update scrollbar finding code to deal with layer trees on both OS X and Windows properly. r=rbarker (e8df49352e)
- Bug 1255224 - Add pref to force glFinish in DXGL path. (default:false) - r=dvander (8d399f8a49)
- Bug 1224199 - Destroy SharedSurfaces before ~GLContext(). - r=jrmuizel (5ad8d11f8e)
- Bug 1232480. Use 'precision' instead of 'prevision' (c7310988fa)
- Bug 1232668. Allow using kTex2DBlit_FragShaderSource on non-ES targets. (1951af5c1c)
- Bug 1235299 - Fix WebGL assertions for copyTexImage2D. r=jgilbert (226b7c14a8)
- Bug 1249189 - Use GL_RED to replace GL_ALPHA in YCbCr convert. r=jgilbert (e1d8ae2513)
- Bug 1256552 - fix int-to-float conversions in RadialGradientEffectD2D1. r=jrmuizel (36bb7f7f0f)
- Bug 1249279 - Let subdocuments' presContexts inherit the DPI setting of their parent, instead of retrieving it from their widget, to avoid using stale values from a currently-hidden widget on a screen with a different DPI. r=bz (4b8f6e0960)
- Bug 1237479 -- nsScriptSecurityManager needs to use the correct user context id in the origin attributes in a few places. r=sicking (90504a4130)
- Bug 1105556 - Call Create(originAttributes) when loadinfo->loadingPrincipal is null, instead of CreatePrincipalWithInheritedAttributes(). r=sicking (fdb341ca53)
- Bug 1253788 - Don't reload inline chrome:// style sheets in nsXBLPrototypeResources. r=bzbarsky (862464ea6c)
- Bug 1261123 - don't needlessly construct nsAutoCString temporaries in nsDefaultURIFixup; r=smaug (08f13674a8)
- Bug 1253673, r=bz (03caab3cce)
- Bug 1259511 - Overwrite loadInfo within AboutProtocolHandler and log warning to console. r=sicking (e2fc868326)
- Bug 905460 - Convert http legacy refs to smart pointers r=dragana a=kwierso (d4bdd102fa)
- Bug 1248564 - "Default authentication credentials (NTLM, Kerb) used in private mode". r=mayhemer (37c5674a0d)
- Bug 345580 - Problem decoding quoted-printable question mark in subject r=biesi (00f66a34a7)
- Bug 906986 - Rework fix for Bug 1241690 to avoid reliance on NrIceCtx inside NrIceMediaStream. r=bwc, r=drno (3d6aabeab6)
- Bug 906986 - Disable TestSrflxCandPairingFilter until bug 1226838 is fixed. r=bwc, r=drno (687281bf8b)
- Bug 906986 - Use the streams from the ice_ctx, don't hold a separate set. r=bwc, r=drno (269cd38ed2)
- Bug 906986 - Genericize some of the test setup and improve logging. r=bwc, r=drno (ad735f2459)
- Bug 906986 - Wrap NrIceCtx in NrIceCtxHandler which will allow us to handle ice restart. r=bwc, r=drno (4f2c1e5866)
- Bug 911216 - Part 12: Windows build bustage fix on a CLOSED TREE. r=efaust (f81e40df57)
- Bug 1261329 - Fix OOM handling in shell dissrc function r=efaust (d61eb121de)
- Bug 1263868 - Properly recover from OOM in ShellAutoEntryMonitor. r=jonco (3830ce7aae)
- Bug 1257722 - Prevent stdout/stderr from getting closed, r=jorendorff (48629efc06)
- Bug 1258847 - Set PTHREAD_MUTEX_ERRORCHECK for js::Mutex in debug builds. r=sfink (48cb353190)
- Bug 1252464 - Remove FrameRange cray cray in favor of using GCVectors. (r=jimb) (60ad943599)
- Bug 1257194: Tracelogger - Check for oom in drainTracelogger, r=bbouvier (7d8299958f)
- Bug 1264961 - Fix OOM case in Debugger::replaceFrameGuts. (r=jimb) (203816a8b3)
- Bug 1257588 - Don't ignore self-hosted frames when getting a saved frame's async cause. r=fitzgen (15b467a950)
- Bug 1258535 - Part 0: Add more and stronger asserts that SavedStacks-related JSAPI methods are called correctly; r=jandem (187251c401)
- Bug 1258535 - Check for the existence of a global before checking if its standard classes are resolved; r=jandem (18f7bbcc69)
- Bug 1264975 - Fix assertion in DebugScope wrapping non-syntactic scopes. (r=jimb) (753e315ddb)
- Bug 1259403 - Tracelogger: Always make sure there are 3 free slots for events, r=bbouvier (67a13b7a14)
- Bug 1231926 - add assertions on BYTEOFFSET_SLOT. r=waldo (3508ea1943)
- Bug 1260725 - Handle and report OOM in census breakdown parsing; r=jorendorff a=kwierso (de669940d1)
- Bug 1263074 - Change the JavaScript syntax error message for the old octal literal notation to suggest the new notation. r=Waldo (4e2457b27a)
- Bug 1257096, don't try to report about unusual unhandled rejected Promises, r=bz,waldo (682e4720d9)
- Bug 1262402: Use the new int64 testing features; r=luke (d213bb4f2c)
- Bug 1263882: Set a default value in DescribeScriptedCaller if the filename is null; r=luke (f66ec211f5)
522 lines
15 KiB
C++
522 lines
15 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
/*
|
|
* A base class which implements nsIStyleSheetLinkingElement and can
|
|
* be subclassed by various content nodes that want to load
|
|
* stylesheets (<style>, <link>, processing instructions, etc).
|
|
*/
|
|
|
|
#include "nsStyleLinkElement.h"
|
|
|
|
#include "mozilla/StyleSheetHandle.h"
|
|
#include "mozilla/StyleSheetHandleInlines.h"
|
|
#include "mozilla/css/Loader.h"
|
|
#include "mozilla/dom/Element.h"
|
|
#include "mozilla/dom/FragmentOrElement.h"
|
|
#include "mozilla/dom/ShadowRoot.h"
|
|
#include "mozilla/Preferences.h"
|
|
#include "nsIContent.h"
|
|
#include "nsIDocument.h"
|
|
#include "nsIDOMComment.h"
|
|
#include "nsIDOMNode.h"
|
|
#include "nsIDOMStyleSheet.h"
|
|
#include "nsUnicharUtils.h"
|
|
#include "nsCRT.h"
|
|
#include "nsXPCOMCIDInternal.h"
|
|
#include "nsUnicharInputStream.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsStyleUtil.h"
|
|
#include "nsQueryObject.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom;
|
|
|
|
static LogModule*
|
|
GetSriLog()
|
|
{
|
|
static LazyLogModule gSriPRLog("SRI");
|
|
return gSriPRLog;
|
|
}
|
|
|
|
nsStyleLinkElement::nsStyleLinkElement()
|
|
: mDontLoadStyle(false)
|
|
, mUpdatesEnabled(true)
|
|
, mLineNumber(1)
|
|
{
|
|
}
|
|
|
|
nsStyleLinkElement::~nsStyleLinkElement()
|
|
{
|
|
nsStyleLinkElement::SetStyleSheet(nullptr);
|
|
}
|
|
|
|
void
|
|
nsStyleLinkElement::Unlink()
|
|
{
|
|
nsStyleLinkElement::SetStyleSheet(nullptr);
|
|
}
|
|
|
|
void
|
|
nsStyleLinkElement::Traverse(nsCycleCollectionTraversalCallback &cb)
|
|
{
|
|
nsStyleLinkElement* tmp = this;
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStyleSheet);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsStyleLinkElement::SetStyleSheet(StyleSheetHandle aStyleSheet)
|
|
{
|
|
if (mStyleSheet) {
|
|
mStyleSheet->SetOwningNode(nullptr);
|
|
}
|
|
|
|
mStyleSheet = aStyleSheet;
|
|
if (mStyleSheet) {
|
|
nsCOMPtr<nsINode> node = do_QueryObject(this);
|
|
if (node) {
|
|
mStyleSheet->SetOwningNode(node);
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP_(StyleSheetHandle)
|
|
nsStyleLinkElement::GetStyleSheet()
|
|
{
|
|
return mStyleSheet;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsStyleLinkElement::InitStyleLinkElement(bool aDontLoadStyle)
|
|
{
|
|
mDontLoadStyle = aDontLoadStyle;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsStyleLinkElement::SetEnableUpdates(bool aEnableUpdates)
|
|
{
|
|
mUpdatesEnabled = aEnableUpdates;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsStyleLinkElement::GetCharset(nsAString& aCharset)
|
|
{
|
|
// descendants have to implement this themselves
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
}
|
|
|
|
/* virtual */ void
|
|
nsStyleLinkElement::OverrideBaseURI(nsIURI* aNewBaseURI)
|
|
{
|
|
NS_NOTREACHED("Base URI can't be overriden in this implementation "
|
|
"of nsIStyleSheetLinkingElement.");
|
|
}
|
|
|
|
/* virtual */ void
|
|
nsStyleLinkElement::SetLineNumber(uint32_t aLineNumber)
|
|
{
|
|
mLineNumber = aLineNumber;
|
|
}
|
|
|
|
/* virtual */ uint32_t
|
|
nsStyleLinkElement::GetLineNumber()
|
|
{
|
|
return mLineNumber;
|
|
}
|
|
|
|
/* static */ bool
|
|
nsStyleLinkElement::IsImportEnabled()
|
|
{
|
|
static bool sAdded = false;
|
|
static bool sImportsEnabled;
|
|
if (!sAdded) {
|
|
// This part runs only once because of the static flag.
|
|
Preferences::AddBoolVarCache(&sImportsEnabled,
|
|
"dom.htmlimports.enabled",
|
|
false);
|
|
sAdded = true;
|
|
}
|
|
|
|
return sImportsEnabled;
|
|
}
|
|
|
|
static uint32_t ToLinkMask(const nsAString& aLink, nsIPrincipal* aPrincipal)
|
|
{
|
|
if (aLink.EqualsLiteral("prefetch"))
|
|
return nsStyleLinkElement::ePREFETCH;
|
|
else if (aLink.EqualsLiteral("dns-prefetch"))
|
|
return nsStyleLinkElement::eDNS_PREFETCH;
|
|
else if (aLink.EqualsLiteral("stylesheet"))
|
|
return nsStyleLinkElement::eSTYLESHEET;
|
|
else if (aLink.EqualsLiteral("next"))
|
|
return nsStyleLinkElement::eNEXT;
|
|
else if (aLink.EqualsLiteral("alternate"))
|
|
return nsStyleLinkElement::eALTERNATE;
|
|
else if (aLink.EqualsLiteral("import") &&
|
|
nsStyleLinkElement::IsImportEnabled())
|
|
return nsStyleLinkElement::eHTMLIMPORT;
|
|
else if (aLink.EqualsLiteral("preconnect"))
|
|
return nsStyleLinkElement::ePRECONNECT;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
uint32_t nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes, nsIPrincipal* aPrincipal)
|
|
{
|
|
uint32_t linkMask = 0;
|
|
nsAString::const_iterator start, done;
|
|
aTypes.BeginReading(start);
|
|
aTypes.EndReading(done);
|
|
if (start == done)
|
|
return linkMask;
|
|
|
|
nsAString::const_iterator current(start);
|
|
bool inString = !nsContentUtils::IsHTMLWhitespace(*current);
|
|
nsAutoString subString;
|
|
|
|
while (current != done) {
|
|
if (nsContentUtils::IsHTMLWhitespace(*current)) {
|
|
if (inString) {
|
|
nsContentUtils::ASCIIToLower(Substring(start, current), subString);
|
|
linkMask |= ToLinkMask(subString, aPrincipal);
|
|
inString = false;
|
|
}
|
|
}
|
|
else {
|
|
if (!inString) {
|
|
start = current;
|
|
inString = true;
|
|
}
|
|
}
|
|
++current;
|
|
}
|
|
if (inString) {
|
|
nsContentUtils::ASCIIToLower(Substring(start, current), subString);
|
|
linkMask |= ToLinkMask(subString, aPrincipal);
|
|
}
|
|
return linkMask;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsStyleLinkElement::UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
|
|
bool* aWillNotify,
|
|
bool* aIsAlternate,
|
|
bool aForceReload)
|
|
{
|
|
if (aForceReload) {
|
|
// We remove this stylesheet from the cache to load a new version.
|
|
nsCOMPtr<nsIContent> thisContent;
|
|
CallQueryInterface(this, getter_AddRefs(thisContent));
|
|
nsCOMPtr<nsIDocument> doc = thisContent->IsInShadowTree() ?
|
|
thisContent->OwnerDoc() : thisContent->GetUncomposedDoc();
|
|
if (doc && doc->CSSLoader()->GetEnabled() &&
|
|
mStyleSheet && !mStyleSheet->IsInline()) {
|
|
doc->CSSLoader()->ObsoleteSheet(mStyleSheet->GetOriginalURI());
|
|
}
|
|
}
|
|
return DoUpdateStyleSheet(nullptr, nullptr, aObserver, aWillNotify,
|
|
aIsAlternate, aForceReload);
|
|
}
|
|
|
|
nsresult
|
|
nsStyleLinkElement::UpdateStyleSheetInternal(nsIDocument *aOldDocument,
|
|
ShadowRoot *aOldShadowRoot,
|
|
bool aForceUpdate)
|
|
{
|
|
bool notify, alternate;
|
|
return DoUpdateStyleSheet(aOldDocument, aOldShadowRoot, nullptr, ¬ify,
|
|
&alternate, aForceUpdate);
|
|
}
|
|
|
|
static bool
|
|
IsScopedStyleElement(nsIContent* aContent)
|
|
{
|
|
// This is quicker than, say, QIing aContent to nsStyleLinkElement
|
|
// and then calling its virtual GetStyleSheetInfo method to find out
|
|
// if it is scoped.
|
|
return (aContent->IsHTMLElement(nsGkAtoms::style) ||
|
|
aContent->IsSVGElement(nsGkAtoms::style)) &&
|
|
aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::scoped);
|
|
}
|
|
|
|
static bool
|
|
HasScopedStyleSheetChild(nsIContent* aContent)
|
|
{
|
|
for (nsIContent* n = aContent->GetFirstChild(); n; n = n->GetNextSibling()) {
|
|
if (IsScopedStyleElement(n)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Called when aElement has had a <style scoped> child removed.
|
|
static void
|
|
UpdateIsElementInStyleScopeFlagOnSubtree(Element* aElement)
|
|
{
|
|
NS_ASSERTION(aElement->IsElementInStyleScope(),
|
|
"only call UpdateIsElementInStyleScopeFlagOnSubtree on a "
|
|
"subtree that has IsElementInStyleScope boolean flag set");
|
|
|
|
if (HasScopedStyleSheetChild(aElement)) {
|
|
return;
|
|
}
|
|
|
|
aElement->ClearIsElementInStyleScope();
|
|
|
|
nsIContent* n = aElement->GetNextNode(aElement);
|
|
while (n) {
|
|
if (HasScopedStyleSheetChild(n)) {
|
|
n = n->GetNextNonChildNode(aElement);
|
|
} else {
|
|
if (n->IsElement()) {
|
|
n->ClearIsElementInStyleScope();
|
|
}
|
|
n = n->GetNextNode(aElement);
|
|
}
|
|
}
|
|
}
|
|
|
|
nsresult
|
|
nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
|
ShadowRoot* aOldShadowRoot,
|
|
nsICSSLoaderObserver* aObserver,
|
|
bool* aWillNotify,
|
|
bool* aIsAlternate,
|
|
bool aForceUpdate)
|
|
{
|
|
*aWillNotify = false;
|
|
|
|
nsCOMPtr<nsIContent> thisContent;
|
|
CallQueryInterface(this, getter_AddRefs(thisContent));
|
|
|
|
// All instances of nsStyleLinkElement should implement nsIContent.
|
|
NS_ENSURE_TRUE(thisContent, NS_ERROR_FAILURE);
|
|
|
|
if (thisContent->IsInAnonymousSubtree() &&
|
|
thisContent->IsAnonymousContentInSVGUseSubtree()) {
|
|
// Stylesheets in <use>-cloned subtrees are disabled until we figure out
|
|
// how they should behave.
|
|
return NS_OK;
|
|
}
|
|
|
|
// Check for a ShadowRoot because link elements are inert in a
|
|
// ShadowRoot.
|
|
ShadowRoot* containingShadow = thisContent->GetContainingShadow();
|
|
if (thisContent->IsHTMLElement(nsGkAtoms::link) &&
|
|
(aOldShadowRoot || containingShadow)) {
|
|
return NS_OK;
|
|
}
|
|
|
|
// XXXheycam ServoStyleSheets do not support <style scoped>.
|
|
Element* oldScopeElement = nullptr;
|
|
if (mStyleSheet) {
|
|
if (mStyleSheet->IsServo()) {
|
|
NS_ERROR("stylo: ServoStyleSheets don't support <style scoped>");
|
|
} else {
|
|
oldScopeElement = mStyleSheet->AsGecko()->GetScopeElement();
|
|
}
|
|
}
|
|
|
|
if (mStyleSheet && (aOldDocument || aOldShadowRoot)) {
|
|
MOZ_ASSERT(!(aOldDocument && aOldShadowRoot),
|
|
"ShadowRoot content is never in document, thus "
|
|
"there should not be a old document and old "
|
|
"ShadowRoot simultaneously.");
|
|
|
|
// We're removing the link element from the document or shadow tree,
|
|
// unload the stylesheet. We want to do this even if updates are
|
|
// disabled, since otherwise a sheet with a stale linking element pointer
|
|
// will be hanging around -- not good!
|
|
if (aOldShadowRoot) {
|
|
aOldShadowRoot->RemoveSheet(mStyleSheet);
|
|
} else {
|
|
aOldDocument->BeginUpdate(UPDATE_STYLE);
|
|
aOldDocument->RemoveStyleSheet(mStyleSheet);
|
|
aOldDocument->EndUpdate(UPDATE_STYLE);
|
|
}
|
|
|
|
nsStyleLinkElement::SetStyleSheet(nullptr);
|
|
if (oldScopeElement) {
|
|
UpdateIsElementInStyleScopeFlagOnSubtree(oldScopeElement);
|
|
}
|
|
}
|
|
|
|
// When static documents are created, stylesheets are cloned manually.
|
|
if (mDontLoadStyle || !mUpdatesEnabled ||
|
|
thisContent->OwnerDoc()->IsStaticDocument()) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsCOMPtr<nsIDocument> doc = thisContent->IsInShadowTree() ?
|
|
thisContent->OwnerDoc() : thisContent->GetUncomposedDoc();
|
|
if (!doc || !doc->CSSLoader()->GetEnabled()) {
|
|
return NS_OK;
|
|
}
|
|
|
|
bool isInline;
|
|
nsCOMPtr<nsIURI> uri = GetStyleSheetURL(&isInline);
|
|
|
|
if (!aForceUpdate && mStyleSheet && !isInline && uri) {
|
|
nsIURI* oldURI = mStyleSheet->GetSheetURI();
|
|
if (oldURI) {
|
|
bool equal;
|
|
nsresult rv = oldURI->Equals(uri, &equal);
|
|
if (NS_SUCCEEDED(rv) && equal) {
|
|
return NS_OK; // We already loaded this stylesheet
|
|
}
|
|
}
|
|
}
|
|
|
|
if (mStyleSheet) {
|
|
if (thisContent->IsInShadowTree()) {
|
|
ShadowRoot* containingShadow = thisContent->GetContainingShadow();
|
|
containingShadow->RemoveSheet(mStyleSheet);
|
|
} else {
|
|
doc->BeginUpdate(UPDATE_STYLE);
|
|
doc->RemoveStyleSheet(mStyleSheet);
|
|
doc->EndUpdate(UPDATE_STYLE);
|
|
}
|
|
|
|
nsStyleLinkElement::SetStyleSheet(nullptr);
|
|
}
|
|
|
|
if (!uri && !isInline) {
|
|
return NS_OK; // If href is empty and this is not inline style then just bail
|
|
}
|
|
|
|
nsAutoString title, type, media;
|
|
bool isScoped;
|
|
bool isAlternate;
|
|
|
|
GetStyleSheetInfo(title, type, media, &isScoped, &isAlternate);
|
|
|
|
if (!type.LowerCaseEqualsLiteral("text/css")) {
|
|
return NS_OK;
|
|
}
|
|
|
|
Element* scopeElement = isScoped ? thisContent->GetParentElement() : nullptr;
|
|
if (scopeElement) {
|
|
NS_ASSERTION(isInline, "non-inline style must not have scope element");
|
|
scopeElement->SetIsElementInStyleScopeFlagOnSubtree(true);
|
|
}
|
|
|
|
bool doneLoading = false;
|
|
nsresult rv = NS_OK;
|
|
if (isInline) {
|
|
nsAutoString text;
|
|
if (!nsContentUtils::GetNodeTextContent(thisContent, false, text, fallible)) {
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
|
|
MOZ_ASSERT(thisContent->NodeInfo()->NameAtom() != nsGkAtoms::link,
|
|
"<link> is not 'inline', and needs different CSP checks");
|
|
if (!nsStyleUtil::CSPAllowsInlineStyle(thisContent,
|
|
thisContent->NodePrincipal(),
|
|
doc->GetDocumentURI(),
|
|
mLineNumber, text, &rv))
|
|
return rv;
|
|
|
|
// Parse the style sheet.
|
|
rv = doc->CSSLoader()->
|
|
LoadInlineStyle(thisContent, text, mLineNumber, title, media,
|
|
scopeElement, aObserver, &doneLoading, &isAlternate);
|
|
}
|
|
else {
|
|
nsAutoString integrity;
|
|
thisContent->GetAttr(kNameSpaceID_None, nsGkAtoms::integrity, integrity);
|
|
if (!integrity.IsEmpty()) {
|
|
MOZ_LOG(GetSriLog(), mozilla::LogLevel::Debug,
|
|
("nsStyleLinkElement::DoUpdateStyleSheet, integrity=%s",
|
|
NS_ConvertUTF16toUTF8(integrity).get()));
|
|
}
|
|
|
|
// XXXbz clone the URI here to work around content policies modifying URIs.
|
|
nsCOMPtr<nsIURI> clonedURI;
|
|
uri->Clone(getter_AddRefs(clonedURI));
|
|
NS_ENSURE_TRUE(clonedURI, NS_ERROR_OUT_OF_MEMORY);
|
|
rv = doc->CSSLoader()->
|
|
LoadStyleLink(thisContent, clonedURI, title, media, isAlternate,
|
|
GetCORSMode(), doc->GetReferrerPolicy(), integrity,
|
|
aObserver, &isAlternate);
|
|
if (NS_FAILED(rv)) {
|
|
// Don't propagate LoadStyleLink() errors further than this, since some
|
|
// consumers (e.g. nsXMLContentSink) will completely abort on innocuous
|
|
// things like a stylesheet load being blocked by the security system.
|
|
doneLoading = true;
|
|
isAlternate = false;
|
|
rv = NS_OK;
|
|
}
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
*aWillNotify = !doneLoading;
|
|
*aIsAlternate = isAlternate;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsStyleLinkElement::UpdateStyleSheetScopedness(bool aIsNowScoped)
|
|
{
|
|
if (!mStyleSheet) {
|
|
return;
|
|
}
|
|
|
|
if (mStyleSheet->IsServo()) {
|
|
// XXXheycam ServoStyleSheets don't support <style scoped>.
|
|
NS_ERROR("stylo: ServoStyleSheets don't support <style scoped>");
|
|
return;
|
|
}
|
|
|
|
CSSStyleSheet* sheet = mStyleSheet->AsGecko();
|
|
|
|
nsCOMPtr<nsIContent> thisContent;
|
|
CallQueryInterface(this, getter_AddRefs(thisContent));
|
|
|
|
Element* oldScopeElement = sheet->GetScopeElement();
|
|
Element* newScopeElement = aIsNowScoped ?
|
|
thisContent->GetParentElement() :
|
|
nullptr;
|
|
|
|
if (oldScopeElement == newScopeElement) {
|
|
return;
|
|
}
|
|
|
|
nsIDocument* document = thisContent->GetOwnerDocument();
|
|
|
|
if (thisContent->IsInShadowTree()) {
|
|
ShadowRoot* containingShadow = thisContent->GetContainingShadow();
|
|
containingShadow->RemoveSheet(mStyleSheet);
|
|
|
|
sheet->SetScopeElement(newScopeElement);
|
|
|
|
containingShadow->InsertSheet(mStyleSheet, thisContent);
|
|
} else {
|
|
document->BeginUpdate(UPDATE_STYLE);
|
|
document->RemoveStyleSheet(mStyleSheet);
|
|
|
|
sheet->SetScopeElement(newScopeElement);
|
|
|
|
document->AddStyleSheet(mStyleSheet);
|
|
document->EndUpdate(UPDATE_STYLE);
|
|
}
|
|
|
|
if (oldScopeElement) {
|
|
UpdateIsElementInStyleScopeFlagOnSubtree(oldScopeElement);
|
|
}
|
|
if (newScopeElement) {
|
|
newScopeElement->SetIsElementInStyleScopeFlagOnSubtree(true);
|
|
}
|
|
}
|