Bug 1123904 - Provide url highlighting in reader mode. r=margaret
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 19 Feb 2015 15:23:56 -0800
changeset 257177 9a4e71f96af9b5f85cf879291b315f65fd71c632
parent 257176 5e5861f36aafadf80c67ba88138baed4acd1cf3c
child 257178 cc01cf09928cfae75fd2b067cca3063331488a4a
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1123904
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1123904 - Provide url highlighting in reader mode. r=margaret
mobile/android/base/Tab.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/Tab.java
+++ b/mobile/android/base/Tab.java
@@ -174,16 +174,20 @@ public class Tab {
     public String getDisplayTitle() {
         if (mTitle != null && mTitle.length() > 0) {
             return mTitle;
         }
 
         return mUrl;
     }
 
+    /**
+     * Returns the base domain of the loaded uri. Note that if the page is
+     * a Reader mode uri, the base domain returned is that of the original uri.
+     */
     public String getBaseDomain() {
         return mBaseDomain;
     }
 
     public Bitmap getFavicon() {
         return mFavicon;
     }
 
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -4425,17 +4425,21 @@ Tab.prototype = {
 
     // Reset state of click-to-play plugin notifications.
     clearTimeout(this.pluginDoorhangerTimeout);
     this.pluginDoorhangerTimeout = null;
     this.shouldShowPluginDoorhanger = true;
     this.clickToPlayPluginsActivated = false;
     // Borrowed from desktop Firefox: http://mxr.mozilla.org/mozilla-central/source/browser/base/content/urlbarBindings.xml#174
     let documentURI = contentWin.document.documentURIObject.spec
-    let matchedURL = documentURI.match(/^((?:[a-z]+:\/\/)?(?:[^\/]+@)?)(.+?)(?::\d+)?(?:\/|$)/);
+
+    // If reader mode, get the base domain for the original url.
+    let strippedURI = this._stripAboutReaderURL(documentURI);
+
+    let matchedURL = strippedURI.match(/^((?:[a-z]+:\/\/)?(?:[^\/]+@)?)(.+?)(?::\d+)?(?:\/|$)/);
     let baseDomain = "";
     if (matchedURL) {
       var domain = "";
       [, , domain] = matchedURL;
 
       try {
         baseDomain = Services.eTLD.getBaseDomainFromHost(domain);
         if (!domain.endsWith(baseDomain)) {
@@ -4483,16 +4487,29 @@ Tab.prototype = {
 
       this.contentDocumentIsDisplayed = false;
       this.hasTouchListener = false;
     } else {
       this.sendViewportUpdate();
     }
   },
 
+  _stripAboutReaderURL: function (url) {
+    if (!url.startsWith("about:reader")) {
+      return url;
+    }
+
+    // From ReaderParent._getOriginalUrl (browser/modules/ReaderParent.jsm).
+    let searchParams = new URLSearchParams(url.substring("about:reader?".length));
+    if (!searchParams.has("url")) {
+        return url;
+    }
+    return decodeURIComponent(searchParams.get("url"));
+  },
+
   // Properties used to cache security state used to update the UI
   _state: null,
   _hostChanged: false, // onLocationChange will flip this bit
 
   onSecurityChange: function(aWebProgress, aRequest, aState) {
     // Don't need to do anything if the data we use to update the UI hasn't changed
     if (this._state == aState && !this._hostChanged)
       return;