зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1691499, add a link field to notification bar buttons to use a link instead, convert learn more buttons in notification bars to links, r=mstriemer,fluent-reviewers,flod
Differential Revision: https://phabricator.services.mozilla.com/D105750
This commit is contained in:
Родитель
18034ea053
Коммит
86db2fec08
|
@ -180,9 +180,7 @@ class DecoderDoctorParent extends JSWindowActorParent {
|
|||
if (sumo) {
|
||||
buttons.push({
|
||||
label: gNavigatorBundle.GetStringFromName("decoder.noCodecs.button"),
|
||||
accessKey: gNavigatorBundle.GetStringFromName(
|
||||
"decoder.noCodecs.accesskey"
|
||||
),
|
||||
supportPage: sumo,
|
||||
callback() {
|
||||
let clickedInPref = Services.prefs.getBoolPref(
|
||||
buttonClickedPref,
|
||||
|
@ -191,11 +189,6 @@ class DecoderDoctorParent extends JSWindowActorParent {
|
|||
if (!clickedInPref) {
|
||||
Services.prefs.setBoolPref(buttonClickedPref, true);
|
||||
}
|
||||
|
||||
let baseURL = Services.urlFormatter.formatURLPref(
|
||||
"app.support.baseURL"
|
||||
);
|
||||
window.openTrustedLinkIn(baseURL + sumo, "tab");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -12,12 +12,6 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"BrowserUIUtils",
|
||||
"resource:///modules/BrowserUIUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "gBrandBundle", function() {
|
||||
return Services.strings.createBundle(
|
||||
"chrome://branding/locale/brand.properties"
|
||||
|
@ -61,21 +55,6 @@ class EncryptedMediaParent extends JSWindowActorParent {
|
|||
return true;
|
||||
}
|
||||
|
||||
getEMEDisabledFragment(aBrowser) {
|
||||
let mainMessage = gNavigatorBundle.GetStringFromName(
|
||||
"emeNotifications.drmContentDisabled.message"
|
||||
);
|
||||
let text = gNavigatorBundle.GetStringFromName(
|
||||
"emeNotifications.drmContentDisabled.learnMoreLabel"
|
||||
);
|
||||
let document = aBrowser.ownerDocument;
|
||||
let baseURL = Services.urlFormatter.formatURLPref("app.support.baseURL");
|
||||
let link = document.createXULElement("label", { is: "text-link" });
|
||||
link.setAttribute("href", baseURL + "drm-content");
|
||||
link.textContent = text;
|
||||
return BrowserUIUtils.getLocalizedFragment(document, mainMessage, link);
|
||||
}
|
||||
|
||||
getMessageWithBrandName(aNotificationId) {
|
||||
let msgId = "emeNotifications." + aNotificationId + ".message";
|
||||
return gNavigatorBundle.formatStringFromName(msgId, [
|
||||
|
@ -117,6 +96,7 @@ class EncryptedMediaParent extends JSWindowActorParent {
|
|||
|
||||
let notificationId;
|
||||
let buttonCallback;
|
||||
let supportPage;
|
||||
// Notification message can be either a string or a DOM fragment.
|
||||
let notificationMessage;
|
||||
switch (status) {
|
||||
|
@ -135,7 +115,10 @@ class EncryptedMediaParent extends JSWindowActorParent {
|
|||
buttonCallback = () => {
|
||||
this.ensureEMEEnabled(browser, keySystem);
|
||||
};
|
||||
notificationMessage = this.getEMEDisabledFragment(browser);
|
||||
notificationMessage = gNavigatorBundle.GetStringFromName(
|
||||
"emeNotifications.drmContentDisabled.message2"
|
||||
);
|
||||
supportPage = "drm-content";
|
||||
break;
|
||||
|
||||
case "cdm-not-installed":
|
||||
|
@ -167,6 +150,9 @@ class EncryptedMediaParent extends JSWindowActorParent {
|
|||
}
|
||||
|
||||
let buttons = [];
|
||||
if (supportPage) {
|
||||
buttons.push({ supportPage });
|
||||
}
|
||||
if (buttonCallback) {
|
||||
let msgPrefix = "emeNotifications." + notificationId + ".";
|
||||
let btnLabelId = msgPrefix + "button.label";
|
||||
|
|
|
@ -968,18 +968,8 @@ const gStoragePressureObserver = {
|
|||
"browser.storageManager.pressureNotification.usageThresholdGB"
|
||||
);
|
||||
let msg = "";
|
||||
let buttons = [];
|
||||
let buttons = [{ supportPage: "storage-permissions" }];
|
||||
let usage = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
||||
buttons.push({
|
||||
"l10n-id": "space-alert-learn-more-button",
|
||||
callback(notificationBar, button) {
|
||||
let learnMoreURL =
|
||||
Services.urlFormatter.formatURLPref("app.support.baseURL") +
|
||||
"storage-permissions";
|
||||
// This is a content URL, loaded from trusted UX.
|
||||
openTrustedLinkIn(learnMoreURL, "tab");
|
||||
},
|
||||
});
|
||||
if (usage < USAGE_THRESHOLD_BYTES) {
|
||||
// The firefox-used space < 5GB, then warn user to free some disk space.
|
||||
// This is because this usage is small and not the main cause for space issue.
|
||||
|
|
|
@ -115,7 +115,7 @@ add_task(async function() {
|
|||
"Should display storage pressure notification"
|
||||
);
|
||||
|
||||
let prefBtn = notification.getElementsByTagName("button")[1];
|
||||
let prefBtn = notification.getElementsByTagName("button")[0];
|
||||
let aboutPrefPromise = openAboutPrefPromise();
|
||||
prefBtn.doCommand();
|
||||
await aboutPrefPromise;
|
||||
|
|
|
@ -3053,29 +3053,9 @@ BrowserGlue.prototype = {
|
|||
var text = placesBundle.formatStringFromName("lockPrompt.text", [
|
||||
applicationName,
|
||||
]);
|
||||
var buttonText = placesBundle.GetStringFromName(
|
||||
"lockPromptInfoButton.label"
|
||||
);
|
||||
var accessKey = placesBundle.GetStringFromName(
|
||||
"lockPromptInfoButton.accessKey"
|
||||
);
|
||||
|
||||
var helpTopic = "places-locked";
|
||||
var url = Services.urlFormatter.formatURLPref("app.support.baseURL");
|
||||
url += helpTopic;
|
||||
|
||||
var win = BrowserWindowTracker.getTopWindow();
|
||||
|
||||
var buttons = [
|
||||
{
|
||||
label: buttonText,
|
||||
accessKey,
|
||||
popup: null,
|
||||
callback(aNotificationBar, aButton) {
|
||||
win.openTrustedLinkIn(url, "tab");
|
||||
},
|
||||
},
|
||||
];
|
||||
var buttons = [{ supportPage: "places-locked" }];
|
||||
|
||||
var notifyBox = win.gBrowser.getNotificationBox();
|
||||
var notification = notifyBox.appendNotification(
|
||||
|
@ -4027,15 +4007,12 @@ BrowserGlue.prototype = {
|
|||
accessKey: win.gNavigatorBundle.getString(
|
||||
"flashHang.helpButton.accesskey"
|
||||
),
|
||||
callback() {
|
||||
win.openTrustedLinkIn(
|
||||
"https://support.mozilla.org/kb/flash-protected-mode-autodisabled",
|
||||
"tab"
|
||||
);
|
||||
},
|
||||
link:
|
||||
"https://support.mozilla.org/kb/flash-protected-mode-autodisabled",
|
||||
},
|
||||
];
|
||||
|
||||
// XXXndeakin is this notification still relevant?
|
||||
win.gNotificationBox.appendNotification(
|
||||
message,
|
||||
"flash-hang",
|
||||
|
|
|
@ -538,9 +538,8 @@ pointerlock-warning-no-domain = This document has control of your pointer. Press
|
|||
## Subframe crash notification
|
||||
|
||||
crashed-subframe-message = <strong>Part of this page crashed.</strong> To let { -brand-product-name } know about this issue and get it fixed faster, please submit a report.
|
||||
crashed-subframe-learnmore =
|
||||
.label = Learn More
|
||||
.accesskey = L
|
||||
crashed-subframe-learnmore-link =
|
||||
.value = Learn More
|
||||
crashed-subframe-submit =
|
||||
.label = Submit report
|
||||
.accesskey = S
|
||||
|
|
|
@ -1330,10 +1330,6 @@ certs-devices =
|
|||
.label = Security Devices…
|
||||
.accesskey = D
|
||||
|
||||
space-alert-learn-more-button =
|
||||
.label = Learn More
|
||||
.accesskey = L
|
||||
|
||||
space-alert-over-5gb-pref-button =
|
||||
.label =
|
||||
{ PLATFORM() ->
|
||||
|
|
|
@ -861,11 +861,9 @@ emeNotifications.drmContentPlaying.button.label = Configure…
|
|||
emeNotifications.drmContentPlaying.button.accesskey = C
|
||||
|
||||
# LOCALIZATION NOTE(emeNotifications.drmContentDisabled.message): NB: inserted via innerHTML, so please don't use <, > or & in this string. %S will be the 'learn more' link
|
||||
emeNotifications.drmContentDisabled.message = You must enable DRM to play some audio or video on this page. %S
|
||||
emeNotifications.drmContentDisabled.message2 = You must enable DRM to play some audio or video on this page.
|
||||
emeNotifications.drmContentDisabled.button.label = Enable DRM
|
||||
emeNotifications.drmContentDisabled.button.accesskey = E
|
||||
# LOCALIZATION NOTE(emeNotifications.drmContentDisabled.learnMoreLabel): NB: inserted via innerHTML, so please don't use <, > or & in this string.
|
||||
emeNotifications.drmContentDisabled.learnMoreLabel = Learn More
|
||||
|
||||
# LOCALIZATION NOTE(emeNotifications.drmContentCDMInstalling.message): NB: inserted via innerHTML, so please don't use <, > or & in this string. %S is brandShortName
|
||||
emeNotifications.drmContentCDMInstalling.message = %S is installing components needed to play the audio or video on this page. Please try again later.
|
||||
|
|
|
@ -54,8 +54,6 @@ detailsPane.itemsCountLabel=One item;#1 items
|
|||
# %S will be replaced with the application name.
|
||||
lockPrompt.title=Browser Startup Error
|
||||
lockPrompt.text=The bookmarks and history system will not be functional because one of %S’s files is in use by another application. Some security software can cause this problem.
|
||||
lockPromptInfoButton.label=Learn More
|
||||
lockPromptInfoButton.accessKey=L
|
||||
|
||||
# LOCALIZATION NOTE (cmd.deleteSinglePage.accesskey,
|
||||
# cmd.deleteMultiplePages.accesskey): these accesskeys can use the same
|
||||
|
|
|
@ -409,11 +409,9 @@ var TabCrashHandler = {
|
|||
|
||||
let buttons = [
|
||||
{
|
||||
"l10n-id": "crashed-subframe-learnmore",
|
||||
"l10n-id": "crashed-subframe-learnmore-link",
|
||||
popup: null,
|
||||
callback: async () => {
|
||||
doc.defaultView.openTrustedLinkIn(SUBFRAMECRASH_LEARNMORE_URI, "tab");
|
||||
},
|
||||
link: SUBFRAMECRASH_LEARNMORE_URI,
|
||||
},
|
||||
{
|
||||
"l10n-id": "crashed-subframe-submit",
|
||||
|
|
|
@ -522,6 +522,11 @@ var ProcessHangMonitor = {
|
|||
let bundle = win.gNavigatorBundle;
|
||||
|
||||
let buttons = [
|
||||
{
|
||||
label: bundle.getString("processHang.add-on.learn-more.text"),
|
||||
link:
|
||||
"https://support.mozilla.org/kb/warning-unresponsive-script#w_other-causes",
|
||||
},
|
||||
{
|
||||
label: bundle.getString("processHang.button_stop.label"),
|
||||
accessKey: bundle.getString("processHang.button_stop.accessKey"),
|
||||
|
@ -549,27 +554,11 @@ var ProcessHangMonitor = {
|
|||
|
||||
let addonName = aps.getExtensionName(report.addonId);
|
||||
|
||||
let label = bundle.getFormattedString("processHang.add-on.label", [
|
||||
message = bundle.getFormattedString("processHang.add-on.label", [
|
||||
addonName,
|
||||
brandBundle.getString("brandShortName"),
|
||||
]);
|
||||
|
||||
let linkText = bundle.getString("processHang.add-on.learn-more.text");
|
||||
let linkURL =
|
||||
"https://support.mozilla.org/kb/warning-unresponsive-script#w_other-causes";
|
||||
|
||||
let link = doc.createXULElement("label", { is: "text-link" });
|
||||
link.setAttribute("role", "link");
|
||||
link.setAttribute(
|
||||
"onclick",
|
||||
`openTrustedLinkIn(${JSON.stringify(linkURL)}, "tab")`
|
||||
);
|
||||
link.setAttribute("value", linkText);
|
||||
|
||||
message = doc.createDocumentFragment();
|
||||
message.appendChild(doc.createTextNode(label + " "));
|
||||
message.appendChild(link);
|
||||
|
||||
buttons.unshift({
|
||||
label: bundle.getString("processHang.button_stop_sandbox.label"),
|
||||
accessKey: bundle.getString(
|
||||
|
|
|
@ -160,8 +160,14 @@ async function testFrameCrash(numTabs) {
|
|||
let buttons = notification.querySelectorAll(".notification-button");
|
||||
is(
|
||||
buttons.length,
|
||||
2,
|
||||
"Notification " + count + " should have only two buttons."
|
||||
1,
|
||||
"Notification " + count + " should have only one button."
|
||||
);
|
||||
let links = notification.querySelectorAll(".text-link");
|
||||
is(
|
||||
links.length,
|
||||
1,
|
||||
"Notification " + count + " should have only one link."
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,33 @@ var testtag_notificationbox_buttons = [
|
|||
}
|
||||
];
|
||||
|
||||
function testtag_notificationbox_buttonpressed(event)
|
||||
var testtag_notificationbox_links = [
|
||||
{
|
||||
label: "Link 1",
|
||||
callback: testtag_notificationbox_buttonpressed,
|
||||
link: "about:mozilla"
|
||||
},
|
||||
{
|
||||
label: "Button 2",
|
||||
accesskey: "u",
|
||||
callback: testtag_notificationbox_buttonpressed,
|
||||
}
|
||||
];
|
||||
|
||||
var testtag_notificationbox_supportpage = [
|
||||
{
|
||||
supportPage: "test1",
|
||||
},
|
||||
{
|
||||
label: "This is an existing label",
|
||||
supportPage: "test2",
|
||||
}
|
||||
];
|
||||
|
||||
function testtag_notificationbox_buttonpressed(notification, button)
|
||||
{
|
||||
SimpleTest.is(button.localName, "button");
|
||||
return false;
|
||||
}
|
||||
|
||||
function testtag_notificationbox(nb)
|
||||
|
@ -278,6 +303,54 @@ var tests =
|
|||
SimpleTest.is(nb.removeAllNotifications(false), undefined, "removeAllNotifications");
|
||||
}
|
||||
},
|
||||
{
|
||||
test(nb, ntf) {
|
||||
ntf = nb.appendNotification("Notification", "note", "happy.png",
|
||||
nb.PRIORITY_INFO_LOW,
|
||||
testtag_notificationbox_links,
|
||||
notification_eventCallback);
|
||||
SimpleTest.is(ntf && ntf.localName == "notification", true, "append link notification with callback");
|
||||
return ntf;
|
||||
},
|
||||
result(nb, ntf) {
|
||||
testtag_notificationbox_State(nb, "append link with callback", ntf, 1);
|
||||
|
||||
let button = ntf.messageDetails.lastElementChild;
|
||||
SimpleTest.is(button.localName, "button", "button is a button");
|
||||
SimpleTest.ok(!button.href, "button href is not set");
|
||||
|
||||
let link = ntf.messageText.lastElementChild;
|
||||
SimpleTest.is(link.localName, "label", "link is a label");
|
||||
SimpleTest.is(link.href, "about:mozilla", "link href is correct");
|
||||
|
||||
SimpleTest.is(nb.removeAllNotifications(false), undefined, "removeAllNotifications");
|
||||
}
|
||||
},
|
||||
{
|
||||
test(nb, ntf) {
|
||||
ntf = nb.appendNotification("Notification", "note", "happy.png",
|
||||
nb.PRIORITY_INFO_LOW,
|
||||
testtag_notificationbox_supportpage,
|
||||
notification_eventCallback);
|
||||
SimpleTest.is(ntf && ntf.localName == "notification", true, "append support page notification");
|
||||
return ntf;
|
||||
},
|
||||
result(nb, ntf) {
|
||||
testtag_notificationbox_State(nb, "append link with callback", ntf, 1);
|
||||
|
||||
let link = ntf.messageText.lastElementChild.previousSibling;
|
||||
SimpleTest.is(link.localName, "label", "link 1 is a label");
|
||||
SimpleTest.ok(link.value != "", "link 1 label is set");
|
||||
SimpleTest.ok(link.href.endsWith("/test1"), "link 1 href is set");
|
||||
|
||||
link = ntf.messageText.lastElementChild;
|
||||
SimpleTest.is(link.localName, "label", "link 2 is a label");
|
||||
SimpleTest.is(link.value, "This is an existing label", "link 2 label is set");
|
||||
SimpleTest.ok(link.href.endsWith("/test2"), "link 2 href is set");
|
||||
|
||||
SimpleTest.is(nb.removeAllNotifications(false), undefined, "removeAllNotifications");
|
||||
}
|
||||
},
|
||||
{
|
||||
test(nb, unused) {
|
||||
// add a number of notifications and check that they are added in order
|
||||
|
@ -382,7 +455,7 @@ var appendPriorityTests = [
|
|||
runTimedTests(appendPriorityTests, -1, nb, ++priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
function testtag_notificationbox_State(nb, testid, expecteditem, expectedcount)
|
||||
|
|
|
@ -107,6 +107,13 @@
|
|||
* 2. This button object definition.
|
||||
* 3. The <button> element.
|
||||
* 4. The "command" event.
|
||||
* If the callback returns false, the notification is closed.
|
||||
* link:
|
||||
* A url to open when the button is clicked. The button is
|
||||
* rendered like a link. The callback is called as well.
|
||||
* supportPage:
|
||||
* Used for a support page link. If no other properties are specified,
|
||||
* defaults to a link with a 'Learn more' label.
|
||||
* popup:
|
||||
* If specified, the button will open the popup element with this
|
||||
* ID, anchored to the button. This is alternative to "callback".
|
||||
|
@ -153,6 +160,8 @@
|
|||
insertPos = notifications[n];
|
||||
}
|
||||
|
||||
MozXULElement.insertFTLIfNeeded("toolkit/global/notification.ftl");
|
||||
|
||||
// Create the Custom Element and connect it to the document immediately.
|
||||
var newitem = document.createXULElement(
|
||||
"notification",
|
||||
|
@ -182,27 +191,52 @@
|
|||
|
||||
if (aButtons) {
|
||||
for (var b = 0; b < aButtons.length; b++) {
|
||||
var button = aButtons[b];
|
||||
var buttonElem = document.createXULElement(
|
||||
"button",
|
||||
button.is ? { is: button.is } : {}
|
||||
);
|
||||
let button = aButtons[b];
|
||||
let buttonElem;
|
||||
|
||||
if (button["l10n-id"]) {
|
||||
buttonElem.setAttribute("data-l10n-id", button["l10n-id"]);
|
||||
let link = button.link;
|
||||
let localeId = button["l10n-id"];
|
||||
if (!link && button.supportPage) {
|
||||
link =
|
||||
Services.urlFormatter.formatURLPref("app.support.baseURL") +
|
||||
button.supportPage;
|
||||
if (!button.label && !localeId) {
|
||||
localeId = "notification-learnmore-default-label";
|
||||
}
|
||||
}
|
||||
|
||||
if (link) {
|
||||
buttonElem = document.createXULElement("label", {
|
||||
is: "text-link",
|
||||
});
|
||||
buttonElem.setAttribute("href", link);
|
||||
buttonElem.classList.add("notification-link");
|
||||
} else {
|
||||
buttonElem.setAttribute("label", button.label);
|
||||
buttonElem = document.createXULElement(
|
||||
"button",
|
||||
button.is ? { is: button.is } : {}
|
||||
);
|
||||
buttonElem.classList.add("notification-button");
|
||||
|
||||
if (button.primary) {
|
||||
buttonElem.classList.add("primary");
|
||||
}
|
||||
}
|
||||
|
||||
if (localeId) {
|
||||
buttonElem.setAttribute("data-l10n-id", localeId);
|
||||
} else {
|
||||
buttonElem.setAttribute(link ? "value" : "label", button.label);
|
||||
if (typeof button.accessKey == "string") {
|
||||
buttonElem.setAttribute("accesskey", button.accessKey);
|
||||
}
|
||||
}
|
||||
|
||||
buttonElem.classList.add("notification-button");
|
||||
if (button.primary) {
|
||||
buttonElem.classList.add("primary");
|
||||
if (link) {
|
||||
newitem.messageText.appendChild(buttonElem);
|
||||
} else {
|
||||
newitem.messageDetails.appendChild(buttonElem);
|
||||
}
|
||||
|
||||
newitem.messageDetails.appendChild(buttonElem);
|
||||
buttonElem.buttonInfo = button;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
notification-learnmore-default-label =
|
||||
.value = Learn more
|
|
@ -84,9 +84,13 @@ notification[type="critical"] > .close-icon:hover:active {
|
|||
}
|
||||
|
||||
.messageText > .text-link {
|
||||
color: inherit !important;
|
||||
text-decoration: underline;
|
||||
margin: 0;
|
||||
margin-block: 0;
|
||||
}
|
||||
|
||||
.messageText > .text-link:not(.notification-link) {
|
||||
color: inherit !important;
|
||||
margin-inline: 0;
|
||||
}
|
||||
|
||||
.messageImage {
|
||||
|
|
Загрузка…
Ссылка в новой задаче