diff --git a/app/extensions/brave/content/scripts/navigator.js b/app/extensions/brave/content/scripts/navigator.js index 02bf81fe8af..40da1665c81 100644 --- a/app/extensions/brave/content/scripts/navigator.js +++ b/app/extensions/brave/content/scripts/navigator.js @@ -27,3 +27,13 @@ if (chrome.contentSettings.ads == 'block') { // Spectre hotfix (https://github.com/brave/browser-laptop/issues/12570) chrome.webFrame.setGlobal('window.SharedArrayBuffer', false) + +if (chrome.contentSettings.mediaPermission == 'block') { + // Needed for https://github.com/brave/browser-laptop/issues/14889 + // Note this is not necessary in non-Electron-based codebases since Chromium + // automatically handles the permission for device enumeration. + // Also: chromium doesn't have mediaPermission in content setting. It is actually + // microphone && camera in chromium. + executeScript("window.MediaDeviceInfo.prototype.__defineGetter__('label', () => { return '' })") + executeScript("window.InputDeviceInfo.prototype.__defineGetter__('label', () => { return '' })") +} diff --git a/js/state/contentSettings.js b/js/state/contentSettings.js index 0c9b249cede..fae51e527b0 100644 --- a/js/state/contentSettings.js +++ b/js/state/contentSettings.js @@ -90,6 +90,10 @@ const getDefaultUserPrefContentSettings = (braveryDefaults, appSettings, appConf setting: getSetting(settings.DO_NOT_TRACK, appSettings) ? 'allow' : 'block', primaryPattern: '*' }], + mediaPermission: [{ + setting: 'block', + primaryPattern: '*' + }], passwordManager: getDefaultPasswordManagerSettings(braveryDefaults, appSettings, appConfig), javascript: [{ setting: braveryDefaults.get('noScript') ? 'block' : 'allow', @@ -280,10 +284,12 @@ const siteSettingsToContentSettings = (currentSiteSettings, defaultContentSettin } }) } - if (typeof siteSetting.get('runInsecureContent') === 'boolean') { - contentSettings = addContentSettings(contentSettings, 'runInsecureContent', primaryPattern, '*', - siteSetting.get('runInsecureContent') ? 'allow' : 'block') - } + ['runInsecureContent', 'autoplay', 'mediaPermission'].forEach((permission) => { + if (typeof siteSetting.get(permission) === 'boolean') { + contentSettings = addContentSettings(contentSettings, permission, primaryPattern, '*', + siteSetting.get(permission) ? 'allow' : 'block') + } + }) if (siteSetting.get('cookieControl')) { if (siteSetting.get('cookieControl') === 'block3rdPartyCookie') { contentSettings = addContentSettings(contentSettings, 'cookies', primaryPattern, '*', 'block') @@ -323,9 +329,6 @@ const siteSettingsToContentSettings = (currentSiteSettings, defaultContentSettin if (typeof siteSetting.get('widevine') === 'number' && braveryDefaults.get('widevine')) { contentSettings = addContentSettings(contentSettings, 'plugins', primaryPattern, '*', 'allow', appConfig.widevine.resourceId) } - if (typeof siteSetting.get('autoplay') === 'boolean') { - contentSettings = addContentSettings(contentSettings, 'autoplay', primaryPattern, '*', siteSetting.get('autoplay') ? 'allow' : 'block') - } }) // On the second pass we consider only shieldsUp === false settings since we want those to take precedence. currentSiteSettings.forEach((siteSetting, hostPattern) => {