[Pkg-mozext-commits] [tabmixplus] 43/73: Refactore openUILinkIn to divert all the calls from places UI to use our preferences, update the function to address the changes in FeedHandler.loadFeed, since Firefox 42+ clicking 'Subscribe to This Page' always show 'Subscribe to this feed' page

David Prévot taffit at moszumanska.debian.org
Mon May 9 02:30:54 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository tabmixplus.

commit b288c65a4b5fd7bcdf567cae7a493e26740f16ba
Author: onemen <tabmix.onemen at gmail.com>
Date:   Mon Apr 18 19:41:15 2016 +0300

    Refactore openUILinkIn to divert all the calls from places UI to use our preferences, update the function to address the changes in FeedHandler.loadFeed, since Firefox 42+ clicking 'Subscribe to This Page' always show 'Subscribe to this feed' page
---
 chrome/content/links/userInterface.js | 38 +++-------------
 chrome/content/minit/tablib.js        |  6 ---
 chrome/content/places/places.js       | 81 +++++++++++++++++++++--------------
 3 files changed, 56 insertions(+), 69 deletions(-)

diff --git a/chrome/content/links/userInterface.js b/chrome/content/links/userInterface.js
index a944536..bae5c1c 100644
--- a/chrome/content/links/userInterface.js
+++ b/chrome/content/links/userInterface.js
@@ -271,43 +271,17 @@ Tabmix.updateUrlBarValue = function TMP_updateUrlBarValue() {
  *
  */
 Tabmix.openUILink_init = function TMP_openUILink_init() {
-  // in Firefox 17 /(openUILinkIn[^\(]*\([^\)]+)(\))/, find the first
-  // openUILinkIn in the comment
   if ("openUILink" in window) {
-    let code = ["openUILinkIn(url, where, params);",
-                "openUILinkIn(url, where, allowKeywordFixup, postData, referrerUrl);"];
-    let source, str = openUILink.toString();
-    if (str.indexOf(code[0]) > -1)
-      source = code[0];
-    else if (str.indexOf(code[1]) > -1)
-      source = code[1];
-    else
-      return; // nothing we can do
-    /**
-     * don't open blank tab when we are about to add new livemark
-     * divert call from PanelUI-history to our function
-     */
+    // divert all the calls from places UI to use our preferences
     this.changeCode(window, "openUILink")._replace(
-      '{',
-      '{\n' +
-       '  if (event && event.target && event.target.parentNode &&\n' +
-       '      event.target.parentNode.id == "PanelUI-historyItems") {\n' +
-       '    TMP_Places.openHistoryItem(url, event);\n' +
-       '    return;\n' +
-       '  }', {check: Tabmix.isVersion(280)}
-    )._replace(
       'aIgnoreAlt = params.ignoreAlt;',
       'aIgnoreAlt = params.ignoreAlt || null;'
     )._replace(
-      source,
-      '  var win = getTopWin();' +
-      '  if (win && where == "current") {' +
-      '    let _addLivemark = /^feed:/.test(url) &&' +
-      '       Services.prefs.getCharPref("browser.feeds.handler") == "bookmarks";' +
-      '    if (!_addLivemark)' +
-      '      where = win.Tabmix.checkCurrent(url);' +
-      '  }' +
-      '  try {$&}  catch (ex) {  }'
+      /openUILinkIn\(.*\);/,
+      'where = TMP_Places.openUILink(url, event, where, params);\n' +
+      '  if (where) {\n' +
+      '    try {\n      $&\n    } catch (ex) {  }\n' +
+      '  }\n'
     )._replace(// fix incompatibility with Omnibar (O is not defined)
       'O.handleSearchQuery',
       'window.Omnibar.handleSearchQuery', {silent: true}
diff --git a/chrome/content/minit/tablib.js b/chrome/content/minit/tablib.js
index 6e17097..00f9b78 100644
--- a/chrome/content/minit/tablib.js
+++ b/chrome/content/minit/tablib.js
@@ -834,12 +834,6 @@ var tablib = { // eslint-disable-line
       TMP_ClosedTabs.populateUndoSubmenu(undoPopup);
     };
 
-    // history menu open in new tab if the curren tab is locked
-    // open in current tab if it blank or if middle click and setting is on
-    HistoryMenu.prototype._onCommand = function HM__onCommand(aEvent) {
-      TMP_Places.historyMenu(aEvent);
-    };
-
     Tabmix.changeCode(HistoryMenu.prototype, "HistoryMenu.prototype._onPopupShowing")._replace(
       'this.toggleRecentlyClosedWindows();',
       '$& \
diff --git a/chrome/content/places/places.js b/chrome/content/places/places.js
index b9b076b..e2a4811 100644
--- a/chrome/content/places/places.js
+++ b/chrome/content/places/places.js
@@ -72,13 +72,6 @@ var TMP_Places = {
       ).defineProperty();
     }
 
-    if ("PlacesViewBase" in window && PlacesViewBase.prototype) {
-      Tabmix.changeCode(PlacesViewBase.prototype, "PlacesViewBase.prototype._setLivemarkSiteURIMenuItem")._replace(
-        "openUILink(this.getAttribute('targetURI'), event);",
-        "TMP_Places.openLivemarkSite(this.getAttribute('targetURI'), event);"
-      ).toCode();
-    }
-
     // prevent error when closing window with sidbar open
     var docURI = window.document.documentURI;
     if (docURI == "chrome://browser/content/bookmarks/bookmarksPanel.xul" ||
@@ -113,37 +106,63 @@ var TMP_Places = {
     }
   },
 
-  // replace openlivemarksite-menuitem with tabmix function
-  openLivemarkSite: function TMP_PC_openLivemarkSite(aUrl, aEvent) {
-    var where = this.fixWhereToOpen(aEvent, whereToOpenLink(aEvent), this.prefBookmark);
+  openMenuItem: function(aUri, aEvent, aParams, aPref) {
+    let pref = "extensions.tabmix.opentabfor." + aPref;
+    let where = this.isBookmarklet(aUri) ? "current" :
+                this.fixWhereToOpen(aEvent, whereToOpenLink(aEvent, false, true), pref);
     if (where == "current")
       Tabmix.getTopWin().gBrowser.selectedBrowser.tabmix_allowLoad = true;
-    openUILinkIn(aUrl, where, {
-      inBackground: Services.prefs.getBoolPref("browser.tabs.loadBookmarksInBackground"),
-      initiatingDoc: aEvent ? aEvent.target.ownerDocument : null
-    });
+    aParams.inBackground = Services.prefs.getBoolPref("browser.tabs.loadBookmarksInBackground");
+    openUILinkIn(aUri, where, aParams);
+  },
+
+  idsMap: {
+    "PanelUI-historyItems": "history",
+    goPopup: "history",
+    bookmarksMenuPopup: "bookmarks",
+    BMB_bookmarksPopup: "bookmarks",
   },
 
-  // we replace HistoryMenu.prototype._onCommand with this function
-  // look in tablib.js
-  historyMenu: function TMP_PC_historyMenu(aEvent) {
-    var node = aEvent.target._placesNode;
+  openUILink: function(url, event, where, params) {
+    // divert all the calls from places UI to use our preferences
+    //   HistoryMenu.prototype._onCommand
+    //   BookmarkingUI._updateRecentBookmarks/onItemCommand
+    //   CustomizableWidgets<.onViewShowing/<.handleResult/onItemCommand
+    //   PlacesViewBase.prototype._setLivemarkSiteURIMenuItem
+    //   FeedHandler.loadFeed
+    let node = event && event.target ? event.target.parentNode : null;
     if (node) {
-      PlacesUIUtils.markPageAsTyped(node.uri);
-      this.openHistoryItem(node.uri, aEvent);
+      // if the id is not in the list, set pref to "bookmarks" when
+      // _placesNode exist
+      let pref = this.idsMap[node.id] || node._placesNode && "bookmarks";
+      if (pref) {
+        this.openMenuItem(url, event, params, pref);
+        return null;
+      }
     }
-  },
 
-  // open PanelUI-historyItems from history button, diverted from openUILink
-  openHistoryItem: function(aUri, aEvent) {
-    var where = this.isBookmarklet(aUri) ? "current" :
-    this.fixWhereToOpen(aEvent, whereToOpenLink(aEvent, false, true), this.prefHistory);
-    if (where == "current")
-      Tabmix.getTopWin().gBrowser.selectedBrowser.tabmix_allowLoad = true;
-    openUILinkIn(aUri, where, {
-      inBackground: Services.prefs.getBoolPref("browser.tabs.loadBookmarksInBackground"),
-      initiatingDoc: aEvent ? aEvent.target.ownerDocument : null
-    });
+    let win = Tabmix.getTopWin();
+    if (!win || where != "current") {
+      return where;
+    }
+
+    let isLoadFeed = Tabmix.callerTrace("FeedHandler.loadFeed", "loadFeed");
+    if (isLoadFeed) {
+      // since Firefox 42 clicking 'Subscribe to This Page' always show
+      // 'Subscribe to this feed' page
+      let subscribe = Tabmix.isVersion(420) ||
+          Services.prefs.getCharPref("browser.feeds.handler") == "ask";
+      let openNewTab = subscribe && Tabmix.whereToOpen(this.prefBookmark).inNew;
+      if (openNewTab) {
+        where = "tab";
+        params.inBackground = getBoolPref("browser.tabs.loadBookmarksInBackground");
+      } else {
+        win.gBrowser.selectedBrowser.tabmix_allowLoad = true;
+      }
+    } else {
+      where = win.Tabmix.checkCurrent(url);
+    }
+    return where;
   },
 
   isBookmarklet: function(url) {

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