add spec
This commit is contained in:
parent
85e13333c3
commit
f32bf08eb3
9 changed files with 83 additions and 26 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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:
|
||||
|
|
7
spec/fixtures/pages/permission-request.html
vendored
Normal file
7
spec/fixtures/pages/permission-request.html
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<script>
|
||||
navigator.webkitGetUserMedia({ audio: true, video: true }, function(mediaStream) {
|
||||
|
||||
}, function(err) {
|
||||
require('electron').ipcRenderer.sendToHost('message', err.name);
|
||||
});
|
||||
</script>
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue