Set up the "DRM not available" messages in a saner way.

This commit is contained in:
wolfbeast 2018-03-17 10:12:55 +01:00 • committed by Roy Tam
commit df053b80f5

View file

@ -45,11 +45,23 @@ var gEMEHandler = {
} }
return true; return true;
}, },
getLearnMoreLink: function(msgId) { getEMEDisabledFragment: function(msgId) {
let text = gNavigatorBundle.getString("emeNotifications." + msgId + ".learnMoreLabel"); 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"); let baseURL = Services.urlFormatter.formatURLPref("app.support.baseURL");
return "<label class='text-link' href='" + baseURL + "drm-content'>" + let link = document.createElement("label");
text + "</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}) { receiveMessage: function({target: browser, data: data}) {
let parsedData; let parsedData;
@ -67,7 +79,8 @@ var gEMEHandler = {
let notificationId; let notificationId;
let buttonCallback; let buttonCallback;
let params = []; // Notification message can be either a string or a DOM fragment.
let notificationMessage;
switch (status) { switch (status) {
case "available": case "available":
case "cdm-created": case "cdm-created":
@ -82,17 +95,17 @@ var gEMEHandler = {
case "cdm-disabled": case "cdm-disabled":
notificationId = "drmContentDisabled"; notificationId = "drmContentDisabled";
buttonCallback = gEMEHandler.ensureEMEEnabled.bind(gEMEHandler, browser, keySystem) buttonCallback = gEMEHandler.ensureEMEEnabled.bind(gEMEHandler, browser, keySystem)
params = [this.getLearnMoreLink(notificationId)]; notificationMessage = this.getEMEDisabledFragment();
break; break;
case "cdm-insufficient-version": case "cdm-insufficient-version":
notificationId = "drmContentCDMInsufficientVersion"; notificationId = "drmContentCDMInsufficientVersion";
params = [this._brandShortName]; notificationMessage = this.getMessageWithBrandName(notificationId);
break; break;
case "cdm-not-installed": case "cdm-not-installed":
notificationId = "drmContentCDMInstalling"; notificationId = "drmContentCDMInstalling";
params = [this._brandShortName]; notificationMessage = this.getMessageWithBrandName(notificationId);
break; break;
case "cdm-not-supported": case "cdm-not-supported":
@ -104,44 +117,29 @@ var gEMEHandler = {
return; return;
} }
this.showNotificationBar(browser, notificationId, keySystem, params, buttonCallback); // Now actually create the notification
},
showNotificationBar: function(browser, notificationId, keySystem, labelParams, callback) {
let box = gBrowser.getNotificationBox(browser); let box = gBrowser.getNotificationBox(browser);
if (box.getNotificationWithValue(notificationId)) { if (box.getNotificationWithValue(notificationId)) {
return; return;
} }
let msgPrefix = "emeNotifications." + notificationId + ".";
let msgId = msgPrefix + "message";
let message = labelParams.length ?
gNavigatorBundle.getFormattedString(msgId, labelParams) :
gNavigatorBundle.getString(msgId);
let buttons = []; let buttons = [];
if (callback) { if (buttonCallback) {
let msgPrefix = "emeNotifications." + notificationId + ".";
let btnLabelId = msgPrefix + "button.label"; let btnLabelId = msgPrefix + "button.label";
let btnAccessKeyId = msgPrefix + "button.accesskey"; let btnAccessKeyId = msgPrefix + "button.accesskey";
buttons.push({ buttons.push({
label: gNavigatorBundle.getString(btnLabelId), label: gNavigatorBundle.getString(btnLabelId),
accessKey: gNavigatorBundle.getString(btnAccessKeyId), accessKey: gNavigatorBundle.getString(btnAccessKeyId),
callback: callback callback: buttonCallback
}); });
} }
let iconURL = "chrome://browser/skin/drm-icon.svg#chains-black"; let iconURL = "chrome://browser/skin/drm-icon.svg#chains-black";
// Do a little dance to get rich content into the notification: box.appendNotification(notificationMessage, notificationId, iconURL,
let fragment = document.createDocumentFragment(); box.PRIORITY_WARNING_MEDIUM, buttons);
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);
}, },
showPopupNotificationForSuccess: function(browser, keySystem) { showPopupNotificationForSuccess: function(browser, keySystem) {
// We're playing EME content! Remove any "we can't play because..." messages. // We're playing EME content! Remove any "we can't play because..." messages.