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
This commit is contained in:
Omkar Konaraddi 2019-07-12 20:54:04 +00:00
Родитель 62f76168bd
Коммит 885533af6a
6 изменённых файлов: 31 добавлений и 38 удалений

Просмотреть файл

@ -36,12 +36,6 @@ XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Provider.UnifiedComplete") Log.repository.getLogger("Urlbar.Provider.UnifiedComplete")
); );
XPCOMUtils.defineLazyGetter(this, "bundle", () =>
Services.strings.createBundle(
"chrome://global/locale/autocomplete.properties"
)
);
// See UnifiedComplete. // See UnifiedComplete.
const TITLE_TAGS_SEPARATOR = " \u2013 "; const TITLE_TAGS_SEPARATOR = " \u2013 ";
@ -299,13 +293,16 @@ function makeUrlbarResult(tokens, info) {
action.params.url action.params.url
); );
} else if (tokens && tokens.length > 1) { } else if (tokens && tokens.length > 1) {
title = bundle.formatStringFromName("bookmarkKeywordSearch", [ title = UrlbarUtils.strings.formatStringFromName(
"bookmarkKeywordSearch",
[
info.comment, info.comment,
tokens tokens
.slice(1) .slice(1)
.map(t => t.value) .map(t => t.value)
.join(" "), .join(" "),
]); ]
);
} }
return new UrlbarResult( return new UrlbarResult(
UrlbarUtils.RESULT_TYPE.KEYWORD, UrlbarUtils.RESULT_TYPE.KEYWORD,

Просмотреть файл

@ -432,6 +432,12 @@ XPCOMUtils.defineLazyGetter(UrlbarUtils.ICON, "DEFAULT", () => {
return PlacesUtils.favicons.defaultFavicon.spec; 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. * UrlbarQueryContext defines a user's autocomplete input from within the urlbar.
* It supplements it with details of how the search results should be obtained * It supplements it with details of how the search results should be obtained

Просмотреть файл

@ -10,19 +10,12 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm" "resource://gre/modules/XPCOMUtils.jsm"
); );
XPCOMUtils.defineLazyModuleGetters(this, { XPCOMUtils.defineLazyModuleGetters(this, {
Services: "resource://gre/modules/Services.jsm",
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm", UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.jsm", UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.jsm",
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm", UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
AppConstants: "resource://gre/modules/AppConstants.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. * Receives and displays address bar autocomplete results.
*/ */
@ -631,7 +624,7 @@ class UrlbarView {
let setURL = false; let setURL = false;
switch (result.type) { switch (result.type) {
case UrlbarUtils.RESULT_TYPE.TAB_SWITCH: case UrlbarUtils.RESULT_TYPE.TAB_SWITCH:
action = bundle.GetStringFromName("switchToTab2"); action = UrlbarUtils.strings.GetStringFromName("switchToTab2");
setURL = true; setURL = true;
break; break;
case UrlbarUtils.RESULT_TYPE.REMOTE_TAB: case UrlbarUtils.RESULT_TYPE.REMOTE_TAB:
@ -639,9 +632,10 @@ class UrlbarView {
setURL = true; setURL = true;
break; break;
case UrlbarUtils.RESULT_TYPE.SEARCH: case UrlbarUtils.RESULT_TYPE.SEARCH:
action = bundle.formatStringFromName("searchWithEngine", [ action = UrlbarUtils.strings.formatStringFromName(
result.payload.engine, "searchWithEngine",
]); [result.payload.engine]
);
break; break;
case UrlbarUtils.RESULT_TYPE.KEYWORD: case UrlbarUtils.RESULT_TYPE.KEYWORD:
isVisitAction = result.payload.input.trim() == result.payload.keyword; isVisitAction = result.payload.input.trim() == result.payload.keyword;
@ -675,7 +669,7 @@ class UrlbarView {
} }
if (isVisitAction) { if (isVisitAction) {
action = bundle.GetStringFromName("visit"); action = UrlbarUtils.strings.GetStringFromName("visit");
title.setAttribute("isurl", "true"); title.setAttribute("isurl", "true");
} else { } else {
title.removeAttribute("isurl"); title.removeAttribute("isurl");
@ -855,9 +849,10 @@ class UrlbarView {
} }
let item = this._rows.children[i]; let item = this._rows.children[i];
let action = item.querySelector(".urlbarView-action"); let action = item.querySelector(".urlbarView-action");
action.textContent = bundle.formatStringFromName("searchWithEngine", [ action.textContent = UrlbarUtils.strings.formatStringFromName(
(engine && engine.name) || result.payload.engine, "searchWithEngine",
]); [(engine && engine.name) || result.payload.engine]
);
// If we just changed the engine from the original engine and it had an // 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 // 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 // failing that the default icon. If we changed it back to the original

Просмотреть файл

@ -87,9 +87,7 @@ add_task(async function test_display_keyword_without_query() {
); );
Assert.equal( Assert.equal(
result.displayed.action, result.displayed.action,
Services.strings UrlbarUtils.strings.GetStringFromName("visit"),
.createBundle("chrome://global/locale/autocomplete.properties")
.GetStringFromName("visit"),
"Should have visit indicated" "Should have visit indicated"
); );
}); });

Просмотреть файл

@ -51,12 +51,11 @@ add_task(async function() {
Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.SEARCH); Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.SEARCH);
Assert.equal(result.displayed.title, "foobar"); Assert.equal(result.displayed.title, "foobar");
let bundle = Services.strings.createBundle(
"chrome://global/locale/autocomplete.properties"
);
Assert.equal( Assert.equal(
result.displayed.action, result.displayed.action,
bundle.formatStringFromName("searchWithEngine", ["SearchEngine"]), UrlbarUtils.strings.formatStringFromName("searchWithEngine", [
"SearchEngine",
]),
"Should have the correct action text" "Should have the correct action text"
); );

Просмотреть файл

@ -131,9 +131,7 @@ async function checkInput(inputStr) {
); );
Assert.equal( Assert.equal(
result.displayed.action, result.displayed.action,
Services.strings UrlbarUtils.strings.GetStringFromName("visit"),
.createBundle("chrome://global/locale/autocomplete.properties")
.GetStringFromName("visit"),
"Should be displaying the correct action text" "Should be displaying the correct action text"
); );
} }