Bug 1677190 - Introduce SessionStoreFunctions for GeckoView package and move the existing SessionStoreFunctions from toolkit to the browser package. r=geckoview-reviewers,farre,nika,owlish

This change utilizes components.conf to distinguish between the contract implementations of nsISessionStoreFunctions per platform.

Differential Revision: https://phabricator.services.mozilla.com/D206904
This commit is contained in:
kycn 2024-04-30 11:17:55 +00:00
parent 5c9ae9edba
commit c34f4a5022
13 changed files with 188 additions and 44 deletions

View file

@ -4,38 +4,40 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { SessionStore } from "resource:///modules/sessionstore/SessionStore.sys.mjs"; import { SessionStore } from "resource:///modules/sessionstore/SessionStore.sys.mjs";
export function UpdateSessionStore( export class SessionStoreFunctions {
aBrowser, UpdateSessionStore(
aBrowsingContext,
aPermanentKey,
aEpoch,
aCollectSHistory,
aData
) {
return SessionStoreFuncInternal.updateSessionStore(
aBrowser, aBrowser,
aBrowsingContext, aBrowsingContext,
aPermanentKey, aPermanentKey,
aEpoch, aEpoch,
aCollectSHistory, aCollectSHistory,
aData aData
); ) {
} return SessionStoreFuncInternal.updateSessionStore(
aBrowser,
aBrowsingContext,
aPermanentKey,
aEpoch,
aCollectSHistory,
aData
);
}
export function UpdateSessionStoreForStorage( UpdateSessionStoreForStorage(
aBrowser,
aBrowsingContext,
aPermanentKey,
aEpoch,
aData
) {
return SessionStoreFuncInternal.updateSessionStoreForStorage(
aBrowser, aBrowser,
aBrowsingContext, aBrowsingContext,
aPermanentKey, aPermanentKey,
aEpoch, aEpoch,
aData aData
); ) {
return SessionStoreFuncInternal.updateSessionStoreForStorage(
aBrowser,
aBrowsingContext,
aPermanentKey,
aEpoch,
aData
);
}
} }
var SessionStoreFuncInternal = { var SessionStoreFuncInternal = {
@ -85,3 +87,7 @@ var SessionStoreFuncInternal = {
); );
}, },
}; };
SessionStoreFunctions.prototype.QueryInterface = ChromeUtils.generateQI([
"nsISessionStoreFunctions",
]);

View file

@ -0,0 +1,12 @@
# 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/.
Classes = [
{
'cid': '{45ce6b2d-ffc8-4051-bb41-37ceeeb19e94}',
'contract_ids': ['@mozilla.org/toolkit/sessionstore-functions;1'],
'esModule': 'resource:///modules/sessionstore/SessionStoreFunctions.sys.mjs',
'constructor': 'SessionStoreFunctions',
},
]

View file

@ -20,6 +20,7 @@ EXTRA_JS_MODULES.sessionstore = [
"SessionSaver.sys.mjs", "SessionSaver.sys.mjs",
"SessionStartup.sys.mjs", "SessionStartup.sys.mjs",
"SessionStore.sys.mjs", "SessionStore.sys.mjs",
"SessionStoreFunctions.sys.mjs",
"SessionWriter.sys.mjs", "SessionWriter.sys.mjs",
"StartupPerformance.sys.mjs", "StartupPerformance.sys.mjs",
"TabAttributes.sys.mjs", "TabAttributes.sys.mjs",
@ -28,6 +29,10 @@ EXTRA_JS_MODULES.sessionstore = [
"TabStateFlusher.sys.mjs", "TabStateFlusher.sys.mjs",
] ]
XPCOM_MANIFESTS += [
"components.conf",
]
TESTING_JS_MODULES += [ TESTING_JS_MODULES += [
"test/SessionStoreTestUtils.sys.mjs", "test/SessionStoreTestUtils.sys.mjs",
] ]

