michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: michael@0: interface nsIDOMWindow; michael@0: interface nsIDOMNode; michael@0: michael@0: /** michael@0: * nsISessionStore keeps track of the current browsing state - i.e. michael@0: * tab history, cookies, scroll state, form data, and window features michael@0: * - and allows to restore everything into one browser window. michael@0: * michael@0: * The nsISessionStore API operates mostly on browser windows and the tabbrowser michael@0: * tabs contained in them: michael@0: * michael@0: * * "Browser windows" are those DOM windows having loaded michael@0: * chrome://browser/content/browser.xul . From overlays you can just pass the michael@0: * global |window| object to the API, though (or |top| from a sidebar). michael@0: * From elsewhere you can get browser windows through the nsIWindowMediator michael@0: * by looking for "navigator:browser" windows. michael@0: * michael@0: * * "Tabbrowser tabs" are all the child nodes of a browser window's michael@0: * |gBrowser.tabContainer| such as e.g. |gBrowser.selectedTab|. michael@0: */ michael@0: michael@0: [scriptable, uuid(0c99811f-6c5f-4a78-9c31-2d266d714175)] michael@0: interface nsISessionStore : nsISupports michael@0: { michael@0: /** michael@0: * Is it possible to restore the previous session. Will always be false when michael@0: * in Private Browsing mode. michael@0: */ michael@0: attribute boolean canRestoreLastSession; michael@0: michael@0: /** michael@0: * Restore the previous session if possible. This will not overwrite the michael@0: * current session. Instead the previous session will be merged into the michael@0: * current session. Current windows will be reused if they were windows that michael@0: * pinned tabs were previously restored into. New windows will be opened as michael@0: * needed. michael@0: * michael@0: * Note: This will throw if there is no previous state to restore. Check with michael@0: * canRestoreLastSession first to avoid thrown errors. michael@0: */ michael@0: void restoreLastSession(); michael@0: michael@0: /** michael@0: * Get the current browsing state. michael@0: * @returns a JSON string representing the session state. michael@0: */ michael@0: AString getBrowserState(); michael@0: michael@0: /** michael@0: * Set the browsing state. michael@0: * This will immediately restore the state of the whole application to the state michael@0: * passed in, *replacing* the current session. michael@0: * michael@0: * @param aState is a JSON string representing the session state. michael@0: */ michael@0: void setBrowserState(in AString aState); michael@0: michael@0: /** michael@0: * @param aWindow is the browser window whose state is to be returned. michael@0: * michael@0: * @returns a JSON string representing a session state with only one window. michael@0: */ michael@0: AString getWindowState(in nsIDOMWindow aWindow); michael@0: michael@0: /** michael@0: * @param aWindow is the browser window whose state is to be set. michael@0: * @param aState is a JSON string representing a session state. michael@0: * @param aOverwrite boolean overwrite existing tabs michael@0: */ michael@0: void setWindowState(in nsIDOMWindow aWindow, in AString aState, in boolean aOverwrite); michael@0: michael@0: /** michael@0: * @param aTab is the tabbrowser tab whose state is to be returned. michael@0: * michael@0: * @returns a JSON string representing the state of the tab michael@0: * (note: doesn't contain cookies - if you need them, use getWindowState instead). michael@0: */ michael@0: AString getTabState(in nsIDOMNode aTab); michael@0: michael@0: /** michael@0: * @param aTab is the tabbrowser tab whose state is to be set. michael@0: * @param aState is a JSON string representing a session state. michael@0: */ michael@0: void setTabState(in nsIDOMNode aTab, in AString aState); michael@0: michael@0: /** michael@0: * Duplicates a given tab as thoroughly as possible. michael@0: * michael@0: * @param aWindow is the browser window into which the tab will be duplicated. michael@0: * @param aTab is the tabbrowser tab to duplicate (can be from a different window). michael@0: * @param aDelta is the offset to the history entry to load in the duplicated tab. michael@0: * @returns a reference to the newly created tab. michael@0: */ michael@0: nsIDOMNode duplicateTab(in nsIDOMWindow aWindow, in nsIDOMNode aTab, michael@0: [optional] in long aDelta); michael@0: michael@0: /** michael@0: * Get the number of restore-able tabs for a browser window michael@0: */ michael@0: unsigned long getClosedTabCount(in nsIDOMWindow aWindow); michael@0: michael@0: /** michael@0: * Get closed tab data michael@0: * michael@0: * @param aWindow is the browser window for which to get closed tab data michael@0: * @returns a JSON string representing the list of closed tabs. michael@0: */ michael@0: AString getClosedTabData(in nsIDOMWindow aWindow); michael@0: michael@0: /** michael@0: * @param aWindow is the browser window to reopen a closed tab in. michael@0: * @param aIndex is the index of the tab to be restored (FIFO ordered). michael@0: * @returns a reference to the reopened tab. michael@0: */ michael@0: nsIDOMNode undoCloseTab(in nsIDOMWindow aWindow, in unsigned long aIndex); michael@0: michael@0: /** michael@0: * @param aWindow is the browser window associated with the closed tab. michael@0: * @param aIndex is the index of the closed tab to be removed (FIFO ordered). michael@0: */ michael@0: nsIDOMNode forgetClosedTab(in nsIDOMWindow aWindow, in unsigned long aIndex); michael@0: michael@0: /** michael@0: * Get the number of restore-able windows michael@0: */ michael@0: unsigned long getClosedWindowCount(); michael@0: michael@0: /** michael@0: * Get closed windows data michael@0: * michael@0: * @returns a JSON string representing the list of closed windows. michael@0: */ michael@0: AString getClosedWindowData(); michael@0: michael@0: /** michael@0: * @param aIndex is the index of the windows to be restored (FIFO ordered). michael@0: * @returns the nsIDOMWindow object of the reopened window michael@0: */ michael@0: nsIDOMWindow undoCloseWindow(in unsigned long aIndex); michael@0: michael@0: /** michael@0: * @param aIndex is the index of the closed window to be removed (FIFO ordered). michael@0: * michael@0: * @throws NS_ERROR_INVALID_ARG michael@0: * when aIndex does not map to a closed window michael@0: */ michael@0: nsIDOMNode forgetClosedWindow(in unsigned long aIndex); michael@0: michael@0: /** michael@0: * @param aWindow is the window to get the value for. michael@0: * @param aKey is the value's name. michael@0: * michael@0: * @returns A string value or an empty string if none is set. michael@0: */ michael@0: AString getWindowValue(in nsIDOMWindow aWindow, in AString aKey); michael@0: michael@0: /** michael@0: * @param aWindow is the browser window to set the value for. michael@0: * @param aKey is the value's name. michael@0: * @param aStringValue is the value itself (use JSON.stringify/parse before setting JS objects). michael@0: */ michael@0: void setWindowValue(in nsIDOMWindow aWindow, in AString aKey, in AString aStringValue); michael@0: michael@0: /** michael@0: * @param aWindow is the browser window to get the value for. michael@0: * @param aKey is the value's name. michael@0: */ michael@0: void deleteWindowValue(in nsIDOMWindow aWindow, in AString aKey); michael@0: michael@0: /** michael@0: * @param aTab is the tabbrowser tab to get the value for. michael@0: * @param aKey is the value's name. michael@0: * michael@0: * @returns A string value or an empty string if none is set. michael@0: */ michael@0: AString getTabValue(in nsIDOMNode aTab, in AString aKey); michael@0: michael@0: /** michael@0: * @param aTab is the tabbrowser tab to set the value for. michael@0: * @param aKey is the value's name. michael@0: * @param aStringValue is the value itself (use JSON.stringify/parse before setting JS objects). michael@0: */ michael@0: void setTabValue(in nsIDOMNode aTab, in AString aKey, in AString aStringValue); michael@0: michael@0: /** michael@0: * @param aTab is the tabbrowser tab to get the value for. michael@0: * @param aKey is the value's name. michael@0: */ michael@0: void deleteTabValue(in nsIDOMNode aTab, in AString aKey); michael@0: michael@0: /** michael@0: * @param aKey is the value's name. michael@0: * michael@0: * @returns A string value or an empty string if none is set. michael@0: */ michael@0: AString getGlobalValue(in AString aKey); michael@0: michael@0: /** michael@0: * @param aKey is the value's name. michael@0: * @param aStringValue is the value itself (use JSON.stringify/parse before setting JS objects). michael@0: */ michael@0: void setGlobalValue(in AString aKey, in AString aStringValue); michael@0: michael@0: /** michael@0: * @param aTab is the browser tab to get the value for. michael@0: * @param aKey is the value's name. michael@0: */ michael@0: void deleteGlobalValue(in AString aKey); michael@0: michael@0: /** michael@0: * @param aName is the name of the attribute to save/restore for all tabbrowser tabs. michael@0: */ michael@0: void persistTabAttribute(in AString aName); michael@0: };