This commit is contained in:
Robo 2016-01-25 22:07:15 +05:30
parent 85e13333c3
commit f32bf08eb3
9 changed files with 83 additions and 26 deletions

View file

@ -282,18 +282,19 @@ brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
return new AtomBrowserMainParts; return new AtomBrowserMainParts;
} }
void AtomBrowserClient::WebNotificationAllowed(int render_process_id, void AtomBrowserClient::WebNotificationAllowed(
const base::Closure& callback) { int render_process_id,
const base::Callback<void(bool)>& callback) {
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(); callback.Run(true);
return; return;
} }
auto permission_helper = auto permission_helper =
WebContentsPermissionHelper::FromWebContents(web_contents); WebContentsPermissionHelper::FromWebContents(web_contents);
if (!permission_helper) { if (!permission_helper) {
callback.Run(); callback.Run(true);
return; return;
} }
permission_helper->RequestWebNotificationPermission(callback); permission_helper->RequestWebNotificationPermission(callback);

View file

@ -81,8 +81,9 @@ class AtomBrowserClient : public brightray::BrowserClient,
// brightray::BrowserClient: // brightray::BrowserClient:
brightray::BrowserMainParts* OverrideCreateBrowserMainParts( brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
const content::MainFunctionParams&) override; const content::MainFunctionParams&) override;
void WebNotificationAllowed(int render_process_id, void WebNotificationAllowed(
const base::Closure& callback) override; int render_process_id,
const base::Callback<void(bool)>& callback) override;
// content::RenderProcessHostObserver: // content::RenderProcessHostObserver:
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;

View file

@ -6,7 +6,39 @@ var slice = [].slice;
// Doesn't exist in early initialization. // Doesn't exist in early initialization.
var webViewManager = null; 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 nextInstanceId = 0;
var permissionRequests; var permissionRequests;
@ -184,7 +216,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 permissionRequests[id]; delete guestPermissionRequestsMap[id];
key = reverseEmbedderElementsMap[id]; key = reverseEmbedderElementsMap[id];
if (key != null) { if (key != null) {
delete reverseEmbedderElementsMap[id]; delete reverseEmbedderElementsMap[id];

View file

@ -28,7 +28,15 @@ const content::MediaStreamDevice* FindDeviceWithId(
void MediaAccessAllowed( void MediaAccessAllowed(
const content::MediaStreamRequest& request, 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::MediaStreamDevices devices;
content::MediaStreamRequestResult result = content::MEDIA_DEVICE_NO_HARDWARE; content::MediaStreamRequestResult result = content::MEDIA_DEVICE_NO_HARDWARE;
@ -83,11 +91,11 @@ void WebContentsPermissionHelper::RequestMediaAccessPermission(
base::Unretained(this), permission)); base::Unretained(this), permission));
return; return;
} }
MediaAccessAllowed(request, callback); MediaAccessAllowed(request, callback, true);
} }
void WebContentsPermissionHelper::RequestWebNotificationPermission( void WebContentsPermissionHelper::RequestWebNotificationPermission(
const base::Closure& callback) { const base::Callback<void(bool)>& callback) {
if (api_web_contents_->IsGuest()) { if (api_web_contents_->IsGuest()) {
const std::string& permission = "webNotification"; const std::string& permission = "webNotification";
permission_map_[permission] = callback; permission_map_[permission] = callback;
@ -98,15 +106,14 @@ void WebContentsPermissionHelper::RequestWebNotificationPermission(
base::Unretained(this), permission)); base::Unretained(this), permission));
return; return;
} }
callback.Run(); callback.Run(true);
} }
void WebContentsPermissionHelper::OnPermissionResponse( void WebContentsPermissionHelper::OnPermissionResponse(
const std::string& permission, bool allowed) { const std::string& permission, bool allowed) {
auto it = permission_map_.find(permission); auto it = permission_map_.find(permission);
if (it != permission_map_.end()) { if (it != permission_map_.end()) {
if (allowed) it->second.Run(allowed);
it->second.Run();
permission_map_.erase(permission); permission_map_.erase(permission);
} }
} }

View file

@ -29,14 +29,15 @@ class WebContentsPermissionHelper
void RequestMediaAccessPermission( void RequestMediaAccessPermission(
const content::MediaStreamRequest& request, const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback); 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); void OnPermissionResponse(const std::string& permission, bool allowed);
private: private:
friend class content::WebContentsUserData<WebContentsPermissionHelper>; 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 api::WebContents* api_web_contents_; // Weak reference

View file

@ -311,7 +311,6 @@ WebViewImpl.prototype.setupWebViewAttributes = function() {
this.attributes[webViewConstants.ATTRIBUTE_ALLOWPOPUPS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_ALLOWPOPUPS, this); this.attributes[webViewConstants.ATTRIBUTE_ALLOWPOPUPS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_ALLOWPOPUPS, this);
this.attributes[webViewConstants.ATTRIBUTE_PRELOAD] = new PreloadAttribute(this); this.attributes[webViewConstants.ATTRIBUTE_PRELOAD] = new PreloadAttribute(this);
this.attributes[webViewConstants.ATTRIBUTE_BLINKFEATURES] = new BlinkFeaturesAttribute(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]; autosizeAttributes = [webViewConstants.ATTRIBUTE_MAXHEIGHT, webViewConstants.ATTRIBUTE_MAXWIDTH, webViewConstants.ATTRIBUTE_MINHEIGHT, webViewConstants.ATTRIBUTE_MINWIDTH];
results = []; results = [];
for (i = 0, len = autosizeAttributes.length; i < len; i++) { for (i = 0, len = autosizeAttributes.length; i < len; i++) {

View 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 The full list of supported feature strings can be found in the
[setFeatureEnabledFromString][blink-feature-string] function. [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 ## Methods
The `webview` tag has the following methods: The `webview` tag has the following methods:

View file

@ -0,0 +1,7 @@
<script>
navigator.webkitGetUserMedia({ audio: true, video: true }, function(mediaStream) {
}, function(err) {
require('electron').ipcRenderer.sendToHost('message', err.name);
});
</script>

View file

@ -624,7 +624,7 @@ describe('<webview> tag', function() {
return document.body.appendChild(webview); 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) { return it('emits when theme color changes', function(done) {
webview.addEventListener('did-change-theme-color', function() { webview.addEventListener('did-change-theme-color', function() {
return done(); return done();
@ -633,4 +633,21 @@ describe('<webview> tag', function() {
return document.body.appendChild(webview); 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);
});
});
}); });