diff options
author | Moonchild <mcwerewolf@wolfbeast.com> | 2019-03-13 07:49:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-13 07:49:07 +0100 |
commit | bf0413359245579e9509146d42cd5547e35da695 (patch) | |
tree | 8218d4f60d9eccacbf42df8cb88094a082d401b4 /application/basilisk/components/webextensions/ext-sessions.js | |
parent | 51b821b3fdc5a7eab2369cb6a6680598a6264b08 (diff) | |
parent | 709bc24e9110eba12f94cfcb8db00a8338ac4098 (diff) | |
download | UXP-bf0413359245579e9509146d42cd5547e35da695.tar UXP-bf0413359245579e9509146d42cd5547e35da695.tar.gz UXP-bf0413359245579e9509146d42cd5547e35da695.tar.lz UXP-bf0413359245579e9509146d42cd5547e35da695.tar.xz UXP-bf0413359245579e9509146d42cd5547e35da695.zip |
Merge pull request #998 from MoonchildProductions/master
Merge master into Sync-weave
Diffstat (limited to 'application/basilisk/components/webextensions/ext-sessions.js')
-rw-r--r-- | application/basilisk/components/webextensions/ext-sessions.js | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/application/basilisk/components/webextensions/ext-sessions.js b/application/basilisk/components/webextensions/ext-sessions.js deleted file mode 100644 index 4c13a1ac3..000000000 --- a/application/basilisk/components/webextensions/ext-sessions.js +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ -/* vim: set sts=2 sw=2 et tw=80: */ -"use strict"; - -Cu.import("resource://gre/modules/ExtensionUtils.jsm"); -var { - promiseObserved, -} = ExtensionUtils; - -XPCOMUtils.defineLazyModuleGetter(this, "SessionStore", - "resource:///modules/sessionstore/SessionStore.jsm"); - -function getRecentlyClosed(maxResults, extension) { - let recentlyClosed = []; - - // Get closed windows - let closedWindowData = SessionStore.getClosedWindowData(false); - for (let window of closedWindowData) { - recentlyClosed.push({ - lastModified: window.closedAt, - window: WindowManager.convertFromSessionStoreClosedData(window, extension)}); - } - - // Get closed tabs - for (let window of WindowListManager.browserWindows()) { - let closedTabData = SessionStore.getClosedTabData(window, false); - for (let tab of closedTabData) { - recentlyClosed.push({ - lastModified: tab.closedAt, - tab: TabManager.for(extension).convertFromSessionStoreClosedData(tab, window)}); - } - } - - // Sort windows and tabs - recentlyClosed.sort((a, b) => b.lastModified - a.lastModified); - return recentlyClosed.slice(0, maxResults); -} - -function createSession(restored, extension, sessionId) { - if (!restored) { - return Promise.reject({message: `Could not restore object using sessionId ${sessionId}.`}); - } - let sessionObj = {lastModified: Date.now()}; - if (restored instanceof Ci.nsIDOMChromeWindow) { - return promiseObserved("sessionstore-single-window-restored", subject => subject == restored).then(() => { - sessionObj.window = WindowManager.convert(extension, restored, {populate: true}); - return Promise.resolve([sessionObj]); - }); - } - sessionObj.tab = TabManager.for(extension).convert(restored); - return Promise.resolve([sessionObj]); -} - -extensions.registerSchemaAPI("sessions", "addon_parent", context => { - let {extension} = context; - return { - sessions: { - getRecentlyClosed: function(filter) { - let maxResults = filter.maxResults == undefined ? this.MAX_SESSION_RESULTS : filter.maxResults; - return Promise.resolve(getRecentlyClosed(maxResults, extension)); - }, - restore: function(sessionId) { - let session, closedId; - if (sessionId) { - closedId = sessionId; - session = SessionStore.undoCloseById(closedId); - } else if (SessionStore.lastClosedObjectType == "window") { - // If the most recently closed object is a window, just undo closing the most recent window. - session = SessionStore.undoCloseWindow(0); - } else { - // It is a tab, and we cannot call SessionStore.undoCloseTab without a window, - // so we must find the tab in which case we can just use its closedId. - let recentlyClosedTabs = []; - for (let window of WindowListManager.browserWindows()) { - let closedTabData = SessionStore.getClosedTabData(window, false); - for (let tab of closedTabData) { - recentlyClosedTabs.push(tab); - } - } - - // Sort the tabs. - recentlyClosedTabs.sort((a, b) => b.closedAt - a.closedAt); - - // Use the closedId of the most recently closed tab to restore it. - closedId = recentlyClosedTabs[0].closedId; - session = SessionStore.undoCloseById(closedId); - } - return createSession(session, extension, closedId); - }, - }, - }; -}); |