Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(998)

Side by Side Diff: chrome/renderer/resources/extensions/web_view_experimental.js

Issue 11093080: <webview>: First stab at implementing media permission request for guests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments from mpcomplete@ Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Shim extension to provide permission request API (and possibly other future
6 // experimental APIs) for <webview> tag.
7 // See web_view.js for details.
8 //
9 // We want to control the permission API feature in <webview> separately from
10 // the <webview> feature itself. <webview> is available in stable channel, but
11 // permission API would only be available for channels CHANNEL_DEV and
12 // CHANNEL_CANARY.
13
14 var WebView = require('webview').WebView;
15
16 /** @type {string} */
17 var REQUEST_TYPE_MEDIA = 'media';
18
19 /** @type {string} */
20 var ERROR_MSG_PERMISSION_ALREADY_DECIDED = '<webview>: ' +
21 'Permission has already been decided for this "permissionrequest" event';
Fady Samuel 2013/02/14 00:11:36 nit: Period at the end of the sentence.
lazyboy 2013/02/14 00:13:56 Done.
22
23 /**
24 * @param {!Object} detail The event details, originated from <object>.
25 * @private
26 */
27 WebView.prototype.maybeSetupPermissionEvent_ = function() {
28 var node = this.node_;
29 var objectNode = this.objectNode_;
30 this.objectNode_.addEventListener('-internal-permissionrequest', function(e) {
31 var evt = new Event('permissionrequest', {bubbles: true, cancelable: true});
32 var detail = e.detail ? JSON.parse(e.detail) : {};
33 ['permission', 'url'].forEach(function(attribName) {
34 evt[attribName] = detail[attribName];
35 });
36 var requestId = detail.requestId;
37
38 if (detail.permission == REQUEST_TYPE_MEDIA &&
39 detail.requestId !== undefined) {
40 // TODO(lazyboy): Also fill in evt.details (see webview specs).
41 // http://crbug.com/141197.
42 var decisionMade = false;
43 // Construct the event.request object.
44 var request = {
45 allow: function() {
46 if (decisionMade) {
47 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED);
48 } else {
49 objectNode['-internal-setPermission'](requestId, true);
50 decisionMade = true;
51 }
52 },
53 deny: function() {
54 if (decisionMade) {
55 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED);
56 } else {
57 objectNode['-internal-setPermission'](requestId, false);
58 decisionMade = true;
59 }
60 }
61 };
62 evt.request = request;
63
64 // Make browser plugin track lifetime of |request|.
65 objectNode['-internal-persistObject'](
66 request, REQUEST_TYPE_MEDIA, requestId);
67
68 var defaultPrevented = !node.dispatchEvent(evt);
69 if (!decisionMade && !defaultPrevented) {
70 decisionMade = true;
71 objectNode['-internal-setPermission'](requestId, false);
72 }
73 }
74 });
75 };
76
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/web_view.js ('k') | chrome/renderer/resources/renderer_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698