mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 16:58:38 +09:00
Set up the "DRM not available" messages in a saner way.
This commit is contained in:
parent
03078aa806
commit
df053b80f5
1 changed files with 28 additions and 30 deletions
|
|
@ -45,11 +45,23 @@ var gEMEHandler = {
|
|||
}
|
||||
return true;
|
||||
},
|
||||
getLearnMoreLink: function(msgId) {
|
||||
let text = gNavigatorBundle.getString("emeNotifications." + msgId + ".learnMoreLabel");
|
||||
getEMEDisabledFragment: function(msgId) {
|
||||
let mainMessage = gNavigatorBundle.getString("emeNotifications.drmContentDisabled.message");
|
||||
let [prefix, suffix] = mainMessage.split(/%(?:\$\d)?S/).map(s => document.createTextNode(s));
|
||||
let text = gNavigatorBundle.getString("emeNotifications.drmContentDisabled.learnMoreLabel");
|
||||
let baseURL = Services.urlFormatter.formatURLPref("app.support.baseURL");
|
||||
return "<label class='text-link' href='" + baseURL + "drm-content'>" +
|
||||
text + "</label>";
|
||||
let link = document.createElement("label");
|
||||
link.className = "text-link";
|
||||
link.setAttribute("href", baseURL + "drm-content");
|
||||
link.textContent = text;
|
||||
|
||||
let fragment = document.createDocumentFragment();
|
||||
[prefix, link, suffix].forEach(n => fragment.appendChild(n));
|
||||
return fragment;
|
||||
},
|
||||
getMessageWithBrandName: function(notificationId) {
|
||||
let msgId = "emeNotifications." + notificationId + ".message";
|
||||
return gNavigatorBundle.getFormattedString(msgId, [this._brandShortName]);
|
||||
},
|
||||
receiveMessage: function({target: browser, data: data}) {
|
||||
let parsedData;
|
||||
|
|
@ -67,7 +79,8 @@ var gEMEHandler = {
|
|||
|
||||
let notificationId;
|
||||
let buttonCallback;
|
||||
let params = [];
|
||||
// Notification message can be either a string or a DOM fragment.
|
||||
let notificationMessage;
|
||||
switch (status) {
|
||||
case "available":
|
||||
case "cdm-created":
|
||||
|
|
@ -82,17 +95,17 @@ var gEMEHandler = {
|
|||
case "cdm-disabled":
|
||||
notificationId = "drmContentDisabled";
|
||||
buttonCallback = gEMEHandler.ensureEMEEnabled.bind(gEMEHandler, browser, keySystem)
|
||||
params = [this.getLearnMoreLink(notificationId)];
|
||||
notificationMessage = this.getEMEDisabledFragment();
|
||||
break;
|
||||
|
||||
case "cdm-insufficient-version":
|
||||
notificationId = "drmContentCDMInsufficientVersion";
|
||||
params = [this._brandShortName];
|
||||
notificationMessage = this.getMessageWithBrandName(notificationId);
|
||||
break;
|
||||
|
||||
case "cdm-not-installed":
|
||||
notificationId = "drmContentCDMInstalling";
|
||||
params = [this._brandShortName];
|
||||
notificationMessage = this.getMessageWithBrandName(notificationId);
|
||||
break;
|
||||
|
||||
case "cdm-not-supported":
|
||||
|
|
@ -104,44 +117,29 @@ var gEMEHandler = {
|
|||
return;
|
||||
}
|
||||
|
||||
this.showNotificationBar(browser, notificationId, keySystem, params, buttonCallback);
|
||||
},
|
||||
showNotificationBar: function(browser, notificationId, keySystem, labelParams, callback) {
|
||||
// Now actually create the notification
|
||||
|
||||
let box = gBrowser.getNotificationBox(browser);
|
||||
if (box.getNotificationWithValue(notificationId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let msgPrefix = "emeNotifications." + notificationId + ".";
|
||||
let msgId = msgPrefix + "message";
|
||||
|
||||
let message = labelParams.length ?
|
||||
gNavigatorBundle.getFormattedString(msgId, labelParams) :
|
||||
gNavigatorBundle.getString(msgId);
|
||||
|
||||
let buttons = [];
|
||||
if (callback) {
|
||||
if (buttonCallback) {
|
||||
let msgPrefix = "emeNotifications." + notificationId + ".";
|
||||
let btnLabelId = msgPrefix + "button.label";
|
||||
let btnAccessKeyId = msgPrefix + "button.accesskey";
|
||||
buttons.push({
|
||||
label: gNavigatorBundle.getString(btnLabelId),
|
||||
accessKey: gNavigatorBundle.getString(btnAccessKeyId),
|
||||
callback: callback
|
||||
callback: buttonCallback
|
||||
});
|
||||
}
|
||||
|
||||
let iconURL = "chrome://browser/skin/drm-icon.svg#chains-black";
|
||||
|
||||
// Do a little dance to get rich content into the notification:
|
||||
let fragment = document.createDocumentFragment();
|
||||
let descriptionContainer = document.createElement("description");
|
||||
descriptionContainer.innerHTML = message;
|
||||
while (descriptionContainer.childNodes.length) {
|
||||
fragment.appendChild(descriptionContainer.childNodes[0]);
|
||||
}
|
||||
|
||||
box.appendNotification(fragment, notificationId, iconURL, box.PRIORITY_WARNING_MEDIUM,
|
||||
buttons);
|
||||
box.appendNotification(notificationMessage, notificationId, iconURL,
|
||||
box.PRIORITY_WARNING_MEDIUM, buttons);
|
||||
},
|
||||
showPopupNotificationForSuccess: function(browser, keySystem) {
|
||||
// We're playing EME content! Remove any "we can't play because..." messages.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue