Bug 1603437 - Make UrlbarInput::trimValue private. r=mak
authorDão Gottwald <dao@mozilla.com>
Fri, 13 Dec 2019 12:49:07 +0000
changeset 506906 727a60b134e2db62109870ec5c79c754ddabe288
parent 506905 9f7039ca819d352fcda67fa542668af11fb3a751
child 506907 127801c9ada50e3bcfa2859592f0fe2c67746bea
push id36915
push userrgurzau@mozilla.com
push dateFri, 13 Dec 2019 21:43:22 +0000
treeherdermozilla-central@f09f24f2b545 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1603437
milestone73.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 1603437 - Make UrlbarInput::trimValue private. r=mak Differential Revision: https://phabricator.services.mozilla.com/D56946
browser/components/BrowserGlue.jsm
browser/components/sessionstore/test/browser_522545.js
browser/components/urlbar/UrlbarInput.jsm
browser/components/urlbar/docs/overview.rst
browser/components/urlbar/tests/browser/browser_urlbarStop.js
browser/components/urlbar/tests/browser/browser_urlbarValueOnTabSwitch.js
--- a/browser/components/BrowserGlue.jsm
+++ b/browser/components/BrowserGlue.jsm
@@ -510,16 +510,17 @@ XPCOMUtils.defineLazyModuleGetters(this,
     "resource:///modules/aboutpages/AboutProtectionsHandler.jsm",
   AddonManager: "resource://gre/modules/AddonManager.jsm",
   AppMenuNotifications: "resource://gre/modules/AppMenuNotifications.jsm",
   AsyncShutdown: "resource://gre/modules/AsyncShutdown.jsm",
   Blocklist: "resource://gre/modules/Blocklist.jsm",
   BookmarkHTMLUtils: "resource://gre/modules/BookmarkHTMLUtils.jsm",
   BookmarkJSONUtils: "resource://gre/modules/BookmarkJSONUtils.jsm",
   BrowserUsageTelemetry: "resource:///modules/BrowserUsageTelemetry.jsm",
+  BrowserUtils: "resource://gre/modules/BrowserUtils.jsm",
   BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
   ContextualIdentityService:
     "resource://gre/modules/ContextualIdentityService.jsm",
   Corroborate: "resource://gre/modules/Corroborate.jsm",
   Discovery: "resource:///modules/Discovery.jsm",
   ExtensionsUI: "resource:///modules/ExtensionsUI.jsm",
   FirefoxMonitor: "resource:///modules/FirefoxMonitor.jsm",
   FxAccounts: "resource://gre/modules/FxAccounts.jsm",
@@ -3506,19 +3507,17 @@ BrowserGlue.prototype = {
         } else {
           title = bundle.GetStringFromName("tabArrivingNotification.title");
         }
         // Use the page URL as the body. We strip the fragment and query (after
         // the `?` and `#` respectively) to reduce size, and also format it the
         // same way that the url bar would.
         body = URIs[0].uri.replace(/([?#]).*$/, "$1");
         let wasTruncated = body.length < URIs[0].uri.length;
-        if (win.gURLBar) {
-          body = win.gURLBar.trimValue(body);
-        }
+        body = BrowserUtils.trimURL(body);
         if (wasTruncated) {
           body = bundle.formatStringFromName(
             "singleTabArrivingWithTruncatedURL.body",
             [body]
           );
         }
       } else {
         title = bundle.GetStringFromName(
--- a/browser/components/sessionstore/test/browser_522545.js
+++ b/browser/components/sessionstore/test/browser_522545.js
@@ -391,17 +391,17 @@ function test() {
         "userTypedValue was null after loading a URI"
       );
       ok(
         !browser.didStartLoadSinceLastUserTyping(),
         "We should have reset the load state when the tab loaded"
       );
       is(
         gURLBar.value,
-        gURLBar.trimValue("http://example.com/"),
+        BrowserUtils.trimURL("http://example.com/"),
         "Address bar's value set after loading URI"
       );
       runNextTest();
     });
   }
 
   let tests = [
     test_newTabFocused,
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -230,30 +230,16 @@ class UrlbarInput {
     this.editor.QueryInterface(Ci.nsIPlaintextEditor).newlineHandling =
       Ci.nsIPlaintextEditor.eNewlinesStripSurroundingWhitespace;
 
     this._setOpenViewOnFocus();
     Services.prefs.addObserver("browser.urlbar.openViewOnFocus", this);
   }
 
   /**
-   * Shortens the given value, usually by removing http:// and trailing slashes,
-   * such that calling nsIURIFixup::createFixupURI with the result will produce
-   * the same URI.
-   *
-   * @param {string} val
-   *   The string to be trimmed if it appears to be URI
-   * @returns {string}
-   *   The trimmed string
-   */
-  trimValue(val) {
-    return UrlbarPrefs.get("trimURLs") ? BrowserUtils.trimURL(val) : val;
-  }
-
-  /**
    * Applies styling to the text in the urlbar input, depending on the text.
    */
   formatValue() {
     // The editor may not exist if the toolbar is not visible.
     if (this.editor) {
       this.valueFormatter.update();
     }
   }
@@ -1079,17 +1065,17 @@ class UrlbarInput {
   _setValue(val, allowTrim) {
     this._untrimmedValue = val;
 
     let originalUrl = ReaderMode.getOriginalUrlObjectForDisplay(val);
     if (originalUrl) {
       val = originalUrl.displaySpec;
     }
 
-    val = allowTrim ? this.trimValue(val) : val;
+    val = allowTrim ? this._trimValue(val) : val;
 
     this.valueIsTyped = false;
     this._resultForCurrentValue = null;
     this.inputField.value = val;
     this.formatValue();
     this.removeAttribute("actiontype");
 
     // Dispatch ValueChange event for accessibility.
@@ -1262,20 +1248,20 @@ class UrlbarInput {
       !UrlbarPrefs.get("decodeURLsOnCopy")
     ) {
       return uri.displaySpec;
     }
 
     // Just the beginning of the URL is selected, or we want a decoded
     // url. First check for a trimmed value.
     let spec = uri.displaySpec;
-    let trimmedSpec = this.trimValue(spec);
+    let trimmedSpec = this._trimValue(spec);
     if (spec != trimmedSpec) {
-      // Prepend the portion that trimValue removed from the beginning.
-      // This assumes trimValue will only truncate the URL at
+      // Prepend the portion that _trimValue removed from the beginning.
+      // This assumes _trimValue will only truncate the URL at
       // the beginning or end (or both).
       let trimmedSegments = spec.split(trimmedSpec);
       selectedVal = trimmedSegments[0] + selectedVal;
     }
 
     return selectedVal;
   }
 
@@ -1343,16 +1329,30 @@ class UrlbarInput {
     this.window.BrowserSearch.recordSearchInTelemetry(
       engine,
       "urlbar",
       details
     );
   }
 
   /**
+   * Shortens the given value, usually by removing http:// and trailing slashes,
+   * such that calling nsIURIFixup::createFixupURI with the result will produce
+   * the same URI.
+   *
+   * @param {string} val
+   *   The string to be trimmed if it appears to be URI
+   * @returns {string}
+   *   The trimmed string
+   */
+  _trimValue(val) {
+    return UrlbarPrefs.get("trimURLs") ? BrowserUtils.trimURL(val) : val;
+  }
+
+  /**
    * If appropriate, this prefixes a search string with 'www.' and suffixes it
    * with browser.fixup.alternate.suffix prior to navigating.
    *
    * @param {Event} event
    *   The event that triggered this query.
    * @param {string} value
    *   The search string that should be canonized.
    * @returns {string}
--- a/browser/components/urlbar/docs/overview.rst
+++ b/browser/components/urlbar/docs/overview.rst
@@ -264,18 +264,16 @@ user and handling their input.
 
 Implements an input box *View*, owns an *UrlbarView*.
 
 .. highlight:: JavaScript
 .. code::
 
   UrlbarInput {
     constructor(options = { textbox, panel });
-    // Used to trim urls when necessary (e.g. removing "http://")
-    trimValue();
     // Uses UrlbarValueFormatter to highlight the base host, search aliases
     // and to keep the host visible on overflow.
     formatValue(val);
     openResults();
     // Converts an internal URI (e.g. a URI with a username or password) into
     // one which we can expose to the user.
     makeURIReadable(uri);
     // Handles an event which would cause a url or text to be opened.
--- a/browser/components/urlbar/tests/browser/browser_urlbarStop.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarStop.js
@@ -11,45 +11,45 @@
 const goodURL = "http://mochi.test:8888/";
 const badURL = "http://mochi.test:8888/whatever.html";
 
 add_task(async function() {
   gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, goodURL);
   await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
   is(
     gURLBar.value,
-    gURLBar.trimValue(goodURL),
+    BrowserUtils.trimURL(goodURL),
     "location bar reflects loaded page"
   );
 
   await typeAndSubmitAndStop(badURL);
   is(
     gURLBar.value,
-    gURLBar.trimValue(goodURL),
+    BrowserUtils.trimURL(goodURL),
     "location bar reflects loaded page after stop()"
   );
   gBrowser.removeCurrentTab();
 
   gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:blank");
   is(gURLBar.value, "", "location bar is empty");
 
   await typeAndSubmitAndStop(badURL);
   is(
     gURLBar.value,
-    gURLBar.trimValue(badURL),
+    BrowserUtils.trimURL(badURL),
     "location bar reflects stopped page in an empty tab"
   );
   gBrowser.removeCurrentTab();
 });
 
 async function typeAndSubmitAndStop(url) {
   await promiseAutocompleteResultPopup(url, window, true);
   is(
     gURLBar.value,
-    gURLBar.trimValue(url),
+    BrowserUtils.trimURL(url),
     "location bar reflects loading page"
   );
 
   let docLoadPromise = BrowserTestUtils.waitForDocLoadAndStopIt(
     url,
     gBrowser.selectedBrowser
   );
 
--- a/browser/components/urlbar/tests/browser/browser_urlbarValueOnTabSwitch.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarValueOnTabSwitch.js
@@ -40,17 +40,17 @@ add_task(async function() {
     false,
     testURL
   );
   BrowserTestUtils.loadURI(deletedURLTab.linkedBrowser, testURL);
   BrowserTestUtils.loadURI(fullURLTab.linkedBrowser, testURL);
   BrowserTestUtils.loadURI(partialURLTab.linkedBrowser, testURL);
   await Promise.all([loaded1, loaded2, loaded3]);
 
-  testURL = gURLBar.trimValue(testURL);
+  testURL = BrowserUtils.trimURL(testURL);
   testPartialURL = testURL.substr(0, testURL.length - charsToDelete);
 
   function cleanUp() {
     gBrowser.removeTab(fullURLTab);
     gBrowser.removeTab(partialURLTab);
     gBrowser.removeTab(deletedURLTab);
   }