From 2a278ceb8fe1c0c40a70de40c39f400db901fd09 Mon Sep 17 00:00:00 2001 From: Robo Date: Sat, 30 Jan 2016 16:49:18 +0530 Subject: [PATCH] delegate to permission manager for other permissions --- atom/browser/api/atom_api_web_contents.cc | 18 ++- atom/browser/api/atom_api_web_contents.h | 4 + atom/browser/atom_browser_client.cc | 4 +- atom/browser/atom_browser_context.cc | 6 + atom/browser/atom_browser_context.h | 7 ++ atom/browser/atom_permission_manager.cc | 107 ++++++++++++++++++ atom/browser/atom_permission_manager.h | 75 ++++++++++++ atom/browser/lib/guest-view-manager.js | 38 +++---- .../browser/web_contents_permission_helper.cc | 56 +++------ atom/browser/web_contents_permission_helper.h | 22 ++-- .../content_converter.cc | 44 +++++++ .../content_converter.h | 14 +++ .../lib/web-view/guest-view-internal.js | 4 +- filenames.gypi | 2 + 14 files changed, 324 insertions(+), 77 deletions(-) create mode 100644 atom/browser/atom_permission_manager.cc create mode 100644 atom/browser/atom_permission_manager.h diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 990d78aa9ca..01c069cf87d 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -13,6 +13,7 @@ #include "atom/browser/atom_browser_client.h" #include "atom/browser/atom_browser_context.h" #include "atom/browser/atom_browser_main_parts.h" +#include "atom/browser/atom_permission_manager.h" #include "atom/browser/native_window.h" #include "atom/browser/web_contents_permission_helper.h" #include "atom/browser/web_contents_preferences.h" @@ -263,8 +264,8 @@ WebContents::WebContents(v8::Isolate* isolate, // Save the preferences in C++. new WebContentsPreferences(web_contents, options); - // Initialze permission helper. - new WebContentsPermissionHelper(web_contents, this); + // Intialize permission helper. + WebContentsPermissionHelper::CreateForWebContents(web_contents); web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent()); @@ -1066,6 +1067,17 @@ bool WebContents::IsGuest() const { return type_ == WEB_VIEW; } +void WebContents::SetPermissionRequestHandler(v8::Local val, + mate::Arguments* args) { + AtomPermissionManager::RequestHandler handler; + if (!(val->IsNull() || mate::ConvertFromV8(args->isolate(), val, &handler))) { + args->ThrowError("Must pass null or function"); + return; + } + GetBrowserContext()->permission_manager() + ->SetPermissionRequestHandler(GetID(), handler); +} + v8::Local WebContents::GetWebPreferences(v8::Isolate* isolate) { WebContentsPreferences* web_preferences = WebContentsPreferences::FromWebContents(web_contents()); @@ -1165,6 +1177,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .SetMethod("_printToPDF", &WebContents::PrintToPDF) .SetMethod("addWorkSpace", &WebContents::AddWorkSpace) .SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace) + .SetMethod("setPermissionRequestHandler", + &WebContents::SetPermissionRequestHandler) .SetProperty("session", &WebContents::Session) .SetProperty("devToolsWebContents", &WebContents::DevToolsWebContents) .SetProperty("debugger", &WebContents::Debugger); diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 6587759efb9..6232aa3bf0c 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -133,6 +133,10 @@ class WebContents : public mate::TrackableObject, void SetAllowTransparency(bool allow); bool IsGuest() const; + // Handler for permission requests. + void SetPermissionRequestHandler(v8::Local val, + mate::Arguments* args); + // Returns the web preferences of current WebContents. v8::Local GetWebPreferences(v8::Isolate* isolate); diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index b395f3dd0cb..1fe435673db 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -288,13 +288,13 @@ void AtomBrowserClient::WebNotificationAllowed( content::WebContents* web_contents = content::WebContents::FromRenderViewHost( content::RenderViewHost::FromID(render_process_id, kDefaultRoutingID)); if (!web_contents) { - callback.Run(true); + callback.Run(false); return; } auto permission_helper = WebContentsPermissionHelper::FromWebContents(web_contents); if (!permission_helper) { - callback.Run(true); + callback.Run(false); return; } permission_helper->RequestWebNotificationPermission(callback); diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index ac59f8c3133..39eee1b8aff 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -13,6 +13,7 @@ #include "atom/browser/net/atom_url_request_job_factory.h" #include "atom/browser/net/asar/asar_protocol_handler.h" #include "atom/browser/net/http_protocol_handler.h" +#include "atom/browser/atom_permission_manager.h" #include "atom/browser/web_view_manager.h" #include "atom/common/atom_version.h" #include "atom/common/chrome_version.h" @@ -67,6 +68,7 @@ AtomBrowserContext::AtomBrowserContext(const std::string& partition, cert_verifier_(nullptr), job_factory_(new AtomURLRequestJobFactory), network_delegate_(new AtomNetworkDelegate), + permission_manager_(new AtomPermissionManager), allow_ntlm_everywhere_(false) { } @@ -169,6 +171,10 @@ content::BrowserPluginGuestManager* AtomBrowserContext::GetGuestManager() { return guest_manager_.get(); } +content::PermissionManager* AtomBrowserContext::GetPermissionManager() { + return permission_manager_.get(); +} + scoped_ptr AtomBrowserContext::CreateCertVerifier() { DCHECK(!cert_verifier_); cert_verifier_ = new AtomCertVerifier; diff --git a/atom/browser/atom_browser_context.h b/atom/browser/atom_browser_context.h index 9c94a60c305..44cd1f5b79e 100644 --- a/atom/browser/atom_browser_context.h +++ b/atom/browser/atom_browser_context.h @@ -14,6 +14,7 @@ namespace atom { class AtomDownloadManagerDelegate; class AtomCertVerifier; class AtomNetworkDelegate; +class AtomPermissionManager; class AtomURLRequestJobFactory; class WebViewManager; @@ -37,6 +38,7 @@ class AtomBrowserContext : public brightray::BrowserContext { // content::BrowserContext: content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; content::BrowserPluginGuestManager* GetGuestManager() override; + content::PermissionManager* GetPermissionManager() override; // brightray::BrowserContext: void RegisterPrefs(PrefRegistrySimple* pref_registry) override; @@ -49,9 +51,14 @@ class AtomBrowserContext : public brightray::BrowserContext { AtomNetworkDelegate* network_delegate() const { return network_delegate_; } + AtomPermissionManager* permission_manager() const { + return permission_manager_.get(); + } + private: scoped_ptr download_manager_delegate_; scoped_ptr guest_manager_; + scoped_ptr permission_manager_; // Managed by brightray::BrowserContext. AtomCertVerifier* cert_verifier_; diff --git a/atom/browser/atom_permission_manager.cc b/atom/browser/atom_permission_manager.cc new file mode 100644 index 00000000000..badef0a1d34 --- /dev/null +++ b/atom/browser/atom_permission_manager.cc @@ -0,0 +1,107 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/atom_permission_manager.h" + +#include "content/public/browser/permission_type.h" +#include "content/public/browser/render_frame_host.h" +#include "content/public/browser/render_process_host.h" + +namespace atom { + +AtomPermissionManager::AtomPermissionManager() + : request_id_(0) { +} + +AtomPermissionManager::~AtomPermissionManager() { +} + +void AtomPermissionManager::SetPermissionRequestHandler( + int id, + const RequestHandler& handler) { + if (handler.is_null()) { + request_handler_map_.erase(id); + return; + } + request_handler_map_[id] = handler; +} + +void AtomPermissionManager::RequestPermission( + content::PermissionType permission, + content::RenderFrameHost* render_frame_host, + const GURL& origin, + const base::Callback& callback) { + bool user_gesture = false; + RequestPermission(permission, render_frame_host, origin, user_gesture, + base::Bind(&AtomPermissionManager::OnPermissionResponse, + base::Unretained(this), callback)); +} + +void AtomPermissionManager::OnPermissionResponse( + const base::Callback& callback, + content::PermissionStatus status) { + if (status == content::PERMISSION_STATUS_GRANTED) + callback.Run(true); + else + callback.Run(false); +} + +int AtomPermissionManager::RequestPermission( + content::PermissionType permission, + content::RenderFrameHost* render_frame_host, + const GURL& requesting_origin, + bool user_gesture, + const ResponseCallback& callback) { + auto request_handler = + request_handler_map_.find(render_frame_host->GetProcess()->GetID()); + if (request_handler != request_handler_map_.end()) { + pending_requests_[++request_id_] = callback; + request_handler->second.Run(permission, callback); + return request_id_; + } + + callback.Run(content::PERMISSION_STATUS_GRANTED); + return kNoPendingOperation; +} + +void AtomPermissionManager::CancelPermissionRequest(int request_id) { + auto request = pending_requests_.find(request_id); + if (request != pending_requests_.end()) { + request->second.Run(content::PERMISSION_STATUS_DENIED); + pending_requests_.erase(request); + } +} + +void AtomPermissionManager::ResetPermission( + content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin) { +} + +content::PermissionStatus AtomPermissionManager::GetPermissionStatus( + content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin) { + return content::PERMISSION_STATUS_DENIED; +} + +void AtomPermissionManager::RegisterPermissionUsage( + content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin) { +} + +int AtomPermissionManager::SubscribePermissionStatusChange( + content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin, + const ResponseCallback& callback) { + return -1; +} + +void AtomPermissionManager::UnsubscribePermissionStatusChange( + int subscription_id) { +} + +} // namespace atom diff --git a/atom/browser/atom_permission_manager.h b/atom/browser/atom_permission_manager.h new file mode 100644 index 00000000000..697bcda6f37 --- /dev/null +++ b/atom/browser/atom_permission_manager.h @@ -0,0 +1,75 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_ATOM_PERMISSION_MANAGER_H_ +#define ATOM_BROWSER_ATOM_PERMISSION_MANAGER_H_ + +#include + +#include "base/callback_forward.h" +#include "base/macros.h" +#include "content/public/browser/permission_manager.h" + +namespace atom { + +class AtomPermissionManager : public content::PermissionManager { + public: + AtomPermissionManager(); + ~AtomPermissionManager() override; + + using ResponseCallback = + base::Callback; + using RequestHandler = + base::Callback; + + void SetPermissionRequestHandler(int id, const RequestHandler& handler); + void RequestPermission( + content::PermissionType permission, + content::RenderFrameHost* render_frame_host, + const GURL& origin, + const base::Callback& callback); + void OnPermissionResponse( + const base::Callback& callback, + content::PermissionStatus status); + + protected: + // content::PermissionManager: + int RequestPermission( + content::PermissionType permission, + content::RenderFrameHost* render_frame_host, + const GURL& requesting_origin, + bool user_gesture, + const ResponseCallback& callback) override; + void CancelPermissionRequest(int request_id) override; + void ResetPermission(content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin) override; + content::PermissionStatus GetPermissionStatus( + content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin) override; + void RegisterPermissionUsage(content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin) override; + int SubscribePermissionStatusChange( + content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin, + const base::Callback& callback) override; + void UnsubscribePermissionStatusChange(int subscription_id) override; + + private: + std::map request_handler_map_; + + std::map pending_requests_; + + int request_id_; + + DISALLOW_COPY_AND_ASSIGN(AtomPermissionManager); +}; + +} // namespace atom + +#endif // ATOM_BROWSER_ATOM_PERMISSION_MANAGER_H_ diff --git a/atom/browser/lib/guest-view-manager.js b/atom/browser/lib/guest-view-manager.js index b50d0c9503f..f529260e797 100644 --- a/atom/browser/lib/guest-view-manager.js +++ b/atom/browser/lib/guest-view-manager.js @@ -36,15 +36,13 @@ var supportedWebViewEvents = [ 'media-started-playing', 'media-paused', 'found-in-page', - 'did-change-theme-color', - 'permission-request' + 'did-change-theme-color' ]; var nextInstanceId = 0; -var permissionRequests; var guestInstances = {}; -var guestPermissionRequestsMap = {}; var embedderElementsMap = {}; +var pendingRequestsMap = {}; var reverseEmbedderElementsMap = {}; // Moves the last element of array to the first one. @@ -137,20 +135,19 @@ var createGuest = function(embedder, params) { if (params.allowtransparency != null) { this.setAllowTransparency(params.allowtransparency); } - return guest.allowPopups = params.allowpopups; + guest.allowPopups = params.allowpopups; + this.setPermissionRequestHandler((permission, callback) => { + if (!pendingRequestsMap[this.viewInstanceId]) + pendingRequestsMap[this.viewInstanceId] = {}; + pendingRequestsMap[this.viewInstanceId][permission] = callback; + embedder.send.apply(embedder, ["ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-" + this.viewInstanceId, "permission-request", permission]); + }); }); // Dispatch events to embedder. fn = function(event) { return guest.on(event, function() { var args = 2 <= arguments.length ? slice.call(arguments, 1) : []; - if (event === 'permission-request') { - if (!guestPermissionRequestsMap[guest.viewInstanceId]) - guestPermissionRequestsMap[guest.viewInstanceId] = {}; - var permission = args[0]; - guestPermissionRequestsMap[guest.viewInstanceId][permission] = args[1]; - args.pop(); - } return embedder.send.apply(embedder, ["ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-" + guest.viewInstanceId, event].concat(slice.call(args))); }); }; @@ -171,6 +168,7 @@ var createGuest = function(embedder, params) { var args = 2 <= arguments.length ? slice.call(arguments, 1) : []; return embedder.send.apply(embedder, ["ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-" + guest.viewInstanceId].concat(slice.call(args))); }); + return id; }; @@ -216,7 +214,7 @@ var destroyGuest = function(embedder, id) { webViewManager.removeGuest(embedder, id); guestInstances[id].guest.destroy(); delete guestInstances[id]; - delete guestPermissionRequestsMap[id]; + delete pendingRequestsMap[id]; key = reverseEmbedderElementsMap[id]; if (key != null) { delete reverseEmbedderElementsMap[id]; @@ -236,13 +234,6 @@ ipcMain.on('ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', function(event, id) { return destroyGuest(event.sender, id); }); -ipcMain.on('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_PERMISSION_RESPONSE', function(event, viewInstanceId, permission, allowed) { - permissionRequests = guestPermissionRequestsMap[viewInstanceId]; - if (permissionRequests && permissionRequests[permission] !== null) { - permissionRequests[permission].apply(null, [allowed]); - } -}); - ipcMain.on('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', function(event, id, params) { var ref1; return (ref1 = guestInstances[id]) != null ? ref1.guest.setSize(params) : void 0; @@ -253,6 +244,13 @@ ipcMain.on('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', function(even return (ref1 = guestInstances[id]) != null ? ref1.guest.setAllowTransparency(allowtransparency) : void 0; }); +ipcMain.on('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_PERMISSION_RESPONSE', function(event, id, permission, allowed) { + if (pendingRequestsMap[id] != null) { + const callback = pendingRequestsMap[id][permission]; + callback.apply(null, [allowed]); + } +}); + // Returns WebContents from its guest id. exports.getGuest = function(id) { var ref1; diff --git a/atom/browser/web_contents_permission_helper.cc b/atom/browser/web_contents_permission_helper.cc index 5c82aa41df6..04a6a5d9883 100644 --- a/atom/browser/web_contents_permission_helper.cc +++ b/atom/browser/web_contents_permission_helper.cc @@ -6,8 +6,9 @@ #include -#include "atom/browser/api/atom_api_web_contents.h" +#include "atom/browser/atom_permission_manager.h" #include "content/public/browser/media_capture_devices.h" +#include "content/public/browser/render_process_host.h" DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::WebContentsPermissionHelper); @@ -67,55 +68,32 @@ void MediaAccessAllowed( } // namespace WebContentsPermissionHelper::WebContentsPermissionHelper( - content::WebContents* web_contents, - api::WebContents* api_web_contents) - : api_web_contents_(api_web_contents) { - web_contents->SetUserData(UserDataKey(), this); + content::WebContents* web_contents) + : web_contents_(web_contents) { } WebContentsPermissionHelper::~WebContentsPermissionHelper() { } +void WebContentsPermissionHelper::RequestPermission( + content::PermissionType permission, + const base::Callback& callback) { + auto rfh = web_contents_->GetMainFrame(); + auto permission_manager = browser_context()->permission_manager(); + auto origin = web_contents_->GetLastCommittedURL(); + permission_manager->RequestPermission(permission, rfh, origin, callback); +} + void WebContentsPermissionHelper::RequestMediaAccessPermission( const content::MediaStreamRequest& request, - const content::MediaResponseCallback& callback) { - if (api_web_contents_->IsGuest()) { - const std::string& permission = "media"; - permission_map_[permission] = base::Bind(&MediaAccessAllowed, - request, - callback); - api_web_contents_->Emit( - "permission-request", - permission, - base::Bind(&WebContentsPermissionHelper::OnPermissionResponse, - base::Unretained(this), permission)); - return; - } - MediaAccessAllowed(request, callback, true); + const content::MediaResponseCallback& response_callback) { + auto callback = base::Bind(&MediaAccessAllowed, request, response_callback); + RequestPermission(content::PermissionType::AUDIO_CAPTURE, callback); } void WebContentsPermissionHelper::RequestWebNotificationPermission( const base::Callback& callback) { - if (api_web_contents_->IsGuest()) { - const std::string& permission = "webNotification"; - permission_map_[permission] = callback; - api_web_contents_->Emit( - "permission-request", - permission, - base::Bind(&WebContentsPermissionHelper::OnPermissionResponse, - base::Unretained(this), permission)); - return; - } - callback.Run(true); -} - -void WebContentsPermissionHelper::OnPermissionResponse( - const std::string& permission, bool allowed) { - auto it = permission_map_.find(permission); - if (it != permission_map_.end()) { - it->second.Run(allowed); - permission_map_.erase(permission); - } + RequestPermission(content::PermissionType::NOTIFICATIONS, callback); } } // namespace atom diff --git a/atom/browser/web_contents_permission_helper.h b/atom/browser/web_contents_permission_helper.h index 4beac035c02..2c845a60f76 100644 --- a/atom/browser/web_contents_permission_helper.h +++ b/atom/browser/web_contents_permission_helper.h @@ -5,25 +5,18 @@ #ifndef ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_ #define ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_ -#include -#include - +#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" namespace atom { -namespace api { -class WebContents; -} - // Applies the permission requested for WebContents. class WebContentsPermissionHelper : public content::WebContentsUserData { public: - WebContentsPermissionHelper(content::WebContents* web_contents, - api::WebContents* api_web_contents); ~WebContentsPermissionHelper() override; void RequestMediaAccessPermission( @@ -32,14 +25,19 @@ class WebContentsPermissionHelper void RequestWebNotificationPermission( const base::Callback& callback); - void OnPermissionResponse(const std::string& permission, bool allowed); + AtomBrowserContext* browser_context() const { + return static_cast(web_contents_->GetBrowserContext()); + } private: + explicit WebContentsPermissionHelper(content::WebContents* web_contents); friend class content::WebContentsUserData; - std::map> permission_map_; + void RequestPermission( + content::PermissionType permission, + const base::Callback& callback); - api::WebContents* api_web_contents_; // Weak reference + content::WebContents* web_contents_; DISALLOW_COPY_AND_ASSIGN(WebContentsPermissionHelper); }; diff --git a/atom/common/native_mate_converters/content_converter.cc b/atom/common/native_mate_converters/content_converter.cc index d79094f79d4..d85188dad1f 100644 --- a/atom/common/native_mate_converters/content_converter.cc +++ b/atom/common/native_mate_converters/content_converter.cc @@ -98,6 +98,50 @@ v8::Local Converter::ToV8( return mate::ConvertToV8(isolate, dict); } +// static +bool Converter::FromV8( + v8::Isolate* isolate, + v8::Local val, + content::PermissionStatus* out) { + std::string status; + if (!ConvertFromV8(isolate, val, &status)) + return false; + + if (status == "granted") + *out = content::PERMISSION_STATUS_GRANTED; + else if (status == "denied" || status.empty()) + *out = content::PERMISSION_STATUS_DENIED; + else + return false; + + return true; +} + +// static +v8::Local Converter::ToV8( + v8::Isolate* isolate, const content::PermissionType& val) { + switch (val) { + case content::PermissionType::MIDI_SYSEX: + return StringToV8(isolate, "midiSysex"); + case content::PermissionType::PUSH_MESSAGING: + return StringToV8(isolate, "pushMessaging"); + case content::PermissionType::NOTIFICATIONS: + return StringToV8(isolate, "notifications"); + case content::PermissionType::GEOLOCATION: + return StringToV8(isolate, "geolocation"); + case content::PermissionType::AUDIO_CAPTURE: + case content::PermissionType::VIDEO_CAPTURE: + return StringToV8(isolate, "media"); + case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: + return StringToV8(isolate, "mediaKeySystem"); + case content::PermissionType::MIDI: + return StringToV8(isolate, "midi"); + case content::PermissionType::DURABLE_STORAGE: + default: + return StringToV8(isolate, "unknown"); + } +} + // static bool Converter::FromV8( v8::Isolate* isolate, diff --git a/atom/common/native_mate_converters/content_converter.h b/atom/common/native_mate_converters/content_converter.h index a5708e022b5..6c9130b1887 100644 --- a/atom/common/native_mate_converters/content_converter.h +++ b/atom/common/native_mate_converters/content_converter.h @@ -7,7 +7,9 @@ #include +#include "content/public/browser/permission_type.h" #include "content/public/common/menu_item.h" +#include "content/public/common/permission_status.mojom.h" #include "content/public/common/stop_find_action.h" #include "native_mate/converter.h" @@ -33,6 +35,18 @@ struct Converter { const ContextMenuParamsWithWebContents& val); }; +template<> +struct Converter { + static bool FromV8(v8::Isolate* isolate, v8::Local val, + content::PermissionStatus* out); +}; + +template<> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + const content::PermissionType& val); +}; + template<> struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Local val, diff --git a/atom/renderer/lib/web-view/guest-view-internal.js b/atom/renderer/lib/web-view/guest-view-internal.js index e6a1519b0f4..acade1f41c0 100644 --- a/atom/renderer/lib/web-view/guest-view-internal.js +++ b/atom/renderer/lib/web-view/guest-view-internal.js @@ -67,10 +67,10 @@ module.exports = { var args = 3 <= arguments.length ? slice.call(arguments, 2) : []; if (eventName === 'permission-request') { var allow = function allow() { - ipcRenderer.send("ATOM_SHELL_GUEST_VIEW_MANAGER_SET_PERMISSION_RESPONSE", viewInstanceId, args[0], true); + ipcRenderer.send("ATOM_SHELL_GUEST_VIEW_MANAGER_SET_PERMISSION_RESPONSE", viewInstanceId, args[0], "granted"); }; var deny = function deny() { - ipcRenderer.send("ATOM_SHELL_GUEST_VIEW_MANAGER_SET_PERMISSION_RESPONSE", viewInstanceId, args[0], false); + ipcRenderer.send("ATOM_SHELL_GUEST_VIEW_MANAGER_SET_PERMISSION_RESPONSE", viewInstanceId, args[0], "denied"); }; args = args.concat([allow, deny]); } diff --git a/filenames.gypi b/filenames.gypi index 3c9cd4b6919..beb4fcac548 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -144,6 +144,8 @@ 'atom/browser/atom_browser_main_parts_posix.cc', 'atom/browser/atom_javascript_dialog_manager.cc', 'atom/browser/atom_javascript_dialog_manager.h', + 'atom/browser/atom_permission_manager.cc', + 'atom/browser/atom_permission_manager.h', 'atom/browser/atom_quota_permission_context.cc', 'atom/browser/atom_quota_permission_context.h', 'atom/browser/atom_resource_dispatcher_host_delegate.cc',