From 885533af6a87414eedc888967c4de8476e94f84c Mon Sep 17 00:00:00 2001 From: Omkar Konaraddi Date: Fri, 12 Jul 2019 20:54:04 +0000 Subject: [PATCH] Bug 1526818 - QuantumBar: Expose an autocomplete.properties bundle from UrlbarUtils r=adw Differential Revision: https://phabricator.services.mozilla.com/D36250 --HG-- extra : moz-landing-system : lando --- .../urlbar/UrlbarProviderUnifiedComplete.jsm | 23 ++++++++--------- browser/components/urlbar/UrlbarUtils.jsm | 6 +++++ browser/components/urlbar/UrlbarView.jsm | 25 ++++++++----------- .../urlbar/tests/browser/browser_keyword.js | 4 +-- .../tests/browser/browser_search_favicon.js | 7 +++--- .../tests/browser/browser_urlbarDecode.js | 4 +-- 6 files changed, 31 insertions(+), 38 deletions(-) diff --git a/browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm b/browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm index 8d76b53e6efd..846dde4dfe26 100644 --- a/browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm +++ b/browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm @@ -36,12 +36,6 @@ XPCOMUtils.defineLazyGetter(this, "logger", () => Log.repository.getLogger("Urlbar.Provider.UnifiedComplete") ); -XPCOMUtils.defineLazyGetter(this, "bundle", () => - Services.strings.createBundle( - "chrome://global/locale/autocomplete.properties" - ) -); - // See UnifiedComplete. const TITLE_TAGS_SEPARATOR = " \u2013 "; @@ -299,13 +293,16 @@ function makeUrlbarResult(tokens, info) { action.params.url ); } else if (tokens && tokens.length > 1) { - title = bundle.formatStringFromName("bookmarkKeywordSearch", [ - info.comment, - tokens - .slice(1) - .map(t => t.value) - .join(" "), - ]); + title = UrlbarUtils.strings.formatStringFromName( + "bookmarkKeywordSearch", + [ + info.comment, + tokens + .slice(1) + .map(t => t.value) + .join(" "), + ] + ); } return new UrlbarResult( UrlbarUtils.RESULT_TYPE.KEYWORD, diff --git a/browser/components/urlbar/UrlbarUtils.jsm b/browser/components/urlbar/UrlbarUtils.jsm index 58b110345a96..79790932d610 100644 --- a/browser/components/urlbar/UrlbarUtils.jsm +++ b/browser/components/urlbar/UrlbarUtils.jsm @@ -432,6 +432,12 @@ XPCOMUtils.defineLazyGetter(UrlbarUtils.ICON, "DEFAULT", () => { return PlacesUtils.favicons.defaultFavicon.spec; }); +XPCOMUtils.defineLazyGetter(UrlbarUtils, "strings", () => { + return Services.strings.createBundle( + "chrome://global/locale/autocomplete.properties" + ); +}); + /** * UrlbarQueryContext defines a user's autocomplete input from within the urlbar. * It supplements it with details of how the search results should be obtained diff --git a/browser/components/urlbar/UrlbarView.jsm b/browser/components/urlbar/UrlbarView.jsm index 264b8e8f6b01..81ae9c1e585c 100644 --- a/browser/components/urlbar/UrlbarView.jsm +++ b/browser/components/urlbar/UrlbarView.jsm @@ -10,19 +10,12 @@ const { XPCOMUtils } = ChromeUtils.import( "resource://gre/modules/XPCOMUtils.jsm" ); XPCOMUtils.defineLazyModuleGetters(this, { - Services: "resource://gre/modules/Services.jsm", UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm", UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.jsm", UrlbarUtils: "resource:///modules/UrlbarUtils.jsm", AppConstants: "resource://gre/modules/AppConstants.jsm", }); -XPCOMUtils.defineLazyGetter(this, "bundle", function() { - return Services.strings.createBundle( - "chrome://global/locale/autocomplete.properties" - ); -}); - /** * Receives and displays address bar autocomplete results. */ @@ -631,7 +624,7 @@ class UrlbarView { let setURL = false; switch (result.type) { case UrlbarUtils.RESULT_TYPE.TAB_SWITCH: - action = bundle.GetStringFromName("switchToTab2"); + action = UrlbarUtils.strings.GetStringFromName("switchToTab2"); setURL = true; break; case UrlbarUtils.RESULT_TYPE.REMOTE_TAB: @@ -639,9 +632,10 @@ class UrlbarView { setURL = true; break; case UrlbarUtils.RESULT_TYPE.SEARCH: - action = bundle.formatStringFromName("searchWithEngine", [ - result.payload.engine, - ]); + action = UrlbarUtils.strings.formatStringFromName( + "searchWithEngine", + [result.payload.engine] + ); break; case UrlbarUtils.RESULT_TYPE.KEYWORD: isVisitAction = result.payload.input.trim() == result.payload.keyword; @@ -675,7 +669,7 @@ class UrlbarView { } if (isVisitAction) { - action = bundle.GetStringFromName("visit"); + action = UrlbarUtils.strings.GetStringFromName("visit"); title.setAttribute("isurl", "true"); } else { title.removeAttribute("isurl"); @@ -855,9 +849,10 @@ class UrlbarView { } let item = this._rows.children[i]; let action = item.querySelector(".urlbarView-action"); - action.textContent = bundle.formatStringFromName("searchWithEngine", [ - (engine && engine.name) || result.payload.engine, - ]); + action.textContent = UrlbarUtils.strings.formatStringFromName( + "searchWithEngine", + [(engine && engine.name) || result.payload.engine] + ); // If we just changed the engine from the original engine and it had an // icon, then make sure the result now uses the new engine's icon or // failing that the default icon. If we changed it back to the original diff --git a/browser/components/urlbar/tests/browser/browser_keyword.js b/browser/components/urlbar/tests/browser/browser_keyword.js index cb7c5ee9193e..41e204b25a71 100644 --- a/browser/components/urlbar/tests/browser/browser_keyword.js +++ b/browser/components/urlbar/tests/browser/browser_keyword.js @@ -87,9 +87,7 @@ add_task(async function test_display_keyword_without_query() { ); Assert.equal( result.displayed.action, - Services.strings - .createBundle("chrome://global/locale/autocomplete.properties") - .GetStringFromName("visit"), + UrlbarUtils.strings.GetStringFromName("visit"), "Should have visit indicated" ); }); diff --git a/browser/components/urlbar/tests/browser/browser_search_favicon.js b/browser/components/urlbar/tests/browser/browser_search_favicon.js index bba259c0577b..089b47c9bb05 100644 --- a/browser/components/urlbar/tests/browser/browser_search_favicon.js +++ b/browser/components/urlbar/tests/browser/browser_search_favicon.js @@ -51,12 +51,11 @@ add_task(async function() { Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.SEARCH); Assert.equal(result.displayed.title, "foobar"); - let bundle = Services.strings.createBundle( - "chrome://global/locale/autocomplete.properties" - ); Assert.equal( result.displayed.action, - bundle.formatStringFromName("searchWithEngine", ["SearchEngine"]), + UrlbarUtils.strings.formatStringFromName("searchWithEngine", [ + "SearchEngine", + ]), "Should have the correct action text" ); diff --git a/browser/components/urlbar/tests/browser/browser_urlbarDecode.js b/browser/components/urlbar/tests/browser/browser_urlbarDecode.js index 9d930d483565..7532d7b12bae 100644 --- a/browser/components/urlbar/tests/browser/browser_urlbarDecode.js +++ b/browser/components/urlbar/tests/browser/browser_urlbarDecode.js @@ -131,9 +131,7 @@ async function checkInput(inputStr) { ); Assert.equal( result.displayed.action, - Services.strings - .createBundle("chrome://global/locale/autocomplete.properties") - .GetStringFromName("visit"), + UrlbarUtils.strings.GetStringFromName("visit"), "Should be displaying the correct action text" ); }