This commit is contained in:
Robo 2016-01-30 19:01:10 +05:30
Родитель 2a278ceb8f
Коммит f7556de9fb
12 изменённых файлов: 61 добавлений и 10 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -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) {
}

Просмотреть файл

@ -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(

Просмотреть файл

@ -24,7 +24,9 @@ class AtomPermissionManager : public content::PermissionManager {
base::Callback<void(content::PermissionType,
const ResponseCallback&)>;
// Handler to dispatch permission requests in JS.
void SetPermissionRequestHandler(int id, const RequestHandler& handler);
void RequestPermission(
content::PermissionType permission,
content::RenderFrameHost* render_frame_host,

Просмотреть файл

@ -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;

Просмотреть файл

@ -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"

Просмотреть файл

@ -7,7 +7,6 @@
#include <vector>
#include "atom/common/native_mate_converters/callback.h"
#include "native_mate/converter.h"
namespace mate {

Просмотреть файл

@ -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.

5
spec/fixtures/pages/permissions/geolocation.html поставляемый Normal file
Просмотреть файл

@ -0,0 +1,5 @@
<script>
navigator.geolocation.getCurrentPosition(() => {}, (err) => {
require('electron').ipcRenderer.sendToHost('message', err.message);
});
</script>

Просмотреть файл

5
spec/fixtures/pages/permissions/midi.html поставляемый Normal file
Просмотреть файл

@ -0,0 +1,5 @@
<script>
navigator.requestMIDIAccess({sysex: true}).then(() => {}, (err) => {
require('electron').ipcRenderer.sendToHost('message', err.name);
});
</script>

Просмотреть файл

@ -645,7 +645,39 @@ describe('<webview> 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);
});