[Pkg-mozext-commits] [tabmixplus] 37/44: Rewrite openLinkWithHistory and openInverseLink, add openLinkInCurrent. Use ContentClick.getParamsForLink to try and get valid url for javascript links. this changes fixed some errors in the old code: tab not move after current tab when link don't have a valid url regression from changeset 6b9be2b7c932 SessionStore.restoreTabContent exist since Firefox 28

David Prévot taffit at moszumanska.debian.org
Wed Oct 15 02:10:05 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 f8cb06beccf6a13884a0102968e267f7dd413602
Author: onemen <tabmix.onemen at gmail.com>
Date:   Sun Oct 12 23:02:46 2014 +0300

    Rewrite openLinkWithHistory and openInverseLink, add openLinkInCurrent. Use ContentClick.getParamsForLink to try and get valid url for javascript links.
    this changes fixed some errors in the old code:
    tab not move after current tab when link don't have a valid url
    regression from changeset 6b9be2b7c932 SessionStore.restoreTabContent exist since Firefox 28
---
 chrome/content/content.js      |   5 ++
 chrome/content/minit/tablib.js | 120 +++++++++++++++++++----------------------
 chrome/content/tabmix.xul      |   4 +-
 modules/ContentClick.jsm       |   5 ++
 4 files changed, 67 insertions(+), 67 deletions(-)

diff --git a/chrome/content/content.js b/chrome/content/content.js
index b48dba7..1615483 100644
--- a/chrome/content/content.js
+++ b/chrome/content/content.js
@@ -60,6 +60,11 @@ let TabmixContentHandler = {
 
   isFrameInContent: function(href, name) {
     return LinkNodeUtils.isFrameInContent(content, href, name);
+  },
+
+  wrapNode: function(node) {
+    let window = TabmixClickEventHandler._focusedWindow;
+    return LinkNodeUtils.wrap(node, window);
   }
 };
 
diff --git a/chrome/content/minit/tablib.js b/chrome/content/minit/tablib.js
index 35b40c7..93ad87b 100644
--- a/chrome/content/minit/tablib.js
+++ b/chrome/content/minit/tablib.js
@@ -886,83 +886,73 @@ var tablib = {
     }
 
     gBrowser.openLinkWithHistory = function (aTab) {
-      var url = gContextMenu.linkURL;
-      if (!isValidUrl(url))
-         url = null;
-
-      var newTab = this.duplicateTab(aTab, url, null, url == null);
-      if (!newTab.selected &&
-          Services.prefs.getBoolPref("browser.sessionstore.restore_on_demand")) {
-        TabmixSessionManager.SessionStore.restoreTabContent(newTab);
-      }
+      var {target, linkURL} = gContextMenu;
+      var url = tablib.getValidUrl(aTab, linkURL, target);
+      if (!url)
+        return;
 
-      if (!url) {
-        try {
-          // flip aTab with newTab
-          // and dispatch click event on the link....
-          newTab.removeAttribute("busy");
-          this.setIcon(newTab, this.getBrowserForTab(aTab).mIconURL);
-          newTab.label = aTab.label;
-          this._tabAttrModified(newTab);
-          newTab.width = aTab.width;
-
-          var index = newTab._tPos;
-          this.moveTabTo(newTab, aTab._tPos);
-          var pos = index > aTab._tPos ? 1 : 0;
-          this.moveTabTo(aTab, index + pos);
-
-          if (Tabmix.prefs.getBoolPref("loadDuplicateInBackground")) {
-            this.selectedTab = newTab;
-            aTab.removeAttribute("visited");
-            aTab.removeAttribute("tabmix_selectedID");
-          }
-          else {
-            aTab.owner = newTab;
-            this.selectedTab = aTab;
-            newTab.setAttribute("tabmix_selectedID", Tabmix._nextSelectedID++);
-            newTab.setAttribute("visited", true);
-            newTab.setAttribute("dontremovevisited", true);
-            aTab.setAttribute("tabmix_selectedID", Tabmix._nextSelectedID++);
-          }
+      var doc = target.ownerDocument;
+      if (typeof gContextMenu._unremotePrincipal == "function")
+        urlSecurityCheck(url, gContextMenu._unremotePrincipal(doc.nodePrincipal));
+      else
+        urlSecurityCheck(url, doc.nodePrincipal);
 
-          var event = document.createEvent("Events");
-          event.initEvent("click", true, false);
-          event.tabmix_openLinkWithHistory = true;
-          event.button = 0;
-          gContextMenu.target.dispatchEvent(event);
+      return this.duplicateTab(aTab, url);
+    }
 
-          newTab = aTab;
-        }
-        catch (ex) {Tabmix.assert(ex);}
-      }
+    Tabmix.changeCode(nsContextMenu.prototype, "nsContextMenu.prototype.openLinkInTab")._replace(
+      'charset: doc.characterSet,',
+      '$&\n                 ' +
+      'inBackground: !Services.prefs.getBoolPref("browser.tabs.loadInBackground"),'
+    ).toCode(false, Tabmix.originalFunctions, "openInverseLink");
 
