delegate to permission manager for other permissions
This commit is contained in:
parent
f32bf08eb3
commit
2a278ceb8f
14 changed files with 324 additions and 77 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include "atom/browser/atom_browser_client.h"
|
#include "atom/browser/atom_browser_client.h"
|
||||||
#include "atom/browser/atom_browser_context.h"
|
#include "atom/browser/atom_browser_context.h"
|
||||||
#include "atom/browser/atom_browser_main_parts.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/native_window.h"
|
||||||
#include "atom/browser/web_contents_permission_helper.h"
|
#include "atom/browser/web_contents_permission_helper.h"
|
||||||
#include "atom/browser/web_contents_preferences.h"
|
#include "atom/browser/web_contents_preferences.h"
|
||||||
|
@ -263,8 +264,8 @@ WebContents::WebContents(v8::Isolate* isolate,
|
||||||
// Save the preferences in C++.
|
// Save the preferences in C++.
|
||||||
new WebContentsPreferences(web_contents, options);
|
new WebContentsPreferences(web_contents, options);
|
||||||
|
|
||||||
// Initialze permission helper.
|
// Intialize permission helper.
|
||||||
new WebContentsPermissionHelper(web_contents, this);
|
WebContentsPermissionHelper::CreateForWebContents(web_contents);
|
||||||
|
|
||||||
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
|
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
|
||||||
|
|
||||||
|
@ -1066,6 +1067,17 @@ bool WebContents::IsGuest() const {
|
||||||
return type_ == WEB_VIEW;
|
return type_ == WEB_VIEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::SetPermissionRequestHandler(v8::Local<v8::Value> 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<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
|
v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
|
||||||
WebContentsPreferences* web_preferences =
|
WebContentsPreferences* web_preferences =
|
||||||
WebContentsPreferences::FromWebContents(web_contents());
|
WebContentsPreferences::FromWebContents(web_contents());
|
||||||
|
@ -1165,6 +1177,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
|
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
|
||||||
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
|
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
|
||||||
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
|
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
|
||||||
|
.SetMethod("setPermissionRequestHandler",
|
||||||
|
&WebContents::SetPermissionRequestHandler)
|
||||||
.SetProperty("session", &WebContents::Session)
|
.SetProperty("session", &WebContents::Session)
|
||||||
.SetProperty("devToolsWebContents", &WebContents::DevToolsWebContents)
|
.SetProperty("devToolsWebContents", &WebContents::DevToolsWebContents)
|
||||||
.SetProperty("debugger", &WebContents::Debugger);
|
.SetProperty("debugger", &WebContents::Debugger);
|
||||||
|
|
|
@ -133,6 +133,10 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
void SetAllowTransparency(bool allow);
|
void SetAllowTransparency(bool allow);
|
||||||
bool IsGuest() const;
|
bool IsGuest() const;
|
||||||
|
|
||||||
|
// Handler for permission requests.
|
||||||
|
void SetPermissionRequestHandler(v8::Local<v8::Value> val,
|
||||||
|
mate::Arguments* args);
|
||||||
|
|
||||||
// Returns the web preferences of current WebContents.
|
// Returns the web preferences of current WebContents.
|
||||||
v8::Local<v8::Value> GetWebPreferences(v8::Isolate* isolate);
|
v8::Local<v8::Value> GetWebPreferences(v8::Isolate* isolate);
|
||||||
|
|
||||||
|
|
|
@ -288,13 +288,13 @@ void AtomBrowserClient::WebNotificationAllowed(
|
||||||
content::WebContents* web_contents = content::WebContents::FromRenderViewHost(
|
content::WebContents* web_contents = content::WebContents::FromRenderViewHost(
|
||||||
content::RenderViewHost::FromID(render_process_id, kDefaultRoutingID));
|
content::RenderViewHost::FromID(render_process_id, kDefaultRoutingID));
|
||||||
if (!web_contents) {
|
if (!web_contents) {
|
||||||
callback.Run(true);
|
callback.Run(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto permission_helper =
|
auto permission_helper =
|
||||||
WebContentsPermissionHelper::FromWebContents(web_contents);
|
WebContentsPermissionHelper::FromWebContents(web_contents);
|
||||||
if (!permission_helper) {
|
if (!permission_helper) {
|
||||||
callback.Run(true);
|
callback.Run(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
permission_helper->RequestWebNotificationPermission(callback);
|
permission_helper->RequestWebNotificationPermission(callback);
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "atom/browser/net/atom_url_request_job_factory.h"
|
#include "atom/browser/net/atom_url_request_job_factory.h"
|
||||||
#include "atom/browser/net/asar/asar_protocol_handler.h"
|
#include "atom/browser/net/asar/asar_protocol_handler.h"
|
||||||
#include "atom/browser/net/http_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/browser/web_view_manager.h"
|
||||||
#include "atom/common/atom_version.h"
|
#include "atom/common/atom_version.h"
|
||||||
#include "atom/common/chrome_version.h"
|
#include "atom/common/chrome_version.h"
|
||||||
|
@ -67,6 +68,7 @@ AtomBrowserContext::AtomBrowserContext(const std::string& partition,
|
||||||
cert_verifier_(nullptr),
|
cert_verifier_(nullptr),
|
||||||
job_factory_(new AtomURLRequestJobFactory),
|
job_factory_(new AtomURLRequestJobFactory),
|
||||||
network_delegate_(new AtomNetworkDelegate),
|
network_delegate_(new AtomNetworkDelegate),
|
||||||
|
permission_manager_(new AtomPermissionManager),
|
||||||
allow_ntlm_everywhere_(false) {
|
allow_ntlm_everywhere_(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +171,10 @@ content::BrowserPluginGuestManager* AtomBrowserContext::GetGuestManager() {
|
||||||
return guest_manager_.get();
|
return guest_manager_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content::PermissionManager* AtomBrowserContext::GetPermissionManager() {
|
||||||
|
return permission_manager_.get();
|
||||||
|
}
|
||||||
|
|
||||||
scoped_ptr<net::CertVerifier> AtomBrowserContext::CreateCertVerifier() {
|
scoped_ptr<net::CertVerifier> AtomBrowserContext::CreateCertVerifier() {
|
||||||
DCHECK(!cert_verifier_);
|
DCHECK(!cert_verifier_);
|
||||||
cert_verifier_ = new AtomCertVerifier;
|
cert_verifier_ = new AtomCertVerifier;
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace atom {
|
||||||
class AtomDownloadManagerDelegate;
|
class AtomDownloadManagerDelegate;
|
||||||
class AtomCertVerifier;
|
class AtomCertVerifier;
|
||||||
class AtomNetworkDelegate;
|
class AtomNetworkDelegate;
|
||||||
|
class AtomPermissionManager;
|
||||||
class AtomURLRequestJobFactory;
|
class AtomURLRequestJobFactory;
|
||||||
class WebViewManager;
|
class WebViewManager;
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
||||||
// content::BrowserContext:
|
// content::BrowserContext:
|
||||||
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
|
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
|
||||||
content::BrowserPluginGuestManager* GetGuestManager() override;
|
content::BrowserPluginGuestManager* GetGuestManager() override;
|
||||||
|
content::PermissionManager* GetPermissionManager() override;
|
||||||
|
|
||||||
// brightray::BrowserContext:
|
// brightray::BrowserContext:
|
||||||
void RegisterPrefs(PrefRegistrySimple* pref_registry) override;
|
void RegisterPrefs(PrefRegistrySimple* pref_registry) override;
|
||||||
|
@ -49,9 +51,14 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
||||||
|
|
||||||
AtomNetworkDelegate* network_delegate() const { return network_delegate_; }
|
AtomNetworkDelegate* network_delegate() const { return network_delegate_; }
|
||||||
|
|
||||||
|
AtomPermissionManager* permission_manager() const {
|
||||||
|
return permission_manager_.get();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
scoped_ptr<AtomDownloadManagerDelegate> download_manager_delegate_;
|
scoped_ptr<AtomDownloadManagerDelegate> download_manager_delegate_;
|
||||||
scoped_ptr<WebViewManager> guest_manager_;
|
scoped_ptr<WebViewManager> guest_manager_;
|
||||||
|
scoped_ptr<AtomPermissionManager> permission_manager_;
|
||||||
|
|
||||||
// Managed by brightray::BrowserContext.
|
// Managed by brightray::BrowserContext.
|
||||||
AtomCertVerifier* cert_verifier_;
|
AtomCertVerifier* cert_verifier_;
|
||||||
|
|
107
atom/browser/atom_permission_manager.cc
Normal file
107
atom/browser/atom_permission_manager.cc
Normal file
|
@ -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<void(bool)>& 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<void(bool)>& 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
|
75
atom/browser/atom_permission_manager.h
Normal file
75
atom/browser/atom_permission_manager.h
Normal file
|
@ -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 <map>
|
||||||
|
|
||||||
|
#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<void(content::PermissionStatus)>;
|
||||||
|
using RequestHandler =
|
||||||
|
base::Callback<void(content::PermissionType,
|
||||||
|
const ResponseCallback&)>;
|
||||||
|
|
||||||
|
void SetPermissionRequestHandler(int id, const RequestHandler& handler);
|
||||||
|
void RequestPermission(
|
||||||
|
content::PermissionType permission,
|
||||||
|
content::RenderFrameHost* render_frame_host,
|
||||||
|
const GURL& origin,
|
||||||
|
const base::Callback<void(bool)>& callback);
|
||||||
|
void OnPermissionResponse(
|
||||||
|
const base::Callback<void(bool)>& 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<void(content::PermissionStatus)>& callback) override;
|
||||||
|
void UnsubscribePermissionStatusChange(int subscription_id) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<int, RequestHandler> request_handler_map_;
|
||||||
|
|
||||||
|
std::map<int, ResponseCallback> pending_requests_;
|
||||||
|
|
||||||
|
int request_id_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(AtomPermissionManager);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace atom
|
||||||
|
|
||||||
|
#endif // ATOM_BROWSER_ATOM_PERMISSION_MANAGER_H_
|
|
@ -36,15 +36,13 @@ var supportedWebViewEvents = [
|
||||||
'media-started-playing',
|
'media-started-playing',
|
||||||
'media-paused',
|
'media-paused',
|
||||||
'found-in-page',
|
'found-in-page',
|
||||||
'did-change-theme-color',
|
'did-change-theme-color'
|
||||||
'permission-request'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
var nextInstanceId = 0;
|
var nextInstanceId = 0;
|
||||||
var permissionRequests;
|
|
||||||
var guestInstances = {};
|
var guestInstances = {};
|
||||||
var guestPermissionRequestsMap = {};
|
|
||||||
var embedderElementsMap = {};
|
var embedderElementsMap = {};
|
||||||
|
var pendingRequestsMap = {};
|
||||||
var reverseEmbedderElementsMap = {};
|
var reverseEmbedderElementsMap = {};
|
||||||
|
|
||||||
// Moves the last element of array to the first one.
|
// Moves the last element of array to the first one.
|
||||||
|
@ -137,20 +135,19 @@ var createGuest = function(embedder, params) {
|
||||||
if (params.allowtransparency != null) {
|
if (params.allowtransparency != null) {
|
||||||
this.setAllowTransparency(params.allowtransparency);
|
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.
|
// Dispatch events to embedder.
|
||||||
fn = function(event) {
|
fn = function(event) {
|
||||||
return guest.on(event, function() {
|
return guest.on(event, function() {
|
||||||
var args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
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)));
|
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) : [];
|
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 embedder.send.apply(embedder, ["ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-" + guest.viewInstanceId].concat(slice.call(args)));
|
||||||
});
|
});
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -216,7 +214,7 @@ var destroyGuest = function(embedder, id) {
|
||||||
webViewManager.removeGuest(embedder, id);
|
webViewManager.removeGuest(embedder, id);
|
||||||
guestInstances[id].guest.destroy();
|
guestInstances[id].guest.destroy();
|
||||||
delete guestInstances[id];
|
delete guestInstances[id];
|
||||||
delete guestPermissionRequestsMap[id];
|
delete pendingRequestsMap[id];
|
||||||
key = reverseEmbedderElementsMap[id];
|
key = reverseEmbedderElementsMap[id];
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
delete reverseEmbedderElementsMap[id];
|
delete reverseEmbedderElementsMap[id];
|
||||||
|
@ -236,13 +234,6 @@ ipcMain.on('ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', function(event, id) {
|
||||||
return destroyGuest(event.sender, 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) {
|
ipcMain.on('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', function(event, id, params) {
|
||||||
var ref1;
|
var ref1;
|
||||||
return (ref1 = guestInstances[id]) != null ? ref1.guest.setSize(params) : void 0;
|
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;
|
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.
|
// Returns WebContents from its guest id.
|
||||||
exports.getGuest = function(id) {
|
exports.getGuest = function(id) {
|
||||||
var ref1;
|
var ref1;
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#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/media_capture_devices.h"
|
||||||
|
#include "content/public/browser/render_process_host.h"
|
||||||
|
|
||||||
DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::WebContentsPermissionHelper);
|
DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::WebContentsPermissionHelper);
|
||||||
|
|
||||||
|
@ -67,55 +68,32 @@ void MediaAccessAllowed(
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
WebContentsPermissionHelper::WebContentsPermissionHelper(
|
WebContentsPermissionHelper::WebContentsPermissionHelper(
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents)
|
||||||
api::WebContents* api_web_contents)
|
: web_contents_(web_contents) {
|
||||||
: api_web_contents_(api_web_contents) {
|
|
||||||
web_contents->SetUserData(UserDataKey(), this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebContentsPermissionHelper::~WebContentsPermissionHelper() {
|
WebContentsPermissionHelper::~WebContentsPermissionHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContentsPermissionHelper::RequestPermission(
|
||||||
|
content::PermissionType permission,
|
||||||
|
const base::Callback<void(bool)>& 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(
|
void WebContentsPermissionHelper::RequestMediaAccessPermission(
|
||||||
const content::MediaStreamRequest& request,
|
const content::MediaStreamRequest& request,
|
||||||
const content::MediaResponseCallback& callback) {
|
const content::MediaResponseCallback& response_callback) {
|
||||||
if (api_web_contents_->IsGuest()) {
|
auto callback = base::Bind(&MediaAccessAllowed, request, response_callback);
|
||||||
const std::string& permission = "media";
|
RequestPermission(content::PermissionType::AUDIO_CAPTURE, callback);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContentsPermissionHelper::RequestWebNotificationPermission(
|
void WebContentsPermissionHelper::RequestWebNotificationPermission(
|
||||||
const base::Callback<void(bool)>& callback) {
|
const base::Callback<void(bool)>& callback) {
|
||||||
if (api_web_contents_->IsGuest()) {
|
RequestPermission(content::PermissionType::NOTIFICATIONS, callback);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -5,25 +5,18 @@
|
||||||
#ifndef ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
#ifndef ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
||||||
#define ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
#define ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
||||||
|
|
||||||
#include <map>
|
#include "atom/browser/atom_browser_context.h"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "base/callback.h"
|
#include "base/callback.h"
|
||||||
|
#include "content/public/browser/permission_type.h"
|
||||||
#include "content/public/browser/web_contents_user_data.h"
|
#include "content/public/browser/web_contents_user_data.h"
|
||||||
#include "content/public/common/media_stream_request.h"
|
#include "content/public/common/media_stream_request.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
namespace api {
|
|
||||||
class WebContents;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Applies the permission requested for WebContents.
|
// Applies the permission requested for WebContents.
|
||||||
class WebContentsPermissionHelper
|
class WebContentsPermissionHelper
|
||||||
: public content::WebContentsUserData<WebContentsPermissionHelper> {
|
: public content::WebContentsUserData<WebContentsPermissionHelper> {
|
||||||
public:
|
public:
|
||||||
WebContentsPermissionHelper(content::WebContents* web_contents,
|
|
||||||
api::WebContents* api_web_contents);
|
|
||||||
~WebContentsPermissionHelper() override;
|
~WebContentsPermissionHelper() override;
|
||||||
|
|
||||||
void RequestMediaAccessPermission(
|
void RequestMediaAccessPermission(
|
||||||
|
@ -32,14 +25,19 @@ class WebContentsPermissionHelper
|
||||||
void RequestWebNotificationPermission(
|
void RequestWebNotificationPermission(
|
||||||
const base::Callback<void(bool)>& callback);
|
const base::Callback<void(bool)>& callback);
|
||||||
|
|
||||||
void OnPermissionResponse(const std::string& permission, bool allowed);
|
AtomBrowserContext* browser_context() const {
|
||||||
|
return static_cast<AtomBrowserContext*>(web_contents_->GetBrowserContext());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
explicit WebContentsPermissionHelper(content::WebContents* web_contents);
|
||||||
friend class content::WebContentsUserData<WebContentsPermissionHelper>;
|
friend class content::WebContentsUserData<WebContentsPermissionHelper>;
|
||||||
|
|
||||||
std::map<std::string, base::Callback<void(bool)>> permission_map_;
|
void RequestPermission(
|
||||||
|
content::PermissionType permission,
|
||||||
|
const base::Callback<void(bool)>& callback);
|
||||||
|
|
||||||
api::WebContents* api_web_contents_; // Weak reference
|
content::WebContents* web_contents_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(WebContentsPermissionHelper);
|
DISALLOW_COPY_AND_ASSIGN(WebContentsPermissionHelper);
|
||||||
};
|
};
|
||||||
|
|
|
@ -98,6 +98,50 @@ v8::Local<v8::Value> Converter<ContextMenuParamsWithWebContents>::ToV8(
|
||||||
return mate::ConvertToV8(isolate, dict);
|
return mate::ConvertToV8(isolate, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
bool Converter<content::PermissionStatus>::FromV8(
|
||||||
|
v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> 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<v8::Value> Converter<content::PermissionType>::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
|
// static
|
||||||
bool Converter<content::StopFindAction>::FromV8(
|
bool Converter<content::StopFindAction>::FromV8(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "content/public/browser/permission_type.h"
|
||||||
#include "content/public/common/menu_item.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 "content/public/common/stop_find_action.h"
|
||||||
#include "native_mate/converter.h"
|
#include "native_mate/converter.h"
|
||||||
|
|
||||||
|
@ -33,6 +35,18 @@ struct Converter<ContextMenuParamsWithWebContents> {
|
||||||
const ContextMenuParamsWithWebContents& val);
|
const ContextMenuParamsWithWebContents& val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Converter<content::PermissionStatus> {
|
||||||
|
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||||
|
content::PermissionStatus* out);
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Converter<content::PermissionType> {
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
const content::PermissionType& val);
|
||||||
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Converter<content::StopFindAction> {
|
struct Converter<content::StopFindAction> {
|
||||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||||
|
|
|
@ -67,10 +67,10 @@ module.exports = {
|
||||||
var args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
|
var args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
|
||||||
if (eventName === 'permission-request') {
|
if (eventName === 'permission-request') {
|
||||||
var allow = function allow() {
|
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() {
|
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]);
|
args = args.concat([allow, deny]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,6 +144,8 @@
|
||||||
'atom/browser/atom_browser_main_parts_posix.cc',
|
'atom/browser/atom_browser_main_parts_posix.cc',
|
||||||
'atom/browser/atom_javascript_dialog_manager.cc',
|
'atom/browser/atom_javascript_dialog_manager.cc',
|
||||||
'atom/browser/atom_javascript_dialog_manager.h',
|
'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.cc',
|
||||||
'atom/browser/atom_quota_permission_context.h',
|
'atom/browser/atom_quota_permission_context.h',
|
||||||
'atom/browser/atom_resource_dispatcher_host_delegate.cc',
|
'atom/browser/atom_resource_dispatcher_host_delegate.cc',
|
||||||
|
|
Loading…
Reference in a new issue