View file

@ -59,7 +59,7 @@
#include "nsBrowserStatusFilter.h" #include "nsBrowserStatusFilter.h"
#include "nsIBrowser.h" #include "nsIBrowser.h"
#include "nsTHashSet.h" #include "nsTHashSet.h"
#include "SessionStoreFunctions.h" #include "nsISessionStoreFunctions.h"
#include "nsIXPConnect.h" #include "nsIXPConnect.h"
#include "nsImportModule.h" #include "nsImportModule.h"
#include "UnitTransforms.h" #include "UnitTransforms.h"
@ -2673,13 +2673,14 @@ void CanonicalBrowsingContext::RestoreState::Resolve() {
nsresult CanonicalBrowsingContext::WriteSessionStorageToSessionStore( nsresult CanonicalBrowsingContext::WriteSessionStorageToSessionStore(
const nsTArray<SSCacheCopy>& aSesssionStorage, uint32_t aEpoch) { const nsTArray<SSCacheCopy>& aSesssionStorage, uint32_t aEpoch) {
nsCOMPtr<nsISessionStoreFunctions> funcs = do_ImportESModule( nsCOMPtr<nsISessionStoreFunctions> sessionStoreFuncs =
"resource://gre/modules/SessionStoreFunctions.sys.mjs", fallible); do_GetService("@mozilla.org/toolkit/sessionstore-functions;1");
if (!funcs) { if (!sessionStoreFuncs) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsCOMPtr<nsIXPConnectWrappedJS> wrapped = do_QueryInterface(funcs); nsCOMPtr<nsIXPConnectWrappedJS> wrapped =
do_QueryInterface(sessionStoreFuncs);
AutoJSAPI jsapi; AutoJSAPI jsapi;
if (!jsapi.Init(wrapped->GetJSObjectGlobal())) { if (!jsapi.Init(wrapped->GetJSObjectGlobal())) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -2700,8 +2701,8 @@ nsresult CanonicalBrowsingContext::WriteSessionStorageToSessionStore(
update.setNull(); update.setNull();
} }
return funcs->UpdateSessionStoreForStorage(Top()->GetEmbedderElement(), this, return sessionStoreFuncs->UpdateSessionStoreForStorage(
key, aEpoch, update); Top()->GetEmbedderElement(), this, key, aEpoch, update);
} }
void CanonicalBrowsingContext::UpdateSessionStoreSessionStorage( void CanonicalBrowsingContext::UpdateSessionStoreSessionStorage(

View file

@ -76,7 +76,7 @@
#include "mozilla/net/PCookieServiceParent.h" #include "mozilla/net/PCookieServiceParent.h"
#include "mozilla/net/CookieServiceParent.h" #include "mozilla/net/CookieServiceParent.h"
#include "SessionStoreFunctions.h" #include "nsISessionStoreFunctions.h"
#include "nsIXPConnect.h" #include "nsIXPConnect.h"
#include "nsImportModule.h" #include "nsImportModule.h"
#include "nsIXULRuntime.h" #include "nsIXULRuntime.h"

View file

@ -0,0 +1,61 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
* 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/. */
import { GeckoViewSessionStore } from "resource://gre/modules/GeckoViewSessionStore.sys.mjs";
export class SessionStoreFunctions {
UpdateSessionStore(
aBrowser,
aBrowsingContext,
aPermanentKey,
aEpoch,
aCollectSHistory,
aData
) {
return GeckoViewSessionStoreFuncInternal.updateSessionStore(
aBrowser,
aBrowsingContext,
aPermanentKey,
aEpoch,
aCollectSHistory,
aData
);
}
}
var GeckoViewSessionStoreFuncInternal = {
updateSessionStore: function SSF_updateSessionStore(
aBrowser,
aBrowsingContext,
aPermanentKey,
aEpoch,
aCollectSHistory,
aData
) {
const { formdata, scroll } = aData;
if (formdata) {
aData.formdata = formdata.toJSON();
}
if (scroll) {
aData.scroll = scroll.toJSON();
}
GeckoViewSessionStore.updateSessionStoreFromTabListener(
aBrowser,
aBrowsingContext,
aPermanentKey,
{
data: aData,
epoch: aEpoch,
sHistoryNeeded: aCollectSHistory,
}
);
},
};
SessionStoreFunctions.prototype.QueryInterface = ChromeUtils.generateQI([
"nsISessionStoreFunctions",
]);

View file

@ -91,6 +91,12 @@ Classes = [
], ],
}, },
}, },
{
'cid': '{ad643d9e-52e3-4385-a57c-b42deb2f5daf}',
'contract_ids': ['@mozilla.org/toolkit/sessionstore-functions;1'],
'esModule': 'resource://gre/modules/SessionStoreFunctions.sys.mjs',
'constructor': 'SessionStoreFunctions',
},
] ]
if defined('MOZ_ANDROID_HISTORY'): if defined('MOZ_ANDROID_HISTORY'):

