]> khamidou — GitHub mirrors - electron.git/commitdiff
add spec
authorRobo <hop2deep@gmail.com>
Mon, 25 Jan 2016 16:37:15 +0000 (22:07 +0530)
committerRobo <hop2deep@gmail.com>
Fri, 29 Jan 2016 09:53:28 +0000 (15:23 +0530)
atom/browser/atom_browser_client.cc
atom/browser/atom_browser_client.h
atom/browser/lib/guest-view-manager.js
atom/browser/web_contents_permission_helper.cc
atom/browser/web_contents_permission_helper.h
atom/renderer/lib/web-view/web-view-attributes.js
docs/api/web-view-tag.md
spec/fixtures/pages/permission-request.html [new file with mode: 0644]
spec/webview-spec.js

index 49637f5342f066b139745844b1233ef151842faf..b395f3dd0cb56c85dc9f1f105cb1b543f4957f19 100644 (file)
@@ -282,18 +282,19 @@ brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
   return new AtomBrowserMainParts;
 }
 
-void AtomBrowserClient::WebNotificationAllowed(int render_process_id,
-                                               const base::Closure& callback) {
+void AtomBrowserClient::WebNotificationAllowed(
+    int render_process_id,
+    const base::Callback<void(bool)>& callback) {
   content::WebContents* web_contents = content::WebContents::FromRenderViewHost(
       content::RenderViewHost::FromID(render_process_id, kDefaultRoutingID));
   if (!web_contents) {
-    callback.Run();
+    callback.Run(true);
     return;
   }
   auto permission_helper =
       WebContentsPermissionHelper::FromWebContents(web_contents);
   if (!permission_helper) {
-    callback.Run();
+    callback.Run(true);
     return;
   }
   permission_helper->RequestWebNotificationPermission(callback);
index 9e0e979db881598b318f1fc69f3fb91b7cb65675..4af66cc041aeaa2b80a5875cc253fc68977402ec 100644 (file)
@@ -81,8 +81,9 @@ class AtomBrowserClient : public brightray::BrowserClient,
   // brightray::BrowserClient:
   brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
       const content::MainFunctionParams&) override;
-  void WebNotificationAllowed(int render_process_id,
-                              const base::Closure& callback) override;
+  void WebNotificationAllowed(
+      int render_process_id,
+      const base::Callback<void(bool)>& callback) override;
 
   // content::RenderProcessHostObserver:
   void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
index 233b1f1e4151e669dbbf9c71b91b8d95fd0c5c9c..b50d0c9503fe8f39aa589b403579a6768a51d3a9 100644 (file)
@@ -6,7 +6,39 @@ var slice = [].slice;
 // Doesn't exist in early initialization.
 var webViewManager = null;
 
-var supportedWebViewEvents = ['load-commit', 'did-finish-load', 'did-fail-load', 'did-frame-finish-load', 'did-start-loading', 'did-stop-loading', 'did-get-response-details', 'did-get-redirect-request', 'dom-ready', 'console-message', 'devtools-opened', 'devtools-closed', 'devtools-focused', 'new-window', 'will-navigate', 'did-navigate', 'did-navigate-in-page', 'close', 'crashed', 'gpu-crashed', 'plugin-crashed', 'destroyed', 'page-title-updated', 'page-favicon-updated', 'enter-html-full-screen', 'leave-html-full-screen', 'media-started-playing', 'media-paused', 'found-in-page', 'did-change-theme-color', 'permission-request'];
+var supportedWebViewEvents = [
+  'load-commit',
+  'did-finish-load',
+  'did-fail-load',
+  'did-frame-finish-load',
+  'did-start-loading',
+  'did-stop-loading',
+  'did-get-response-details',
+  'did-get-redirect-request',
+  'dom-ready',
+  'console-message',
+  'devtools-opened',
+  'devtools-closed',
+  'devtools-focused',
+  'new-window',
+  'will-navigate',
+  'did-navigate',
+  'did-navigate-in-page',
+  'close',
+  'crashed',
+  'gpu-crashed',
+  'plugin-crashed',
+  'destroyed',
+  'page-title-updated',
+  'page-favicon-updated',
+  'enter-html-full-screen',
+  'leave-html-full-screen',
+  'media-started-playing',
+  'media-paused',
+  'found-in-page',
+  'did-change-theme-color',
+  'permission-request'
+];
 
 var nextInstanceId = 0;
 var permissionRequests;
@@ -184,7 +216,7 @@ var destroyGuest = function(embedder, id) {
   webViewManager.removeGuest(embedder, id);
   guestInstances[id].guest.destroy();
   delete guestInstances[id];
-  delete permissionRequests[id];
+  delete guestPermissionRequestsMap[id];
   key = reverseEmbedderElementsMap[id];
   if (key != null) {
     delete reverseEmbedderElementsMap[id];
index 91ae60461770120c9a847b8a099ebae33f3d099c..5c82aa41df60526845d7396797af74775cc5804c 100644 (file)
@@ -28,7 +28,15 @@ const content::MediaStreamDevice* FindDeviceWithId(
 
 void MediaAccessAllowed(
     const content::MediaStreamRequest& request,
-    const content::MediaResponseCallback& callback) {
+    const content::MediaResponseCallback& callback,
+    bool allowed) {
+  if (!allowed) {
+    callback.Run(content::MediaStreamDevices(),
+                 content::MEDIA_DEVICE_PERMISSION_DENIED,
+                 scoped_ptr<content::MediaStreamUI>());
+    return;
+  }
+
   content::MediaStreamDevices devices;
   content::MediaStreamRequestResult result = content::MEDIA_DEVICE_NO_HARDWARE;
 
@@ -83,11 +91,11 @@ void WebContentsPermissionHelper::RequestMediaAccessPermission(
                    base::Unretained(this), permission));
     return;
   }
-  MediaAccessAllowed(request, callback);
+  MediaAccessAllowed(request, callback, true);
 }
 
 void WebContentsPermissionHelper::RequestWebNotificationPermission(
-    const base::Closure& callback) {
+    const base::Callback<void(bool)>& callback) {
   if (api_web_contents_->IsGuest()) {
     const std::string& permission = "webNotification";
     permission_map_[permission] = callback;
@@ -98,15 +106,14 @@ void WebContentsPermissionHelper::RequestWebNotificationPermission(
                    base::Unretained(this), permission));
     return;
   }
-  callback.Run();
+  callback.Run(true);
 }
 
 void WebContentsPermissionHelper::OnPermissionResponse(
     const std::string& permission, bool allowed) {
   auto it = permission_map_.find(permission);
   if (it != permission_map_.end()) {
-    if (allowed)
-      it->second.Run();
+    it->second.Run(allowed);
     permission_map_.erase(permission);
   }
 }
index 80e76fd685a3119a6ba7328e5be049b4acbd9ba5..4beac035c0247a2947769827de55c36c39a85b55 100644 (file)
@@ -29,14 +29,15 @@ class WebContentsPermissionHelper
   void RequestMediaAccessPermission(
       const content::MediaStreamRequest& request,
       const content::MediaResponseCallback& callback);
-  void RequestWebNotificationPermission(const base::Closure& callback);
+  void RequestWebNotificationPermission(
+      const base::Callback<void(bool)>& callback);
 
   void OnPermissionResponse(const std::string& permission, bool allowed);
 
  private:
   friend class content::WebContentsUserData<WebContentsPermissionHelper>;
 
-  std::map<std::string, base::Closure> permission_map_;
+  std::map<std::string, base::Callback<void(bool)>> permission_map_;
 
   api::WebContents* api_web_contents_;  // Weak reference
 
index 180924f5b569ed42fa998624665265af56724612..4ad4bd72501201e9affa456f50e8103e1c407d7e 100644 (file)
@@ -311,7 +311,6 @@ WebViewImpl.prototype.setupWebViewAttributes = function() {
   this.attributes[webViewConstants.ATTRIBUTE_ALLOWPOPUPS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_ALLOWPOPUPS, this);
   this.attributes[webViewConstants.ATTRIBUTE_PRELOAD] = new PreloadAttribute(this);
   this.attributes[webViewConstants.ATTRIBUTE_BLINKFEATURES] = new BlinkFeaturesAttribute(this);
-  this.attributes[webViewConstants.ATTRIBUTE_DISABLEWEBNOTIFICATION] = new BooleanAttribute(webViewConstants.ATTRIBUTE_DISABLEWEBNOTIFICATION, this);
   autosizeAttributes = [webViewConstants.ATTRIBUTE_MAXHEIGHT, webViewConstants.ATTRIBUTE_MAXWIDTH, webViewConstants.ATTRIBUTE_MINHEIGHT, webViewConstants.ATTRIBUTE_MINWIDTH];
   results = [];
   for (i = 0, len = autosizeAttributes.length; i < len; i++) {
index 630dbdc958576b0e782a3f58f110472046c2c593..67a3d12171ce9479fe79b9e82747b7e30ae99352 100644 (file)
@@ -167,14 +167,6 @@ A list of strings which specifies the blink features to be enabled separated by
 The full list of supported feature strings can be found in the
 [setFeatureEnabledFromString][blink-feature-string] function.
 
-### `disablewebnotification`
-
-```html
-<webview src="https://www.github.com/" disablewebnotification></webview>
-```
-
-If "on", the guest page will have web notifications disabled.
-
 ## Methods
 
 The `webview` tag has the following methods:
diff --git a/spec/fixtures/pages/permission-request.html b/spec/fixtures/pages/permission-request.html
new file mode 100644 (file)
index 0000000..0d968a9
--- /dev/null
@@ -0,0 +1,7 @@
+<script>
+  navigator.webkitGetUserMedia({ audio: true, video: true }, function(mediaStream) {
+
+  }, function(err) {
+    require('electron').ipcRenderer.sendToHost('message', err.name);
+  });
+</script>
index 0eaa59c5fd3c56d1675729f770af381931e694be..e40afcaefeb119cbff0c6a2037b07d6f18af32c4 100644 (file)
@@ -624,7 +624,7 @@ describe('<webview> tag', function() {
       return document.body.appendChild(webview);
     });
   });
-  return xdescribe('did-change-theme-color event', function() {
+  xdescribe('did-change-theme-color event', function() {
     return it('emits when theme color changes', function(done) {
       webview.addEventListener('did-change-theme-color', function() {
         return done();
@@ -633,4 +633,21 @@ describe('<webview> tag', function() {
       return document.body.appendChild(webview);
     });
   });
+  describe('permission-request event', function() {
+    it ('emits when using navigator.getUserMedia api', function(done) {
+      webview.addEventListener('ipc-message', function(e) {
+        assert(e.channel, 'message');
+        assert(e.args, ['PermissionDeniedError']);
+        done();
+      });
+      webview.addEventListener('permission-request', function(e) {
+        if (e.permission === 'media') {
+          e.deny();
+        }
+      });
+      webview.src = "file://" + fixtures + "/pages/permission-request.html";
+      webview.setAttribute('nodeintegration', 'on');
+      document.body.appendChild(webview);
+    });
+  });
 });