Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #13475 from brave/permissions_host
Browse files Browse the repository at this point in the history
Permission host mismatch
  • Loading branch information
bsclifton committed Mar 27, 2018
1 parent 0a049dd commit cd7a878
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ function registerPermissionHandler (session, partition) {
const isPrivate = module.exports.isPrivate(partition)
// Keep track of per-site permissions granted for this session.
let permissions = null
session.setPermissionRequestHandler((origin, mainFrameUrl, permissionTypes, muonCb) => {
session.setPermissionRequestHandler((mainFrameOrigin, requestingUrl, permissionTypes, muonCb) => {
if (!permissions) {
permissions = {
media: {
Expand Down Expand Up @@ -439,35 +439,29 @@ function registerPermissionHandler (session, partition) {
// TODO(bridiver) - the permission handling should be converted to an action because we should never call `appStore.getState()`
// Check whether there is a persistent site setting for this host
const appState = appStore.getState()
const isBraveOrigin = origin.startsWith(`chrome-extension://${config.braveExtensionId}/`)
const isPDFOrigin = origin.startsWith(`${pdfjsOrigin}/`)
const isBraveOrigin = mainFrameOrigin.startsWith(`chrome-extension://${config.braveExtensionId}/`)
const isPDFOrigin = mainFrameOrigin.startsWith(`${pdfjsOrigin}/`)
let settings
let tempSettings
if (mainFrameUrl === appUrlUtil.getBraveExtIndexHTML() || isPDFOrigin || isBraveOrigin) {
let requestingOrigin = getOrigin(requestingUrl) || requestingUrl

if (requestingUrl === appUrlUtil.getBraveExtIndexHTML() || isPDFOrigin || isBraveOrigin) {
// lookup, display and store site settings by the origin alias
origin = isPDFOrigin ? 'PDF Viewer' : 'Brave Browser'
requestingOrigin = isPDFOrigin ? 'PDF Viewer' : 'Brave Browser'
// display on all tabs
mainFrameUrl = null
mainFrameOrigin = null
// Lookup by exact host pattern match since 'Brave Browser' is not
// a parseable URL
settings = siteSettings.getSiteSettingsForHostPattern(appState.get('siteSettings'), origin)
tempSettings = siteSettings.getSiteSettingsForHostPattern(appState.get('temporarySiteSettings'), origin)
} else if (mainFrameUrl.startsWith('magnet:')) {
// Show "Allow magnet URL to open an external application?", instead of
// "Allow null to open an external application?"
// This covers an edge case where you open a magnet link tab, then disable Torrent Viewer
// and restart Brave. I don't think it needs localization. See 'Brave Browser' above.
origin = 'Magnet URL'
settings = siteSettings.getSiteSettingsForHostPattern(appState.get('siteSettings'), requestingOrigin)
tempSettings = siteSettings.getSiteSettingsForHostPattern(appState.get('temporarySiteSettings'), requestingOrigin)
} else {
// Strip trailing slash
origin = getOrigin(origin)
settings = siteSettings.getSiteSettingsForURL(appState.get('siteSettings'), origin)
tempSettings = siteSettings.getSiteSettingsForURL(appState.get('temporarySiteSettings'), origin)
settings = siteSettings.getSiteSettingsForURL(appState.get('siteSettings'), requestingOrigin)
tempSettings = siteSettings.getSiteSettingsForURL(appState.get('temporarySiteSettings'), requestingOrigin)
}

let response = []

if (origin == null) {
if (requestingOrigin == null) {
response = new Array(permissionTypes.length)
response.fill(false, 0, permissionTypes.length)
muonCb(response)
Expand All @@ -481,9 +475,9 @@ function registerPermissionHandler (session, partition) {
if (!permissions[permission]) {
console.warn('WARNING: got unregistered permission request', permission)
response.push(false)
} else if (permission === 'fullscreen' &&
} else if (permission === 'fullscreen' && mainFrameOrigin &&
// The Torrent Viewer extension is always allowed to show fullscreen media
origin.startsWith('chrome-extension://' + config.torrentExtensionId)) {
mainFrameOrigin.startsWith('chrome-extension://' + config.torrentExtensionId)) {
response.push(true)
} else if (permission === 'fullscreen' && alwaysAllowFullscreen) {
// Always allow fullscreen if setting is ON
Expand All @@ -509,7 +503,7 @@ function registerPermissionHandler (session, partition) {

// Display 'Brave Browser' if the origin is null; ex: when a mailto: link
// is opened in a new tab via right-click
const message = locale.translation('permissionMessage').replace(/{{\s*host\s*}}/, origin || 'Brave Browser').replace(/{{\s*permission\s*}}/, permissions[permission].action)
const message = locale.translation('permissionMessage').replace(/{{\s*host\s*}}/, requestingOrigin || 'Brave Browser').replace(/{{\s*permission\s*}}/, permissions[permission].action)

// If this is a duplicate, clear the previous callback and use the new one
if (permissionCallbacks[message]) {
Expand All @@ -523,9 +517,9 @@ function registerPermissionHandler (session, partition) {
{text: locale.translation('deny')},
{text: locale.translation('allow')}
],
frameOrigin: getOrigin(mainFrameUrl),
frameOrigin: getOrigin(mainFrameOrigin),
options: {
persist: !!origin,
persist: !!requestingOrigin,
index: i
},
message
Expand All @@ -542,7 +536,7 @@ function registerPermissionHandler (session, partition) {
response[index] = result
if (persist) {
// remember site setting for this host
appActions.changeSiteSetting(origin, permission + 'Permission', result, isPrivate)
appActions.changeSiteSetting(requestingOrigin, permission + 'Permission', result, isPrivate)
}
if (response.length === permissionTypes.length) {
permissionCallbacks[message] = null
Expand Down

0 comments on commit cd7a878

Please sign in to comment.