View file

@ -49,6 +49,7 @@ EXTRA_JS_MODULES += [
"GeckoViewStartup.sys.mjs", "GeckoViewStartup.sys.mjs",
"LoginStorageDelegate.sys.mjs", "LoginStorageDelegate.sys.mjs",
"PromptCollection.sys.mjs", "PromptCollection.sys.mjs",
"SessionStoreFunctions.sys.mjs",
"ShareDelegate.sys.mjs", "ShareDelegate.sys.mjs",
] ]

View file

@ -184,4 +184,51 @@ export var GeckoViewSessionStore = {
return listener; return listener;
}, },
updateSessionStoreFromTabListener(
browser,
browsingContext,
permanentKey,
update,
forStorage = false
) {
permanentKey = browser?.permanentKey ?? permanentKey;
if (!permanentKey) {
return;
}
if (browsingContext.isReplaced) {
return;
}
const listener = this.getOrCreateSHistoryListener(
permanentKey,
browsingContext
);
if (listener) {
const historychange =
// If it is not the scheduled update (tab closed, window closed etc),
// try to store the loading non-web-controlled page opened in _blank
// first.
(forStorage &&
lazy.SessionHistory.collectNonWebControlledBlankLoadingSession(
browsingContext
)) ||
listener.collect(permanentKey, browsingContext, {
collectFull: !!update.sHistoryNeeded,
writeToCache: false,
});
if (historychange) {
update.data.historychange = historychange;
}
}
const win =
browsingContext.embedderElement?.ownerGlobal ||
browsingContext.currentWindowGlobal?.browsingContext?.window;
this.onTabStateUpdate(permanentKey, win, update);
},
}; };

View file

