From 0de0160110d272286aaa6fa960f9c82953235d4e Mon Sep 17 00:00:00 2001 From: "dietrich%mozilla.com" Date: Wed, 5 Jul 2006 20:56:05 +0000 Subject: [PATCH] Bug 332774 Create API allowing extensions to hook into the session-restore service (r=mconnor) git-svn-id: svn://10.0.0.236/trunk@201597 18797224-902f-48f8-a5cc-f745e15eee43 --- .../sessionstore/nsISessionStore.idl | 50 ++++++- .../sessionstore/src/nsSessionStore.js | 17 ++- .../sessionstore/test/nsSessionStoreTest.xul | 140 ++++++++++++++++++ 3 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 mozilla/browser/components/sessionstore/test/nsSessionStoreTest.xul diff --git a/mozilla/browser/components/sessionstore/nsISessionStore.idl b/mozilla/browser/components/sessionstore/nsISessionStore.idl index acc848ff657..4d5b9d7f842 100644 --- a/mozilla/browser/components/sessionstore/nsISessionStore.idl +++ b/mozilla/browser/components/sessionstore/nsISessionStore.idl @@ -39,6 +39,7 @@ #include "nsISupports.idl" interface nsIDOMWindow; +interface nsIDOMNode; /** * nsISessionStore keeps track of the current browsing state - i.e. @@ -46,7 +47,7 @@ interface nsIDOMWindow; * - and allows to restore everything into one window. */ -[scriptable, uuid(38bad250-0021-11db-92e3-0800200c9a66)] +[scriptable, uuid(320996f0-0c5e-11db-9cd8-0800200c9a66)] interface nsISessionStore : nsISupports { /** @@ -66,4 +67,51 @@ interface nsISessionStore : nsISupports * Indicates the window to be restored (FIFO ordered). */ void undoCloseTab(in nsIDOMWindow aWindow, in unsigned long aIndex); + + /** + * @param aWindow is the window to get the value for. + * @param aKey is the value's name. + * + * @return A string value or "" if none is set. + */ + string getWindowValue(in nsIDOMWindow aWindow, in string aKey); + + /** + * @param aWindow is the window to set the value for. + * @param aKey is the value's name. + * @param aStringValue is the value itself (use toSource/eval before setting JS objects). + */ + void setWindowValue(in nsIDOMWindow aWindow, in string aKey, in string aStringValue); + + /** + * @param aWindow is the window to get the value for. + * @param aKey is the value's name. + */ + void deleteWindowValue(in nsIDOMWindow aWindow, in string aKey); + + /** + * @param aTab is the tab to get the value for. + * @param aKey is the value's name. + * + * @return A string value or "" if none is set. + */ + string getTabValue(in nsIDOMNode aTab, in string aKey); + + /** + * @param aTab is the tab to set the value for. + * @param aKey is the value's name. + * @param aStringValue is the value itself (use toSource/eval before setting JS objects). + */ + void setTabValue(in nsIDOMNode aTab, in string aKey, in string aStringValue); + + /** + * @param aTab is the tab to get the value for. + * @param aKey is the value's name. + */ + void deleteTabValue(in nsIDOMNode aTab, in string aKey); + + /** + * @param aName is the name of the attribute to save/restore for all xul:tabs. + */ + void persistTabAttribute(in string aName); }; diff --git a/mozilla/browser/components/sessionstore/src/nsSessionStore.js b/mozilla/browser/components/sessionstore/src/nsSessionStore.js index 5de3ab09247..9b17502c5c4 100644 --- a/mozilla/browser/components/sessionstore/src/nsSessionStore.js +++ b/mozilla/browser/components/sessionstore/src/nsSessionStore.js @@ -737,6 +737,13 @@ SessionStoreService.prototype = { } }, + deleteWindowValue: function sss_deleteWindowValue(aWindow, aKey) { + if (this._windows[aWindow.__SSi].extData[aKey]) + delete this._windows[aWindow.__SSi].extData[aKey]; + else + Components.returnCode = -1; //zeniko: or should we rather fail silently? + }, + getTabValue: function sss_getTabValue(aTab, aKey) { var data = aTab.__SS_extdata || {}; return data[aKey] || ""; @@ -747,9 +754,17 @@ SessionStoreService.prototype = { aTab.__SS_extdata = {}; } aTab.__SS_extdata[aKey] = aStringValue; - this.saveStateDelayed(aTop.ownerDocument.defaultView); + this.saveStateDelayed(aTab.ownerDocument.defaultView); }, + deleteTabValue: function sss_deleteTabValue(aTab, aKey) { + if (aTab.__SS_extdata[aKey]) + delete aTab.__SS_extdata[aKey]; + else + Components.returnCode = -1; //zeniko: or should we rather fail silently? + }, + + persistTabAttribute: function sss_persistTabAttribute(aName) { this.xulAttributes.push(aName); this.saveStateDelayed(); diff --git a/mozilla/browser/components/sessionstore/test/nsSessionStoreTest.xul b/mozilla/browser/components/sessionstore/test/nsSessionStoreTest.xul new file mode 100644 index 00000000000..304b7292116 --- /dev/null +++ b/mozilla/browser/components/sessionstore/test/nsSessionStoreTest.xul @@ -0,0 +1,140 @@ + + + + + + + +