Bug 1968202 - Generalize GlobalStyleSheetCache to support author stylesheets. r=smaug
In bug 1967507 I changed the timing of AnonymousContent stylesheet loading in a way that it perturbed a css cache test because of accessiblecaret.css https://hg.mozilla.org/mozilla-central/rev/a6a294ae1d18 However that made me realize that accessiblecaret.css is loaded virtually in all processes, and it should be using the same mechanism we use for UA sheets, rather than using all the CSS loader machinery in-content. Same goes for details.css. Expand GlobalStyleSheetCache to allow UA and Author sheets, and allow ShadowRoot to get built-in stylesheets appended. This allows accessiblecaret.css and details.css not to be marked as content-accessible. We could do the same at the document level for plaintext.css and co, but that seems a bit less common, so maybe fine. Differential Revision: https://phabricator.services.mozilla.com/D250909
This commit is contained in:
committed by
ealvarez@mozilla.com
parent
fdfcdea8cd
commit
e2ac38c2a8
@@ -997,8 +997,8 @@ class StyleSheetsManager extends EventEmitter {
|
|||||||
// FIXME(bug 1826538): Make accessiblecaret.css and similar UA-widget
|
// FIXME(bug 1826538): Make accessiblecaret.css and similar UA-widget
|
||||||
// sheets system sheets, then remove this special-case.
|
// sheets system sheets, then remove this special-case.
|
||||||
if (
|
if (
|
||||||
href === "resource://content-accessible/accessiblecaret.css" ||
|
href === "resource://gre-resources/accessiblecaret.css" ||
|
||||||
href === "resource://content-accessible/details.css" ||
|
href === "resource://gre-resources/details.css" ||
|
||||||
(href === "resource://devtools-highlighter-styles/highlighters.css" &&
|
(href === "resource://devtools-highlighter-styles/highlighters.css" &&
|
||||||
this.#targetActor.sessionContext.type !== "all")
|
this.#targetActor.sessionContext.type !== "all")
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "mozilla/dom/TrustedTypeUtils.h"
|
#include "mozilla/dom/TrustedTypeUtils.h"
|
||||||
#include "mozilla/dom/TrustedTypesConstants.h"
|
#include "mozilla/dom/TrustedTypesConstants.h"
|
||||||
#include "mozilla/dom/UnbindContext.h"
|
#include "mozilla/dom/UnbindContext.h"
|
||||||
|
#include "mozilla/GlobalStyleSheetCache.h"
|
||||||
#include "mozilla/EventDispatcher.h"
|
#include "mozilla/EventDispatcher.h"
|
||||||
#include "mozilla/IdentifierMapEntry.h"
|
#include "mozilla/IdentifierMapEntry.h"
|
||||||
#include "mozilla/PresShell.h"
|
#include "mozilla/PresShell.h"
|
||||||
@@ -548,6 +549,15 @@ void ShadowRoot::StyleSheetApplicableStateChanged(StyleSheet& aSheet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShadowRoot::AppendBuiltInStyleSheet(BuiltInStyleSheet aSheet) {
|
||||||
|
auto* cache = GlobalStyleSheetCache::Singleton();
|
||||||
|
// NOTE(emilio): It's important to Clone() the stylesheet to avoid leaking,
|
||||||
|
// since the built-in sheet is kept alive forever, and AppendStyleSheet will
|
||||||
|
// set the associated shadow root and global of the stylesheet.
|
||||||
|
RefPtr sheet = cache->BuiltInSheet(aSheet)->Clone(nullptr, nullptr);
|
||||||
|
AppendStyleSheet(*sheet);
|
||||||
|
}
|
||||||
|
|
||||||
void ShadowRoot::RemoveSheetFromStyles(StyleSheet& aSheet) {
|
void ShadowRoot::RemoveSheetFromStyles(StyleSheet& aSheet) {
|
||||||
MOZ_ASSERT(aSheet.IsApplicable());
|
MOZ_ASSERT(aSheet.IsApplicable());
|
||||||
MOZ_ASSERT(mServoStyles);
|
MOZ_ASSERT(mServoStyles);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class EventChainPreVisitor;
|
|||||||
class ServoStyleRuleMap;
|
class ServoStyleRuleMap;
|
||||||
|
|
||||||
enum class StyleRuleChangeKind : uint32_t;
|
enum class StyleRuleChangeKind : uint32_t;
|
||||||
|
enum class BuiltInStyleSheet : uint8_t;
|
||||||
|
|
||||||
namespace css {
|
namespace css {
|
||||||
class Rule;
|
class Rule;
|
||||||
@@ -98,6 +99,9 @@ class ShadowRoot final : public DocumentFragment, public DocumentOrShadowRoot {
|
|||||||
void SheetCloned(StyleSheet&);
|
void SheetCloned(StyleSheet&);
|
||||||
void StyleSheetApplicableStateChanged(StyleSheet&);
|
void StyleSheetApplicableStateChanged(StyleSheet&);
|
||||||
|
|
||||||
|
// Adds a built-in author style-sheet to the shadow tree.
|
||||||
|
void AppendBuiltInStyleSheet(BuiltInStyleSheet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clones internal state, for example stylesheets, of aOther to 'this'.
|
* Clones internal state, for example stylesheets, of aOther to 'this'.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -101,20 +101,7 @@ void HTMLDetailsElement::SetupShadowTree() {
|
|||||||
nsNodeInfoManager* nim = OwnerDoc()->NodeInfoManager();
|
nsNodeInfoManager* nim = OwnerDoc()->NodeInfoManager();
|
||||||
RefPtr<NodeInfo> slotNodeInfo = nim->GetNodeInfo(
|
RefPtr<NodeInfo> slotNodeInfo = nim->GetNodeInfo(
|
||||||
nsGkAtoms::slot, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE);
|
nsGkAtoms::slot, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE);
|
||||||
{
|
sr->AppendBuiltInStyleSheet(BuiltInStyleSheet::Details);
|
||||||
RefPtr<NodeInfo> linkNodeInfo = nim->GetNodeInfo(
|
|
||||||
nsGkAtoms::link, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE);
|
|
||||||
RefPtr<nsGenericHTMLElement> link =
|
|
||||||
NS_NewHTMLLinkElement(linkNodeInfo.forget());
|
|
||||||
if (NS_WARN_IF(!link)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
link->SetAttr(nsGkAtoms::rel, u"stylesheet"_ns, IgnoreErrors());
|
|
||||||
link->SetAttr(nsGkAtoms::href,
|
|
||||||
u"resource://content-accessible/details.css"_ns,
|
|
||||||
IgnoreErrors());
|
|
||||||
sr->AppendChildTo(link, kNotify, IgnoreErrors());
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
RefPtr<nsGenericHTMLElement> slot =
|
RefPtr<nsGenericHTMLElement> slot =
|
||||||
NS_NewHTMLSlotElement(do_AddRef(slotNodeInfo));
|
NS_NewHTMLSlotElement(do_AddRef(slotNodeInfo));
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "AccessibleCaretLogger.h"
|
#include "AccessibleCaretLogger.h"
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
|
#include "mozilla/BuiltInStyleSheets.h"
|
||||||
#include "mozilla/ErrorResult.h"
|
#include "mozilla/ErrorResult.h"
|
||||||
#include "mozilla/FloatingPoint.h"
|
#include "mozilla/FloatingPoint.h"
|
||||||
#include "mozilla/PresShell.h"
|
#include "mozilla/PresShell.h"
|
||||||
@@ -203,7 +204,6 @@ void AccessibleCaret::CreateCaretElement() const {
|
|||||||
// Content structure of AccessibleCaret
|
// Content structure of AccessibleCaret
|
||||||
// <div class="moz-accessiblecaret"> <- CaretElement()
|
// <div class="moz-accessiblecaret"> <- CaretElement()
|
||||||
// <#shadow-root>
|
// <#shadow-root>
|
||||||
// <link rel="stylesheet" href="accessiblecaret.css">
|
|
||||||
// <div id="text-overlay"> <- TextOverlayElement()
|
// <div id="text-overlay"> <- TextOverlayElement()
|
||||||
// <div id="image"> <- CaretImageElement()
|
// <div id="image"> <- CaretImageElement()
|
||||||
|
|
||||||
@@ -215,20 +215,7 @@ void AccessibleCaret::CreateCaretElement() const {
|
|||||||
|
|
||||||
ShadowRoot* root = mCaretElementHolder->Root();
|
ShadowRoot* root = mCaretElementHolder->Root();
|
||||||
Document* doc = host.OwnerDoc();
|
Document* doc = host.OwnerDoc();
|
||||||
{
|
root->AppendBuiltInStyleSheet(BuiltInStyleSheet::AccessibleCaret);
|
||||||
RefPtr<NodeInfo> linkNodeInfo = doc->NodeInfoManager()->GetNodeInfo(
|
|
||||||
nsGkAtoms::link, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE);
|
|
||||||
RefPtr<nsGenericHTMLElement> link =
|
|
||||||
NS_NewHTMLLinkElement(linkNodeInfo.forget());
|
|
||||||
if (NS_WARN_IF(!link)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
link->SetAttr(nsGkAtoms::rel, u"stylesheet"_ns, IgnoreErrors());
|
|
||||||
link->SetAttr(nsGkAtoms::href,
|
|
||||||
u"resource://content-accessible/accessiblecaret.css"_ns,
|
|
||||||
IgnoreErrors());
|
|
||||||
root->AppendChildTo(link, kNotify, IgnoreErrors());
|
|
||||||
}
|
|
||||||
|
|
||||||
auto CreateAndAppendChildElement = [&](const nsLiteralString& aElementId) {
|
auto CreateAndAppendChildElement = [&](const nsLiteralString& aElementId) {
|
||||||
RefPtr<Element> child = doc->CreateHTMLElement(nsGkAtoms::div);
|
RefPtr<Element> child = doc->CreateHTMLElement(nsGkAtoms::div);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ async function testApplicableStateChangeEvent(testRoot) {
|
|||||||
// accessiblecaret.css might be reported, interfering with the test
|
// accessiblecaret.css might be reported, interfering with the test
|
||||||
// assertions, so let's ignore it
|
// assertions, so let's ignore it
|
||||||
return (
|
return (
|
||||||
e.stylesheet?.href === "resource://content-accessible/accessiblecaret.css"
|
e.stylesheet?.href === "resource://gre-resources/accessiblecaret.css"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
35
layout/style/BuiltInStyleSheetList.h
Normal file
35
layout/style/BuiltInStyleSheetList.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/* -*- 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/. */
|
||||||
|
|
||||||
|
/* list of user agent style sheets that GlobalStyleSheetCache manages */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* STYLE_SHEET(identifier_, url_, flags_)
|
||||||
|
*
|
||||||
|
* identifier_
|
||||||
|
* An identifier for the style sheet, suitable for use as an enum class value.
|
||||||
|
*
|
||||||
|
* url_
|
||||||
|
* The URL of the style sheet.
|
||||||
|
*
|
||||||
|
* flags_
|
||||||
|
* UserStyleSheetType indicating whether the sheet can be safely placed in
|
||||||
|
* shared memory, and the kind of sheet it is.
|
||||||
|
*/
|
||||||
|
|
||||||
|
STYLE_SHEET(ContentEditable, "resource://gre/res/contenteditable.css", UA)
|
||||||
|
STYLE_SHEET(CounterStyles, "resource://gre-resources/counterstyles.css", UA)
|
||||||
|
STYLE_SHEET(Forms, "resource://gre-resources/forms.css", UA)
|
||||||
|
STYLE_SHEET(HTML, "resource://gre-resources/html.css", UA)
|
||||||
|
STYLE_SHEET(MathML, "resource://gre-resources/mathml.css", UA)
|
||||||
|
STYLE_SHEET(NoFrames, "resource://gre-resources/noframes.css", UA)
|
||||||
|
STYLE_SHEET(Quirk, "resource://gre-resources/quirk.css", UA)
|
||||||
|
STYLE_SHEET(Scrollbars, "resource://gre-resources/scrollbars.css", UA)
|
||||||
|
STYLE_SHEET(SVG, "resource://gre/res/svg.css", UA)
|
||||||
|
STYLE_SHEET(UA, "resource://gre-resources/ua.css", UA)
|
||||||
|
STYLE_SHEET(XUL, "chrome://global/content/xul.css", UAUnshared)
|
||||||
|
STYLE_SHEET(AccessibleCaret, "resource://gre-resources/accessiblecaret.css", Author)
|
||||||
|
STYLE_SHEET(Details, "resource://gre-resources/details.css", Author)
|
||||||
38
layout/style/BuiltInStyleSheets.h
Normal file
38
layout/style/BuiltInStyleSheets.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/* -*- 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/. */
|
||||||
|
|
||||||
|
/* an identifier for User Agent style sheets */
|
||||||
|
|
||||||
|
#ifndef mozilla_BuiltInStyleSheets_h
|
||||||
|
#define mozilla_BuiltInStyleSheets_h
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "mozilla/TypedEnumBits.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
enum class BuiltInStyleSheetFlags : uint8_t {
|
||||||
|
UA = 1,
|
||||||
|
Author = 1 << 1,
|
||||||
|
// By default sheets are shared, except xul.css which we only need in the
|
||||||
|
// parent process.
|
||||||
|
NotShared = 1 << 2,
|
||||||
|
|
||||||
|
UAUnshared = (UA | NotShared),
|
||||||
|
};
|
||||||
|
|
||||||
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(BuiltInStyleSheetFlags);
|
||||||
|
|
||||||
|
enum class BuiltInStyleSheet : uint8_t {
|
||||||
|
#define STYLE_SHEET(identifier_, url_, flags_) identifier_,
|
||||||
|
#include "mozilla/BuiltInStyleSheetList.h"
|
||||||
|
#undef STYLE_SHEET
|
||||||
|
Count
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
|
#endif // mozilla_BuiltInStyleSheets_h
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "mozilla/dom/SRIMetadata.h"
|
#include "mozilla/dom/SRIMetadata.h"
|
||||||
#include "mozilla/ipc/SharedMemoryHandle.h"
|
#include "mozilla/ipc/SharedMemoryHandle.h"
|
||||||
#include "mozilla/ipc/SharedMemoryMapping.h"
|
#include "mozilla/ipc/SharedMemoryMapping.h"
|
||||||
|
#include "mozilla/ServoBindings.h"
|
||||||
#include "MainThreadUtils.h"
|
#include "MainThreadUtils.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "nsIConsoleService.h"
|
#include "nsIConsoleService.h"
|
||||||
@@ -30,8 +31,6 @@
|
|||||||
#include "nsServiceManagerUtils.h"
|
#include "nsServiceManagerUtils.h"
|
||||||
#include "nsXULAppAPI.h"
|
#include "nsXULAppAPI.h"
|
||||||
|
|
||||||
#include <mozilla/ServoBindings.h>
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
// The GlobalStyleSheetCache is responsible for sharing user agent style sheet
|
// The GlobalStyleSheetCache is responsible for sharing user agent style sheet
|
||||||
@@ -130,15 +129,30 @@ nsresult GlobalStyleSheetCache::Observe(nsISupports* aSubject,
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STYLE_SHEET(identifier_, url_, shared_) \
|
static constexpr struct {
|
||||||
NotNull<StyleSheet*> GlobalStyleSheetCache::identifier_##Sheet() { \
|
nsLiteralCString mURL;
|
||||||
if (!m##identifier_##Sheet) { \
|
BuiltInStyleSheetFlags mFlags;
|
||||||
m##identifier_##Sheet = LoadSheetURL(url_, eAgentSheetFeatures, eCrash); \
|
} kBuiltInSheetInfo[] = {
|
||||||
} \
|
#define STYLE_SHEET(identifier_, url_, flags_) \
|
||||||
return WrapNotNull(m##identifier_##Sheet); \
|
{nsLiteralCString(url_), BuiltInStyleSheetFlags::flags_},
|
||||||
}
|
#include "mozilla/BuiltInStyleSheetList.h"
|
||||||
#include "mozilla/UserAgentStyleSheetList.h"
|
|
||||||
#undef STYLE_SHEET
|
#undef STYLE_SHEET
|
||||||
|
};
|
||||||
|
|
||||||
|
NotNull<StyleSheet*> GlobalStyleSheetCache::BuiltInSheet(
|
||||||
|
BuiltInStyleSheet aSheet) {
|
||||||
|
auto& slot = mBuiltIns[aSheet];
|
||||||
|
if (!slot) {
|
||||||
|
const auto& info = kBuiltInSheetInfo[size_t(aSheet)];
|
||||||
|
const auto parsingMode = (info.mFlags & BuiltInStyleSheetFlags::UA)
|
||||||
|
? eAgentSheetFeatures
|
||||||
|
: eAuthorSheetFeatures;
|
||||||
|
MOZ_ASSERT(info.mFlags & BuiltInStyleSheetFlags::UA ||
|
||||||
|
info.mFlags & BuiltInStyleSheetFlags::Author);
|
||||||
|
slot = LoadSheetURL(info.mURL, parsingMode, eCrash);
|
||||||
|
}
|
||||||
|
return WrapNotNull(slot);
|
||||||
|
}
|
||||||
|
|
||||||
StyleSheet* GlobalStyleSheetCache::GetUserContentSheet() {
|
StyleSheet* GlobalStyleSheetCache::GetUserContentSheet() {
|
||||||
return mUserContentSheet;
|
return mUserContentSheet;
|
||||||
@@ -194,9 +208,9 @@ size_t GlobalStyleSheetCache::SizeOfIncludingThis(
|
|||||||
|
|
||||||
#define MEASURE(s) n += s ? s->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
#define MEASURE(s) n += s ? s->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
||||||
|
|
||||||
#define STYLE_SHEET(identifier_, url_, shared_) MEASURE(m##identifier_##Sheet);
|
for (const auto& sheet : mBuiltIns) {
|
||||||
#include "mozilla/UserAgentStyleSheetList.h"
|
MEASURE(sheet);
|
||||||
#undef STYLE_SHEET
|
}
|
||||||
|
|
||||||
MEASURE(mUserChromeSheet);
|
MEASURE(mUserChromeSheet);
|
||||||
MEASURE(mUserContentSheet);
|
MEASURE(mUserContentSheet);
|
||||||
@@ -270,21 +284,25 @@ GlobalStyleSheetCache::GlobalStyleSheetCache() {
|
|||||||
reinterpret_cast<const Header*>(sSharedMemory.data())) {
|
reinterpret_cast<const Header*>(sSharedMemory.data())) {
|
||||||
MOZ_RELEASE_ASSERT(header->mMagic == Header::kMagic);
|
MOZ_RELEASE_ASSERT(header->mMagic == Header::kMagic);
|
||||||
|
|
||||||
#define STYLE_SHEET(identifier_, url_, shared_) \
|
for (auto kind : MakeEnumeratedRange(BuiltInStyleSheet::Count)) {
|
||||||
if (shared_) { \
|
const auto& info = kBuiltInSheetInfo[size_t(kind)];
|
||||||
LoadSheetFromSharedMemory(url_, &m##identifier_##Sheet, \
|
if (info.mFlags & BuiltInStyleSheetFlags::NotShared) {
|
||||||
eAgentSheetFeatures, header, \
|
continue;
|
||||||
UserAgentStyleSheetID::identifier_); \
|
}
|
||||||
|
const auto parsingMode = (info.mFlags & BuiltInStyleSheetFlags::UA)
|
||||||
|
? eAgentSheetFeatures
|
||||||
|
: eAuthorSheetFeatures;
|
||||||
|
LoadSheetFromSharedMemory(info.mURL, &mBuiltIns[kind], parsingMode,
|
||||||
|
header, kind);
|
||||||
}
|
}
|
||||||
#include "mozilla/UserAgentStyleSheetList.h"
|
|
||||||
#undef STYLE_SHEET
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalStyleSheetCache::LoadSheetFromSharedMemory(
|
void GlobalStyleSheetCache::LoadSheetFromSharedMemory(
|
||||||
const char* aURL, RefPtr<StyleSheet>* aSheet, SheetParsingMode aParsingMode,
|
const nsACString& aURL, RefPtr<StyleSheet>* aSheet,
|
||||||
const Header* aHeader, UserAgentStyleSheetID aSheetID) {
|
SheetParsingMode aParsingMode, const Header* aHeader,
|
||||||
|
BuiltInStyleSheet aSheetID) {
|
||||||
auto i = size_t(aSheetID);
|
auto i = size_t(aSheetID);
|
||||||
|
|
||||||
auto sheet =
|
auto sheet =
|
||||||
@@ -377,19 +395,20 @@ void GlobalStyleSheetCache::InitSharedSheetsInParent() {
|
|||||||
// Normally calling ToShared on UA sheets should not fail. It happens
|
// Normally calling ToShared on UA sheets should not fail. It happens
|
||||||
// in practice in odd cases that seem like corrupted installations; see bug
|
// in practice in odd cases that seem like corrupted installations; see bug
|
||||||
// 1621773. On failure, return early and fall back to non-shared sheets.
|
// 1621773. On failure, return early and fall back to non-shared sheets.
|
||||||
#define STYLE_SHEET(identifier_, url_, shared_) \
|
for (auto kind : MakeEnumeratedRange(BuiltInStyleSheet::Count)) {
|
||||||
if (shared_) { \
|
auto i = size_t(kind);
|
||||||
StyleSheet* sheet = identifier_##Sheet(); \
|
const auto& info = kBuiltInSheetInfo[i];
|
||||||
size_t i = size_t(UserAgentStyleSheetID::identifier_); \
|
if (info.mFlags & BuiltInStyleSheetFlags::NotShared) {
|
||||||
URLExtraData::sShared[i] = sheet->URLData(); \
|
continue;
|
||||||
header->mSheets[i] = sheet->ToShared(builder.get(), message); \
|
}
|
||||||
if (!header->mSheets[i]) { \
|
StyleSheet* sheet = BuiltInSheet(kind);
|
||||||
CrashReporter::AppendAppNotesToCrashReport("\n"_ns + message); \
|
URLExtraData::sShared[i] = sheet->URLData();
|
||||||
return; \
|
header->mSheets[i] = sheet->ToShared(builder.get(), message);
|
||||||
} \
|
if (!header->mSheets[i]) {
|
||||||
|
CrashReporter::AppendAppNotesToCrashReport("\n"_ns + message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#include "mozilla/UserAgentStyleSheetList.h"
|
|
||||||
#undef STYLE_SHEET
|
|
||||||
|
|
||||||
// Finished writing into the shared memory. Freeze it, so that a process
|
// Finished writing into the shared memory. Freeze it, so that a process
|
||||||
// can't confuse other processes by changing the UA style sheet contents.
|
// can't confuse other processes by changing the UA style sheet contents.
|
||||||
@@ -479,7 +498,7 @@ void GlobalStyleSheetCache::InitFromProfile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<StyleSheet> GlobalStyleSheetCache::LoadSheetURL(
|
RefPtr<StyleSheet> GlobalStyleSheetCache::LoadSheetURL(
|
||||||
const char* aURL, SheetParsingMode aParsingMode,
|
const nsACString& aURL, SheetParsingMode aParsingMode,
|
||||||
FailureAction aFailureAction) {
|
FailureAction aFailureAction) {
|
||||||
nsCOMPtr<nsIURI> uri;
|
nsCOMPtr<nsIURI> uri;
|
||||||
NS_NewURI(getter_AddRefs(uri), aURL);
|
NS_NewURI(getter_AddRefs(uri), aURL);
|
||||||
|
|||||||
@@ -10,11 +10,11 @@
|
|||||||
#include "nsIMemoryReporter.h"
|
#include "nsIMemoryReporter.h"
|
||||||
#include "nsIObserver.h"
|
#include "nsIObserver.h"
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
|
#include "mozilla/BuiltInStyleSheets.h"
|
||||||
#include "mozilla/MemoryReporting.h"
|
#include "mozilla/MemoryReporting.h"
|
||||||
#include "mozilla/PreferenceSheet.h"
|
#include "mozilla/PreferenceSheet.h"
|
||||||
#include "mozilla/NotNull.h"
|
#include "mozilla/NotNull.h"
|
||||||
#include "mozilla/StaticPtr.h"
|
#include "mozilla/StaticPtr.h"
|
||||||
#include "mozilla/UserAgentStyleSheetID.h"
|
|
||||||
#include "mozilla/css/Loader.h"
|
#include "mozilla/css/Loader.h"
|
||||||
#include "mozilla/ipc/SharedMemoryHandle.h"
|
#include "mozilla/ipc/SharedMemoryHandle.h"
|
||||||
#include "mozilla/ipc/SharedMemoryMapping.h"
|
#include "mozilla/ipc/SharedMemoryMapping.h"
|
||||||
@@ -43,11 +43,15 @@ class GlobalStyleSheetCache final : public nsIObserver,
|
|||||||
|
|
||||||
static GlobalStyleSheetCache* Singleton();
|
static GlobalStyleSheetCache* Singleton();
|
||||||
|
|
||||||
#define STYLE_SHEET(identifier_, url_, shared_) \
|
#define STYLE_SHEET(identifier_, url_, flags_) \
|
||||||
NotNull<StyleSheet*> identifier_##Sheet();
|
NotNull<StyleSheet*> identifier_##Sheet() { \
|
||||||
#include "mozilla/UserAgentStyleSheetList.h"
|
return BuiltInSheet(BuiltInStyleSheet::identifier_); \
|
||||||
|
}
|
||||||
|
#include "mozilla/BuiltInStyleSheetList.h"
|
||||||
#undef STYLE_SHEET
|
#undef STYLE_SHEET
|
||||||
|
|
||||||
|
NotNull<StyleSheet*> BuiltInSheet(BuiltInStyleSheet);
|
||||||
|
|
||||||
StyleSheet* GetUserContentSheet();
|
StyleSheet* GetUserContentSheet();
|
||||||
StyleSheet* GetUserChromeSheet();
|
StyleSheet* GetUserChromeSheet();
|
||||||
|
|
||||||
@@ -87,7 +91,7 @@ class GlobalStyleSheetCache final : public nsIObserver,
|
|||||||
struct Header {
|
struct Header {
|
||||||
static constexpr uint32_t kMagic = 0x55415353;
|
static constexpr uint32_t kMagic = 0x55415353;
|
||||||
uint32_t mMagic; // Must be set to kMagic.
|
uint32_t mMagic; // Must be set to kMagic.
|
||||||
const StyleLockedCssRules* mSheets[size_t(UserAgentStyleSheetID::Count)];
|
const StyleLockedCssRules* mSheets[size_t(BuiltInStyleSheet::Count)];
|
||||||
uint8_t mBuffer[1];
|
uint8_t mBuffer[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -97,25 +101,25 @@ class GlobalStyleSheetCache final : public nsIObserver,
|
|||||||
void InitFromProfile();
|
void InitFromProfile();
|
||||||
void InitSharedSheetsInParent();
|
void InitSharedSheetsInParent();
|
||||||
void InitMemoryReporter();
|
void InitMemoryReporter();
|
||||||
RefPtr<StyleSheet> LoadSheetURL(const char* aURL,
|
RefPtr<StyleSheet> LoadSheetURL(const nsACString& aURL,
|
||||||
css::SheetParsingMode aParsingMode,
|
css::SheetParsingMode aParsingMode,
|
||||||
css::FailureAction aFailureAction);
|
css::FailureAction aFailureAction);
|
||||||
RefPtr<StyleSheet> LoadSheetFile(nsIFile* aFile,
|
RefPtr<StyleSheet> LoadSheetFile(nsIFile* aFile,
|
||||||
css::SheetParsingMode aParsingMode);
|
css::SheetParsingMode aParsingMode);
|
||||||
RefPtr<StyleSheet> LoadSheet(nsIURI* aURI, css::SheetParsingMode aParsingMode,
|
RefPtr<StyleSheet> LoadSheet(nsIURI* aURI, css::SheetParsingMode aParsingMode,
|
||||||
css::FailureAction aFailureAction);
|
css::FailureAction aFailureAction);
|
||||||
void LoadSheetFromSharedMemory(const char* aURL, RefPtr<StyleSheet>* aSheet,
|
void LoadSheetFromSharedMemory(const nsACString& aURL,
|
||||||
|
RefPtr<StyleSheet>* aSheet,
|
||||||
css::SheetParsingMode, const Header*,
|
css::SheetParsingMode, const Header*,
|
||||||
UserAgentStyleSheetID);
|
BuiltInStyleSheet);
|
||||||
|
|
||||||
static StaticRefPtr<GlobalStyleSheetCache> gStyleCache;
|
static StaticRefPtr<GlobalStyleSheetCache> gStyleCache;
|
||||||
static StaticRefPtr<css::Loader> gCSSLoader;
|
static StaticRefPtr<css::Loader> gCSSLoader;
|
||||||
static StaticRefPtr<nsIURI> gUserContentSheetURL;
|
static StaticRefPtr<nsIURI> gUserContentSheetURL;
|
||||||
|
|
||||||
#define STYLE_SHEET(identifier_, url_, shared_) \
|
EnumeratedArray<BuiltInStyleSheet, RefPtr<StyleSheet>,
|
||||||
RefPtr<StyleSheet> m##identifier_##Sheet;
|
size_t(BuiltInStyleSheet::Count)>
|
||||||
#include "mozilla/UserAgentStyleSheetList.h"
|
mBuiltIns;
|
||||||
#undef STYLE_SHEET
|
|
||||||
|
|
||||||
RefPtr<StyleSheet> mUserChromeSheet;
|
RefPtr<StyleSheet> mUserChromeSheet;
|
||||||
RefPtr<StyleSheet> mUserContentSheet;
|
RefPtr<StyleSheet> mUserContentSheet;
|
||||||
|
|||||||
@@ -1510,10 +1510,7 @@ Loader::Completed Loader::ParseSheet(
|
|||||||
}
|
}
|
||||||
AUTO_PROFILER_LABEL_CATEGORY_PAIR_RELEVANT_FOR_JS(LAYOUT_CSSParsing);
|
AUTO_PROFILER_LABEL_CATEGORY_PAIR_RELEVANT_FOR_JS(LAYOUT_CSSParsing);
|
||||||
|
|
||||||
// TODO(emilio): fix browser_css_cache.js to deal with accessiblecaret.css.
|
|
||||||
if (!loadData->mURI || !IsPrivilegedURI(loadData->mURI)) {
|
|
||||||
++mParsedSheetCount;
|
++mParsedSheetCount;
|
||||||
}
|
|
||||||
|
|
||||||
loadData->mIsBeingParsed = true;
|
loadData->mIsBeingParsed = true;
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,6 @@ void URLExtraData::Shutdown() {
|
|||||||
URLExtraData::~URLExtraData() = default;
|
URLExtraData::~URLExtraData() = default;
|
||||||
|
|
||||||
StaticRefPtr<URLExtraData>
|
StaticRefPtr<URLExtraData>
|
||||||
URLExtraData::sShared[size_t(UserAgentStyleSheetID::Count)];
|
URLExtraData::sShared[size_t(BuiltInStyleSheet::Count)];
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "mozilla/StaticPtr.h"
|
#include "mozilla/StaticPtr.h"
|
||||||
#include "mozilla/UserAgentStyleSheetID.h"
|
#include "mozilla/BuiltInStyleSheets.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsIPrincipal.h"
|
#include "nsIPrincipal.h"
|
||||||
#include "nsIReferrerInfo.h"
|
#include "nsIReferrerInfo.h"
|
||||||
@@ -66,8 +66,7 @@ struct URLExtraData {
|
|||||||
|
|
||||||
// URLExtraData objects that shared style sheets use a sheet ID index to
|
// URLExtraData objects that shared style sheets use a sheet ID index to
|
||||||
// refer to.
|
// refer to.
|
||||||
static StaticRefPtr<URLExtraData>
|
static StaticRefPtr<URLExtraData> sShared[size_t(BuiltInStyleSheet::Count)];
|
||||||
sShared[size_t(UserAgentStyleSheetID::Count)];
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~URLExtraData();
|
~URLExtraData();
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
/* -*- 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/. */
|
|
||||||
|
|
||||||
/* an identifier for User Agent style sheets */
|
|
||||||
|
|
||||||
#ifndef mozilla_UserAgentStyleSheetID_h
|
|
||||||
#define mozilla_UserAgentStyleSheetID_h
|
|
||||||
|
|
||||||
namespace mozilla {
|
|
||||||
|
|
||||||
enum class UserAgentStyleSheetID : uint8_t {
|
|
||||||
#define STYLE_SHEET(identifier_, url_, shared_) identifier_,
|
|
||||||
#include "mozilla/UserAgentStyleSheetList.h"
|
|
||||||
#undef STYLE_SHEET
|
|
||||||
Count
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mozilla
|
|
||||||
|
|
||||||
#endif // mozilla_UserAgentStyleSheetID_h
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
/* -*- 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/. */
|
|
||||||
|
|
||||||
/* list of user agent style sheets that GlobalStyleSheetCache manages */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* STYLE_SHEET(identifier_, url_, shared_)
|
|
||||||
*
|
|
||||||
* identifier_
|
|
||||||
* An identifier for the style sheet, suitable for use as an enum class value.
|
|
||||||
*
|
|
||||||
* url_
|
|
||||||
* The URL of the style sheet.
|
|
||||||
*
|
|
||||||
* shared_
|
|
||||||
* A boolean indicating whether the sheet can be safely placed in shared
|
|
||||||
* memory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
STYLE_SHEET(ContentEditable, "resource://gre/res/contenteditable.css", true)
|
|
||||||
STYLE_SHEET(CounterStyles, "resource://gre-resources/counterstyles.css", true)
|
|
||||||
STYLE_SHEET(Forms, "resource://gre-resources/forms.css", true)
|
|
||||||
STYLE_SHEET(HTML, "resource://gre-resources/html.css", true)
|
|
||||||
STYLE_SHEET(MathML, "resource://gre-resources/mathml.css", true)
|
|
||||||
STYLE_SHEET(NoFrames, "resource://gre-resources/noframes.css", true)
|
|
||||||
STYLE_SHEET(Quirk, "resource://gre-resources/quirk.css", true)
|
|
||||||
STYLE_SHEET(Scrollbars, "resource://gre-resources/scrollbars.css", true)
|
|
||||||
STYLE_SHEET(SVG, "resource://gre/res/svg.css", true)
|
|
||||||
STYLE_SHEET(UA, "resource://gre-resources/ua.css", true)
|
|
||||||
STYLE_SHEET(XUL, "chrome://global/content/xul.css", false)
|
|
||||||
@@ -10,6 +10,8 @@ toolkit.jar:
|
|||||||
res/noframes.css (res/noframes.css)
|
res/noframes.css (res/noframes.css)
|
||||||
res/scrollbars.css (res/scrollbars.css)
|
res/scrollbars.css (res/scrollbars.css)
|
||||||
res/forms.css (res/forms.css)
|
res/forms.css (res/forms.css)
|
||||||
|
res/accessiblecaret.css (res/accessiblecaret.css)
|
||||||
|
res/details.css (res/details.css)
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
res/accessiblecaret-normal.svg (res/accessiblecaret-normal.svg)
|
res/accessiblecaret-normal.svg (res/accessiblecaret-normal.svg)
|
||||||
res/accessiblecaret-tilt-left.svg (res/accessiblecaret-tilt-left.svg)
|
res/accessiblecaret-tilt-left.svg (res/accessiblecaret-tilt-left.svg)
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ EXPORTS.mozilla += [
|
|||||||
"AnimatedPropertyIDSet.h",
|
"AnimatedPropertyIDSet.h",
|
||||||
"AnimationCollection.h",
|
"AnimationCollection.h",
|
||||||
"AttributeStyles.h",
|
"AttributeStyles.h",
|
||||||
|
"BuiltInStyleSheetList.h",
|
||||||
|
"BuiltInStyleSheets.h",
|
||||||
"CachedInheritingStyles.h",
|
"CachedInheritingStyles.h",
|
||||||
"ComputedStyle.h",
|
"ComputedStyle.h",
|
||||||
"ComputedStyleInlines.h",
|
"ComputedStyleInlines.h",
|
||||||
@@ -122,8 +124,6 @@ EXPORTS.mozilla += [
|
|||||||
"TimelineCollection.h",
|
"TimelineCollection.h",
|
||||||
"TimelineManager.h",
|
"TimelineManager.h",
|
||||||
"URLExtraData.h",
|
"URLExtraData.h",
|
||||||
"UserAgentStyleSheetID.h",
|
|
||||||
"UserAgentStyleSheetList.h",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
EXPORTS.mozilla.dom += [
|
EXPORTS.mozilla.dom += [
|
||||||
@@ -296,9 +296,7 @@ RESOURCE_FILES += [
|
|||||||
|
|
||||||
CONTENT_ACCESSIBLE_FILES += [
|
CONTENT_ACCESSIBLE_FILES += [
|
||||||
"ImageDocument.css",
|
"ImageDocument.css",
|
||||||
"res/accessiblecaret.css",
|
|
||||||
"res/close-12.svg",
|
"res/close-12.svg",
|
||||||
"res/details.css",
|
|
||||||
"res/plaintext.css",
|
"res/plaintext.css",
|
||||||
"res/viewsource.css",
|
"res/viewsource.css",
|
||||||
"TopLevelImageDocument.css",
|
"TopLevelImageDocument.css",
|
||||||
|
|||||||
@@ -8911,7 +8911,6 @@ pub unsafe extern "C" fn Servo_SharedMemoryBuilder_AddStylesheet(
|
|||||||
) -> *const LockedCssRules {
|
) -> *const LockedCssRules {
|
||||||
// Assert some things we assume when we create a style sheet from shared
|
// Assert some things we assume when we create a style sheet from shared
|
||||||
// memory.
|
// memory.
|
||||||
debug_assert_eq!(contents.origin, Origin::UserAgent);
|
|
||||||
debug_assert_eq!(contents.quirks_mode, QuirksMode::NoQuirks);
|
debug_assert_eq!(contents.quirks_mode, QuirksMode::NoQuirks);
|
||||||
debug_assert!(contents.source_map_url.read().is_none());
|
debug_assert!(contents.source_map_url.read().is_none());
|
||||||
debug_assert!(contents.source_url.read().is_none());
|
debug_assert!(contents.source_url.read().is_none());
|
||||||
|
|||||||
Reference in New Issue
Block a user