Skip to content

Commit

Permalink
Bug 1873772 - Only report XULStore load errors in the parent process;…
Browse files Browse the repository at this point in the history
… r=mossop

Differential Revision: https://phabricator.services.mozilla.com/D198086
  • Loading branch information
gregtatum committed Jan 17, 2024
1 parent 5d78535 commit 44b676d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
7 changes: 7 additions & 0 deletions dom/xul/XULPersist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions toolkit/components/xulstore/XULStore.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions toolkit/components/xulstore/components.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ Classes = [
'interfaces': ['nsIXULStore'],
'esModule': 'resource://gre/modules/XULStore.sys.mjs',
'constructor': 'XULStore',
'processes': ProcessSelector.MAIN_PROCESS_ONLY,
},
]
10 changes: 10 additions & 0 deletions xpfe/appshell/AppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 44b676d

Please sign in to comment.