-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathEncryptedMediaParent.sys.mjs
321 lines (288 loc) · 9.41 KB
/
EncryptedMediaParent.sys.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
/* 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/. */
const lazy = {};
ChromeUtils.defineLazyGetter(lazy, "gBrandBundle", function () {
return Services.strings.createBundle(
"chrome://branding/locale/brand.properties"
);
});
ChromeUtils.defineLazyGetter(lazy, "gNavigatorBundle", function () {
return Services.strings.createBundle(
"chrome://browser/locale/browser.properties"
);
});
ChromeUtils.defineLazyGetter(lazy, "gFluentStrings", function () {
return new Localization(["branding/brand.ftl", "browser/browser.ftl"], true);
});
export class EncryptedMediaParent extends JSWindowActorParent {
isUiEnabled() {
return Services.prefs.getBoolPref("browser.eme.ui.enabled");
}
ensureEMEEnabled(aBrowser, aKeySystem) {
Services.prefs.setBoolPref("media.eme.enabled", true);
if (
aKeySystem &&
aKeySystem == "com.widevine.alpha" &&
Services.prefs.getPrefType("media.gmp-widevinecdm.enabled") &&
!Services.prefs.getBoolPref("media.gmp-widevinecdm.enabled")
) {
Services.prefs.setBoolPref("media.gmp-widevinecdm.enabled", true);
}
aBrowser.reload();
}
isKeySystemVisible(aKeySystem) {
if (!aKeySystem) {
return false;
}
if (
aKeySystem == "com.widevine.alpha" &&
Services.prefs.getPrefType("media.gmp-widevinecdm.visible")
) {
return Services.prefs.getBoolPref("media.gmp-widevinecdm.visible");
}
return true;
}
getMessageWithBrandName(aNotificationId) {
let msgId = "emeNotifications." + aNotificationId + ".message";
return lazy.gNavigatorBundle.formatStringFromName(msgId, [
lazy.gBrandBundle.GetStringFromName("brandShortName"),
]);
}
async receiveMessage(aMessage) {
if (!this.handledMessages) {
this.handledMessages = new Set();
}
// The top level browsing context's embedding element should be a xul browser element.
let browser = this.browsingContext.top.embedderElement;
if (!browser) {
// We don't have a browser so bail!
return;
}
let parsedData;
try {
parsedData = JSON.parse(aMessage.data);
} catch (ex) {
console.error("Malformed EME video message with data: ", aMessage.data);
return;
}
let { status, keySystem } = parsedData;
if (this.handledMessages.has(status)) {
return;
}
// First, see if we need to do updates. We don't need to do anything for
// hidden keysystems:
if (!this.isKeySystemVisible(keySystem)) {
return;
}
if (status == "cdm-not-installed") {
Services.obs.notifyObservers(browser, "EMEVideo:CDMMissing");
}
// Don't need to show UI if disabled.
if (!this.isUiEnabled()) {
return;
}
let notificationId;
let buttonCallback;
let supportPage;
// Notification message can be either a string or a DOM fragment.
let notificationMessage;
switch (status) {
case "available":
case "cdm-created":
// Only show the chain icon for proprietary CDMs. Clearkey is not one.
if (keySystem != "org.w3.clearkey") {
this.showPopupNotificationForSuccess(browser, keySystem);
}
this.reportEMEDecryptionProbe();
// ... and bail!
return;
case "api-disabled":
case "cdm-disabled":
this.handledMessages.add(status);
notificationId = "drmContentDisabled";
buttonCallback = () => {
this.ensureEMEEnabled(browser, keySystem);
};
notificationMessage = lazy.gNavigatorBundle.GetStringFromName(
"emeNotifications.drmContentDisabled.message2"
);
supportPage = "drm-content";
break;
case "cdm-not-installed":
this.handledMessages.add(status);
notificationId = "drmContentCDMInstalling";
notificationMessage = this.getMessageWithBrandName(notificationId);
break;
case "cdm-not-supported":
// Not to pop up user-level notification because they cannot do anything
// about it.
return;
default:
console.error(
new Error(
"Unknown message ('" +
status +
"') dealing with EME key request: " +
aMessage.data
)
);
return;
}
// Now actually create the notification
let notificationBox = browser.getTabBrowser().getNotificationBox(browser);
if (notificationBox.getNotificationWithValue(notificationId)) {
this.handledMessages.delete(status);
return;
}
let buttons = [];
if (supportPage) {
buttons.push({ supportPage });
}
if (buttonCallback) {
let msgPrefix = "emeNotifications." + notificationId + ".";
let manageLabelId = msgPrefix + "button.label";
let manageAccessKeyId = msgPrefix + "button.accesskey";
buttons.push({
label: lazy.gNavigatorBundle.GetStringFromName(manageLabelId),
accessKey: lazy.gNavigatorBundle.GetStringFromName(manageAccessKeyId),
callback: buttonCallback,
});
}
let iconURL = "chrome://browser/skin/drm-icon.svg";
await notificationBox.appendNotification(
notificationId,
{
label: notificationMessage,
image: iconURL,
priority: notificationBox.PRIORITY_INFO_HIGH,
},
buttons
);
this.handledMessages.delete(status);
}
async showPopupNotificationForSuccess(aBrowser) {
// We're playing EME content! Remove any "we can't play because..." messages.
let notificationBox = aBrowser.getTabBrowser().getNotificationBox(aBrowser);
["drmContentDisabled", "drmContentCDMInstalling"].forEach(function (value) {
let notification = notificationBox.getNotificationWithValue(value);
if (notification) {
notificationBox.removeNotification(notification);
}
});
// Don't bother creating it if it's already there:
if (
aBrowser.ownerGlobal.PopupNotifications.getNotification(
"drmContentPlaying",
aBrowser
)
) {
return;
}
let msgId = "eme-notifications-drm-content-playing";
let manageLabelId = "eme-notifications-drm-content-playing-manage";
let manageAccessKeyId =
"eme-notifications-drm-content-playing-manage-accesskey";
let dismissLabelId = "eme-notifications-drm-content-playing-dismiss";
let dismissAccessKeyId =
"eme-notifications-drm-content-playing-dismiss-accesskey";
let [
message,
manageLabel,
manageAccessKey,
dismissLabel,
dismissAccessKey,
] = await lazy.gFluentStrings.formatValues([
msgId,
manageLabelId,
manageAccessKeyId,
dismissLabelId,
dismissAccessKeyId,
]);
let anchorId = "eme-notification-icon";
let firstPlayPref = "browser.eme.ui.firstContentShown";
let document = aBrowser.ownerDocument;
if (
!Services.prefs.getPrefType(firstPlayPref) ||
!Services.prefs.getBoolPref(firstPlayPref)
) {
document.getElementById(anchorId).setAttribute("firstplay", "true");
Services.prefs.setBoolPref(firstPlayPref, true);
} else {
document.getElementById(anchorId).removeAttribute("firstplay");
}
let mainAction = {
label: manageLabel,
accessKey: manageAccessKey,
callback() {
aBrowser.ownerGlobal.openPreferences("general-drm");
},
dismiss: true,
};
let secondaryActions = [
{
label: dismissLabel,
accessKey: dismissAccessKey,
callback: () => {},
dismiss: true,
},
];
let options = {
dismissed: true,
eventCallback: aTopic => aTopic == "swapping",
learnMoreURL:
Services.urlFormatter.formatURLPref("app.support.baseURL") +
"drm-content",
hideClose: true,
};
aBrowser.ownerGlobal.PopupNotifications.show(
aBrowser,
"drmContentPlaying",
message,
anchorId,
mainAction,
secondaryActions,
options
);
}
async reportEMEDecryptionProbe() {
let hasHardwareDecryption = false;
let hasSoftwareClearlead = false;
let hasHardwareClearlead = false;
let hasHdcp22Plus = false;
let hasWMF = false;
// Get CDM capabilities from the GMP process.
let infos = [];
let cdmInfo = await ChromeUtils.getGMPContentDecryptionModuleInformation();
infos.push(...cdmInfo);
// Get CDM capabilities from the MFCDM process, if exists.
if (ChromeUtils.getWMFContentDecryptionModuleInformation !== undefined) {
hasWMF = true;
cdmInfo = await ChromeUtils.getWMFContentDecryptionModuleInformation();
infos.push(...cdmInfo);
}
for (let info of infos) {
if (info.isHardwareDecryption) {
hasHardwareDecryption = true;
}
if (info.clearlead) {
if (info.isHardwareDecryption) {
hasHardwareClearlead = true;
} else {
hasSoftwareClearlead = true;
}
}
if (info.isHDCP22Compatible) {
hasHdcp22Plus = true;
}
}
Glean.mediadrm.decryption.has_hardware_decryption.set(
hasHardwareDecryption
);
Glean.mediadrm.decryption.has_hardware_clearlead.set(hasHardwareClearlead);
Glean.mediadrm.decryption.has_software_clearlead.set(hasSoftwareClearlead);
Glean.mediadrm.decryption.has_hdcp22_plus.set(hasHdcp22Plus);
Glean.mediadrm.decryption.has_wmf.set(hasWMF);
}
}