]> khamidou — GitHub mirrors - electron.git/commitdiff
add fullscreen permission type
authorRobo <hop2deep@gmail.com>
Mon, 1 Feb 2016 10:03:38 +0000 (15:33 +0530)
committerRobo <hop2deep@gmail.com>
Mon, 1 Feb 2016 10:52:05 +0000 (16:22 +0530)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/web_contents_permission_helper.cc
atom/browser/web_contents_permission_helper.h
docs/api/session.md
spec/webview-spec.js

index 67af2022dbc8d839cdfb8fa5d0a3b140a71a2074..d26a3593cb09623fcbfefa43cd323bb8a6fb24ab 100644 (file)
@@ -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");
 }
index cd6d0e7b60832fc422337bd51baf8786663c3aaa..3e31d26efdf1e62106ab41ae074f57cd7c91fea8 100644 (file)
@@ -133,6 +133,11 @@ class WebContents : public mate::TrackableObject<WebContents>,
   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<v8::Value> GetWebPreferences(v8::Isolate* isolate);
 
index 6b017aa1342e2d0ffadf0e9963a77902dcede1e6..6cade6aa3526906a920e584034e1462fbb80f7b3 100644 (file)
@@ -102,6 +102,12 @@ void WebContentsPermissionHelper::RequestPermission(
       base::Bind(&OnPermissionResponse, callback));
 }
 
+void WebContentsPermissionHelper::RequestFullscreenPermission(
+    const base::Callback<void(bool)>& callback) {
+  RequestPermission((content::PermissionType)(PermissionType::FULLSCREEN),
+                    callback);
+}
+
 void WebContentsPermissionHelper::RequestMediaAccessPermission(
     const content::MediaStreamRequest& request,
     const content::MediaResponseCallback& response_callback) {
index 68682340ceb69d9922d702ae09c588001a74609b..90ae6dff56f5249aeb880e52b6839f26017d474f 100644 (file)
@@ -22,6 +22,8 @@ class WebContentsPermissionHelper
     FULLSCREEN
   };
 
+  void RequestFullscreenPermission(
+      const base::Callback<void(bool)>& callback);
   void RequestMediaAccessPermission(
       const content::MediaStreamRequest& request,
       const content::MediaResponseCallback& callback);
index c70be61de8927e2d3a3fe65daac3e672c9998b4f..724dab390d2342e5b505a772189939b507be2060 100644 (file)
@@ -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);
 });
 ```
 
index 6a386604676484d8b7c7c6ad4a4037b019752609..cac5fb56b4441593ede86d0600716c5c02409515 100644 (file)
@@ -639,7 +639,7 @@ describe('<webview> 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);