From b575cd0ef936531b178408eef628fc3033e57cd4 Mon Sep 17 00:00:00 2001 From: Robo Date: Mon, 1 Feb 2016 15:33:38 +0530 Subject: [PATCH] add fullscreen permission type --- atom/browser/api/atom_api_web_contents.cc | 12 ++++++++++++ atom/browser/api/atom_api_web_contents.h | 5 +++++ atom/browser/web_contents_permission_helper.cc | 6 ++++++ atom/browser/web_contents_permission_helper.h | 2 ++ docs/api/session.md | 8 ++++---- spec/webview-spec.js | 2 +- 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 67af2022dbc..d26a3593cb0 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -390,6 +390,18 @@ void WebContents::HandleKeyboardEvent( void WebContents::EnterFullscreenModeForTab(content::WebContents* source, const GURL& origin) { + auto permission_helper = + WebContentsPermissionHelper::FromWebContents(source); + auto callback = base::Bind(&WebContents::OnEnterFullscreenModeForTab, + base::Unretained(this), source, origin); + permission_helper->RequestFullscreenPermission(callback); +} + +void WebContents::OnEnterFullscreenModeForTab(content::WebContents* source, + const GURL& origin, + bool allowed) { + if (!allowed) + return; CommonWebContentsDelegate::EnterFullscreenModeForTab(source, origin); Emit("enter-html-full-screen"); } diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index cd6d0e7b608..3e31d26efdf 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -133,6 +133,11 @@ class WebContents : public mate::TrackableObject, void SetAllowTransparency(bool allow); bool IsGuest() const; + // Callback triggered on permission response. + void OnEnterFullscreenModeForTab(content::WebContents* source, + const GURL& origin, + bool allowed); + // Returns the web preferences of current WebContents. v8::Local GetWebPreferences(v8::Isolate* isolate); diff --git a/atom/browser/web_contents_permission_helper.cc b/atom/browser/web_contents_permission_helper.cc index 6b017aa1342..6cade6aa352 100644 --- a/atom/browser/web_contents_permission_helper.cc +++ b/atom/browser/web_contents_permission_helper.cc @@ -102,6 +102,12 @@ void WebContentsPermissionHelper::RequestPermission( base::Bind(&OnPermissionResponse, callback)); } +void WebContentsPermissionHelper::RequestFullscreenPermission( + const base::Callback& callback) { + RequestPermission((content::PermissionType)(PermissionType::FULLSCREEN), + callback); +} + void WebContentsPermissionHelper::RequestMediaAccessPermission( const content::MediaStreamRequest& request, const content::MediaResponseCallback& response_callback) { diff --git a/atom/browser/web_contents_permission_helper.h b/atom/browser/web_contents_permission_helper.h index 68682340ceb..90ae6dff56f 100644 --- a/atom/browser/web_contents_permission_helper.h +++ b/atom/browser/web_contents_permission_helper.h @@ -22,6 +22,8 @@ class WebContentsPermissionHelper FULLSCREEN }; + void RequestFullscreenPermission( + const base::Callback& callback); void RequestMediaAccessPermission( const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback); diff --git a/docs/api/session.md b/docs/api/session.md index c70be61de89..724dab390d2 100644 --- a/docs/api/session.md +++ b/docs/api/session.md @@ -293,22 +293,22 @@ myWindow.webContents.session.setCertificateVerifyProc(function(hostname, cert, c * `handler` Function * `webContents` Object - [WebContents](web-contents.md) requesting the permission. - * `permission` String - Enum of 'media', 'geolocation', 'notifications', 'midiSysex'. + * `permission` String - Enum of 'media', 'geolocation', 'notifications', 'midiSysex', 'pointerLock', 'fullscreen'. * `callback` Function - Allow or deny the permission. Sets the handler which can be used to respond to permission requests for the `session`. -Calling `callback('granted')` will allow the permission and `callback('denied')` will reject it. +Calling `callback(true)` will allow the permission and `callback(false)` will reject it. ```javascript session.fromPartition(partition).setPermissionRequestHandler(function(webContents, permission, callback) { if (webContents.getURL() === host) { if (permission == "notifications") { - callback(); // denied. + callback(false); // denied. return; } } - callback('granted'); + callback(true); }); ``` diff --git a/spec/webview-spec.js b/spec/webview-spec.js index 6a386604676..cac5fb56b44 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -639,7 +639,7 @@ describe(' tag', function() { var listener = function(webContents, permission, callback) { if (webContents.getId() === webview.getId() ) { assert.equal(permission, requested_permission); - callback("denied"); + callback(false); } }; session.fromPartition(webview.partition).setPermissionRequestHandler(listener);