Bug 1873772 - Only report XULStore load errors in the parent process; r=mossop

Differential Revision: https://phabricator.services.mozilla.com/D198086
This commit is contained in:
Greg Tatum 2024-01-17 17:18:47 +00:00
parent 5d785358b6
commit 44b676d37a
5 changed files with 43 additions and 1 deletions

View file

@ -12249,7 +12249,7 @@ void Document::SetReadyStateInternal(ReadyState aReadyState,
if (READYSTATE_INTERACTIVE == aReadyState &&
NodePrincipal()->IsSystemPrincipal()) {
if (!mXULPersist) {
if (!mXULPersist && XRE_IsParentProcess()) {
mXULPersist = new XULPersist(this);
mXULPersist->Init();
}

View file

@ -19,6 +19,13 @@ class nsCOMArray;
namespace mozilla::dom {
/**
* This class synchronizes element attributes (such as window sizing) with the
* live elements in a Document and with the XULStore. The XULStore persists
* these attributes to the file system. This class is created and owned by the
* Document and must only be created in the parent process. It only presists
* chrome document element attributes.
*/
class XULPersist final : public nsStubDocumentObserver {
public:
NS_DECL_ISUPPORTS

View file

@ -12,6 +12,30 @@ const WRITE_DELAY_MS = (debugMode ? 3 : 30) * 1000;
const XULSTORE_CID = Components.ID("{6f46b6f4-c8b1-4bd4-a4fa-9ebbed0753ea}");
const STOREDB_FILENAME = "xulstore.json";
/**
* The XULStore retains XULElement attributes such as the sizing and styling. These are
* stored in the user's profile directory inside of "xulstore.json". The JSON is
* stored based on the chrome URL of the resource.
*
* For instance the "chrome://browser/content/browser.xhtml" main window sizing could be
* stored like so:
*
* {
* "chrome://browser/content/browser.xhtml": {
* "main-window": {
* "screenX": "1104",
* "screenY": "25",
* "width": "1904",
* "height": "1612",
* "sizemode": "normal"
* },
* ...
* }
* }
*
* The XULStore can only be loaded in the parent process. See the XULStore
* and XULPersist C++ classes for how this is integrated from the C++ side.
*/
export function XULStore() {
if (!Services.appinfo.inSafeMode) {
this.load();

View file

@ -12,5 +12,6 @@ Classes = [
'interfaces': ['nsIXULStore'],
'esModule': 'resource://gre/modules/XULStore.sys.mjs',
'constructor': 'XULStore',
'processes': ProcessSelector.MAIN_PROCESS_ONLY,
},
]

View file

@ -1704,6 +1704,11 @@ static void ConvertWindowSize(nsIAppWindow* aWin, const nsAtom* aAttr,
}
nsresult AppWindow::GetPersistentValue(const nsAtom* aAttr, nsAString& aValue) {
if (!XRE_IsParentProcess()) {
// The XULStore is only available in the parent process.
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<dom::Element> docShellElement = GetWindowDOMElement();
if (!docShellElement) {
return NS_ERROR_FAILURE;
@ -1941,6 +1946,11 @@ nsresult AppWindow::MaybeSaveEarlyWindowPersistentValues(
nsresult AppWindow::SetPersistentValue(const nsAtom* aAttr,
const nsAString& aValue) {
if (!XRE_IsParentProcess()) {
// The XULStore is only available in the parent process.
return NS_ERROR_UNEXPECTED;
}
nsAutoString uri;
nsAutoString windowElementId;
nsresult rv = GetDocXulStoreKeys(uri, windowElementId);