diff --git a/mobile/android/base/Tab.java b/mobile/android/base/Tab.java index 2602d3f840a9..ac413c3e2577 100644 --- a/mobile/android/base/Tab.java +++ b/mobile/android/base/Tab.java @@ -179,6 +179,10 @@ public class Tab { 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; } diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 53e5232016be..1a7f51f751a6 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -4430,7 +4430,11 @@ Tab.prototype = { 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 = ""; @@ -4488,6 +4492,19 @@ Tab.prototype = { } }, + _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