@@ -15,6 +15,7 @@ const getBaseDomain = require('../js/lib/baseDomain').getBaseDomain
15
15
const getSetting = require ( '../js/settings' ) . getSetting
16
16
const settings = require ( '../js/constants/settings' )
17
17
const ipcMain = electron . ipcMain
18
+ const dialog = electron . dialog
18
19
19
20
const beforeSendHeadersFilteringFns = [ ]
20
21
const beforeRequestFilteringFns = [ ]
@@ -112,6 +113,70 @@ function registerForBeforeSendHeaders (session) {
112
113
} )
113
114
}
114
115
116
+ /**
117
+ * Register permission request handler
118
+ * @param {Object } session to add permission request handler on
119
+ */
120
+ function registerPermissionHandler ( session ) {
121
+ // Keep track of per-site permissions granted for this session.
122
+ // TODO: Localize strings
123
+ let permissions = {
124
+ media : {
125
+ action : 'use your camera and/or microphone' ,
126
+ hosts : { }
127
+ } ,
128
+ geolocation : {
129
+ action : 'see your location' ,
130
+ hosts : { }
131
+ } ,
132
+ notifications : {
133
+ action : 'show you notifications' ,
134
+ hosts : { }
135
+ } ,
136
+ midiSysex : {
137
+ action : 'use web MIDI' ,
138
+ hosts : { }
139
+ } ,
140
+ pointerLock : {
141
+ action : 'disable your mouse cursor' ,
142
+ hosts : { }
143
+ } ,
144
+ fullscreen : {
145
+ action : 'be fullscreen' ,
146
+ hosts : { }
147
+ }
148
+ }
149
+ session . setPermissionRequestHandler ( ( webContents , permission , cb ) => {
150
+ let host = urlParse ( webContents . getURL ( ) ) . host
151
+ let isAllowed = permissions [ permission ] . hosts [ host ]
152
+ if ( isAllowed !== undefined ) {
153
+ cb ( isAllowed )
154
+ } else {
155
+ // TODO: Add option to remember decision between restarts.
156
+ let result = dialog . showMessageBox ( {
157
+ type : 'question' ,
158
+ message : host + ' is requesting permission to ' + permissions [ permission ] . action ,
159
+ buttons : [ 'Deny' , 'Allow' ] ,
160
+ defaultId : 0 ,
161
+ cancelId : 0
162
+ } )
163
+ let isTemp = dialog . showMessageBox ( {
164
+ type : 'question' ,
165
+ title : 'Remember this decision?' ,
166
+ message : 'Would you like to remember this decision on ' + host + ' until Brave closes?' ,
167
+ buttons : [ 'Yes' , 'No' ] ,
168
+ defaultId : 0 ,
169
+ cancelId : 0
170
+ } )
171
+ result = ! ! ( result )
172
+ cb ( result )
173
+ if ( ! isTemp ) {
174
+ permissions [ permission ] . hosts [ host ] = result
175
+ }
176
+ }
177
+ } )
178
+ }
179
+
115
180
module . exports . isThirdPartyHost = ( baseContextHost , testHost ) => {
116
181
// TODO: Always return true if these are IP addresses that aren't the same
117
182
if ( ! testHost || ! baseContextHost ) {
@@ -126,7 +191,7 @@ module.exports.isThirdPartyHost = (baseContextHost, testHost) => {
126
191
}
127
192
128
193
function initForPartition ( partition ) {
129
- [ registerForBeforeRequest , registerForBeforeSendHeaders ] . forEach ( fn => {
194
+ [ registerPermissionHandler , registerForBeforeRequest , registerForBeforeSendHeaders ] . forEach ( fn => {
130
195
fn ( session . fromPartition ( partition ) )
131
196
} )
132
197
}
0 commit comments