Refine page media type availability

This commit is contained in:
hensm
2019-09-30 11:16:57 +01:00
parent d1dd2b188c
commit aa10be339b

View File

@@ -35,20 +35,49 @@ export function stringify (
export function getMediaTypesForPageUrl (
pageUrl: string): ReceiverSelectorMediaType {
let availableMediaTypes =
ReceiverSelectorMediaType.App
| ReceiverSelectorMediaType.Tab
| ReceiverSelectorMediaType.Screen
| ReceiverSelectorMediaType.File;
const url = new URL(pageUrl);
let availableMediaTypes = ReceiverSelectorMediaType.File;
/**
* Remove "Screen" option when on an insecure origin as
* MediaDevices.getDisplayMedia will not exist (and legacy
* MediaDevices.getUserMedia mediaSource constraint will
* fail).
* Content scripts are prohibited from running on some
* Mozilla domains.
*/
if (!pageUrl.startsWith("https://")) {
availableMediaTypes &= ~ReceiverSelectorMediaType.Screen;
const blockedHosts = [
"accounts-static.cdn.mozilla.net"
, "accounts.firefox.com"
, "addons.cdn.mozilla.net"
, "addons.mozilla.org"
, "api.accounts.firefox.com"
, "content.cdn.mozilla.net"
, "content.cdn.mozilla.net"
, "discovery.addons.mozilla.org"
, "input.mozilla.org"
, "install.mozilla.org"
, "oauth.accounts.firefox.com"
, "profile.accounts.firefox.com"
, "support.mozilla.org"
, "sync.services.mozilla.com"
, "testpilot.firefox.com"
];
if (blockedHosts.includes(url.host)) {
return availableMediaTypes;
}
// Only meant to run on normal web pages
if (url.protocol === "http:" || url.protocol === "https:") {
availableMediaTypes |= (
ReceiverSelectorMediaType.App
| ReceiverSelectorMediaType.Tab);
}
/**
* When on an insecure origin, MediaDevices.getDisplayMedia
* will not exist (and legacy MediaDevices.getUserMedia
* mediaSource constraint will fail).
*/
if (url.protocol === "https:") {
availableMediaTypes |= ReceiverSelectorMediaType.Screen;
}
return availableMediaTypes;