diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 01c069cf87d..c6ab110b832 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1177,7 +1177,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .SetMethod("_printToPDF", &WebContents::PrintToPDF) .SetMethod("addWorkSpace", &WebContents::AddWorkSpace) .SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace) - .SetMethod("setPermissionRequestHandler", + .SetMethod("_setPermissionRequestHandler", &WebContents::SetPermissionRequestHandler) .SetProperty("session", &WebContents::Session) .SetProperty("devToolsWebContents", &WebContents::DevToolsWebContents) diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index 39eee1b8aff..35358ac08a4 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -65,10 +65,10 @@ std::string RemoveWhitespace(const std::string& str) { AtomBrowserContext::AtomBrowserContext(const std::string& partition, bool in_memory) : brightray::BrowserContext(partition, in_memory), + permission_manager_(new AtomPermissionManager), cert_verifier_(nullptr), job_factory_(new AtomURLRequestJobFactory), network_delegate_(new AtomNetworkDelegate), - permission_manager_(new AtomPermissionManager), allow_ntlm_everywhere_(false) { } diff --git a/atom/browser/atom_permission_manager.cc b/atom/browser/atom_permission_manager.cc index badef0a1d34..ccd456e7c20 100644 --- a/atom/browser/atom_permission_manager.cc +++ b/atom/browser/atom_permission_manager.cc @@ -4,6 +4,7 @@ #include "atom/browser/atom_permission_manager.h" +#include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/permission_type.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" @@ -53,8 +54,14 @@ int AtomPermissionManager::RequestPermission( const GURL& requesting_origin, bool user_gesture, const ResponseCallback& callback) { - auto request_handler = - request_handler_map_.find(render_frame_host->GetProcess()->GetID()); + int process_id = render_frame_host->GetProcess()->GetID(); + auto request_handler = request_handler_map_.find(process_id); + + if (permission == content::PermissionType::MIDI_SYSEX) { + content::ChildProcessSecurityPolicy::GetInstance()-> + GrantSendMidiSysExMessage(process_id); + } + if (request_handler != request_handler_map_.end()) { pending_requests_[++request_id_] = callback; request_handler->second.Run(permission, callback); @@ -83,7 +90,7 @@ content::PermissionStatus AtomPermissionManager::GetPermissionStatus( content::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin) { - return content::PERMISSION_STATUS_DENIED; + return content::PERMISSION_STATUS_GRANTED; } void AtomPermissionManager::RegisterPermissionUsage( diff --git a/atom/browser/atom_permission_manager.h b/atom/browser/atom_permission_manager.h index 697bcda6f37..fb449037f64 100644 --- a/atom/browser/atom_permission_manager.h +++ b/atom/browser/atom_permission_manager.h @@ -24,7 +24,9 @@ class AtomPermissionManager : public content::PermissionManager { base::Callback; + // Handler to dispatch permission requests in JS. void SetPermissionRequestHandler(int id, const RequestHandler& handler); + void RequestPermission( content::PermissionType permission, content::RenderFrameHost* render_frame_host, diff --git a/atom/browser/lib/guest-view-manager.js b/atom/browser/lib/guest-view-manager.js index f529260e797..d4332070fa6 100644 --- a/atom/browser/lib/guest-view-manager.js +++ b/atom/browser/lib/guest-view-manager.js @@ -136,7 +136,9 @@ var createGuest = function(embedder, params) { this.setAllowTransparency(params.allowtransparency); } guest.allowPopups = params.allowpopups; - this.setPermissionRequestHandler((permission, callback) => { + + // Dispatches permission request event. + this._setPermissionRequestHandler((permission, callback) => { if (!pendingRequestsMap[this.viewInstanceId]) pendingRequestsMap[this.viewInstanceId] = {}; pendingRequestsMap[this.viewInstanceId][permission] = callback; diff --git a/atom/browser/web_contents_permission_helper.h b/atom/browser/web_contents_permission_helper.h index 2c845a60f76..749e90184c2 100644 --- a/atom/browser/web_contents_permission_helper.h +++ b/atom/browser/web_contents_permission_helper.h @@ -6,7 +6,6 @@ #define ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_ #include "atom/browser/atom_browser_context.h" -#include "base/callback.h" #include "content/public/browser/permission_type.h" #include "content/public/browser/web_contents_user_data.h" #include "content/public/common/media_stream_request.h" diff --git a/atom/common/api/event_emitter_caller.h b/atom/common/api/event_emitter_caller.h index 26a4cbc45b9..a2567da9d10 100644 --- a/atom/common/api/event_emitter_caller.h +++ b/atom/common/api/event_emitter_caller.h @@ -7,7 +7,6 @@ #include -#include "atom/common/native_mate_converters/callback.h" #include "native_mate/converter.h" namespace mate { diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 67a3d12171c..229ee12f1a5 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -740,7 +740,7 @@ Emitted when DevTools is focused / opened. Returns: -* `permission` String - The type of permission being requested. Enum of 'media', 'webNotification'. +* `permission` String - The type of permission being requested. Enum of 'media', 'notifications', 'midiSysex', 'geolocation'. * `allow` Function - Allows the permission. * `deny` Function - Deny the permission. This is the default behaviour if `allow` is not called. diff --git a/spec/fixtures/pages/permissions/geolocation.html b/spec/fixtures/pages/permissions/geolocation.html new file mode 100644 index 00000000000..1d1b4fc4245 --- /dev/null +++ b/spec/fixtures/pages/permissions/geolocation.html @@ -0,0 +1,5 @@ + diff --git a/spec/fixtures/pages/permission-request.html b/spec/fixtures/pages/permissions/media.html similarity index 100% rename from spec/fixtures/pages/permission-request.html rename to spec/fixtures/pages/permissions/media.html diff --git a/spec/fixtures/pages/permissions/midi.html b/spec/fixtures/pages/permissions/midi.html new file mode 100644 index 00000000000..c6bd8c137e3 --- /dev/null +++ b/spec/fixtures/pages/permissions/midi.html @@ -0,0 +1,5 @@ + diff --git a/spec/webview-spec.js b/spec/webview-spec.js index e40afcaefeb..190a3266090 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -645,7 +645,39 @@ describe(' tag', function() { e.deny(); } }); - webview.src = "file://" + fixtures + "/pages/permission-request.html"; + webview.src = "file://" + fixtures + "/pages/permissions/media.html"; + webview.setAttribute('nodeintegration', 'on'); + document.body.appendChild(webview); + }); + + it ('emits when using navigator.geolocation api', function(done) { + webview.addEventListener('ipc-message', function(e) { + assert(e.channel, 'message'); + assert(e.args, ['ERROR(1): User denied Geolocation']); + done(); + }); + webview.addEventListener('permission-request', function(e) { + if (e.permission === 'geolocation') { + e.deny(); + } + }); + webview.src = "file://" + fixtures + "/pages/permissions/geolocation.html"; + webview.setAttribute('nodeintegration', 'on'); + document.body.appendChild(webview); + }); + + it ('emits when using navigator.requestMIDIAccess api', function(done) { + webview.addEventListener('ipc-message', function(e) { + assert(e.channel, 'message'); + assert(e.args, ['SecurityError']); + done(); + }); + webview.addEventListener('permission-request', function(e) { + if (e.permission === 'midiSysex') { + e.deny(); + } + }); + webview.src = "file://" + fixtures + "/pages/permissions/midi.html"; webview.setAttribute('nodeintegration', 'on'); document.body.appendChild(webview); });