Skip to content

Commit

Permalink
Bug 1845150 - Update notificationbox usage for search engine removal …
Browse files Browse the repository at this point in the history
…notification r=search-reviewers,fluent-reviewers,Standard8,bolsson

Notification can be triggered locally via this snippet:

```js
BrowserSearch.removalOfSearchEngineNotificationBox("Google", "Foogle")
```

Differential Revision: https://phabricator.services.mozilla.com/D194312
  • Loading branch information
hannajones committed Jan 4, 2024
1 parent f78c584 commit ba93129
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 28 deletions.
3 changes: 0 additions & 3 deletions browser/app/profile/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,6 @@ pref("browser.download.clearHistoryOnDelete", 0);
pref("browser.helperApps.showOpenOptionForPdfJS", true);
pref("browser.helperApps.showOpenOptionForViewableInternally", true);

// search engine removal URL
pref("browser.search.searchEngineRemoval", "https://support.mozilla.org/1/firefox/%VERSION%/%OS%/%LOCALE%/search-engine-removal");

// search engines URL
pref("browser.search.searchEnginesURL", "https://addons.mozilla.org/%LOCALE%/firefox/search-engines/");

Expand Down
34 changes: 11 additions & 23 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4290,26 +4290,8 @@ const BrowserSearch = {
* @param {string} newEngine
* name of the application default engine to replaced the removed engine.
*/
removalOfSearchEngineNotificationBox(oldEngine, newEngine) {
let messageFragment = document.createDocumentFragment();
let message = document.createElement("span");
let link = document.createXULElement("label", {
is: "text-link",
});

link.href = Services.urlFormatter.formatURLPref(
"browser.search.searchEngineRemoval"
);
link.setAttribute("data-l10n-name", "remove-search-engine-article");
document.l10n.setAttributes(message, "removed-search-engine-message", {
oldEngine,
newEngine,
});

message.appendChild(link);
messageFragment.appendChild(message);

let button = [
async removalOfSearchEngineNotificationBox(oldEngine, newEngine) {
let buttons = [
{
"l10n-id": "remove-search-engine-button",
primary: true,
Expand All @@ -4320,15 +4302,21 @@ const BrowserSearch = {
gNotificationBox.removeNotification(notificationBox);
},
},
{
supportPage: "search-engine-removal",
},
];

gNotificationBox.appendNotification(
await gNotificationBox.appendNotification(
"search-engine-removal",
{
label: messageFragment,
label: {
"l10n-id": "removed-search-engine-message2",
"l10n-args": { oldEngine, newEngine },
},
priority: gNotificationBox.PRIORITY_SYSTEM,
},
button
buttons
);

// Update engine name in the placeholder to the new default engine name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ add_task(async function test_change_default_engine_updates_placeholder() {
);

info("Show search engine removal info bar");
BrowserSearch.removalOfSearchEngineNotificationBox(
await BrowserSearch.removalOfSearchEngineNotificationBox(
extraEngine.name,
originalEngine.name
);
Expand Down
2 changes: 1 addition & 1 deletion browser/locales/en-US/browser/search.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ searchbar-icon =
## $oldEngine (String) - the search engine to be removed.
## $newEngine (String) - the search engine to replace the removed search engine.

removed-search-engine-message = <strong>Your default search engine has been changed.</strong> { $oldEngine } is no longer available as a default search engine in { -brand-short-name }. { $newEngine } is now your default search engine. To change to another default search engine, go to settings. <label data-l10n-name="remove-search-engine-article">Learn more</label>
removed-search-engine-message2 = <strong>Your default search engine has been changed.</strong> { $oldEngine } is no longer available as a default search engine in { -brand-short-name }. { $newEngine } is now your default search engine. To change to another default search engine, go to settings.
remove-search-engine-button = OK
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/

import re
import fluent.syntax.ast as FTL
from fluent.migrate.transforms import TransformPattern


class STRIP_LABEL(TransformPattern):
# Used to remove `<label data-l10n-name="remove-search-engine-article">` from a string
def visit_TextElement(self, node):
node.value = re.sub(
'\s?<label data-l10n-name="remove-search-engine-article">.+?</label>\s?',
"",
node.value,
)
return node


def migrate(ctx):
"""Bug 1845150 - Use moz-message-bar instead of message-bar in notificationbox.js, part {index}."""
search_ftl = "browser/browser/search.ftl"
ctx.add_transforms(
search_ftl,
search_ftl,
[
FTL.Message(
id=FTL.Identifier("removed-search-engine-message2"),
value=STRIP_LABEL(search_ftl, "removed-search-engine-message"),
),
],
)

0 comments on commit ba93129

Please sign in to comment.