mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 548939 - Use SessionStore in tab engine [r=Mardak]
Created a fake SessionStore service for Fennec that imitates the parts of Firefox's SessionStore API that we need. Then used the now "consistent" SessionStore service in the Tabs engine.
This commit is contained in:
parent
6734a1e7b5
commit
59471f450c
@ -104,13 +104,6 @@ TabStore.prototype = {
|
||||
__proto__: Store.prototype,
|
||||
_remoteClients: {},
|
||||
|
||||
get _sessionStore() {
|
||||
let sessionStore = Cc["@mozilla.org/browser/sessionstore;1"].
|
||||
getService(Ci.nsISessionStore);
|
||||
this.__defineGetter__("_sessionStore", function() { return sessionStore;});
|
||||
return this._sessionStore;
|
||||
},
|
||||
|
||||
itemExists: function TabStore_itemExists(id) {
|
||||
return id == Clients.clientID;
|
||||
},
|
||||
@ -119,33 +112,36 @@ TabStore.prototype = {
|
||||
getAllTabs: function getAllTabs(filter) {
|
||||
let filteredUrls = new RegExp(Svc.Prefs.get("engine.tabs.filteredUrls"), "i");
|
||||
|
||||
// Iterate through each tab of each window
|
||||
let allTabs = [];
|
||||
let wins = Svc.WinMediator.getEnumerator("navigator:browser");
|
||||
while (wins.hasMoreElements()) {
|
||||
// Get the tabs for both Firefox and Fennec
|
||||
let window = wins.getNext();
|
||||
let tabs = window.gBrowser && window.gBrowser.tabContainer.childNodes;
|
||||
tabs = tabs || window.Browser._tabs;
|
||||
|
||||
// Extract various pieces of tab data
|
||||
Array.forEach(tabs, function(tab) {
|
||||
let browser = tab.linkedBrowser || tab.browser;
|
||||
let url = browser.currentURI.spec;
|
||||
|
||||
// Filter out some urls if necessary
|
||||
if (filter && filteredUrls.test(url))
|
||||
let currentState = JSON.parse(Svc.Session.getBrowserState());
|
||||
currentState.windows.forEach(function(window) {
|
||||
window.tabs.forEach(function(tab) {
|
||||
// Make sure there are history entries to look at.
|
||||
if (!tab.entries.length)
|
||||
return;
|
||||
// Until we store full or partial history, just grab the current entry.
|
||||
// index is 1 based, so make sure we adjust.
|
||||
let entry = tab.entries[tab.index - 1];
|
||||
|
||||
// Filter out some urls if necessary. SessionStore can return empty
|
||||
// tabs in some cases - easiest thing is to just ignore them for now.
|
||||
if (!entry.url || filter && filteredUrls.test(entry.url))
|
||||
return;
|
||||
|
||||
// weaveLastUsed will only be set if the tab was ever selected (or
|
||||
// opened after Weave was running). So it might not ever be set.
|
||||
// I think it's also possible that attributes[.image] might not be set
|
||||
// so handle that as well.
|
||||
allTabs.push({
|
||||
title: browser.contentTitle || "",
|
||||
urlHistory: [url],
|
||||
icon: browser.mIconURL || "",
|
||||
lastUsed: tab.lastUsed || 0
|
||||
title: entry.title || "",
|
||||
urlHistory: [entry.url],
|
||||
icon: tab.attributes && tab.attributes.image || "",
|
||||
lastUsed: tab.extData && tab.extData.weaveLastUsed || 0
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return allTabs;
|
||||
},
|
||||
|
||||
@ -248,7 +244,8 @@ TabTracker.prototype = {
|
||||
this._changedIDs[Clients.clientID] = true;
|
||||
|
||||
// Store a timestamp in the tab to track when it was last used
|
||||
event.originalTarget.lastUsed = Math.floor(Date.now() / 1000);
|
||||
Svc.Session.setTabValue(event.originalTarget, "weaveLastUsed",
|
||||
Math.floor(Date.now() / 1000));
|
||||
},
|
||||
|
||||
get changedIDs() this._changedIDs,
|
||||
|
@ -787,6 +787,57 @@ let FakeSvc = {
|
||||
"@mozilla.org/privatebrowsing;1": {
|
||||
autoStarted: false,
|
||||
privateBrowsingEnabled: false
|
||||
},
|
||||
// Session Restore
|
||||
"@mozilla.org/browser/sessionstore;1": {
|
||||
setTabValue: function(tab, key, value) {
|
||||
if (!tab.__SS_extdata)
|
||||
tab.__SS_extdata = {};
|
||||
tab.__SS_extData[key] = value;
|
||||
},
|
||||
getBrowserState: function() {
|
||||
// Fennec should have only one window. Not more, not less.
|
||||
let state = { windows: [{ tabs: [] }] };
|
||||
let window = Svc.WinMediator.getMostRecentWindow("navigator:browser");
|
||||
|
||||
// Extract various pieces of tab data
|
||||
window.Browser._tabs.forEach(function(tab) {
|
||||
let tabState = { entries: [{}] };
|
||||
let browser = tab.browser;
|
||||
|
||||
// Cases when we want to skip the tab. Could come up if we get
|
||||
// state as a tab is opening or closing.
|
||||
if (!browser || !browser.currentURI || !browser.sessionHistory)
|
||||
return;
|
||||
|
||||
let history = browser.sessionHistory;
|
||||
if (history.count > 0) {
|
||||
// We're only grabbing the current history entry for now.
|
||||
let entry = history.getEntryAtIndex(history.index, false);
|
||||
tabState.entries[0].url = entry.URI.spec;
|
||||
// Like SessionStore really does it...
|
||||
if (entry.title && entry.title != entry.url)
|
||||
tabState.entries[0].title = entry.title;
|
||||
}
|
||||
// index is 1-based
|
||||
tabState.index = 1;
|
||||
|
||||
// Get the image for the tab. Fennec doesn't quite work the same
|
||||
// way as Firefox, so we'll just get this from the browser object.
|
||||
tabState.attributes = { image: browser.mIconURL };
|
||||
|
||||
// Collect the extdata
|
||||
if (tab.__SS_extdata) {
|
||||
tabState.extData = {};
|
||||
for (let key in tab.__SS_extdata)
|
||||
tabState.extData[key] = tab.__SS_extdata[key];
|
||||
}
|
||||
|
||||
// Add the tab to the window
|
||||
state.windows[0].tabs.push(tabState);
|
||||
});
|
||||
return JSON.stringify(state);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -818,6 +869,7 @@ Svc.Obs = Observers;
|
||||
["Version", "@mozilla.org/xpcom/version-comparator;1", "nsIVersionComparator"],
|
||||
["WinMediator", "@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator"],
|
||||
["WinWatcher", "@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher"],
|
||||
["Session", "@mozilla.org/browser/sessionstore;1", "nsISessionStore"],
|
||||
].forEach(function(lazy) Utils.lazySvc(Svc, lazy[0], lazy[1], Ci[lazy[2]]));
|
||||
|
||||
let Str = {};
|
||||
|
Loading…
Reference in New Issue
Block a user