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 #3965 from brave/permission-fixes
Browse files Browse the repository at this point in the history
use origin for the notification message and for site settings and cho…
  • Loading branch information
diracdeltas authored Sep 14, 2016
2 parents 77b2440 + 47e100c commit 8a43d49
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 31 deletions.
32 changes: 21 additions & 11 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,24 +318,34 @@ function registerPermissionHandler (session, partition) {
}
}
}
const url = mainFrameUrl || origin
// Allow notifications for the main app
if (url === appUrlUtil.getIndexHTML() && permission === 'notifications' ||
url.startsWith('chrome-extension://') && permission === 'openExternal') {
cb(true)
return
}

if (!permissions[permission]) {
console.log('WARNING: got unregistered permission request', permission)
cb(false)
return
}

// TOOD(bridiver) - this seems overly permissive and we should narrow this down
// to the specific extension that required it which is most likely PDFJS
if (origin.startsWith('chrome-extension://') && permission === 'openExternal') {
cb(true)
return
}

if (mainFrameUrl === appUrlUtil.getIndexHTML() || origin.startsWith('chrome-extension://' + config.braveExtensionId)) {
// lookup, display and store site settings by "Brave Browser"
origin = 'Brave Browser'
// display on all tabs
mainFrameUrl = null
} else {
// Strip trailing slash
origin = getOrigin(origin)
}

// Check whether there is a persistent site setting for this host
const appState = AppStore.getState()
const settings = siteSettings.getSiteSettingsForURL(appState.get('siteSettings'), url)
const tempSettings = siteSettings.getSiteSettingsForURL(appState.get('temporarySiteSettings'), url)
const settings = siteSettings.getSiteSettingsForHostPattern(appState.get('siteSettings'), origin)
const tempSettings = siteSettings.getSiteSettingsForHostPattern(appState.get('temporarySiteSettings'), origin)
const permissionName = permission + 'Permission'
if (settings) {
let isAllowed = settings.get(permissionName)
Expand Down Expand Up @@ -365,7 +375,7 @@ function registerPermissionHandler (session, partition) {
{text: locale.translation('deny')},
{text: locale.translation('allow')}
],
origin,
frameOrigin: getOrigin(mainFrameUrl),
options: {
persist: true
},
Expand All @@ -380,7 +390,7 @@ function registerPermissionHandler (session, partition) {
cb(result)
if (persist) {
// remember site setting for this host over http(s)
appActions.changeSiteSetting(getOrigin(url), permission + 'Permission', result, isPrivate)
appActions.changeSiteSetting(origin, permission + 'Permission', result, isPrivate)
}
}
})
Expand Down
7 changes: 0 additions & 7 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,6 @@ app.on('ready', () => {
electron.clipboard.writeText(text)
})

ipcMain.on(messages.SHOW_NOTIFICATION, (e, msg) => {
if (BrowserWindow.getFocusedWindow()) {
BrowserWindow.getFocusedWindow().webContents.send(messages.SHOW_NOTIFICATION,
locale.translation(msg))
}
})

ipcMain.on(messages.CHECK_FLASH_INSTALLED, (e) => {
flash.checkFlashInstalled((installed) => {
e.sender.send(messages.FLASH_UPDATED, installed)
Expand Down
4 changes: 0 additions & 4 deletions js/about/aboutActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ const AboutActions = {
ipc.send(messages.CHECK_FLASH_INSTALLED)
},

showNotification: function (msg) {
ipc.send(messages.SHOW_NOTIFICATION, msg)
},

setResourceEnabled: function (resourceName, enabled) {
AboutActions.dispatchAction({
actionType: AppConstants.APP_SET_RESOURCE_ENABLED,
Expand Down
2 changes: 0 additions & 2 deletions js/about/passwords.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class PasswordItem extends React.Component {
onCopy () {
if (this.state.decrypted !== null) {
aboutActions.setClipboard(this.state.decrypted)
aboutActions.showNotification('passwordCopied')
} else {
this.decrypt(false)
}
Expand All @@ -74,7 +73,6 @@ class PasswordItem extends React.Component {
return
}
aboutActions.setClipboard(details.decrypted)
aboutActions.showNotification('passwordCopied')
this.setState({
decrypted: details.decrypted
})
Expand Down
3 changes: 1 addition & 2 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,7 @@ class Frame extends ImmutableComponent {
} else {
flash.checkFlashInstalled((installed) => {
if (installed) {
currentWindow.webContents.send(messages.SHOW_NOTIFICATION,
locale.translation('flashInstalled'))
void new window.Notification(locale.translation('flashInstalled'))
} else if (noFlashCallback) {
noFlashCallback()
}
Expand Down
4 changes: 0 additions & 4 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,6 @@ class Main extends ImmutableComponent {
frameProps && windowActions.setRedirectedBy(frameProps, ruleset, details.url)
})

ipc.on(messages.SHOW_NOTIFICATION, (e, text) => {
void new window.Notification(text)
})

ipc.on(messages.SHORTCUT_ACTIVE_FRAME_BACK, this.onBack)
ipc.on(messages.SHORTCUT_ACTIVE_FRAME_FORWARD, this.onForward)

Expand Down
1 change: 0 additions & 1 deletion js/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const messages = {
ENTER_FULL_SCREEN: _,
SET_CLIPBOARD: _,
GOT_CANVAS_FINGERPRINTING: _,
SHOW_NOTIFICATION: _, /** @arg {string} l10n id of desktop notification message */
GO_BACK: _,
GO_FORWARD: _,
RELOAD: _,
Expand Down

0 comments on commit 8a43d49

Please sign in to comment.