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
|
|
|
|
2019-11-26 01:08:43 +03:00
|
|
|
#ifndef mozilla_GlobalStyleSheetCache_h__
|
|
|
|
#define mozilla_GlobalStyleSheetCache_h__
|
2004-03-09 22:59:09 +03:00
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
#include "nsIMemoryReporter.h"
|
2004-03-09 22:59:09 +03:00
|
|
|
#include "nsIObserver.h"
|
2019-03-30 03:23:49 +03:00
|
|
|
#include "base/shared_memory.h"
|
2012-06-19 07:26:34 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2019-03-07 00:34:30 +03:00
|
|
|
#include "mozilla/PreferenceSheet.h"
|
2019-01-11 06:12:28 +03:00
|
|
|
#include "mozilla/NotNull.h"
|
2014-06-26 20:29:05 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2015-10-14 00:43:16 +03:00
|
|
|
#include "mozilla/css/Loader.h"
|
2004-03-09 22:59:09 +03:00
|
|
|
|
2013-01-18 04:45:12 +04:00
|
|
|
class nsIFile;
|
2010-05-12 00:41:47 +04:00
|
|
|
class nsIURI;
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-06-20 14:32:49 +04:00
|
|
|
class CSSStyleSheet;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2004-03-09 22:59:09 +03:00
|
|
|
|
2016-12-06 20:25:00 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
|
|
|
// Enum defining how error should be handled.
|
|
|
|
enum FailureAction { eCrash = 0, eLogToConsole };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-06 20:25:00 +03:00
|
|
|
} // namespace css
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-11-26 01:08:43 +03:00
|
|
|
class GlobalStyleSheetCache final : public nsIObserver,
|
|
|
|
public nsIMemoryReporter {
|
2019-03-30 03:23:49 +03:00
|
|
|
public:
|
2004-03-09 22:59:09 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
2013-12-08 10:09:10 +04:00
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2004-03-09 22:59:09 +03:00
|
|
|
|
2019-11-26 01:08:43 +03:00
|
|
|
static GlobalStyleSheetCache* Singleton();
|
2016-02-24 10:01:12 +03:00
|
|
|
|
2019-03-30 03:23:49 +03:00
|
|
|
#define STYLE_SHEET(identifier_, url_, shared_) \
|
2019-11-26 01:30:09 +03:00
|
|
|
NotNull<StyleSheet*> identifier_##Sheet();
|
2018-12-05 23:08:35 +03:00
|
|
|
#include "mozilla/UserAgentStyleSheetList.h"
|
|
|
|
#undef STYLE_SHEET
|
|
|
|
|
2019-11-26 01:30:09 +03:00
|
|
|
StyleSheet* GetUserContentSheet();
|
|
|
|
StyleSheet* GetUserChromeSheet();
|
|
|
|
StyleSheet* ChromePreferenceSheet();
|
|
|
|
StyleSheet* ContentPreferenceSheet();
|
2015-06-16 04:34:48 +03:00
|
|
|
|
|
|
|
static void InvalidatePreferenceSheets();
|
2021-08-20 16:03:40 +03:00
|
|
|
static bool AffectedByPref(const nsACString&);
|
2004-03-09 22:59:09 +03:00
|
|
|
|
|
|
|
static void Shutdown();
|
|
|
|
|
2016-07-21 13:57:35 +03:00
|
|
|
static void SetUserContentCSSURL(nsIURI* aURI);
|
|
|
|
|
2019-11-26 01:30:09 +03:00
|
|
|
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
|
2012-01-03 06:19:14 +04:00
|
|
|
|
2019-03-30 03:23:49 +03:00
|
|
|
// Set the shared memory segment to load the shared UA sheets from.
|
|
|
|
// Called early on in a content process' life from
|
2019-11-26 01:08:43 +03:00
|
|
|
// ContentChild::InitSharedUASheets, before the GlobalStyleSheetCache
|
2019-03-30 03:23:49 +03:00
|
|
|
// singleton has been created.
|
2021-11-05 14:21:04 +03:00
|
|
|
static void SetSharedMemory(const base::SharedMemoryHandle& aHandle,
|
2019-03-30 03:23:49 +03:00
|
|
|
uintptr_t aAddress);
|
|
|
|
|
|
|
|
// Obtain a shared memory handle for the shared UA sheets to pass into a
|
|
|
|
// content process. Called by ContentParent::InitInternal shortly after
|
|
|
|
// a content process has been created.
|
|
|
|
bool ShareToProcess(base::ProcessId aProcessId,
|
|
|
|
base::SharedMemoryHandle* aHandle);
|
|
|
|
|
|
|
|
// Returns the address of the shared memory segment that holds the shared UA
|
|
|
|
// sheets.
|
|
|
|
uintptr_t GetSharedMemoryAddress() {
|
2019-11-07 14:19:27 +03:00
|
|
|
return sSharedMemory ? uintptr_t(sSharedMemory->memory()) : 0;
|
2019-03-30 03:23:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Size of the shared memory buffer we'll create to store the shared UA
|
|
|
|
// sheets. We choose a value that is big enough on both 64 bit and 32 bit.
|
|
|
|
//
|
|
|
|
// If this isn't big enough for the current contents of the shared UA
|
|
|
|
// sheets, we'll crash under InitSharedSheetsInParent.
|
2019-08-23 22:36:45 +03:00
|
|
|
static constexpr size_t kSharedMemorySize = 1024 * 450;
|
2019-03-30 03:23:49 +03:00
|
|
|
|
2004-03-09 22:59:09 +03:00
|
|
|
private:
|
2019-03-30 03:23:49 +03:00
|
|
|
// Shared memory header.
|
|
|
|
struct Header {
|
|
|
|
static constexpr uint32_t kMagic = 0x55415353;
|
|
|
|
uint32_t mMagic; // Must be set to kMagic.
|
2019-11-26 01:30:09 +03:00
|
|
|
const ServoCssRules* mSheets[size_t(UserAgentStyleSheetID::Count)];
|
2019-03-30 03:23:49 +03:00
|
|
|
uint8_t mBuffer[1];
|
|
|
|
};
|
|
|
|
|
2019-11-26 01:08:43 +03:00
|
|
|
GlobalStyleSheetCache();
|
|
|
|
~GlobalStyleSheetCache();
|
2004-03-09 22:59:09 +03:00
|
|
|
|
|
|
|
void InitFromProfile();
|
2019-03-30 03:23:49 +03:00
|
|
|
void InitSharedSheetsInParent();
|
2013-11-07 09:35:30 +04:00
|
|
|
void InitMemoryReporter();
|
2019-11-26 01:30:09 +03:00
|
|
|
RefPtr<StyleSheet> LoadSheetURL(const char* aURL,
|
|
|
|
css::SheetParsingMode aParsingMode,
|
|
|
|
css::FailureAction aFailureAction);
|
|
|
|
RefPtr<StyleSheet> LoadSheetFile(nsIFile* aFile,
|
|
|
|
css::SheetParsingMode aParsingMode);
|
|
|
|
RefPtr<StyleSheet> LoadSheet(nsIURI* aURI, css::SheetParsingMode aParsingMode,
|
|
|
|
css::FailureAction aFailureAction);
|
|
|
|
void LoadSheetFromSharedMemory(const char* aURL, RefPtr<StyleSheet>* aSheet,
|
|
|
|
css::SheetParsingMode, Header*,
|
|
|
|
UserAgentStyleSheetID);
|
|
|
|
void BuildPreferenceSheet(RefPtr<StyleSheet>* aSheet,
|
|
|
|
const PreferenceSheet::Prefs&);
|
|
|
|
|
|
|
|
static StaticRefPtr<GlobalStyleSheetCache> gStyleCache;
|
|
|
|
static StaticRefPtr<css::Loader> gCSSLoader;
|
|
|
|
static StaticRefPtr<nsIURI> gUserContentSheetURL;
|
2018-12-24 04:34:37 +03:00
|
|
|
|
2019-03-30 03:23:49 +03:00
|
|
|
#define STYLE_SHEET(identifier_, url_, shared_) \
|
2019-11-26 01:30:09 +03:00
|
|
|
RefPtr<StyleSheet> m##identifier_##Sheet;
|
2018-12-24 04:34:37 +03:00
|
|
|
#include "mozilla/UserAgentStyleSheetList.h"
|
|
|
|
#undef STYLE_SHEET
|
|
|
|
|
2019-11-26 01:30:09 +03:00
|
|
|
RefPtr<StyleSheet> mChromePreferenceSheet;
|
|
|
|
RefPtr<StyleSheet> mContentPreferenceSheet;
|
|
|
|
RefPtr<StyleSheet> mUserChromeSheet;
|
|
|
|
RefPtr<StyleSheet> mUserContentSheet;
|
2019-03-30 03:23:49 +03:00
|
|
|
|
|
|
|
// Shared memory segment storing shared style sheets.
|
2019-11-26 01:30:09 +03:00
|
|
|
static StaticAutoPtr<base::SharedMemory> sSharedMemory;
|
2019-03-30 03:23:49 +03:00
|
|
|
|
|
|
|
// How much of the shared memory buffer we ended up using. Used for memory
|
2019-11-07 14:19:27 +03:00
|
|
|
// reporting in the parent process.
|
|
|
|
static size_t sUsedSharedMemory;
|
2004-03-09 22:59:09 +03:00
|
|
|
};
|
|
|
|
|
2019-11-26 01:08:43 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2004-03-09 22:59:09 +03:00
|
|
|
#endif
|