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

Side by Side Diff: chrome/renderer/resources/extensions/web_view.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: Reup patch, with new style event handling + fix tests. Created 8 years, 1 month 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Shim that simulates a <webview> tag via Mutation Observers. 5 // Shim that simulates a <webview> tag via Mutation Observers.
6 // 6 //
7 // The actual tag is implemented via the browser plugin. The internals of this 7 // The actual tag is implemented via the browser plugin. The internals of this
8 // are hidden via Shadow DOM. 8 // are hidden via Shadow DOM.
9 9
10 var WEB_VIEW_ATTRIBUTES = ['src']; 10 var WEB_VIEW_ATTRIBUTES = ['src'];
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 return objectNode[attributeName]; 116 return objectNode[attributeName];
117 }, 117 },
118 // No setter. 118 // No setter.
119 enumerable: true 119 enumerable: true
120 }) 120 })
121 }, this); 121 }, this);
122 122
123 for (var eventName in WEB_VIEW_EVENTS) { 123 for (var eventName in WEB_VIEW_EVENTS) {
124 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]); 124 this.setupEvent_(eventName, WEB_VIEW_EVENTS[eventName]);
125 } 125 }
126 this.setupPermissionRequestEvent_();
127 }
128
129 /**
130 * @private
131 */
132 WebView.prototype.setupPermissionRequestEvent_ = function(mutation) {
sadrul 2012/11/16 03:59:53 Can setupEvent_ be reused for this? setupEvent_ ca
lazyboy 2012/11/16 06:27:09 Yes that makes sense. Done.
133 var node = this.node_;
134 var objectNode = this.objectNode_;
135 this.objectNode_.addEventListener('-internal-permissionrequest', function(e) {
136 var detail = e.detail ? JSON.parse(e.detail) : {};
137 if (detail.reason == 'media') {
138 var request_id = detail.request_id;
139 if (request_id !== undefined) {
140 var evt = new Event('permissionrequest');
141 // TODO(lazyboy): Also fill in evt.url and evt.details (see webview
142 // specs).
143 evt.reason = detail.reason;
144 evt.allow = function() {
145 objectNode.setMediaPermission(request_id, true /* allow */);
146 };
147 evt.deny = function() {
148 objectNode.setMediaPermission(request_id, false /* allow */);
Fady Samuel 2012/11/16 03:42:59 This looks good. Looks like what we discussed.
149 }
150 node.dispatchEvent(evt);
151 }
152 }
153 });
126 }; 154 };
127 155
128 /** 156 /**
129 * @private 157 * @private
130 */ 158 */
131 WebView.prototype.handleMutation_ = function(mutation) { 159 WebView.prototype.handleMutation_ = function(mutation) {
132 switch (mutation.attributeName) { 160 switch (mutation.attributeName) {
133 case 'src': 161 case 'src':
134 // We need to set .src directly on the shadow element so that 162 // We need to set .src directly on the shadow element so that
135 // BrowserPluginBindings catches this as src attribute mutation. The 163 // BrowserPluginBindings catches this as src attribute mutation. The
(...skipping 22 matching lines...) Expand all
158 var node = this.node_; 186 var node = this.node_;
159 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { 187 this.objectNode_.addEventListener('-internal-' + eventname, function(e) {
160 var evt = new Event(eventname); 188 var evt = new Event(eventname);
161 var detail = e.detail ? JSON.parse(e.detail) : {}; 189 var detail = e.detail ? JSON.parse(e.detail) : {};
162 attribs.forEach(function(attribName) { 190 attribs.forEach(function(attribName) {
163 evt[attribName] = detail[attribName]; 191 evt[attribName] = detail[attribName];
164 }); 192 });
165 node.dispatchEvent(evt); 193 node.dispatchEvent(evt);
166 }); 194 });
167 } 195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698