-      return newTab;
-    }
+    gBrowser.openInverseLink = function (aTab) {
+      var {target, linkURL} = gContextMenu;
+      var url = tablib.getValidUrl(aTab, linkURL, target);
+      if (!url)
+        return;
 
-    gBrowser.openInverseLink = function () {
-      var url = gContextMenu.linkURL;
-      if (!isValidUrl(url))
-        return null;
+      // the next line is insertion point for treeStyleTab extension look in
+      // treeStyleTab hacks.js
+      var newTab = null;
+
+      gContextMenu.linkURL = url;
+      // originalFunctions.openInverseLink is a copy of original
+      // nsContextMenu.prototype.openLinkInTab
+      Tabmix.originalFunctions.openInverseLink.apply(gContextMenu);
+    }
 
-      // aTab is for treeStyleTab extension look in treeStyleTab hacks.js
-      var aTab = this.selectedTab;
+    tablib.openLinkInCurrent = function() {
+      var {target, linkURL} = gContextMenu;
+      var url = tablib.getValidUrl(gBrowser.selectedTab, linkURL, target);
+      if (!url)
+        return;
 
-      var bgPref = Services.prefs.getBoolPref("browser.tabs.loadInBackground");
-      var newTab = this.loadOneTab(url, null, null, null, !bgPref, true);
-      if (url == "about:blank")
-        tablib.setURLBarFocus();
-      return newTab;
+      gContextMenu.linkURL = url;
+      gBrowser.selectedBrowser.tabmix_allowLoad = true;
+      gContextMenu.openLinkInCurrent();
     }
 
-  ///XXX why we add this to window ?
-    window.isValidUrl = function (aUrl) {
+    tablib.getValidUrl = function(tab, url, target) {
       // valid urls don't contain spaces ' '; if we have a space it isn't a valid url.
       // Also disallow dropping javascript: or data: urls--bail out
-      if (!aUrl || !aUrl.length || aUrl.indexOf(" ", 0) != -1 ||
-           /^\s*(javascript|data):/.test(aUrl))
-        return false;
+      let isValid = function(aUrl) {
+        if (!aUrl || !aUrl.length || aUrl.indexOf(" ", 0) != -1 ||
+             /^\s*(javascript|data):/.test(aUrl))
+          return false;
+        return true;
+      }
 
-      return true;
+      if (!isValid(url)) {
+        let json = {button: 0, shiftKey: false, ctrlKey: false, metaKey: false,
+                    altKey: false, target: {},
+                    tabmix_openLinkWithHistory: true};
+        let result = Tabmix.ContentClick.getParamsForLink(json,
+              target, url,
+              tab.linkedBrowser, document.commandDispatcher.focusedWindow);
+        return result._href && isValid(result._href) ? result._href : null;
+      }
+      return url;
     }
 
     gBrowser.closeAllTabs = function TMP_closeAllTabs() {
diff --git a/chrome/content/tabmix.xul b/chrome/content/tabmix.xul
index d4b03ce..40343ed 100644
--- a/chrome/content/tabmix.xul
+++ b/chrome/content/tabmix.xul
@@ -110,11 +110,11 @@
 
     <popup id="contentAreaContextMenu">
       <menuitem id="context-openlinkincurrent" label="&linkhere.label;" accesskey="&linkhere.accesskey;"
-                oncommand="gBrowser.mCurrentBrowser.tabmix_allowLoad = true; gContextMenu.openLinkInCurrent();"/>
+                oncommand="tablib.openLinkInCurrent();"/>
       <menuitem id="tm-openinverselink" label="" fglabel="&linkForegroundTab.label;" bglabel="&linkBackgroundTab.label;"
          fgaccesskey="&linkForegroundTab.accesskey;" bgaccesskey="&linkBackgroundTab.accesskey;"
          insertafter="context-openlinkintab"
-         oncommand="gBrowser.openInverseLink();"/>
+         oncommand="gBrowser.openInverseLink(gBrowser.mCurrentTab);"/>
       <menuitem id="tm-openAllLinks" label="&openalllinks.label;" accesskey="&openalllinks.accesskey;"
          insertafter="context-openlinkintab" oncommand="TabmixContext.openMultipleLinks();"/>
       <menuitem id="tm-linkWithhistory" label="&linkwithhistory.label;" accesskey="&linkwithhistory.accesskey;"
diff --git a/modules/ContentClick.jsm b/modules/ContentClick.jsm
index e4e3c61..7bea3be 100644
--- a/modules/ContentClick.jsm
+++ b/modules/ContentClick.jsm
@@ -156,6 +156,11 @@ let ContentClickInternal = {
   },
 
   getParamsForLink: function(event, linkNode, href, browser, focusedWindow) {
+    if (browser.getAttribute("remote") == "true" &&
+        TabmixSvc.syncHandlers.has(browser.permanentKey)) {
+      let handler = TabmixSvc.syncHandlers.get(browser.permanentKey);
+      linkNode = handler.wrapNode(linkNode);
+    }
     let wrappedNode = this.getWrappedNode(linkNode, focusedWindow, event.button == 0);
     return this._getParamsForLink(event, wrappedNode, href, browser);
   },

-- 
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