@ -24,7 +24,7 @@
#include "nsIXULRuntime.h" #include "nsIXULRuntime.h"
#include "nsPresContext.h" #include "nsPresContext.h"
#include "nsPrintfCString.h" #include "nsPrintfCString.h"
#include "SessionStoreFunctions.h" #include "nsISessionStoreFunctions.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; using namespace mozilla::dom;
@ -436,9 +436,13 @@ void TabListener::UpdateSessionStore(bool aIsFlush) {
data.mIsPrivate.Construct() = mSessionStore->GetPrivateModeEnabled(); data.mIsPrivate.Construct() = mSessionStore->GetPrivateModeEnabled();
} }
nsCOMPtr<nsISessionStoreFunctions> funcs = do_ImportESModule( nsCOMPtr<nsISessionStoreFunctions> sessionStoreFuncs =
"resource://gre/modules/SessionStoreFunctions.sys.mjs", fallible); do_GetService("@mozilla.org/toolkit/sessionstore-functions;1");
nsCOMPtr<nsIXPConnectWrappedJS> wrapped = do_QueryInterface(funcs); if (!sessionStoreFuncs) {
return;
}
nsCOMPtr<nsIXPConnectWrappedJS> wrapped =
do_QueryInterface(sessionStoreFuncs);
if (!wrapped) { if (!wrapped) {
return; return;
} }
@ -456,7 +460,7 @@ void TabListener::UpdateSessionStore(bool aIsFlush) {
JS::Rooted<JS::Value> key(jsapi.cx(), JS::Rooted<JS::Value> key(jsapi.cx(),
context->Canonical()->Top()->PermanentKey()); context->Canonical()->Top()->PermanentKey());
nsresult rv = funcs->UpdateSessionStore( nsresult rv = sessionStoreFuncs->UpdateSessionStore(
mOwnerContent, context, key, mEpoch, mOwnerContent, context, key, mEpoch,
mSessionStore->GetAndClearSHistoryChanged(), update); mSessionStore->GetAndClearSHistoryChanged(), update);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {

View file

@ -19,7 +19,7 @@
#include "mozilla/dom/InProcessParent.h" #include "mozilla/dom/InProcessParent.h"
#include "mozilla/dom/SessionStoreChild.h" #include "mozilla/dom/SessionStoreChild.h"
#include "mozilla/dom/SessionStoreUtilsBinding.h" #include "mozilla/dom/SessionStoreUtilsBinding.h"
#include "SessionStoreFunctions.h" #include "nsISessionStoreFunctions.h"
#include "nsISupports.h" #include "nsISupports.h"
#include "nsIXULRuntime.h" #include "nsIXULRuntime.h"
#include "nsImportModule.h" #include "nsImportModule.h"
@ -146,9 +146,14 @@ static void DoSessionStoreUpdate(CanonicalBrowsingContext* aBrowsingContext,
data.mScroll.Construct(aScroll); data.mScroll.Construct(aScroll);
} }
nsCOMPtr<nsISessionStoreFunctions> funcs = do_ImportESModule( nsCOMPtr<nsISessionStoreFunctions> sessionStoreFuncs =
"resource://gre/modules/SessionStoreFunctions.sys.mjs", fallible); do_GetService("@mozilla.org/toolkit/sessionstore-functions;1");
nsCOMPtr<nsIXPConnectWrappedJS> wrapped = do_QueryInterface(funcs); if (!sessionStoreFuncs) {
return;
}
nsCOMPtr<nsIXPConnectWrappedJS> wrapped =
do_QueryInterface(sessionStoreFuncs);
if (!wrapped) { if (!wrapped) {
return; return;
} }
@ -166,8 +171,8 @@ static void DoSessionStoreUpdate(CanonicalBrowsingContext* aBrowsingContext,
JS::Rooted<JS::Value> key(jsapi.cx(), JS::Rooted<JS::Value> key(jsapi.cx(),
aBrowsingContext->Top()->PermanentKey()); aBrowsingContext->Top()->PermanentKey());
Unused << funcs->UpdateSessionStore(nullptr, aBrowsingContext, key, aEpoch, Unused << sessionStoreFuncs->UpdateSessionStore(
aNeedCollectSHistory, update); nullptr, aBrowsingContext, key, aEpoch, aNeedCollectSHistory, update);
} }
#endif #endif

View file

@ -31,15 +31,11 @@ UNIFIED_SOURCES += [
"SessionStoreUtils.cpp", "SessionStoreUtils.cpp",
] ]
EXTRA_JS_MODULES += [
"SessionStoreFunctions.sys.mjs",
]
XPIDL_MODULE = "sessionstore" XPIDL_MODULE = "sessionstore"
XPIDL_SOURCES += [ XPIDL_SOURCES += [
"nsISessionStoreFunctions.idl",
"nsISessionStoreRestoreData.idl", "nsISessionStoreRestoreData.idl",
"SessionStoreFunctions.idl",
] ]
IPDL_SOURCES += [ IPDL_SOURCES += [