2004-03-09 22:59:09 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-01-18 04:45:12 +04:00
|
|
|
/* 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/. */
|
2004-03-09 22:59:09 +03:00
|
|
|
|
|
|
|
#include "nsLayoutStylesheetCache.h"
|
|
|
|
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2014-02-26 16:26:14 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheet.h"
|
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Loader.h"
|
2016-02-26 04:51:02 +03:00
|
|
|
#include "mozilla/dom/SRIMetadata.h"
|
2017-03-28 12:05:12 +03:00
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#include "nsColor.h"
|
2016-12-06 20:25:00 +03:00
|
|
|
#include "nsIConsoleService.h"
|
2004-03-09 22:59:09 +03:00
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIObserverService.h"
|
2004-11-25 01:48:45 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2009-06-22 15:34:41 +04:00
|
|
|
#include "nsIXULRuntime.h"
|
2017-03-28 12:05:12 +03:00
|
|
|
#include "nsPresContext.h"
|
2014-09-10 05:10:18 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2016-07-21 13:57:35 +03:00
|
|
|
#include "nsXULAppAPI.h"
|
2004-03-09 22:59:09 +03:00
|
|
|
|
2016-12-06 20:25:00 +03:00
|
|
|
// Includes for the crash report annotation in ErrorLoadingSheet.
|
2015-10-13 01:03:56 +03:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "mozilla/Omnijar.h"
|
|
|
|
#include "nsDirectoryService.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsExceptionHandler.h"
|
|
|
|
#include "nsIChromeRegistry.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsISubstitutingProtocolHandler.h"
|
2015-11-16 11:18:45 +03:00
|
|
|
#include "zlib.h"
|
|
|
|
#include "nsZipArchive.h"
|
2015-10-13 01:03:56 +03:00
|
|
|
#endif
|
|
|
|
|
2014-02-26 16:26:14 +04:00
|
|
|
using namespace mozilla;
|
2015-10-14 00:43:16 +03:00
|
|
|
using namespace mozilla::css;
|
2014-02-26 16:26:14 +04:00
|
|
|
|
|
|
|
static bool sNumberControlEnabled;
|
|
|
|
|
|
|
|
#define NUMBER_CONTROL_PREF "dom.forms.number"
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(
|
2013-12-08 10:09:10 +04:00
|
|
|
nsLayoutStylesheetCache, nsIObserver, nsIMemoryReporter)
|
2004-03-09 22:59:09 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLayoutStylesheetCache::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData)
|
2004-03-09 22:59:09 +03:00
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, "profile-before-change")) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mUserContentSheet = nullptr;
|
|
|
|
mUserChromeSheet = nullptr;
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
else if (!strcmp(aTopic, "profile-do-change")) {
|
|
|
|
InitFromProfile();
|
|
|
|
}
|
|
|
|
else if (strcmp(aTopic, "chrome-flush-skin-caches") == 0 ||
|
|
|
|
strcmp(aTopic, "chrome-flush-caches") == 0) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mScrollbarsSheet = nullptr;
|
|
|
|
mFormsSheet = nullptr;
|
2014-02-26 16:26:14 +04:00
|
|
|
mNumberControlSheet = nullptr;
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Unexpected observer topic.");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2004-03-09 22:59:09 +03:00
|
|
|
nsLayoutStylesheetCache::ScrollbarsSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
if (!mScrollbarsSheet) {
|
2006-06-15 07:20:19 +04:00
|
|
|
// Scrollbars don't need access to unsafe rules
|
2014-09-12 01:41:35 +04:00
|
|
|
LoadSheetURL("chrome://global/skin/scrollbars.css",
|
2017-04-28 07:17:14 +03:00
|
|
|
&mScrollbarsSheet, eSafeAgentSheetFeatures, eCrash);
|
2004-03-23 21:26:43 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return mScrollbarsSheet;
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2004-03-09 22:59:09 +03:00
|
|
|
nsLayoutStylesheetCache::FormsSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
if (!mFormsSheet) {
|
2006-06-15 07:20:19 +04:00
|
|
|
// forms.css needs access to unsafe rules
|
2014-09-12 01:41:35 +04:00
|
|
|
LoadSheetURL("resource://gre-resources/forms.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mFormsSheet, eAgentSheetFeatures, eCrash);
|
2004-03-23 21:26:43 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return mFormsSheet;
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2014-02-26 16:26:14 +04:00
|
|
|
nsLayoutStylesheetCache::NumberControlSheet()
|
|
|
|
{
|
|
|
|
if (!sNumberControlEnabled) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
if (!mNumberControlSheet) {
|
2014-09-12 01:41:35 +04:00
|
|
|
LoadSheetURL("resource://gre-resources/number-control.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mNumberControlSheet, eAgentSheetFeatures, eCrash);
|
2014-02-26 16:26:14 +04:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return mNumberControlSheet;
|
2014-02-26 16:26:14 +04:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2004-03-09 22:59:09 +03:00
|
|
|
nsLayoutStylesheetCache::UserContentSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
return mUserContentSheet;
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2004-03-09 22:59:09 +03:00
|
|
|
nsLayoutStylesheetCache::UserChromeSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
return mUserChromeSheet;
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2008-11-03 05:29:51 +03:00
|
|
|
nsLayoutStylesheetCache::UASheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
if (!mUASheet) {
|
2016-01-15 01:11:44 +03:00
|
|
|
LoadSheetURL("resource://gre-resources/ua.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mUASheet, eAgentSheetFeatures, eCrash);
|
2016-01-15 01:11:44 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return mUASheet;
|
2008-11-03 05:29:51 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2014-05-24 23:29:11 +04:00
|
|
|
nsLayoutStylesheetCache::HTMLSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
return mHTMLSheet;
|
2014-05-24 23:29:11 +04:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2014-05-24 22:51:06 +04:00
|
|
|
nsLayoutStylesheetCache::MinimalXULSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
return mMinimalXULSheet;
|
2014-05-24 22:51:06 +04:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2014-05-24 22:51:06 +04:00
|
|
|
nsLayoutStylesheetCache::XULSheet()
|
|
|
|
{
|
2017-03-07 14:43:16 +03:00
|
|
|
if (!mXULSheet) {
|
|
|
|
LoadSheetURL("chrome://global/content/xul.css",
|
|
|
|
&mXULSheet, eAgentSheetFeatures, eCrash);
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return mXULSheet;
|
2014-05-24 22:51:06 +04:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2008-11-03 05:29:51 +03:00
|
|
|
nsLayoutStylesheetCache::QuirkSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
return mQuirkSheet;
|
2008-11-03 05:29:51 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2014-05-24 22:46:38 +04:00
|
|
|
nsLayoutStylesheetCache::SVGSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
return mSVGSheet;
|
2014-05-24 22:46:38 +04:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2014-05-24 22:46:38 +04:00
|
|
|
nsLayoutStylesheetCache::MathMLSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
if (!mMathMLSheet) {
|
2014-09-12 01:41:35 +04:00
|
|
|
LoadSheetURL("resource://gre-resources/mathml.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mMathMLSheet, eAgentSheetFeatures, eCrash);
|
2014-05-24 22:46:38 +04:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return mMathMLSheet;
|
2014-05-24 22:46:38 +04:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2014-06-12 05:12:00 +04:00
|
|
|
nsLayoutStylesheetCache::CounterStylesSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
return mCounterStylesSheet;
|
2014-06-12 05:12:00 +04:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2015-06-16 04:34:47 +03:00
|
|
|
nsLayoutStylesheetCache::NoScriptSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
if (!mNoScriptSheet) {
|
2016-01-04 01:26:58 +03:00
|
|
|
LoadSheetURL("resource://gre-resources/noscript.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mNoScriptSheet, eAgentSheetFeatures, eCrash);
|
2015-06-16 04:34:47 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return mNoScriptSheet;
|
2015-06-16 04:34:47 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2015-06-16 04:34:47 +03:00
|
|
|
nsLayoutStylesheetCache::NoFramesSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
if (!mNoFramesSheet) {
|
2016-01-04 01:26:58 +03:00
|
|
|
LoadSheetURL("resource://gre-resources/noframes.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mNoFramesSheet, eAgentSheetFeatures, eCrash);
|
2015-06-16 04:34:47 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return mNoFramesSheet;
|
2015-06-16 04:34:47 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2015-06-16 04:34:48 +03:00
|
|
|
nsLayoutStylesheetCache::ChromePreferenceSheet(nsPresContext* aPresContext)
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
if (!mChromePreferenceSheet) {
|
2016-04-14 02:55:47 +03:00
|
|
|
BuildPreferenceSheet(&mChromePreferenceSheet, aPresContext);
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return mChromePreferenceSheet;
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2015-06-16 04:34:48 +03:00
|
|
|
nsLayoutStylesheetCache::ContentPreferenceSheet(nsPresContext* aPresContext)
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
if (!mContentPreferenceSheet) {
|
2016-04-14 02:55:47 +03:00
|
|
|
BuildPreferenceSheet(&mContentPreferenceSheet, aPresContext);
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return mContentPreferenceSheet;
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2015-06-16 04:34:48 +03:00
|
|
|
nsLayoutStylesheetCache::ContentEditableSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
if (!mContentEditableSheet) {
|
2015-06-16 04:34:48 +03:00
|
|
|
LoadSheetURL("resource://gre/res/contenteditable.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mContentEditableSheet, eAgentSheetFeatures, eCrash);
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return mContentEditableSheet;
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet*
|
2015-06-16 04:34:48 +03:00
|
|
|
nsLayoutStylesheetCache::DesignModeSheet()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
if (!mDesignModeSheet) {
|
2015-06-16 04:34:48 +03:00
|
|
|
LoadSheetURL("resource://gre/res/designmode.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mDesignModeSheet, eAgentSheetFeatures, eCrash);
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return mDesignModeSheet;
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
|
|
|
|
2004-03-09 22:59:09 +03:00
|
|
|
void
|
|
|
|
nsLayoutStylesheetCache::Shutdown()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
gCSSLoader_Gecko = nullptr;
|
|
|
|
gCSSLoader_Servo = nullptr;
|
2017-06-05 23:57:36 +03:00
|
|
|
NS_WARNING_ASSERTION(!gStyleCache_Gecko || !gUserContentSheetURL_Gecko,
|
|
|
|
"Got the URL but never used by Gecko?");
|
|
|
|
NS_WARNING_ASSERTION(!gStyleCache_Servo || !gUserContentSheetURL_Servo,
|
|
|
|
"Got the URL but never used by Servo?");
|
2016-02-24 10:01:12 +03:00
|
|
|
gStyleCache_Gecko = nullptr;
|
|
|
|
gStyleCache_Servo = nullptr;
|
2017-05-03 14:48:48 +03:00
|
|
|
gUserContentSheetURL_Gecko = nullptr;
|
|
|
|
gUserContentSheetURL_Servo = nullptr;
|
2016-07-21 13:57:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLayoutStylesheetCache::SetUserContentCSSURL(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(XRE_IsContentProcess(), "Only used in content processes.");
|
2017-05-03 14:48:48 +03:00
|
|
|
gUserContentSheetURL_Gecko = aURI;
|
|
|
|
gUserContentSheetURL_Servo = aURI;
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
|
2013-12-08 10:09:10 +04:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(LayoutStylesheetCacheMallocSizeOf)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLayoutStylesheetCache::CollectReports(nsIHandleReportCallback* aHandleReport,
|
2014-05-21 10:06:54 +04:00
|
|
|
nsISupports* aData, bool aAnonymize)
|
2012-01-03 06:19:14 +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-cache", KIND_HEAP, UNITS_BYTES,
|
|
|
|
SizeOfIncludingThis(LayoutStylesheetCacheMallocSizeOf),
|
|
|
|
"Memory used for some built-in style sheets.");
|
2016-08-24 08:23:45 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2012-01-03 06:19:14 +04:00
|
|
|
}
|
|
|
|
|
2013-12-08 10:09:10 +04:00
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
2013-11-07 09:35:30 +04:00
|
|
|
nsLayoutStylesheetCache::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
|
|
|
|
#define MEASURE(s) n += s ? s->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
|
2015-06-16 04:34:48 +03:00
|
|
|
MEASURE(mChromePreferenceSheet);
|
2015-06-16 04:34:48 +03:00
|
|
|
MEASURE(mContentEditableSheet);
|
2015-06-16 04:34:48 +03:00
|
|
|
MEASURE(mContentPreferenceSheet);
|
2014-09-12 01:41:35 +04:00
|
|
|
MEASURE(mCounterStylesSheet);
|
2015-06-16 04:34:48 +03:00
|
|
|
MEASURE(mDesignModeSheet);
|
2012-01-03 06:19:14 +04:00
|
|
|
MEASURE(mFormsSheet);
|
2014-05-24 23:29:11 +04:00
|
|
|
MEASURE(mHTMLSheet);
|
2014-09-12 01:41:35 +04:00
|
|
|
MEASURE(mMathMLSheet);
|
2014-05-24 22:51:06 +04:00
|
|
|
MEASURE(mMinimalXULSheet);
|
2015-06-16 04:34:47 +03:00
|
|
|
MEASURE(mNoFramesSheet);
|
2015-06-16 04:34:47 +03:00
|
|
|
MEASURE(mNoScriptSheet);
|
2014-09-12 01:41:35 +04:00
|
|
|
MEASURE(mNumberControlSheet);
|
2012-01-03 06:19:14 +04:00
|
|
|
MEASURE(mQuirkSheet);
|
2014-05-24 22:46:38 +04:00
|
|
|
MEASURE(mSVGSheet);
|
2014-09-12 01:41:35 +04:00
|
|
|
MEASURE(mScrollbarsSheet);
|
|
|
|
MEASURE(mUASheet);
|
|
|
|
MEASURE(mUserChromeSheet);
|
|
|
|
MEASURE(mUserContentSheet);
|
|
|
|
MEASURE(mXULSheet);
|
2012-01-03 06:19:14 +04:00
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
2016-02-24 10:01:12 +03:00
|
|
|
// - gCSSLoader_Gecko
|
|
|
|
// - gCSSLoader_Servo
|
2012-01-03 06:19:14 +04:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
nsLayoutStylesheetCache::nsLayoutStylesheetCache(StyleBackendType aType)
|
|
|
|
: mBackendType(aType)
|
2004-03-09 22:59:09 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
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
|
|
|
mozilla::services::GetObserverService();
|
2004-03-09 22:59:09 +03:00
|
|
|
NS_ASSERTION(obsSvc, "No global observer service?");
|
|
|
|
|
|
|
|
if (obsSvc) {
|
2011-10-17 18:59:28 +04:00
|
|
|
obsSvc->AddObserver(this, "profile-before-change", false);
|
|
|
|
obsSvc->AddObserver(this, "profile-do-change", false);
|
|
|
|
obsSvc->AddObserver(this, "chrome-flush-skin-caches", false);
|
|
|
|
obsSvc->AddObserver(this, "chrome-flush-caches", false);
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
InitFromProfile();
|
2008-11-03 05:29:51 +03:00
|
|
|
|
|
|
|
// And make sure that we load our UA sheets. No need to do this
|
|
|
|
// per-profile, since they're profile-invariant.
|
2014-09-12 01:41:35 +04:00
|
|
|
LoadSheetURL("resource://gre-resources/counterstyles.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mCounterStylesSheet, eAgentSheetFeatures, eCrash);
|
2016-11-16 09:02:58 +03:00
|
|
|
LoadSheetURL("resource://gre-resources/html.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mHTMLSheet, eAgentSheetFeatures, eCrash);
|
2014-09-12 01:41:35 +04:00
|
|
|
LoadSheetURL("chrome://global/content/minimal-xul.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mMinimalXULSheet, eAgentSheetFeatures, eCrash);
|
2014-09-12 01:41:35 +04:00
|
|
|
LoadSheetURL("resource://gre-resources/quirk.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mQuirkSheet, eAgentSheetFeatures, eCrash);
|
2014-09-12 01:41:35 +04:00
|
|
|
LoadSheetURL("resource://gre/res/svg.css",
|
2016-12-06 20:25:00 +03:00
|
|
|
&mSVGSheet, eAgentSheetFeatures, eCrash);
|
2017-03-07 14:43:16 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
// We know we need xul.css for the UI, so load that now too:
|
|
|
|
XULSheet();
|
|
|
|
}
|
2014-09-12 01:41:35 +04:00
|
|
|
|
2017-05-03 14:48:48 +03:00
|
|
|
auto& userContentSheetURL = aType == StyleBackendType::Gecko ?
|
|
|
|
gUserContentSheetURL_Gecko :
|
|
|
|
gUserContentSheetURL_Servo;
|
|
|
|
if (userContentSheetURL) {
|
2016-07-21 13:57:35 +03:00
|
|
|
MOZ_ASSERT(XRE_IsContentProcess(), "Only used in content processes.");
|
2017-05-03 14:48:48 +03:00
|
|
|
LoadSheet(userContentSheetURL, &mUserContentSheet, eUserSheetFeatures, eLogToConsole);
|
|
|
|
userContentSheetURL = nullptr;
|
2016-07-21 13:57:35 +03:00
|
|
|
}
|
|
|
|
|
2014-11-14 01:11:20 +03:00
|
|
|
// The remaining sheets are created on-demand do to their use being rarer
|
|
|
|
// (which helps save memory for Firefox OS apps) or because they need to
|
|
|
|
// be re-loadable in DependentPrefChanged.
|
2012-01-03 06:19:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsLayoutStylesheetCache::~nsLayoutStylesheetCache()
|
|
|
|
{
|
2013-12-08 10:09:10 +04:00
|
|
|
mozilla::UnregisterWeakMemoryReporter(this);
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
void
|
|
|
|
nsLayoutStylesheetCache::InitMemoryReporter()
|
|
|
|
{
|
2013-12-08 10:09:10 +04:00
|
|
|
mozilla::RegisterWeakMemoryReporter(this);
|
2013-11-07 09:35:30 +04:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
/* static */ nsLayoutStylesheetCache*
|
|
|
|
nsLayoutStylesheetCache::For(StyleBackendType aType)
|
2004-03-09 22:59:09 +03:00
|
|
|
{
|
2014-09-12 01:41:35 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
bool mustInit = !gStyleCache_Gecko && !gStyleCache_Servo;
|
|
|
|
auto& cache = aType == StyleBackendType::Gecko ? gStyleCache_Gecko :
|
|
|
|
gStyleCache_Servo;
|
|
|
|
|
|
|
|
if (!cache) {
|
|
|
|
cache = new nsLayoutStylesheetCache(aType);
|
|
|
|
cache->InitMemoryReporter();
|
|
|
|
}
|
2004-03-09 22:59:09 +03:00
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
if (mustInit) {
|
|
|
|
// Initialization that only needs to be done once for both
|
|
|
|
// nsLayoutStylesheetCaches.
|
2004-03-09 22:59:09 +03:00
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
Preferences::AddBoolVarCache(&sNumberControlEnabled, NUMBER_CONTROL_PREF,
|
|
|
|
true);
|
2014-02-26 16:26:14 +04:00
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
// For each pref that controls a CSS feature that a UA style sheet depends
|
|
|
|
// on (such as a pref that enables a property that a UA style sheet uses),
|
|
|
|
// register DependentPrefChanged as a callback to ensure that the relevant
|
|
|
|
// style sheets will be re-parsed.
|
|
|
|
// Preferences::RegisterCallback(&DependentPrefChanged,
|
|
|
|
// "layout.css.example-pref.enabled");
|
|
|
|
Preferences::RegisterCallback(&DependentPrefChanged,
|
|
|
|
"layout.css.grid.enabled");
|
|
|
|
}
|
2014-11-14 01:11:19 +03:00
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
return cache;
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLayoutStylesheetCache::InitFromProfile()
|
|
|
|
{
|
2009-06-22 15:34:41 +04:00
|
|
|
nsCOMPtr<nsIXULRuntime> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
|
|
|
|
if (appInfo) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool inSafeMode = false;
|
2009-06-22 15:34:41 +04:00
|
|
|
appInfo->GetInSafeMode(&inSafeMode);
|
|
|
|
if (inSafeMode)
|
|
|
|
return;
|
|
|
|
}
|
2004-03-09 22:59:09 +03:00
|
|
|
nsCOMPtr<nsIFile> contentFile;
|
|
|
|
nsCOMPtr<nsIFile> chromeFile;
|
|
|
|
|
|
|
|
NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR,
|
|
|
|
getter_AddRefs(contentFile));
|
|
|
|
if (!contentFile) {
|
|
|
|
// if we don't have a profile yet, that's OK!
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
contentFile->Clone(getter_AddRefs(chromeFile));
|
|
|
|
if (!chromeFile) return;
|
|
|
|
|
|
|
|
contentFile->Append(NS_LITERAL_STRING("userContent.css"));
|
|
|
|
chromeFile->Append(NS_LITERAL_STRING("userChrome.css"));
|
|
|
|
|
2016-12-06 20:25:00 +03:00
|
|
|
LoadSheetFile(contentFile, &mUserContentSheet, eUserSheetFeatures, eLogToConsole);
|
|
|
|
LoadSheetFile(chromeFile, &mUserChromeSheet, eUserSheetFeatures, eLogToConsole);
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
void
|
2014-09-12 01:41:35 +04:00
|
|
|
nsLayoutStylesheetCache::LoadSheetURL(const char* aURL,
|
2016-09-26 15:03:25 +03:00
|
|
|
RefPtr<StyleSheet>* aSheet,
|
2016-12-06 20:25:00 +03:00
|
|
|
SheetParsingMode aParsingMode,
|
|
|
|
FailureAction aFailureAction)
|
2014-09-12 01:41:35 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), aURL);
|
2016-12-06 20:25:00 +03:00
|
|
|
LoadSheet(uri, aSheet, aParsingMode, aFailureAction);
|
2014-09-12 01:41:35 +04:00
|
|
|
if (!aSheet) {
|
|
|
|
NS_ERROR(nsPrintfCString("Could not load %s", aURL).get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-09 22:59:09 +03:00
|
|
|
void
|
2015-10-14 00:43:16 +03:00
|
|
|
nsLayoutStylesheetCache::LoadSheetFile(nsIFile* aFile,
|
2016-09-26 15:03:25 +03:00
|
|
|
RefPtr<StyleSheet>* aSheet,
|
2016-12-06 20:25:00 +03:00
|
|
|
SheetParsingMode aParsingMode,
|
|
|
|
FailureAction aFailureAction)
|
2004-03-09 22:59:09 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool exists = false;
|
2004-03-09 22:59:09 +03:00
|
|
|
aFile->Exists(&exists);
|
|
|
|
|
|
|
|
if (!exists) return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewFileURI(getter_AddRefs(uri), aFile);
|
|
|
|
|
2016-12-06 20:25:00 +03:00
|
|
|
LoadSheet(uri, aSheet, aParsingMode, aFailureAction);
|
2004-03-09 22:59:09 +03:00
|
|
|
}
|
|
|
|
|
2015-10-13 01:03:56 +03:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2015-11-16 11:18:45 +03:00
|
|
|
static inline nsresult
|
|
|
|
ComputeCRC32(nsIFile* aFile, uint32_t* aResult)
|
|
|
|
{
|
|
|
|
PRFileDesc* fd;
|
|
|
|
nsresult rv = aFile->OpenNSPRFileDesc(PR_RDONLY, 0, &fd);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
uint32_t crc = crc32(0, nullptr, 0);
|
|
|
|
|
|
|
|
unsigned char buf[512];
|
|
|
|
int32_t n;
|
|
|
|
while ((n = PR_Read(fd, buf, sizeof(buf))) > 0) {
|
|
|
|
crc = crc32(crc, buf, n);
|
|
|
|
}
|
|
|
|
PR_Close(fd);
|
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = crc;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-13 01:03:56 +03:00
|
|
|
static void
|
|
|
|
ListInterestingFiles(nsString& aAnnotation, nsIFile* aFile,
|
|
|
|
const nsTArray<nsString>& aInterestingFilenames)
|
|
|
|
{
|
|
|
|
nsString filename;
|
|
|
|
aFile->GetLeafName(filename);
|
|
|
|
for (const nsString& interestingFilename : aInterestingFilenames) {
|
|
|
|
if (interestingFilename == filename) {
|
|
|
|
nsString path;
|
|
|
|
aFile->GetPath(path);
|
|
|
|
aAnnotation.AppendLiteral(" ");
|
|
|
|
aAnnotation.Append(path);
|
|
|
|
aAnnotation.AppendLiteral(" (");
|
|
|
|
int64_t size;
|
|
|
|
if (NS_SUCCEEDED(aFile->GetFileSize(&size))) {
|
2016-12-14 19:32:21 +03:00
|
|
|
aAnnotation.AppendPrintf("%" PRId64, size);
|
2015-10-13 01:03:56 +03:00
|
|
|
} else {
|
|
|
|
aAnnotation.AppendLiteral("???");
|
|
|
|
}
|
2015-11-16 11:18:45 +03:00
|
|
|
aAnnotation.AppendLiteral(" bytes, crc32 = ");
|
|
|
|
uint32_t crc;
|
|
|
|
nsresult rv = ComputeCRC32(aFile, &crc);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aAnnotation.AppendPrintf("0x%08x)\n", crc);
|
|
|
|
} else {
|
|
|
|
aAnnotation.AppendPrintf("error 0x%08x)\n", uint32_t(rv));
|
|
|
|
}
|
2015-10-13 01:03:56 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isDir = false;
|
|
|
|
aFile->IsDirectory(&isDir);
|
|
|
|
|
|
|
|
if (!isDir) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> entries;
|
|
|
|
if (NS_FAILED(aFile->GetDirectoryEntries(getter_AddRefs(entries)))) {
|
|
|
|
aAnnotation.AppendLiteral(" (failed to enumerated directory)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
bool hasMore = false;
|
|
|
|
if (NS_FAILED(entries->HasMoreElements(&hasMore))) {
|
|
|
|
aAnnotation.AppendLiteral(" (failed during directory enumeration)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!hasMore) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> entry;
|
|
|
|
if (NS_FAILED(entries->GetNext(getter_AddRefs(entry)))) {
|
|
|
|
aAnnotation.AppendLiteral(" (failed during directory enumeration)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> file = do_QueryInterface(entry);
|
|
|
|
if (file) {
|
|
|
|
ListInterestingFiles(aAnnotation, file, aInterestingFilenames);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a crash report annotation to help debug issues with style
|
|
|
|
// sheets failing to load (bug 1194856).
|
|
|
|
static void
|
|
|
|
AnnotateCrashReport(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
nsAutoCString spec;
|
|
|
|
nsAutoCString scheme;
|
|
|
|
nsDependentCSubstring filename;
|
|
|
|
if (aURI) {
|
2016-08-31 13:10:10 +03:00
|
|
|
spec = aURI->GetSpecOrDefault();
|
2015-10-13 01:03:56 +03:00
|
|
|
aURI->GetScheme(scheme);
|
|
|
|
int32_t i = spec.RFindChar('/');
|
|
|
|
if (i != -1) {
|
|
|
|
filename.Rebind(spec, i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString annotation;
|
|
|
|
|
|
|
|
// The URL of the sheet that failed to load.
|
|
|
|
annotation.AppendLiteral("Error loading sheet: ");
|
|
|
|
annotation.Append(NS_ConvertUTF8toUTF16(spec).get());
|
|
|
|
annotation.Append('\n');
|
|
|
|
|
2015-11-16 11:18:45 +03:00
|
|
|
annotation.AppendLiteral("NS_ERROR_FILE_CORRUPTION reason: ");
|
|
|
|
if (nsZipArchive::sFileCorruptedReason) {
|
|
|
|
annotation.Append(NS_ConvertUTF8toUTF16(nsZipArchive::sFileCorruptedReason).get());
|
|
|
|
annotation.Append('\n');
|
|
|
|
} else {
|
|
|
|
annotation.AppendLiteral("(none)\n");
|
|
|
|
}
|
|
|
|
|
2015-10-13 01:03:56 +03:00
|
|
|
// The jar: or file: URL that the sheet's resource: or chrome: URL
|
|
|
|
// resolves to.
|
|
|
|
if (scheme.EqualsLiteral("resource")) {
|
|
|
|
annotation.AppendLiteral("Real location: ");
|
|
|
|
nsCOMPtr<nsISubstitutingProtocolHandler> handler;
|
|
|
|
nsCOMPtr<nsIIOService> io(do_GetIOService());
|
|
|
|
if (io) {
|
|
|
|
nsCOMPtr<nsIProtocolHandler> ph;
|
|
|
|
io->GetProtocolHandler(scheme.get(), getter_AddRefs(ph));
|
|
|
|
if (ph) {
|
|
|
|
handler = do_QueryInterface(ph);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!handler) {
|
|
|
|
annotation.AppendLiteral("(ResolveURI failed)\n");
|
|
|
|
} else {
|
|
|
|
nsAutoCString resolvedSpec;
|
2016-11-04 13:13:13 +03:00
|
|
|
nsresult rv = handler->ResolveURI(aURI, resolvedSpec);
|
|
|
|
if (NS_FAILED(rv)) {
|
2016-12-14 19:32:21 +03:00
|
|
|
annotation.AppendPrintf("(ResolveURI failed with 0x%08" PRIx32 ")\n",
|
|
|
|
static_cast<uint32_t>(rv));
|
2016-11-04 13:13:13 +03:00
|
|
|
}
|
2015-10-13 01:03:56 +03:00
|
|
|
annotation.Append(NS_ConvertUTF8toUTF16(resolvedSpec));
|
|
|
|
annotation.Append('\n');
|
|
|
|
}
|
|
|
|
} else if (scheme.EqualsLiteral("chrome")) {
|
|
|
|
annotation.AppendLiteral("Real location: ");
|
|
|
|
nsCOMPtr<nsIChromeRegistry> reg =
|
|
|
|
mozilla::services::GetChromeRegistryService();
|
|
|
|
if (!reg) {
|
|
|
|
annotation.AppendLiteral("(no chrome registry)\n");
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIURI> resolvedURI;
|
|
|
|
reg->ConvertChromeURL(aURI, getter_AddRefs(resolvedURI));
|
|
|
|
if (!resolvedURI) {
|
|
|
|
annotation.AppendLiteral("(ConvertChromeURL failed)\n");
|
|
|
|
} else {
|
2016-08-31 13:10:10 +03:00
|
|
|
annotation.Append(
|
|
|
|
NS_ConvertUTF8toUTF16(resolvedURI->GetSpecOrDefault()));
|
2015-10-13 01:03:56 +03:00
|
|
|
annotation.Append('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsString> interestingFiles;
|
|
|
|
interestingFiles.AppendElement(NS_LITERAL_STRING("chrome.manifest"));
|
|
|
|
interestingFiles.AppendElement(NS_LITERAL_STRING("omni.ja"));
|
|
|
|
interestingFiles.AppendElement(NS_ConvertUTF8toUTF16(filename));
|
|
|
|
|
|
|
|
annotation.AppendLiteral("GRE directory: ");
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
nsDirectoryService::gService->Get(NS_GRE_DIR, NS_GET_IID(nsIFile),
|
|
|
|
getter_AddRefs(file));
|
|
|
|
if (file) {
|
|
|
|
// The Firefox installation directory.
|
|
|
|
nsString path;
|
|
|
|
file->GetPath(path);
|
|
|
|
annotation.Append(path);
|
|
|
|
annotation.Append('\n');
|
|
|
|
|
|
|
|
// List interesting files -- any chrome.manifest or omni.ja file or any file
|
|
|
|
// whose name is the sheet's filename -- under the Firefox installation
|
|
|
|
// directory.
|
|
|
|
annotation.AppendLiteral("Interesting files in the GRE directory:\n");
|
|
|
|
ListInterestingFiles(annotation, file, interestingFiles);
|
|
|
|
|
|
|
|
// If the Firefox installation directory has a chrome.manifest file, let's
|
|
|
|
// see what's in it.
|
|
|
|
file->Append(NS_LITERAL_STRING("chrome.manifest"));
|
|
|
|
bool exists = false;
|
|
|
|
file->Exists(&exists);
|
|
|
|
if (exists) {
|
|
|
|
annotation.AppendLiteral("Contents of chrome.manifest:\n[[[\n");
|
|
|
|
PRFileDesc* fd;
|
|
|
|
if (NS_SUCCEEDED(file->OpenNSPRFileDesc(PR_RDONLY, 0, &fd))) {
|
|
|
|
nsCString contents;
|
|
|
|
char buf[512];
|
|
|
|
int32_t n;
|
|
|
|
while ((n = PR_Read(fd, buf, sizeof(buf))) > 0) {
|
|
|
|
contents.Append(buf, n);
|
|
|
|
}
|
|
|
|
if (n < 0) {
|
|
|
|
annotation.AppendLiteral(" (error while reading)\n");
|
|
|
|
} else {
|
|
|
|
annotation.Append(NS_ConvertUTF8toUTF16(contents));
|
|
|
|
}
|
|
|
|
PR_Close(fd);
|
|
|
|
}
|
|
|
|
annotation.AppendLiteral("]]]\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
annotation.AppendLiteral("(none)\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// The jar: or file: URL prefix that chrome: and resource: URLs get translated
|
|
|
|
// to.
|
|
|
|
annotation.AppendLiteral("GRE omnijar URI string: ");
|
|
|
|
nsCString uri;
|
|
|
|
nsresult rv = Omnijar::GetURIString(Omnijar::GRE, uri);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
annotation.AppendLiteral("(failed)\n");
|
|
|
|
} else {
|
|
|
|
annotation.Append(NS_ConvertUTF8toUTF16(uri));
|
|
|
|
annotation.Append('\n');
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsZipArchive> zip = Omnijar::GetReader(Omnijar::GRE);
|
2015-10-13 01:03:56 +03:00
|
|
|
if (zip) {
|
|
|
|
// List interesting files in the GRE omnijar.
|
|
|
|
annotation.AppendLiteral("Interesting files in the GRE omnijar:\n");
|
|
|
|
nsZipFind* find;
|
|
|
|
rv = zip->FindInit(nullptr, &find);
|
|
|
|
if (NS_FAILED(rv)) {
|
2016-12-14 19:32:21 +03:00
|
|
|
annotation.AppendPrintf(" (FindInit failed with 0x%08" PRIx32 ")\n",
|
|
|
|
static_cast<uint32_t>(rv));
|
2015-10-13 01:03:56 +03:00
|
|
|
} else if (!find) {
|
|
|
|
annotation.AppendLiteral(" (FindInit returned null)\n");
|
|
|
|
} else {
|
|
|
|
const char* result;
|
|
|
|
uint16_t len;
|
|
|
|
while (NS_SUCCEEDED(find->FindNext(&result, &len))) {
|
|
|
|
nsCString itemPathname;
|
|
|
|
nsString itemFilename;
|
|
|
|
itemPathname.Append(result, len);
|
|
|
|
int32_t i = itemPathname.RFindChar('/');
|
|
|
|
if (i != -1) {
|
|
|
|
itemFilename = NS_ConvertUTF8toUTF16(Substring(itemPathname, i + 1));
|
|
|
|
}
|
|
|
|
for (const nsString& interestingFile : interestingFiles) {
|
|
|
|
if (interestingFile == itemFilename) {
|
|
|
|
annotation.AppendLiteral(" ");
|
|
|
|
annotation.Append(NS_ConvertUTF8toUTF16(itemPathname));
|
|
|
|
nsZipItem* item = zip->GetItem(itemPathname.get());
|
|
|
|
if (!item) {
|
|
|
|
annotation.AppendLiteral(" (GetItem failed)\n");
|
|
|
|
} else {
|
|
|
|
annotation.AppendPrintf(" (%d bytes, crc32 = 0x%08x)\n",
|
|
|
|
item->RealSize(),
|
|
|
|
item->CRC32());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete find;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
annotation.AppendLiteral("No GRE omnijar\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("SheetLoadFailure"),
|
|
|
|
NS_ConvertUTF16toUTF8(annotation));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-09-10 05:10:18 +04:00
|
|
|
static void
|
2016-12-06 20:25:00 +03:00
|
|
|
ErrorLoadingSheet(nsIURI* aURI, const char* aMsg, FailureAction aFailureAction)
|
|
|
|
{
|
|
|
|
nsPrintfCString errorMessage("%s loading built-in stylesheet '%s'",
|
|
|
|
aMsg,
|
|
|
|
aURI ? aURI->GetSpecOrDefault().get() : "");
|
|
|
|
if (aFailureAction == eLogToConsole) {
|
|
|
|
nsCOMPtr<nsIConsoleService> cs = do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
if (cs) {
|
|
|
|
cs->LogStringMessage(NS_ConvertUTF8toUTF16(errorMessage).get());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-13 01:03:56 +03:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
AnnotateCrashReport(aURI);
|
|
|
|
#endif
|
2016-12-06 20:25:00 +03:00
|
|
|
NS_RUNTIMEABORT(errorMessage.get());
|
2014-09-10 05:10:18 +04:00
|
|
|
}
|
|
|
|
|
2004-03-09 22:59:09 +03:00
|
|
|
void
|
2010-03-03 00:00:53 +03:00
|
|
|
nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI,
|
2016-09-26 15:03:25 +03:00
|
|
|
RefPtr<StyleSheet>* aSheet,
|
2016-12-06 20:25:00 +03:00
|
|
|
SheetParsingMode aParsingMode,
|
|
|
|
FailureAction aFailureAction)
|
2004-03-09 22:59:09 +03:00
|
|
|
{
|
|
|
|
if (!aURI) {
|
2016-12-06 20:25:00 +03:00
|
|
|
ErrorLoadingSheet(aURI, "null URI", eCrash);
|
2004-03-09 22:59:09 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
auto& loader = mBackendType == StyleBackendType::Gecko ?
|
|
|
|
gCSSLoader_Gecko :
|
|
|
|
gCSSLoader_Servo;
|
|
|
|
|
|
|
|
if (!loader) {
|
2017-03-13 12:00:57 +03:00
|
|
|
loader = new Loader(mBackendType, nullptr);
|
2016-02-24 10:01:12 +03:00
|
|
|
if (!loader) {
|
2016-12-06 20:25:00 +03:00
|
|
|
ErrorLoadingSheet(aURI, "no Loader", eCrash);
|
2014-09-10 05:10:18 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-03-03 00:00:53 +03:00
|
|
|
}
|
2004-03-09 22:59:09 +03:00
|
|
|
|
2015-11-16 11:18:45 +03:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
nsZipArchive::sFileCorruptedReason = nullptr;
|
|
|
|
#endif
|
2016-04-14 02:55:47 +03:00
|
|
|
nsresult rv = loader->LoadSheetSync(aURI, aParsingMode, true, aSheet);
|
2014-09-10 05:10:18 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2016-12-06 20:25:00 +03:00
|
|
|
ErrorLoadingSheet(aURI,
|
2016-12-14 19:32:21 +03:00
|
|
|
nsPrintfCString("LoadSheetSync failed with error %" PRIx32, static_cast<uint32_t>(rv)).get(),
|
2016-12-06 20:25:00 +03:00
|
|
|
aFailureAction);
|
2006-06-15 07:20:19 +04:00
|
|
|
}
|
2010-03-03 00:00:53 +03:00
|
|
|
}
|
2004-03-09 22:59:09 +03:00
|
|
|
|
2014-11-14 01:11:19 +03:00
|
|
|
/* static */ void
|
2016-09-26 15:03:25 +03:00
|
|
|
nsLayoutStylesheetCache::InvalidateSheet(RefPtr<StyleSheet>* aGeckoSheet,
|
|
|
|
RefPtr<StyleSheet>* aServoSheet)
|
2014-11-14 01:11:19 +03:00
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
MOZ_ASSERT(gCSSLoader_Gecko || gCSSLoader_Servo,
|
|
|
|
"pref changed before we loaded a sheet?");
|
2014-11-14 01:11:19 +03:00
|
|
|
|
2016-03-01 05:57:05 +03:00
|
|
|
const bool gotGeckoSheet = aGeckoSheet && *aGeckoSheet;
|
|
|
|
const bool gotServoSheet = aServoSheet && *aServoSheet;
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
// Make sure sheets have the expected types
|
2016-03-01 05:57:05 +03:00
|
|
|
MOZ_ASSERT(!gotGeckoSheet || (*aGeckoSheet)->IsGecko());
|
|
|
|
MOZ_ASSERT(!gotServoSheet || (*aServoSheet)->IsServo());
|
2016-02-24 10:01:12 +03:00
|
|
|
// Make sure the URIs match
|
2016-03-01 05:57:05 +03:00
|
|
|
MOZ_ASSERT(!gotServoSheet || !gotGeckoSheet ||
|
2016-02-24 10:01:12 +03:00
|
|
|
(*aGeckoSheet)->GetSheetURI() == (*aServoSheet)->GetSheetURI(),
|
|
|
|
"Sheets passed should have the same URI");
|
|
|
|
|
|
|
|
nsIURI* uri;
|
2016-03-01 05:57:05 +03:00
|
|
|
if (gotGeckoSheet) {
|
2016-02-24 10:01:12 +03:00
|
|
|
uri = (*aGeckoSheet)->GetSheetURI();
|
2016-03-01 05:57:05 +03:00
|
|
|
} else if (gotServoSheet) {
|
2016-02-24 10:01:12 +03:00
|
|
|
uri = (*aServoSheet)->GetSheetURI();
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
if (gCSSLoader_Gecko) {
|
|
|
|
gCSSLoader_Gecko->ObsoleteSheet(uri);
|
|
|
|
}
|
|
|
|
if (gCSSLoader_Servo) {
|
|
|
|
gCSSLoader_Servo->ObsoleteSheet(uri);
|
|
|
|
}
|
2016-03-01 05:57:05 +03:00
|
|
|
if (gotGeckoSheet) {
|
2016-02-24 10:01:12 +03:00
|
|
|
*aGeckoSheet = nullptr;
|
|
|
|
}
|
2016-03-01 05:57:05 +03:00
|
|
|
if (gotServoSheet) {
|
2016-02-24 10:01:12 +03:00
|
|
|
*aServoSheet = nullptr;
|
2014-11-14 01:11:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsLayoutStylesheetCache::DependentPrefChanged(const char* aPref, void* aData)
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
MOZ_ASSERT(gStyleCache_Gecko || gStyleCache_Servo,
|
|
|
|
"pref changed after shutdown?");
|
2014-11-14 01:11:19 +03:00
|
|
|
|
|
|
|
// Cause any UA style sheets whose parsing depends on the value of prefs
|
2016-02-24 10:01:12 +03:00
|
|
|
// to be re-parsed by dropping the sheet from gCSSLoader_{Gecko,Servo}'s cache
|
|
|
|
// then setting our cached sheet pointer to null. This will only work for
|
|
|
|
// sheets that are loaded lazily.
|
2016-02-24 10:01:12 +03:00
|
|
|
|
|
|
|
#define INVALIDATE(sheet_) \
|
|
|
|
InvalidateSheet(gStyleCache_Gecko ? &gStyleCache_Gecko->sheet_ : nullptr, \
|
|
|
|
gStyleCache_Servo ? &gStyleCache_Servo->sheet_ : nullptr);
|
|
|
|
|
|
|
|
INVALIDATE(mUASheet); // for layout.css.grid.enabled
|
|
|
|
|
|
|
|
#undef INVALIDATE
|
2014-11-14 01:11:19 +03:00
|
|
|
}
|
|
|
|
|
2015-06-16 04:34:48 +03:00
|
|
|
/* static */ void
|
|
|
|
nsLayoutStylesheetCache::InvalidatePreferenceSheets()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
if (gStyleCache_Gecko) {
|
|
|
|
gStyleCache_Gecko->mContentPreferenceSheet = nullptr;
|
|
|
|
gStyleCache_Gecko->mChromePreferenceSheet = nullptr;
|
|
|
|
}
|
|
|
|
if (gStyleCache_Servo) {
|
|
|
|
gStyleCache_Servo->mContentPreferenceSheet = nullptr;
|
|
|
|
gStyleCache_Servo->mChromePreferenceSheet = nullptr;
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-26 15:03:25 +03:00
|
|
|
nsLayoutStylesheetCache::BuildPreferenceSheet(RefPtr<StyleSheet>* aSheet,
|
2015-06-16 04:34:48 +03:00
|
|
|
nsPresContext* aPresContext)
|
|
|
|
{
|
2016-02-26 04:51:02 +03:00
|
|
|
if (mBackendType == StyleBackendType::Gecko) {
|
2016-08-02 23:12:27 +03:00
|
|
|
*aSheet = new CSSStyleSheet(eAgentSheetFeatures, CORS_NONE,
|
2017-01-05 06:29:56 +03:00
|
|
|
mozilla::net::RP_Unset);
|
2016-02-26 04:51:02 +03:00
|
|
|
} else {
|
2016-08-02 23:12:27 +03:00
|
|
|
*aSheet = new ServoStyleSheet(eAgentSheetFeatures, CORS_NONE,
|
2017-01-05 06:29:56 +03:00
|
|
|
mozilla::net::RP_Unset, dom::SRIMetadata());
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet* sheet = *aSheet;
|
2016-04-14 02:55:47 +03:00
|
|
|
|
2015-06-16 04:34:48 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), "about:PreferenceStyleSheet", nullptr);
|
|
|
|
MOZ_ASSERT(uri, "URI creation shouldn't fail");
|
|
|
|
|
2016-04-14 02:55:47 +03:00
|
|
|
sheet->SetURIs(uri, uri, uri);
|
2016-09-26 15:03:25 +03:00
|
|
|
sheet->SetComplete();
|
2015-06-16 04:34:48 +03:00
|
|
|
|
2016-01-04 02:25:28 +03:00
|
|
|
static const uint32_t kPreallocSize = 1024;
|
|
|
|
|
2016-01-04 01:26:59 +03:00
|
|
|
nsString sheetText;
|
2016-01-04 02:25:28 +03:00
|
|
|
sheetText.SetCapacity(kPreallocSize);
|
2015-06-16 04:34:48 +03:00
|
|
|
|
2016-01-04 01:26:59 +03:00
|
|
|
#define NS_GET_R_G_B(color_) \
|
|
|
|
NS_GET_R(color_), NS_GET_G(color_), NS_GET_B(color_)
|
2015-06-16 04:34:48 +03:00
|
|
|
|
2016-01-04 01:26:59 +03:00
|
|
|
sheetText.AppendLiteral(
|
|
|
|
"@namespace url(http://www.w3.org/1999/xhtml);\n"
|
|
|
|
"@namespace svg url(http://www.w3.org/2000/svg);\n");
|
|
|
|
|
|
|
|
// Rules for link styling.
|
|
|
|
nscolor linkColor = aPresContext->DefaultLinkColor();
|
|
|
|
nscolor activeColor = aPresContext->DefaultActiveLinkColor();
|
|
|
|
nscolor visitedColor = aPresContext->DefaultVisitedLinkColor();
|
|
|
|
|
|
|
|
sheetText.AppendPrintf(
|
|
|
|
"*|*:link { color: #%02x%02x%02x; }\n"
|
2016-07-20 06:13:13 +03:00
|
|
|
"*|*:any-link:active { color: #%02x%02x%02x; }\n"
|
2016-01-04 01:26:59 +03:00
|
|
|
"*|*:visited { color: #%02x%02x%02x; }\n",
|
|
|
|
NS_GET_R_G_B(linkColor),
|
|
|
|
NS_GET_R_G_B(activeColor),
|
|
|
|
NS_GET_R_G_B(visitedColor));
|
|
|
|
|
|
|
|
bool underlineLinks =
|
|
|
|
aPresContext->GetCachedBoolPref(kPresContext_UnderlineLinks);
|
|
|
|
sheetText.AppendPrintf(
|
2016-07-20 06:13:13 +03:00
|
|
|
"*|*:any-link%s { text-decoration: %s; }\n",
|
2016-01-04 01:26:59 +03:00
|
|
|
underlineLinks ? ":not(svg|a)" : "",
|
|
|
|
underlineLinks ? "underline" : "none");
|
2015-06-16 04:34:48 +03:00
|
|
|
|
|
|
|
// Rules for focus styling.
|
|
|
|
|
|
|
|
bool focusRingOnAnything = aPresContext->GetFocusRingOnAnything();
|
|
|
|
uint8_t focusRingWidth = aPresContext->FocusRingWidth();
|
|
|
|
uint8_t focusRingStyle = aPresContext->GetFocusRingStyle();
|
|
|
|
|
|
|
|
if ((focusRingWidth != 1 && focusRingWidth <= 4) || focusRingOnAnything) {
|
|
|
|
if (focusRingWidth != 1) {
|
|
|
|
// If the focus ring width is different from the default, fix buttons
|
|
|
|
// with rings.
|
2016-01-04 01:26:59 +03:00
|
|
|
sheetText.AppendPrintf(
|
2015-06-16 04:34:48 +03:00
|
|
|
"button::-moz-focus-inner, input[type=\"reset\"]::-moz-focus-inner, "
|
|
|
|
"input[type=\"button\"]::-moz-focus-inner, "
|
|
|
|
"input[type=\"submit\"]::-moz-focus-inner { "
|
2016-01-04 01:26:59 +03:00
|
|
|
"border: %dpx %s transparent !important; }\n",
|
2015-06-16 04:34:48 +03:00
|
|
|
focusRingWidth,
|
2016-01-04 01:26:59 +03:00
|
|
|
focusRingStyle == 0 ? "solid" : "dotted");
|
|
|
|
|
|
|
|
sheetText.AppendLiteral(
|
|
|
|
"button:focus::-moz-focus-inner, "
|
|
|
|
"input[type=\"reset\"]:focus::-moz-focus-inner, "
|
|
|
|
"input[type=\"button\"]:focus::-moz-focus-inner, "
|
|
|
|
"input[type=\"submit\"]:focus::-moz-focus-inner { "
|
|
|
|
"border-color: ButtonText !important; }\n");
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
|
|
|
|
2016-01-04 01:26:59 +03:00
|
|
|
sheetText.AppendPrintf(
|
|
|
|
"%s { outline: %dpx %s !important; %s}\n",
|
|
|
|
focusRingOnAnything ?
|
|
|
|
":focus" :
|
|
|
|
"*|*:link:focus, *|*:visited:focus",
|
|
|
|
focusRingWidth,
|
|
|
|
focusRingStyle == 0 ? // solid
|
|
|
|
"solid -moz-mac-focusring" : "dotted WindowText",
|
|
|
|
focusRingStyle == 0 ? // solid
|
|
|
|
"-moz-outline-radius: 3px; outline-offset: 1px; " : "");
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aPresContext->GetUseFocusColors()) {
|
|
|
|
nscolor focusText = aPresContext->FocusTextColor();
|
|
|
|
nscolor focusBG = aPresContext->FocusBackgroundColor();
|
2016-01-04 01:26:59 +03:00
|
|
|
sheetText.AppendPrintf(
|
2015-06-16 04:34:48 +03:00
|
|
|
"*:focus, *:focus > font { color: #%02x%02x%02x !important; "
|
2016-01-04 01:26:59 +03:00
|
|
|
"background-color: #%02x%02x%02x !important; }\n",
|
|
|
|
NS_GET_R_G_B(focusText),
|
|
|
|
NS_GET_R_G_B(focusBG));
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
2016-01-04 01:26:59 +03:00
|
|
|
|
2016-01-04 02:25:28 +03:00
|
|
|
NS_ASSERTION(sheetText.Length() <= kPreallocSize,
|
|
|
|
"kPreallocSize should be big enough to build preference style "
|
|
|
|
"sheet without reallocation");
|
|
|
|
|
2016-04-14 02:55:47 +03:00
|
|
|
if (sheet->IsGecko()) {
|
|
|
|
sheet->AsGecko()->ReparseSheet(sheetText);
|
2016-02-26 04:51:02 +03:00
|
|
|
} else {
|
2016-12-17 12:58:56 +03:00
|
|
|
ServoStyleSheet* servoSheet = sheet->AsServo();
|
|
|
|
// NB: The pref sheet never has @import rules.
|
|
|
|
nsresult rv =
|
2017-05-14 18:11:18 +03:00
|
|
|
servoSheet->ParseSheet(nullptr, sheetText, uri, uri, nullptr, 0,
|
|
|
|
eCompatibility_FullStandards);
|
2016-08-31 13:10:10 +03:00
|
|
|
// Parsing the about:PreferenceStyleSheet URI can only fail on OOM. If we
|
|
|
|
// are OOM before we parsed any documents we might as well abort.
|
|
|
|
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
|
2016-02-26 04:51:02 +03:00
|
|
|
}
|
2016-01-04 01:26:59 +03:00
|
|
|
|
|
|
|
#undef NS_GET_R_G_B
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
|
|
|
|
2014-06-26 20:29:05 +04:00
|
|
|
mozilla::StaticRefPtr<nsLayoutStylesheetCache>
|
2016-02-24 10:01:12 +03:00
|
|
|
nsLayoutStylesheetCache::gStyleCache_Gecko;
|
|
|
|
|
|
|
|
mozilla::StaticRefPtr<nsLayoutStylesheetCache>
|
|
|
|
nsLayoutStylesheetCache::gStyleCache_Servo;
|
2005-12-09 14:10:36 +03:00
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
mozilla::StaticRefPtr<mozilla::css::Loader>
|
|
|
|
nsLayoutStylesheetCache::gCSSLoader_Gecko;
|
|
|
|
|
|
|
|
mozilla::StaticRefPtr<mozilla::css::Loader>
|
|
|
|
nsLayoutStylesheetCache::gCSSLoader_Servo;
|
2016-07-21 13:57:35 +03:00
|
|
|
|
|
|
|
mozilla::StaticRefPtr<nsIURI>
|
2017-05-03 14:48:48 +03:00
|
|
|
nsLayoutStylesheetCache::gUserContentSheetURL_Gecko;
|
|
|
|
|
|
|
|
mozilla::StaticRefPtr<nsIURI>
|
|
|
|
nsLayoutStylesheetCache::gUserContentSheetURL_Servo;
|