зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1497146 part 1 - Add SessionStoreUtils.webidl r=nika
Let SessionStoreUtils be a WebIDL namespace, rather than a XPCOM service Differential Revision: https://phabricator.services.mozilla.com/D9776 --HG-- rename : toolkit/components/sessionstore/nsISessionStoreUtils.idl => dom/chrome-webidl/SessionStoreUtils.webidl rename : toolkit/components/sessionstore/nsSessionStoreUtils.cpp => toolkit/components/sessionstore/SessionStoreUtils.cpp extra : moz-landing-system : lando
This commit is contained in:
Родитель
317e3adf36
Коммит
15328d9c7b
|
@ -17,9 +17,6 @@ ChromeUtils.defineModuleGetter(this, "SessionStorage",
|
|||
ChromeUtils.defineModuleGetter(this, "Utils",
|
||||
"resource://gre/modules/sessionstore/Utils.jsm");
|
||||
|
||||
const ssu = Cc["@mozilla.org/browser/sessionstore/utils;1"]
|
||||
.getService(Ci.nsISessionStoreUtils);
|
||||
|
||||
/**
|
||||
* This module implements the content side of session restoration. The chrome
|
||||
* side is handled by SessionStore.jsm. The functions in this module are called
|
||||
|
@ -140,7 +137,8 @@ ContentRestoreInternal.prototype = {
|
|||
|
||||
// Make sure to reset the capabilities and attributes in case this tab gets
|
||||
// reused.
|
||||
ssu.restoreDocShellCapabilities(this.docShell, tabData.disallow);
|
||||
SessionStoreUtils.restoreDocShellCapabilities(this.docShell, tabData.disallow);
|
||||
|
||||
|
||||
if (tabData.storage && this.docShell instanceof Ci.nsIDocShell) {
|
||||
SessionStorage.restore(this.docShell, tabData.storage);
|
||||
|
@ -298,7 +296,7 @@ ContentRestoreInternal.prototype = {
|
|||
// Restore scroll data.
|
||||
Utils.restoreFrameTreeData(window, scrollPositions, (frame, data) => {
|
||||
if (data.scroll) {
|
||||
ssu.restoreScrollPosition(frame, data.scroll);
|
||||
SessionStoreUtils.restoreScrollPosition(frame, data);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
|
@ -26,8 +26,6 @@ ChromeUtils.defineModuleGetter(this, "SessionStorage",
|
|||
|
||||
ChromeUtils.defineModuleGetter(this, "Utils",
|
||||
"resource://gre/modules/sessionstore/Utils.jsm");
|
||||
const ssu = Cc["@mozilla.org/browser/sessionstore/utils;1"]
|
||||
.getService(Ci.nsISessionStoreUtils);
|
||||
|
||||
// A bound to the size of data to store for DOM Storage.
|
||||
const DOM_STORAGE_LIMIT_PREF = "browser.sessionstore.dom_storage_limit";
|
||||
|
@ -151,7 +149,7 @@ class EventListener extends Handler {
|
|||
constructor(store) {
|
||||
super(store);
|
||||
|
||||
ssu.addDynamicFrameFilteredListener(this.mm, "load", this, true);
|
||||
SessionStoreUtils.addDynamicFrameFilteredListener(this.mm, "load", this, true);
|
||||
}
|
||||
|
||||
handleEvent(event) {
|
||||
|
@ -329,7 +327,7 @@ class ScrollPositionListener extends Handler {
|
|||
constructor(store) {
|
||||
super(store);
|
||||
|
||||
ssu.addDynamicFrameFilteredListener(this.mm, "scroll", this, false);
|
||||
SessionStoreUtils.addDynamicFrameFilteredListener(this.mm, "scroll", this, false);
|
||||
this.stateChangeNotifier.addObserver(this);
|
||||
}
|
||||
|
||||
|
@ -346,7 +344,7 @@ class ScrollPositionListener extends Handler {
|
|||
}
|
||||
|
||||
collect() {
|
||||
return mapFrameTree(this.mm, ssu.collectScrollPosition.bind(ssu));
|
||||
return mapFrameTree(this.mm, SessionStoreUtils.collectScrollPosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,7 +369,7 @@ class FormDataListener extends Handler {
|
|||
constructor(store) {
|
||||
super(store);
|
||||
|
||||
ssu.addDynamicFrameFilteredListener(this.mm, "input", this, true);
|
||||
SessionStoreUtils.addDynamicFrameFilteredListener(this.mm, "input", this, true);
|
||||
this.stateChangeNotifier.addObserver(this);
|
||||
}
|
||||
|
||||
|
@ -411,7 +409,7 @@ class DocShellCapabilitiesListener extends Handler {
|
|||
}
|
||||
|
||||
onPageLoadStarted() {
|
||||
let caps = ssu.collectDocShellCapabilities(this.mm.docShell);
|
||||
let caps = SessionStoreUtils.collectDocShellCapabilities(this.mm.docShell);
|
||||
|
||||
// Send new data only when the capability list changes.
|
||||
if (caps != this._latestCapabilities) {
|
||||
|
@ -466,14 +464,14 @@ class SessionStorageListener extends Handler {
|
|||
resetEventListener() {
|
||||
if (!this._listener) {
|
||||
this._listener =
|
||||
ssu.addDynamicFrameFilteredListener(this.mm, "MozSessionStorageChanged",
|
||||
this, true);
|
||||
SessionStoreUtils.addDynamicFrameFilteredListener(this.mm, "MozSessionStorageChanged",
|
||||
this, true);
|
||||
}
|
||||
}
|
||||
|
||||
removeEventListener() {
|
||||
ssu.removeDynamicFrameFilteredListener(this.mm, "MozSessionStorageChanged",
|
||||
this._listener, true);
|
||||
SessionStoreUtils.removeDynamicFrameFilteredListener(this.mm, "MozSessionStorageChanged",
|
||||
this._listener, true);
|
||||
this._listener = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,6 @@ var EXPORTED_SYMBOLS = ["SessionStorage"];
|
|||
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const ssu = Cc["@mozilla.org/browser/sessionstore/utils;1"]
|
||||
.createInstance(Ci.nsISessionStoreUtils);
|
||||
|
||||
// A bound to the size of data to store for DOM Storage.
|
||||
const DOM_STORAGE_LIMIT_PREF = "browser.sessionstore.dom_storage_limit";
|
||||
|
||||
|
@ -56,7 +53,7 @@ function forEachNonDynamicChildFrame(frame, cb) {
|
|||
cb(frame);
|
||||
|
||||
// Call the callback recursively for each descendant.
|
||||
ssu.forEachNonDynamicChildFrame(frame, subframe => {
|
||||
SessionStoreUtils.forEachNonDynamicChildFrame(frame, subframe => {
|
||||
return forEachNonDynamicChildFrame(subframe, cb);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -103,22 +103,17 @@ add_task(async function test_frametree_dynamic() {
|
|||
|
||||
async function countNonDynamicFrames(browser) {
|
||||
return ContentTask.spawn(browser, null, async () => {
|
||||
const ssu = Cc["@mozilla.org/browser/sessionstore/utils;1"]
|
||||
.getService(Ci.nsISessionStoreUtils);
|
||||
|
||||
let count = 0;
|
||||
ssu.forEachNonDynamicChildFrame(content, () => count++);
|
||||
SessionStoreUtils.forEachNonDynamicChildFrame(content, () => count++);
|
||||
return count;
|
||||
});
|
||||
}
|
||||
|
||||
async function enumerateIndexes(browser) {
|
||||
return ContentTask.spawn(browser, null, async () => {
|
||||
const ssu = Cc["@mozilla.org/browser/sessionstore/utils;1"]
|
||||
.getService(Ci.nsISessionStoreUtils);
|
||||
|
||||
let indexes = [];
|
||||
ssu.forEachNonDynamicChildFrame(content, (frame, i) => indexes.push(i));
|
||||
SessionStoreUtils.forEachNonDynamicChildFrame(
|
||||
content, (frame, i) => indexes.push(i));
|
||||
return indexes.join(",");
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,40 +2,26 @@
|
|||
* 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/. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface mozIDOMWindowProxy;
|
||||
interface nsIDocShell;
|
||||
webidl EventTarget;
|
||||
webidl Document;
|
||||
interface mozIDOMWindow;
|
||||
interface nsISupports;
|
||||
|
||||
/**
|
||||
* A callback passed to nsISessionStoreUtils.forEachNonDynamicChildFrame().
|
||||
* A callback passed to SessionStoreUtils.forEachNonDynamicChildFrame().
|
||||
*/
|
||||
[function, scriptable, uuid(8199ebf7-76c0-43d6-bcbe-913dd3de3ebf)]
|
||||
interface nsISessionStoreUtilsFrameCallback : nsISupports
|
||||
{
|
||||
/**
|
||||
* handleFrame() will be called once for each non-dynamic child frame of the
|
||||
* given parent |frame|. The second argument is the |index| of the frame in
|
||||
* the list of all child frames.
|
||||
*/
|
||||
void handleFrame(in mozIDOMWindowProxy frame, in unsigned long index);
|
||||
};
|
||||
callback SessionStoreUtilsFrameCallback = void (WindowProxy frame, unsigned long index);
|
||||
|
||||
/**
|
||||
* SessionStore utility functions implemented in C++ for performance reasons.
|
||||
*/
|
||||
[scriptable, uuid(2be448ef-c783-45de-a0df-442bccbb4532)]
|
||||
interface nsISessionStoreUtils : nsISupports
|
||||
{
|
||||
[ChromeOnly, Exposed=Window]
|
||||
namespace SessionStoreUtils {
|
||||
/**
|
||||
* Calls the given |callback| once for each non-dynamic child frame of the
|
||||
* given |window|.
|
||||
*/
|
||||
void forEachNonDynamicChildFrame(in mozIDOMWindowProxy window,
|
||||
in nsISessionStoreUtilsFrameCallback callback);
|
||||
[Throws]
|
||||
void forEachNonDynamicChildFrame(WindowProxy window,
|
||||
SessionStoreUtilsFrameCallback callback);
|
||||
|
||||
/**
|
||||
* Takes the given listener, wraps it in a filter that filters out events from
|
||||
|
@ -47,11 +33,11 @@ interface nsISessionStoreUtils : nsISupports
|
|||
* This is implemented as a native filter, rather than a JS-based one, for
|
||||
* performance reasons.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
nsISupports addDynamicFrameFilteredListener(in EventTarget target,
|
||||
in AString type,
|
||||
in jsval listener,
|
||||
in boolean useCapture);
|
||||
[Throws]
|
||||
nsISupports? addDynamicFrameFilteredListener(EventTarget target,
|
||||
DOMString type,
|
||||
any listener,
|
||||
boolean useCapture);
|
||||
|
||||
/**
|
||||
* Remove the passed-in filtered listener from the given event target, if it's
|
||||
|
@ -63,21 +49,22 @@ interface nsISessionStoreUtils : nsISupports
|
|||
* caller doesn't actually have something that WebIDL considers an
|
||||
* EventListener.
|
||||
*/
|
||||
void removeDynamicFrameFilteredListener(in EventTarget target,
|
||||
in AString type,
|
||||
in nsISupports listener,
|
||||
in boolean useCapture);
|
||||
[Throws]
|
||||
void removeDynamicFrameFilteredListener(EventTarget target,
|
||||
DOMString type,
|
||||
nsISupports listener,
|
||||
boolean useCapture);
|
||||
|
||||
/*
|
||||
* Save the docShell.allow* properties
|
||||
*/
|
||||
ACString collectDocShellCapabilities(in nsIDocShell docShell);
|
||||
ByteString collectDocShellCapabilities(nsIDocShell docShell);
|
||||
|
||||
/*
|
||||
* Restore the docShell.allow* properties
|
||||
*/
|
||||
void restoreDocShellCapabilities(in nsIDocShell docShell,
|
||||
in ACString disallowCapabilities);
|
||||
void restoreDocShellCapabilities(nsIDocShell docShell,
|
||||
ByteString disallowCapabilities);
|
||||
|
||||
/**
|
||||
* Collects scroll position data for any given |frame| in the frame hierarchy.
|
||||
|
@ -88,13 +75,17 @@ interface nsISessionStoreUtils : nsISupports
|
|||
* Returns null when there is no scroll data we want to store for the
|
||||
* given |frame|.
|
||||
*/
|
||||
ACString collectScrollPosition(in Document document);
|
||||
SSScrollPositionDict collectScrollPosition(Document document);
|
||||
|
||||
/**
|
||||
* Restores scroll position data for any given |frame| in the frame hierarchy.
|
||||
*
|
||||
* @param frame (DOMWindow)
|
||||
* @param value (ACString)
|
||||
* @param value (object, see collectScrollPosition())
|
||||
*/
|
||||
void restoreScrollPosition(in mozIDOMWindow frame, in ACString data);
|
||||
void restoreScrollPosition(Window frame, optional SSScrollPositionDict data);
|
||||
};
|
||||
|
||||
dictionary SSScrollPositionDict {
|
||||
ByteString scroll;
|
||||
};
|
|
@ -50,6 +50,7 @@ WEBIDL_FILES = [
|
|||
'MozStorageStatementRow.webidl',
|
||||
'PrecompiledScript.webidl',
|
||||
'PromiseDebugging.webidl',
|
||||
'SessionStoreUtils.webidl',
|
||||
'StructuredCloneHolder.webidl',
|
||||
'TelemetryStopwatch.webidl',
|
||||
'WebExtensionContentScript.webidl',
|
||||
|
|
|
@ -15,9 +15,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
SessionHistory: "resource://gre/modules/sessionstore/SessionHistory.jsm",
|
||||
});
|
||||
|
||||
const ssu = Cc["@mozilla.org/browser/sessionstore/utils;1"]
|
||||
.getService(Ci.nsISessionStoreUtils);
|
||||
|
||||
class GeckoViewContentChild extends GeckoViewChildModule {
|
||||
onInit() {
|
||||
debug `onInit`;
|
||||
|
@ -85,7 +82,8 @@ class GeckoViewContentChild extends GeckoViewChildModule {
|
|||
|
||||
collectSessionState() {
|
||||
let history = SessionHistory.collect(docShell);
|
||||
let [formdata, scrolldata] = this.Utils.mapFrameTree(content, FormData.collect, ssu.collectScrollPosition.bind(ssu));
|
||||
let [formdata, scrolldata] = this.Utils.mapFrameTree(
|
||||
content, FormData.collect, SessionStoreUtils.collectScrollPosition);
|
||||
|
||||
// Save the current document resolution.
|
||||
let zoom = 1;
|
||||
|
@ -214,7 +212,7 @@ class GeckoViewContentChild extends GeckoViewChildModule {
|
|||
if (scrolldata) {
|
||||
this.Utils.restoreFrameTreeData(content, scrolldata, (frame, data) => {
|
||||
if (data.scroll) {
|
||||
ssu.restoreScrollPosition(frame, data.scroll);
|
||||
SessionStoreUtils.restoreScrollPosition(frame, data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,9 +20,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Log", "resource://gre/modules/AndroidLog.jsm", "AndroidLog");
|
||||
|
||||
const ssu = Cc["@mozilla.org/browser/sessionstore/utils;1"]
|
||||
.getService(Ci.nsISessionStoreUtils);
|
||||
|
||||
function dump(a) {
|
||||
Services.console.logStringMessage(a);
|
||||
}
|
||||
|
@ -932,7 +929,8 @@ SessionStore.prototype = {
|
|||
|
||||
// Save the scroll position itself.
|
||||
let content = aBrowser.contentWindow;
|
||||
let [scrolldata] = Utils.mapFrameTree(content, ssu.collectScrollPosition.bind(ssu));
|
||||
let [scrolldata] =
|
||||
Utils.mapFrameTree(content, SessionStoreUtils.collectScrollPosition);
|
||||
scrolldata = scrolldata || {};
|
||||
|
||||
// Save the current document resolution.
|
||||
|
@ -1418,7 +1416,7 @@ SessionStore.prototype = {
|
|||
log("_restoreScrollPosition()");
|
||||
Utils.restoreFrameTreeData(aBrowser.contentWindow, aScrollData, (frame, data) => {
|
||||
if (data.scroll) {
|
||||
ssu.restoreScrollPosition(frame, data.scroll);
|
||||
SessionStoreUtils.restoreScrollPosition(frame, data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -37,8 +37,6 @@
|
|||
#include "mozilla/AddonManagerStartup.h"
|
||||
#include "mozilla/ExtensionPolicyService.h"
|
||||
|
||||
#include "nsSessionStoreUtils.h"
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include "NativeFileWatcherWin.h"
|
||||
#else
|
||||
|
@ -131,8 +129,6 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(AddonManagerStartup,
|
|||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(ExtensionPolicyService,
|
||||
ExtensionPolicyService::GetInstance)
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSessionStoreUtils)
|
||||
|
||||
#if defined(ENABLE_TESTS)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(TelemetryGeckoViewTestingImpl)
|
||||
#endif
|
||||
|
@ -169,7 +165,6 @@ NS_DEFINE_NAMED_CID(NATIVE_OSFILE_INTERNALS_SERVICE_CID);
|
|||
NS_DEFINE_NAMED_CID(NS_ADDONCONTENTPOLICY_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_ADDON_MANAGER_STARTUP_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_ADDON_POLICY_SERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_SESSIONSTOREUTILS_CID);
|
||||
NS_DEFINE_NAMED_CID(NATIVE_FILEWATCHER_SERVICE_CID);
|
||||
#if defined(ENABLE_TESTS)
|
||||
NS_DEFINE_NAMED_CID(NS_TELEMETRYGECKOVIEWTESTING_CID);
|
||||
|
@ -221,8 +216,6 @@ static const Module::CIDEntry kToolkitCIDs[] = {
|
|||
AddonManagerStartupConstructor},
|
||||
{&kNS_ADDON_POLICY_SERVICE_CID, false, nullptr,
|
||||
ExtensionPolicyServiceConstructor},
|
||||
{&kNS_SESSIONSTOREUTILS_CID, false, nullptr,
|
||||
nsSessionStoreUtilsConstructor},
|
||||
{&kNATIVE_FILEWATCHER_SERVICE_CID, false, nullptr,
|
||||
NativeFileWatcherServiceConstructor},
|
||||
#if defined(ENABLE_TESTS)
|
||||
|
@ -268,7 +261,6 @@ static const Module::ContractIDEntry kToolkitContracts[] = {
|
|||
{NS_ADDONCONTENTPOLICY_CONTRACTID, &kNS_ADDONCONTENTPOLICY_CID},
|
||||
{NS_ADDONMANAGERSTARTUP_CONTRACTID, &kNS_ADDON_MANAGER_STARTUP_CID},
|
||||
{NS_ADDON_POLICY_SERVICE_CONTRACTID, &kNS_ADDON_POLICY_SERVICE_CID},
|
||||
{NS_SESSIONSTOREUTILS_CONTRACTID, &kNS_SESSIONSTOREUTILS_CID},
|
||||
{NATIVE_FILEWATCHER_SERVICE_CONTRACTID, &kNATIVE_FILEWATCHER_SERVICE_CID},
|
||||
#if defined(ENABLE_TESTS)
|
||||
{NS_TELEMETRYGECKOVIEWTESTING_CONTRACTID,
|
||||
|
|
|
@ -2,19 +2,13 @@
|
|||
* 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/. */
|
||||
|
||||
#include "nsSessionStoreUtils.h"
|
||||
|
||||
#include "mozilla/dom/Event.h"
|
||||
#include "mozilla/dom/EventListenerBinding.h"
|
||||
#include "mozilla/dom/EventTarget.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsGlobalWindowOuter.h"
|
||||
#include "nsIScrollableFrame.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsCharSeparatedTokenizer.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "mozilla/dom/SessionStoreUtils.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
|
@ -37,7 +31,7 @@ class DynamicFrameEventFilter final : public nsIDOMEventListener {
|
|||
}
|
||||
|
||||
private:
|
||||
~DynamicFrameEventFilter() {}
|
||||
~DynamicFrameEventFilter() = default;
|
||||
|
||||
bool TargetInNonDynamicDocShell(Event* aEvent) {
|
||||
EventTarget* target = aEvent->GetTarget();
|
||||
|
@ -75,30 +69,39 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(DynamicFrameEventFilter)
|
|||
|
||||
} // anonymous namespace
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsSessionStoreUtils, nsISessionStoreUtils)
|
||||
/* static */ void SessionStoreUtils::ForEachNonDynamicChildFrame(
|
||||
const GlobalObject& aGlobal, WindowProxyHolder& aWindow,
|
||||
SessionStoreUtilsFrameCallback& aCallback, ErrorResult& aRv) {
|
||||
if (!aWindow.get()) {
|
||||
aRv.Throw(NS_ERROR_INVALID_ARG);
|
||||
return;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSessionStoreUtils::ForEachNonDynamicChildFrame(
|
||||
mozIDOMWindowProxy* aWindow, nsISessionStoreUtilsFrameCallback* aCallback) {
|
||||
NS_ENSURE_TRUE(aWindow, NS_ERROR_INVALID_ARG);
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> outer = nsPIDOMWindowOuter::From(aWindow);
|
||||
NS_ENSURE_TRUE(outer, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell = outer->GetDocShell();
|
||||
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIDocShell> docShell = aWindow.get()->GetDocShell();
|
||||
if (!docShell) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t length;
|
||||
nsresult rv = docShell->GetChildCount(&length);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
aRv = docShell->GetChildCount(&length);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < length; ++i) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> item;
|
||||
docShell->GetChildAt(i, getter_AddRefs(item));
|
||||
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
|
||||
if (!item) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShell> childDocShell(do_QueryInterface(item));
|
||||
NS_ENSURE_TRUE(childDocShell, NS_ERROR_FAILURE);
|
||||
if (!childDocShell) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
bool isDynamic = false;
|
||||
nsresult rv = childDocShell->GetCreatedDynamically(&isDynamic);
|
||||
|
@ -107,65 +110,60 @@ nsSessionStoreUtils::ForEachNonDynamicChildFrame(
|
|||
}
|
||||
|
||||
int32_t childOffset = childDocShell->GetChildOffset();
|
||||
aCallback->HandleFrame(item->GetWindow(), childOffset);
|
||||
aCallback.Call(WindowProxyHolder(item->GetWindow()->GetBrowsingContext()),
|
||||
childOffset);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSessionStoreUtils::AddDynamicFrameFilteredListener(
|
||||
EventTarget* aTarget, const nsAString& aType,
|
||||
JS::Handle<JS::Value> aListener, bool aUseCapture, JSContext* aCx,
|
||||
nsISupports** aResult) {
|
||||
/* static */ already_AddRefed<nsISupports>
|
||||
SessionStoreUtils::AddDynamicFrameFilteredListener(
|
||||
const GlobalObject& aGlobal, EventTarget& aTarget, const nsAString& aType,
|
||||
JS::Handle<JS::Value> aListener, bool aUseCapture, ErrorResult& aRv) {
|
||||
if (NS_WARN_IF(!aListener.isObject())) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
aRv.Throw(NS_ERROR_INVALID_ARG);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_ENSURE_TRUE(aTarget, NS_ERROR_NO_INTERFACE);
|
||||
|
||||
JS::Rooted<JSObject*> obj(aCx, &aListener.toObject());
|
||||
JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
|
||||
JSContext* cx = aGlobal.Context();
|
||||
JS::Rooted<JSObject*> obj(cx, &aListener.toObject());
|
||||
JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));
|
||||
RefPtr<EventListener> listener =
|
||||
new EventListener(aCx, obj, global, GetIncumbentGlobal());
|
||||
|
||||
new EventListener(cx, obj, global, GetIncumbentGlobal());
|
||||
nsCOMPtr<nsIDOMEventListener> filter(new DynamicFrameEventFilter(listener));
|
||||
|
||||
nsresult rv = aTarget->AddEventListener(aType, filter, aUseCapture);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
aRv = aTarget.AddEventListener(aType, filter, aUseCapture);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
filter.forget(aResult);
|
||||
return NS_OK;
|
||||
return filter.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSessionStoreUtils::RemoveDynamicFrameFilteredListener(EventTarget* aTarget,
|
||||
const nsAString& aType,
|
||||
nsISupports* aListener,
|
||||
bool aUseCapture) {
|
||||
NS_ENSURE_TRUE(aTarget, NS_ERROR_NO_INTERFACE);
|
||||
|
||||
/* static */ void SessionStoreUtils::RemoveDynamicFrameFilteredListener(
|
||||
const GlobalObject& global, EventTarget& aTarget, const nsAString& aType,
|
||||
nsISupports* aListener, bool aUseCapture, ErrorResult& aRv) {
|
||||
nsCOMPtr<nsIDOMEventListener> listener = do_QueryInterface(aListener);
|
||||
NS_ENSURE_TRUE(listener, NS_ERROR_NO_INTERFACE);
|
||||
if (!listener) {
|
||||
aRv.Throw(NS_ERROR_NO_INTERFACE);
|
||||
return;
|
||||
}
|
||||
|
||||
aTarget->RemoveEventListener(aType, listener, aUseCapture);
|
||||
return NS_OK;
|
||||
aTarget.RemoveEventListener(aType, listener, aUseCapture);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSessionStoreUtils::CollectDocShellCapabilities(
|
||||
nsIDocShell* aDocShell, nsACString& aDisallowCapabilities) {
|
||||
/* static */ void SessionStoreUtils::CollectDocShellCapabilities(
|
||||
const GlobalObject& aGlobal, nsIDocShell* aDocShell, nsCString& aRetVal) {
|
||||
bool allow;
|
||||
|
||||
#define TRY_ALLOWPROP(y) \
|
||||
PR_BEGIN_MACRO \
|
||||
aDocShell->GetAllow##y(&allow); \
|
||||
if (!allow) { \
|
||||
if (!aDisallowCapabilities.IsEmpty()) { \
|
||||
aDisallowCapabilities.Append(','); \
|
||||
} \
|
||||
aDisallowCapabilities.Append(#y); \
|
||||
} \
|
||||
#define TRY_ALLOWPROP(y) \
|
||||
PR_BEGIN_MACRO \
|
||||
aDocShell->GetAllow##y(&allow); \
|
||||
if (!allow) { \
|
||||
if (!aRetVal.IsEmpty()) { \
|
||||
aRetVal.Append(','); \
|
||||
} \
|
||||
aRetVal.Append(#y); \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
TRY_ALLOWPROP(Plugins);
|
||||
|
@ -180,15 +178,12 @@ nsSessionStoreUtils::CollectDocShellCapabilities(
|
|||
TRY_ALLOWPROP(Auth);
|
||||
TRY_ALLOWPROP(ContentRetargeting);
|
||||
TRY_ALLOWPROP(ContentRetargetingOnChildren);
|
||||
|
||||
#undef TRY_ALLOWPROP
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSessionStoreUtils::RestoreDocShellCapabilities(
|
||||
nsIDocShell* aDocShell, const nsACString& aDisallowCapabilities) {
|
||||
/* static */ void SessionStoreUtils::RestoreDocShellCapabilities(
|
||||
const GlobalObject& aGlobal, nsIDocShell* aDocShell,
|
||||
const nsCString& aDisallowCapabilities) {
|
||||
aDocShell->SetAllowPlugins(true);
|
||||
aDocShell->SetAllowJavascript(true);
|
||||
aDocShell->SetAllowMetaRedirects(true);
|
||||
|
@ -230,23 +225,19 @@ nsSessionStoreUtils::RestoreDocShellCapabilities(
|
|||
aDocShell->SetAllowContentRetargetingOnChildren(false);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSessionStoreUtils::CollectScrollPosition(Document* aDocument,
|
||||
nsACString& aRet) {
|
||||
aRet.Truncate();
|
||||
|
||||
nsIPresShell* presShell = aDocument->GetShell();
|
||||
/* static */ void SessionStoreUtils::CollectScrollPosition(
|
||||
const GlobalObject& aGlobal, Document& aDocument,
|
||||
SSScrollPositionDict& aRetVal) {
|
||||
nsIPresShell* presShell = aDocument.GetShell();
|
||||
if (!presShell) {
|
||||
return NS_OK;
|
||||
return;
|
||||
}
|
||||
|
||||
nsIScrollableFrame* frame = presShell->GetRootScrollFrameAsScrollable();
|
||||
if (!frame) {
|
||||
return NS_OK;
|
||||
return;
|
||||
}
|
||||
|
||||
nsPoint scrollPos = frame->GetScrollPosition();
|
||||
|
@ -254,22 +245,21 @@ nsSessionStoreUtils::CollectScrollPosition(Document* aDocument,
|
|||
int scrollY = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.y);
|
||||
|
||||
if ((scrollX != 0) || (scrollY != 0)) {
|
||||
const nsPrintfCString position("%d,%d", scrollX, scrollY);
|
||||
aRet.Assign(position);
|
||||
aRetVal.mScroll.Construct() = nsPrintfCString("%d,%d", scrollX, scrollY);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSessionStoreUtils::RestoreScrollPosition(mozIDOMWindow* aWindow,
|
||||
const nsACString& aPos) {
|
||||
nsCCharSeparatedTokenizer tokenizer(aPos, ',');
|
||||
/* static */ void SessionStoreUtils::RestoreScrollPosition(
|
||||
const GlobalObject& aGlobal, nsGlobalWindowInner& aWindow,
|
||||
const SSScrollPositionDict& aData) {
|
||||
if (!aData.mScroll.WasPassed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCCharSeparatedTokenizer tokenizer(aData.mScroll.Value(), ',');
|
||||
nsAutoCString token(tokenizer.nextToken());
|
||||
int pos_X = atoi(token.get());
|
||||
token = tokenizer.nextToken();
|
||||
int pos_Y = atoi(token.get());
|
||||
nsGlobalWindowInner::Cast(aWindow)->ScrollTo(pos_X, pos_Y);
|
||||
|
||||
return NS_OK;
|
||||
aWindow.ScrollTo(pos_X, pos_Y);
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_SessionStoreUtils_h
|
||||
#define mozilla_dom_SessionStoreUtils_h
|
||||
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/SessionStoreUtilsBinding.h"
|
||||
|
||||
class nsIDocument;
|
||||
class nsGlobalWindowInner;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class GlobalObject;
|
||||
struct SSScrollPositionDict;
|
||||
|
||||
class SessionStoreUtils {
|
||||
public:
|
||||
static void ForEachNonDynamicChildFrame(
|
||||
const GlobalObject& aGlobal, WindowProxyHolder& aWindow,
|
||||
SessionStoreUtilsFrameCallback& aCallback, ErrorResult& aRv);
|
||||
|
||||
static already_AddRefed<nsISupports> AddDynamicFrameFilteredListener(
|
||||
const GlobalObject& aGlobal, EventTarget& aTarget, const nsAString& aType,
|
||||
JS::Handle<JS::Value> aListener, bool aUseCapture, ErrorResult& aRv);
|
||||
|
||||
static void RemoveDynamicFrameFilteredListener(
|
||||
const GlobalObject& aGlobal, EventTarget& aTarget, const nsAString& aType,
|
||||
nsISupports* aListener, bool aUseCapture, ErrorResult& aRv);
|
||||
|
||||
static void CollectDocShellCapabilities(const GlobalObject& aGlobal,
|
||||
nsIDocShell* aDocShell,
|
||||
nsCString& aRetVal);
|
||||
|
||||
static void RestoreDocShellCapabilities(
|
||||
const GlobalObject& aGlobal, nsIDocShell* aDocShell,
|
||||
const nsCString& aDisallowCapabilities);
|
||||
|
||||
static void CollectScrollPosition(const GlobalObject& aGlobal,
|
||||
Document& aDocument,
|
||||
SSScrollPositionDict& aRetVal);
|
||||
|
||||
static void RestoreScrollPosition(const GlobalObject& aGlobal,
|
||||
nsGlobalWindowInner& aWindow,
|
||||
const SSScrollPositionDict& data);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_SessionStoreUtils_h
|
|
@ -4,18 +4,12 @@
|
|||
# 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/.
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
'nsISessionStoreUtils.idl',
|
||||
]
|
||||
|
||||
XPIDL_MODULE = 'toolkit_sessionstore'
|
||||
|
||||
EXPORTS += [
|
||||
'nsSessionStoreUtils.h',
|
||||
EXPORTS.mozilla.dom += [
|
||||
'SessionStoreUtils.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'nsSessionStoreUtils.cpp',
|
||||
'SessionStoreUtils.cpp',
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/* 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/. */
|
||||
|
||||
#ifndef nsSessionStoreUtils_h
|
||||
#define nsSessionStoreUtils_h
|
||||
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsISessionStoreUtils.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define NS_SESSIONSTOREUTILS_CID \
|
||||
{ \
|
||||
0xd713b4be, 0x8285, 0x4cab, { \
|
||||
0x9c, 0x0e, 0x0b, 0xbc, 0x38, 0xbf, 0xb9, 0x3c \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NS_SESSIONSTOREUTILS_CONTRACTID \
|
||||
"@mozilla.org/browser/sessionstore/utils;1"
|
||||
|
||||
class nsSessionStoreUtils final : public nsISessionStoreUtils {
|
||||
public:
|
||||
NS_DECL_NSISESSIONSTOREUTILS
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
private:
|
||||
~nsSessionStoreUtils() {}
|
||||
};
|
||||
|
||||
#endif // nsSessionStoreUtils_h
|
|
@ -14,9 +14,6 @@ ChromeUtils.defineModuleGetter(this, "NetUtil",
|
|||
XPCOMUtils.defineLazyServiceGetter(this, "serializationHelper",
|
||||
"@mozilla.org/network/serialization-helper;1",
|
||||
"nsISerializationHelper");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "ssu",
|
||||
"@mozilla.org/browser/sessionstore/utils;1",
|
||||
"nsISessionStoreUtils");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "eTLDService",
|
||||
"@mozilla.org/network/effective-tld-service;1",
|
||||
"nsIEffectiveTLDService");
|
||||
|
@ -161,22 +158,11 @@ var Utils = Object.freeze({
|
|||
*/
|
||||
mapFrameTree(frame, ...dataCollectors) {
|
||||
// Collect data for the current frame.
|
||||
let objs = dataCollectors.map(function(dataCollector) {
|
||||
let obj = dataCollector(frame.document);
|
||||
if (!obj || typeof(obj) == "object") {
|
||||
return obj || {};
|
||||
}
|
||||
// Currently, we return string type when collecting scroll position.
|
||||
// Will switched to webidl and return objects in the future.
|
||||
if (typeof(obj) == "string") {
|
||||
return {scroll: obj};
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
let objs = dataCollectors.map(dataCollector => dataCollector(frame.document) || {});
|
||||
let children = dataCollectors.map(() => []);
|
||||
|
||||
// Recurse into child frames.
|
||||
ssu.forEachNonDynamicChildFrame(frame, (subframe, index) => {
|
||||
SessionStoreUtils.forEachNonDynamicChildFrame(frame, (subframe, index) => {
|
||||
let results = this.mapFrameTree(subframe, ...dataCollectors);
|
||||
if (!results) {
|
||||
return;
|
||||
|
@ -217,7 +203,7 @@ var Utils = Object.freeze({
|
|||
}
|
||||
|
||||
// Recurse into child frames.
|
||||
ssu.forEachNonDynamicChildFrame(frame, (subframe, index) => {
|
||||
SessionStoreUtils.forEachNonDynamicChildFrame(frame, (subframe, index) => {
|
||||
if (data.children[index]) {
|
||||
this.restoreFrameTreeData(subframe, data.children[index], cb);
|
||||
}
|
||||
|
|
|
@ -467,6 +467,7 @@ module.exports = {
|
|||
"ReportingObserver": false,
|
||||
"Request": false,
|
||||
"Response": false,
|
||||
"SessionStoreUtils": false,
|
||||
"SVGAElement": false,
|
||||
"SVGAngle": false,
|
||||
"SVGAnimateElement": false,
|
||||
|
|
Загрузка…
Ссылка в новой задаче