[Pkg-mozext-commits] [tabmixplus] 19/123: [e10s] Use frame script for accessing docShell capabilities
David Prévot
taffit at moszumanska.debian.org
Wed Sep 17 21:16:23 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository tabmixplus.
commit 371734caa0a3896b3b4628103e0c5d6e31ed1ab0
Author: onemen <tabmix.onemen at gmail.com>
Date: Wed Aug 13 22:42:22 2014 +0300
[e10s] Use frame script for accessing docShell capabilities
---
chrome/content/content.js | 42 +++++++++++++++
chrome/content/overlay/tabContextMenu.xul | 17 +++---
chrome/content/session/session.js | 43 ++++++++++-----
chrome/content/tabmix.js | 4 ++
modules/DocShellCapabilities.jsm | 89 +++++++++++++++++++++++++++++++
5 files changed, 174 insertions(+), 21 deletions(-)
diff --git a/chrome/content/content.js b/chrome/content/content.js
new file mode 100644
index 0000000..7d2d1cf
--- /dev/null
+++ b/chrome/content/content.js
@@ -0,0 +1,42 @@
+"use strict";
+
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
+
+// DocShellCapabilities exist since Firefox 27
+XPCOMUtils.defineLazyModuleGetter(this, "DocShellCapabilities",
+ "resource:///modules/sessionstore/DocShellCapabilities.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "TabmixSvc",
+ "resource://tabmixplus/Services.jsm");
+
+let MessageListener = {
+ MESSAGES: [
+ "Tabmix:restorePermissions",
+ "Tabmix:collectPermissions",
+ ],
+
+ init: function () {
+ this.MESSAGES.forEach(m => addMessageListener(m, this));
+ },
+
+ receiveMessage: function ({name, data}) {
+ switch (name) {
+ case "Tabmix:restorePermissions":
+ let disallow = new Set(data.disallow && data.disallow.split(","));
+ DocShellCapabilities.restore(docShell, disallow);
+ sendSyncMessage("Tabmix:restoPermissionsComplete", {
+ disallow: data.disallow,
+ reload: data.reload
+ });
+ break;
+ case "Tabmix:collectPermissions":
+ let caps = DocShellCapabilities.collect(docShell).join(",");
+ sendSyncMessage("Tabmix:collectPermissionsComplete", {caps: caps});
+ break;
+ }
+ }
+};
+
+MessageListener.init();
diff --git a/chrome/content/overlay/tabContextMenu.xul b/chrome/content/overlay/tabContextMenu.xul
index c02c734..0d53b4f 100644
--- a/chrome/content/overlay/tabContextMenu.xul
+++ b/chrome/content/overlay/tabContextMenu.xul
@@ -98,16 +98,15 @@
<menu id="tm-docShell" insertbefore="context_closeTab"
label="&docShellMenu.label;" accesskey="&docShellMenu.accesskey;">
<menupopup
- onpopupshowing='for(var i = 0; i != childNodes.length; i++) {childNodes[i].setAttribute("checked",gBrowser.getBrowserForTab(TabContextMenu.contextTab).docShell[childNodes[i].value]);}
- event.stopPropagation();'
+ onpopupshowing="Tabmix.docShellCapabilities.onGet(this.childNodes, TabContextMenu.contextTab);
+ event.stopPropagation();"
onpopupshown="event.stopPropagation();"
- oncommand="var currentDocShell = gBrowser.getBrowserForTab(TabContextMenu.contextTab).docShell; currentDocShell[event.originalTarget.value] = !currentDocShell[event.originalTarget.value];
- gBrowser.reloadTab(TabContextMenu.contextTab);">
- <menuitem label="&allowImage.label;" value="allowImages" class="menuitem-iconic" type="checkbox" checked="true" />
- <menuitem label="&allowFrame.label;" value="allowSubframes" class="menuitem-iconic" type="checkbox" checked="true" />
- <menuitem label="&allowRedirect.label;" value="allowMetaRedirects" class="menuitem-iconic" type="checkbox" checked="true" />
- <menuitem label="&allowPlugin.label;" value="allowPlugins" class="menuitem-iconic" type="checkbox" checked="true" />
- <menuitem label="&allowJavascript.label;" value="allowJavascript" class="menuitem-iconic" type="checkbox" checked="true" />
+ oncommand="Tabmix.docShellCapabilities.onSet(TabContextMenu.contextTab,event.originalTarget);">
+ <menuitem label="&allowImage.label;" value="Images" class="menuitem-iconic" type="checkbox" checked="true" />
+ <menuitem label="&allowFrame.label;" value="Subframes" class="menuitem-iconic" type="checkbox" checked="true" />
+ <menuitem label="&allowRedirect.label;" value="MetaRedirects" class="menuitem-iconic" type="checkbox" checked="true" />
+ <menuitem label="&allowPlugin.label;" value="Plugins" class="menuitem-iconic" type="checkbox" checked="true" />
+ <menuitem label="&allowJavascript.label;" value="Javascript" class="menuitem-iconic" type="checkbox" checked="true" />
</menupopup>
</menu>
<menuitem id="tm-freezeTab" insertbefore="context_closeTab"
diff --git a/chrome/content/session/session.js b/chrome/content/session/session.js
index c1b3912..d35eb27 100644
--- a/chrome/content/session/session.js
+++ b/chrome/content/session/session.js
@@ -126,10 +126,10 @@ var TabmixSessionData = {
if (checkPref && !Tabmix.prefs.getBoolPref("sessions.save.permissions"))
tabProperties += "11111";
else {
- var aTabDocShell = gBrowser.getBrowserForTab(aTab).docShell;
- for ( j = 0; j < this.docShellItems.length; j++ ){
- tabProperties += aTabDocShell["allow" + this.docShellItems[j]] ? "1" : "0";
- }
+ let disallow = Tabmix.docShellCapabilities.collect(aTab);
+ this.docShellItems.forEach(function(item) {
+ tabProperties += disallow.indexOf(item) != -1 ? "0" : "1";
+ });
}
// save fixed label data
@@ -245,14 +245,13 @@ var TabmixSessionData = {
if (TabmixTabbar.lockallTabs || aTab.hasAttribute("locked"))
Tabmix.setItem(aTab, "_locked", aTab.hasAttribute("locked"));
- if (checkPref && !Tabmix.prefs.getBoolPref("sessions.save.permissions")) return;
- var aPermission;
- var aTabDocShell = gBrowser.getBrowserForTab(aTab).docShell;
- for ( j = 0; j < this.docShellItems.length; j++ ) {
- aPermission = tabProperties.charAt(j + k) == "1";
- if (aTabDocShell["allow" + this.docShellItems[j]] != aPermission)
- aTabDocShell["allow" + this.docShellItems[j]] = aPermission;
- }
+ if (checkPref && !Tabmix.prefs.getBoolPref("sessions.save.permissions"))
+ return;
+
+ let disallow = this.docShellItems.filter(function(item, i) {
+ return tabProperties.charAt(i + k) == "0";
+ });
+ Tabmix.docShellCapabilities.restore(aTab, disallow);
},
getTabValue: function TMP_sData_getTabValue(tab, id, parse) {
@@ -352,6 +351,12 @@ var TabmixSessionManager = {
},
_init: function SM__init() {
+ if (Tabmix.isVersion(320)) {
+ XPCOMUtils.defineLazyModuleGetter(this, "TabState",
+ "resource:///modules/sessionstore/TabState.jsm");
+ XPCOMUtils.defineLazyModuleGetter(this, "TabStateCache",
+ "resource:///modules/sessionstore/TabStateCache.jsm");
+ }
// just in case tablib isn't init yet
// when Webmail Notifier extension istalled and user have master password
// we can get here before the browser window is loaded
@@ -3305,6 +3310,15 @@ try{
delete aTab.__SS_extdata;
// delete any sesionRestore data
delete browser.__SS_data;
+
+ // clear TabStateCache
+ if (Tabmix.isVersion(320)) {
+ let data = this.TabStateCache.get(browser) || {};
+ for (let key of Object.keys(data)) {
+ data[key] = null;
+ }
+ this.TabStateCache.update(browser, data);
+ }
},
updateSelected: function(newIndex, removeAttribute) {
@@ -3533,6 +3547,11 @@ try{
let sh = browser.webNavigation.sessionHistory;
sh.getEntryAtIndex(savedHistory.index, true);
sh.reloadCurrentEntry();
+
+ // Flush all data from the content script synchronously.
+ if (Tabmix.isVersion(320))
+ this.TabState.flush(browser);
+
} catch (ex) {Tabmix.log("error in loadOneTab\n" + ex)};
}, // end of "loadOneTab : function(...............)"
diff --git a/chrome/content/tabmix.js b/chrome/content/tabmix.js
index 98556e9..a87b3b3 100644
--- a/chrome/content/tabmix.js
+++ b/chrome/content/tabmix.js
@@ -324,6 +324,8 @@ var TMP_eventListener = {
Tabmix.lazy_import(Tabmix, "autoReload", "AutoReload", "AutoReload");
Tabmix.lazy_import(Tabmix, "renameTab", "RenameTab", "RenameTab");
Tabmix.lazy_import(TabmixSessionManager, "_decode", "Decode", "Decode");
+ Tabmix.lazy_import(Tabmix, "docShellCapabilities",
+ "DocShellCapabilities", "DocShellCapabilities", true, [window]);
} catch (ex) {Tabmix.assert(ex);}
this._tabEvents = ["SSTabRestoring", "PrivateTab:PrivateChanged",
@@ -1005,6 +1007,8 @@ var TMP_eventListener = {
Tabmix.navToolbox.deinit();
Tabmix.australisUI.deinit();
+ if (Tabmix.DocShellCapabilitiesInitialized)
+ Tabmix.docShellCapabilities.deinit(window);
},
// some theme not useing updated Tabmix tab binding
diff --git a/modules/DocShellCapabilities.jsm b/modules/DocShellCapabilities.jsm
new file mode 100644
index 0000000..e430801
--- /dev/null
+++ b/modules/DocShellCapabilities.jsm
@@ -0,0 +1,89 @@
+"use strict";
+
+this.EXPORTED_SYMBOLS = ["DocShellCapabilities"];
+
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "TabStateCache",
+ "resource:///modules/sessionstore/TabStateCache.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "TabmixSvc",
+ "resource://tabmixplus/Services.jsm");
+
+this.DocShellCapabilities = {
+ init: function(window) {
+ this.useFrameScript = TabmixSvc.version(320);
+ if (this.useFrameScript) {
+ let mm = window.getGroupMessageManager("browsers");
+ mm.addMessageListener("Tabmix:restoPermissionsComplete", this);
+ mm.loadFrameScript("chrome://tabmixplus/content/content.js", true);
+ }
+ },
+
+ deinit: function(window) {
+ if (this.useFrameScript) {
+ let mm = window.getGroupMessageManager("browsers");
+ mm.removeMessageListener("Tabmix:restoPermissionsComplete", this);
+ }
+ },
+
+ receiveMessage: function(message) {
+ if (message.name == "Tabmix:restoPermissionsComplete") {
+ let browser = message.target;
+ if (message.data.reload)
+ browser.reload();
+ else {
+ // Update the persistent tab state cache
+ TabStateCache.update(browser, {
+ disallow: message.data.disallow || null
+ });
+ }
+ }
+ },
+
+ caps: ["Images","Subframes","MetaRedirects","Plugins","Javascript"],
+
+ collect: function(tab) {
+ let state = TabmixSvc.ss.getTabState(tab);
+ return TabmixSvc.JSON.parse(state).disallow || "";
+ },
+
+ restore: function(tab, disallow, reload) {
+ let browser = tab.linkedBrowser;
+ if (reload && tab.getAttribute("pending") == "true")
+ reload = false;
+
+ if (!this.useFrameScript) {
+ let browserDocShell = browser.docShell;
+ disallow = new Set(disallow);
+ for (let cap of this.caps)
+ browserDocShell["allow" + cap] = !disallow.has(cap);
+ if (reload)
+ browser.reload();
+ return;
+ }
+
+ browser.messageManager.sendAsyncMessage("Tabmix:restorePermissions",
+ {disallow: disallow.join(","), reload: reload || false});
+ },
+
+ /*** for tab context menu ***/
+
+ onGet: function(nodes, tab) {
+ let disallow = this.collect(tab);
+ for (let i = 0; i < nodes.length; i++) {
+ nodes[i].setAttribute("checked", disallow.indexOf(nodes[i].value) == -1);
+ }
+ },
+
+ onSet: function(tab, node) {
+ let nodes = node.parentNode.childNodes;
+ let disallow = [];
+ for (let i = 0; i < nodes.length; i++) {
+ if (nodes[i].getAttribute("checked") != "true")
+ disallow.push(nodes[i].value);
+ }
+ this.restore(tab, disallow, true);
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/tabmixplus.git
More information about the Pkg-mozext-commits
mailing list