2013-01-18 04:45:12 +04: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: */
|
2012-05-21 15:12:37 +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/. */
|
2005-01-15 03:10:19 +03:00
|
|
|
|
2006-03-30 09:56:38 +04:00
|
|
|
/* implementation of interface for managing user and user-agent style sheets */
|
|
|
|
|
2005-01-15 03:10:19 +03:00
|
|
|
#include "nsStyleSheetService.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2017-01-05 10:32:22 +03:00
|
|
|
#include "mozilla/PreloadedStyleSheet.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheet.h"
|
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Loader.h"
|
2013-08-27 21:10:39 +04:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2017-03-20 05:33:49 +03:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2013-08-27 21:10:39 +04:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2005-03-23 05:34:30 +03:00
|
|
|
#include "nsIURI.h"
|
2005-01-15 03:10:19 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2005-01-15 03:10:19 +03:00
|
|
|
#include "nsNetUtil.h"
|
2016-10-24 17:59:09 +03:00
|
|
|
#include "nsIConsoleService.h"
|
2006-06-08 18:32:20 +04:00
|
|
|
#include "nsIObserverService.h"
|
2009-11-18 16:58:44 +03:00
|
|
|
#include "nsLayoutStatics.h"
|
2018-02-13 20:08:42 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-10-12 08:05:38 +04:00
|
|
|
|
2013-08-27 21:10:39 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsStyleSheetService *nsStyleSheetService::gInstance = nullptr;
|
2005-01-15 03:10:19 +03:00
|
|
|
|
|
|
|
nsStyleSheetService::nsStyleSheetService()
|
|
|
|
{
|
2016-08-23 18:24:54 +03:00
|
|
|
static_assert(0 == AGENT_SHEET && 1 == USER_SHEET && 2 == AUTHOR_SHEET,
|
|
|
|
"Convention for Style Sheet");
|
2005-01-15 03:10:19 +03:00
|
|
|
NS_ASSERTION(!gInstance, "Someone is using CreateInstance instead of GetService");
|
|
|
|
gInstance = this;
|
2009-11-18 16:25:02 +03:00
|
|
|
nsLayoutStatics::AddRef();
|
2005-01-15 03:10:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleSheetService::~nsStyleSheetService()
|
|
|
|
{
|
2013-11-07 09:35:30 +04:00
|
|
|
UnregisterWeakMemoryReporter(this);
|
2013-01-18 04:45:12 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
gInstance = nullptr;
|
2009-11-18 16:25:02 +03:00
|
|
|
nsLayoutStatics::Release();
|
2005-01-15 03:10:19 +03:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(
|
2013-12-08 10:09:10 +04:00
|
|
|
nsStyleSheetService, nsIStyleSheetService, nsIMemoryReporter)
|
2005-01-15 03:10:19 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleSheetService::RegisterFromEnumerator(nsICategoryManager *aManager,
|
|
|
|
const char *aCategory,
|
|
|
|
nsISimpleEnumerator *aEnumerator,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aSheetType)
|
2005-01-15 03:10:19 +03:00
|
|
|
{
|
|
|
|
if (!aEnumerator)
|
|
|
|
return;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasMore;
|
2005-01-15 03:10:19 +03:00
|
|
|
while (NS_SUCCEEDED(aEnumerator->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> element;
|
|
|
|
if (NS_FAILED(aEnumerator->GetNext(getter_AddRefs(element))))
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsCString> icStr = do_QueryInterface(element);
|
|
|
|
NS_ASSERTION(icStr,
|
|
|
|
"category manager entries must be nsISupportsCStrings");
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString name;
|
2005-01-15 03:10:19 +03:00
|
|
|
icStr->GetData(name);
|
|
|
|
|
2017-08-16 06:58:35 +03:00
|
|
|
nsCString spec;
|
2005-01-15 03:10:19 +03:00
|
|
|
aManager->GetCategoryEntry(aCategory, name.get(), getter_Copies(spec));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), spec);
|
|
|
|
if (uri)
|
2006-06-08 18:32:20 +04:00
|
|
|
LoadAndRegisterSheetInternal(uri, aSheetType);
|
2005-01-15 03:10:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-21 05:42:27 +03:00
|
|
|
static bool
|
|
|
|
SheetHasURI(StyleSheet* aSheet, nsIURI* aSheetURI)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aSheetURI);
|
|
|
|
|
|
|
|
bool result;
|
|
|
|
nsIURI* uri = aSheet->GetSheetURI();
|
|
|
|
return uri &&
|
|
|
|
NS_SUCCEEDED(uri->Equals(aSheetURI, &result)) &&
|
|
|
|
result;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2017-09-29 02:45:09 +03:00
|
|
|
nsStyleSheetService::FindSheetByURI(mozilla::StyleBackendType aBackendType,
|
|
|
|
uint32_t aSheetType,
|
2015-11-17 09:04:09 +03:00
|
|
|
nsIURI* aSheetURI)
|
2005-03-23 05:34:30 +03:00
|
|
|
{
|
2018-02-01 07:04:04 +03:00
|
|
|
SheetArray& sheets = Sheets(aBackendType)[aSheetType];
|
2017-02-21 05:42:27 +03:00
|
|
|
for (int32_t i = sheets.Length() - 1; i >= 0; i-- ) {
|
|
|
|
if (SheetHasURI(sheets[i], aSheetURI)) {
|
2005-03-23 05:34:30 +03:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-01-15 03:10:19 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSheetService::Init()
|
|
|
|
{
|
2014-05-25 00:37:48 +04:00
|
|
|
// If you make changes here, consider whether
|
|
|
|
// SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded should be updated too.
|
|
|
|
|
2013-08-27 21:10:39 +04:00
|
|
|
// Child processes get their style sheets from the ContentParent.
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
2013-08-27 21:10:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-15 03:10:19 +03:00
|
|
|
// Enumerate all of the style sheet URIs registered in the category
|
|
|
|
// manager and load them.
|
|
|
|
|
|
|
|
nsCOMPtr<nsICategoryManager> catMan =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(catMan, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> sheets;
|
|
|
|
catMan->EnumerateCategory("agent-style-sheets", getter_AddRefs(sheets));
|
|
|
|
RegisterFromEnumerator(catMan, "agent-style-sheets", sheets, AGENT_SHEET);
|
|
|
|
|
|
|
|
catMan->EnumerateCategory("user-style-sheets", getter_AddRefs(sheets));
|
|
|
|
RegisterFromEnumerator(catMan, "user-style-sheets", sheets, USER_SHEET);
|
|
|
|
|
2012-10-16 23:45:50 +04:00
|
|
|
catMan->EnumerateCategory("author-style-sheets", getter_AddRefs(sheets));
|
|
|
|
RegisterFromEnumerator(catMan, "author-style-sheets", sheets, AUTHOR_SHEET);
|
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
RegisterWeakMemoryReporter(this);
|
|
|
|
|
2005-01-15 03:10:19 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStyleSheetService::LoadAndRegisterSheet(nsIURI *aSheetURI,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aSheetType)
|
2006-06-08 18:32:20 +04:00
|
|
|
{
|
2016-10-24 17:59:09 +03:00
|
|
|
// Warn developers if their stylesheet URL has a #ref at the end.
|
|
|
|
// Stylesheet URIs don't benefit from having a #ref suffix -- and if the
|
|
|
|
// sheet is a data URI, someone might've created this #ref by accident (and
|
|
|
|
// truncated their data-URI stylesheet) by using an unescaped # character in
|
|
|
|
// a #RRGGBB color or #foo() ID-selector in their data-URI representation.
|
|
|
|
bool hasRef;
|
|
|
|
nsresult rv = aSheetURI->GetHasRef(&hasRef);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (aSheetURI && hasRef) {
|
|
|
|
nsCOMPtr<nsIConsoleService> consoleService =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
NS_WARNING_ASSERTION(consoleService, "Failed to get console service!");
|
|
|
|
if (consoleService) {
|
|
|
|
const char16_t* message = u"nsStyleSheetService::LoadAndRegisterSheet: "
|
|
|
|
u"URI contains unescaped hash character, which might be truncating "
|
|
|
|
u"the sheet, if it's a data URI.";
|
|
|
|
consoleService->LogStringMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = LoadAndRegisterSheetInternal(aSheetURI, aSheetType);
|
2006-06-08 18:32:20 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2017-02-21 05:42:27 +03:00
|
|
|
// Hold on to a copy of the registered PresShells.
|
|
|
|
nsTArray<nsCOMPtr<nsIPresShell>> toNotify(mPresShells);
|
|
|
|
for (nsIPresShell* presShell : toNotify) {
|
2018-03-21 15:01:25 +03:00
|
|
|
StyleSheet* sheet = Sheets(StyleBackendType::Servo)[aSheetType].LastElement();
|
|
|
|
presShell->NotifyStyleSheetServiceSheetAdded(sheet, aSheetType);
|
2006-06-08 18:32:20 +04:00
|
|
|
}
|
2013-08-27 21:10:39 +04:00
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2013-08-27 21:10:39 +04:00
|
|
|
nsTArray<dom::ContentParent*> children;
|
|
|
|
dom::ContentParent::GetAll(children);
|
|
|
|
|
|
|
|
if (children.IsEmpty()) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-11-24 10:29:24 +04:00
|
|
|
mozilla::ipc::URIParams uri;
|
2013-08-27 21:10:39 +04:00
|
|
|
SerializeURI(aSheetURI, uri);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < children.Length(); i++) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << children[i]->SendLoadAndRegisterSheet(uri, aSheetType);
|
2013-08-27 21:10:39 +04:00
|
|
|
}
|
|
|
|
}
|
2006-06-08 18:32:20 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-02-21 05:42:27 +03:00
|
|
|
static nsresult
|
|
|
|
LoadSheet(nsIURI* aURI,
|
|
|
|
css::SheetParsingMode aParsingMode,
|
|
|
|
RefPtr<StyleSheet>* aResult)
|
|
|
|
{
|
2018-03-28 18:33:01 +03:00
|
|
|
RefPtr<css::Loader> loader = new css::Loader;
|
2017-02-21 05:42:27 +03:00
|
|
|
return loader->LoadSheetSync(aURI, aParsingMode, true, aResult);
|
|
|
|
}
|
|
|
|
|
2006-06-08 18:32:20 +04:00
|
|
|
nsresult
|
|
|
|
nsStyleSheetService::LoadAndRegisterSheetInternal(nsIURI *aSheetURI,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aSheetType)
|
2005-01-15 03:10:19 +03:00
|
|
|
{
|
2006-02-26 22:39:06 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aSheetURI);
|
2005-03-23 05:34:30 +03:00
|
|
|
|
2015-10-14 00:43:16 +03:00
|
|
|
css::SheetParsingMode parsingMode;
|
|
|
|
switch (aSheetType) {
|
|
|
|
case AGENT_SHEET:
|
|
|
|
parsingMode = css::eAgentSheetFeatures;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case USER_SHEET:
|
|
|
|
parsingMode = css::eUserSheetFeatures;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUTHOR_SHEET:
|
|
|
|
parsingMode = css::eAuthorSheetFeatures;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_WARNING("invalid sheet type argument");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
|
2018-03-21 15:01:25 +03:00
|
|
|
RefPtr<StyleSheet> servoSheet;
|
2018-03-28 18:33:01 +03:00
|
|
|
nsresult rv = LoadSheet(aSheetURI, parsingMode, &servoSheet);
|
2018-03-21 15:01:25 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
MOZ_ASSERT(servoSheet);
|
|
|
|
mServoSheets[aSheetType].AppendElement(servoSheet);
|
2005-01-15 03:10:19 +03:00
|
|
|
|
2017-02-21 05:42:27 +03:00
|
|
|
return NS_OK;
|
2005-03-23 05:34:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStyleSheetService::SheetRegistered(nsIURI *sheetURI,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aSheetType, bool *_retval)
|
2005-03-23 05:34:30 +03:00
|
|
|
{
|
2012-10-16 23:45:50 +04:00
|
|
|
NS_ENSURE_ARG(aSheetType == AGENT_SHEET ||
|
|
|
|
aSheetType == USER_SHEET ||
|
|
|
|
aSheetType == AUTHOR_SHEET);
|
2005-03-23 05:34:30 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(sheetURI);
|
|
|
|
NS_PRECONDITION(_retval, "Null out param");
|
|
|
|
|
2018-02-01 07:04:04 +03:00
|
|
|
// Check to see if we have the sheet.
|
|
|
|
StyleBackendType backendType =
|
|
|
|
StyleBackendType::Servo;
|
|
|
|
*_retval = (FindSheetByURI(backendType, aSheetType, sheetURI) >= 0);
|
2005-03-23 05:34:30 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-20 05:33:49 +03:00
|
|
|
static nsresult
|
|
|
|
GetParsingMode(uint32_t aSheetType, css::SheetParsingMode* aParsingMode)
|
|
|
|
{
|
|
|
|
switch (aSheetType) {
|
|
|
|
case nsStyleSheetService::AGENT_SHEET:
|
|
|
|
*aParsingMode = css::eAgentSheetFeatures;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case nsStyleSheetService::USER_SHEET:
|
|
|
|
*aParsingMode = css::eUserSheetFeatures;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case nsStyleSheetService::AUTHOR_SHEET:
|
|
|
|
*aParsingMode = css::eAuthorSheetFeatures;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_WARNING("invalid sheet type argument");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-09 13:43:33 +04:00
|
|
|
NS_IMETHODIMP
|
2017-01-05 10:32:22 +03:00
|
|
|
nsStyleSheetService::PreloadSheet(nsIURI* aSheetURI, uint32_t aSheetType,
|
|
|
|
nsIPreloadedStyleSheet** aSheet)
|
2014-07-09 13:43:33 +04:00
|
|
|
{
|
2015-09-03 21:41:39 +03:00
|
|
|
NS_PRECONDITION(aSheet, "Null out param");
|
2015-10-14 00:43:16 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aSheetURI);
|
2017-01-05 10:32:22 +03:00
|
|
|
|
2015-10-14 00:43:16 +03:00
|
|
|
css::SheetParsingMode parsingMode;
|
2017-03-20 05:33:49 +03:00
|
|
|
nsresult rv = GetParsingMode(aSheetType, &parsingMode);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-10-14 00:43:16 +03:00
|
|
|
|
2017-03-20 05:33:49 +03:00
|
|
|
RefPtr<PreloadedStyleSheet> sheet;
|
|
|
|
rv = PreloadedStyleSheet::Create(aSheetURI, parsingMode,
|
|
|
|
getter_AddRefs(sheet));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-10-14 00:43:16 +03:00
|
|
|
|
2017-03-20 05:33:49 +03:00
|
|
|
rv = sheet->Preload();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-10-14 00:43:16 +03:00
|
|
|
|
2017-03-20 05:33:49 +03:00
|
|
|
sheet.forget(aSheet);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStyleSheetService::PreloadSheetAsync(nsIURI* aSheetURI, uint32_t aSheetType,
|
|
|
|
JSContext* aCx,
|
|
|
|
JS::MutableHandleValue aRval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aSheetURI);
|
|
|
|
|
|
|
|
css::SheetParsingMode parsingMode;
|
|
|
|
nsresult rv = GetParsingMode(aSheetType, &parsingMode);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIGlobalObject> global =
|
|
|
|
xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx));
|
|
|
|
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
ErrorResult errv;
|
|
|
|
RefPtr<dom::Promise> promise = dom::Promise::Create(global, errv);
|
|
|
|
if (errv.Failed()) {
|
|
|
|
return errv.StealNSResult();
|
2015-10-14 00:43:16 +03:00
|
|
|
}
|
2014-07-09 13:43:33 +04:00
|
|
|
|
2017-01-05 10:32:22 +03:00
|
|
|
RefPtr<PreloadedStyleSheet> sheet;
|
2017-03-20 05:33:49 +03:00
|
|
|
rv = PreloadedStyleSheet::Create(aSheetURI, parsingMode,
|
|
|
|
getter_AddRefs(sheet));
|
2014-07-09 13:43:33 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2016-02-24 10:01:12 +03:00
|
|
|
|
2017-03-20 05:33:49 +03:00
|
|
|
sheet->PreloadAsync(WrapNotNull(promise));
|
|
|
|
|
|
|
|
if (!ToJSValue(aCx, promise, aRval)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-07-09 13:43:33 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-03-23 05:34:30 +03:00
|
|
|
NS_IMETHODIMP
|
2013-08-27 21:10:39 +04:00
|
|
|
nsStyleSheetService::UnregisterSheet(nsIURI *aSheetURI, uint32_t aSheetType)
|
2005-03-23 05:34:30 +03:00
|
|
|
{
|
2012-10-16 23:45:50 +04:00
|
|
|
NS_ENSURE_ARG(aSheetType == AGENT_SHEET ||
|
|
|
|
aSheetType == USER_SHEET ||
|
|
|
|
aSheetType == AUTHOR_SHEET);
|
2013-08-27 21:10:39 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aSheetURI);
|
2005-03-23 05:34:30 +03:00
|
|
|
|
2017-09-29 02:45:09 +03:00
|
|
|
// We have to search for Gecko and Servo sheets separately.
|
2018-02-01 07:04:04 +03:00
|
|
|
int32_t foundIndex;
|
|
|
|
|
2017-09-29 02:45:09 +03:00
|
|
|
|
|
|
|
// Now search for Servo, which may or may not be present.
|
|
|
|
RefPtr<StyleSheet> servoSheet;
|
|
|
|
foundIndex = FindSheetByURI(StyleBackendType::Servo,
|
|
|
|
aSheetType, aSheetURI);
|
|
|
|
if (foundIndex >= 0) {
|
|
|
|
servoSheet = mServoSheets[aSheetType][foundIndex];
|
|
|
|
mServoSheets[aSheetType].RemoveElementAt(foundIndex);
|
|
|
|
}
|
2017-02-21 05:42:27 +03:00
|
|
|
|
|
|
|
// Hold on to a copy of the registered PresShells.
|
|
|
|
nsTArray<nsCOMPtr<nsIPresShell>> toNotify(mPresShells);
|
|
|
|
for (nsIPresShell* presShell : toNotify) {
|
|
|
|
if (presShell->StyleSet()) {
|
2018-02-01 07:04:04 +03:00
|
|
|
StyleSheet* sheet =
|
|
|
|
servoSheet;
|
2017-09-29 02:45:09 +03:00
|
|
|
if (sheet) {
|
|
|
|
presShell->NotifyStyleSheetServiceSheetRemoved(sheet, aSheetType);
|
|
|
|
}
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
2015-11-17 09:04:09 +03:00
|
|
|
}
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2013-08-27 21:10:39 +04:00
|
|
|
nsTArray<dom::ContentParent*> children;
|
|
|
|
dom::ContentParent::GetAll(children);
|
|
|
|
|
|
|
|
if (children.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-24 10:29:24 +04:00
|
|
|
mozilla::ipc::URIParams uri;
|
2013-08-27 21:10:39 +04:00
|
|
|
SerializeURI(aSheetURI, uri);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < children.Length(); i++) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << children[i]->SendUnregisterSheet(uri, aSheetType);
|
2013-08-27 21:10:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-15 03:10:19 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-10-12 08:05:38 +04:00
|
|
|
|
2012-10-16 23:45:56 +04:00
|
|
|
//static
|
|
|
|
nsStyleSheetService *
|
|
|
|
nsStyleSheetService::GetInstance()
|
|
|
|
{
|
|
|
|
static bool first = true;
|
|
|
|
if (first) {
|
|
|
|
// make sure at first call that it's inited
|
|
|
|
nsCOMPtr<nsIStyleSheetService> dummy =
|
|
|
|
do_GetService(NS_STYLESHEETSERVICE_CONTRACTID);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gInstance;
|
|
|
|
}
|
|
|
|
|
2013-12-08 10:09:10 +04:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(StyleSheetServiceMallocSizeOf)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStyleSheetService::CollectReports(nsIHandleReportCallback* aHandleReport,
|
2014-05-21 10:06:54 +04:00
|
|
|
nsISupports* aData, bool aAnonymize)
|
2013-11-07 09:35:30 +04:00
|
|
|
{
|
2016-08-24 08:23:45 +03:00
|
|
|
MOZ_COLLECT_REPORT(
|
2013-12-08 10:09:10 +04:00
|
|
|
"explicit/layout/style-sheet-service", KIND_HEAP, UNITS_BYTES,
|
|
|
|
SizeOfIncludingThis(StyleSheetServiceMallocSizeOf),
|
|
|
|
"Memory used for style sheets held by the style sheet service.");
|
2016-08-24 08:23:45 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2013-11-07 09:35:30 +04:00
|
|
|
}
|
|
|
|
|
2012-10-12 08:05:38 +04:00
|
|
|
size_t
|
2013-11-07 09:35:30 +04:00
|
|
|
nsStyleSheetService::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-10-12 08:05:38 +04:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
2018-02-01 07:04:04 +03:00
|
|
|
for (auto* sheetArrays : {
|
|
|
|
&mServoSheets,
|
|
|
|
}) {
|
2017-02-21 05:42:27 +03:00
|
|
|
for (auto& sheetArray : *sheetArrays) {
|
|
|
|
n += sheetArray.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
for (StyleSheet* sheet : sheetArray) {
|
|
|
|
if (sheet) {
|
|
|
|
n += sheet->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
}
|
2015-11-17 09:04:09 +03:00
|
|
|
}
|
|
|
|
}
|
2012-10-12 08:05:38 +04:00
|
|
|
return n;
|
|
|
|
}
|
2017-02-17 10:56:28 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleSheetService::RegisterPresShell(nsIPresShell* aPresShell)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mPresShells.Contains(aPresShell));
|
|
|
|
mPresShells.AppendElement(aPresShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleSheetService::UnregisterPresShell(nsIPresShell* aPresShell)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPresShells.Contains(aPresShell));
|
|
|
|
mPresShells.RemoveElement(aPresShell);
|
|
|
|
}
|