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

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

Issue 12189018: <webview>: Implement WebRequest API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT + cleanup Created 7 years, 7 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 extension to provide permission request API (and possibly other future 5 // Shim extension to provide permission request API (and possibly other future
6 // experimental APIs) for <webview> tag. 6 // experimental APIs) for <webview> tag.
7 // See web_view.js for details. 7 // See web_view.js for details.
8 // 8 //
9 // We want to control the permission API feature in <webview> separately from 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 10 // the <webview> feature itself. <webview> is available in stable channel, but
11 // permission API would only be available for channels CHANNEL_DEV and 11 // permission API would only be available for channels CHANNEL_DEV and
12 // CHANNEL_CANARY. 12 // CHANNEL_CANARY.
13 13
14 var WebView = require('webView').WebView; 14 var WebView = require('webView').WebView;
15 15 var GetExtensionAPIDefinitions =
16 requireNative('apiDefinitions').GetExtensionAPIDefinitions;
17 var WebRequestEvent = require('webRequest').WebRequestEvent;
16 var forEach = require('utils').forEach; 18 var forEach = require('utils').forEach;
17 19
18 /** @type {Array.<string>} */ 20 /** @type {Array.<string>} */
19 var PERMISSION_TYPES = ['download', 'media', 'geolocation', 'pointerLock']; 21 var PERMISSION_TYPES = ['download', 'media', 'geolocation', 'pointerLock'];
20 22
21 /** @type {string} */ 23 /** @type {string} */
22 var REQUEST_TYPE_NEW_WINDOW = 'newwindow'; 24 var REQUEST_TYPE_NEW_WINDOW = 'newwindow';
23 25
24 /** @type {string} */ 26 /** @type {string} */
25 var ERROR_MSG_PERMISSION_ALREADY_DECIDED = '<webview>: ' + 27 var ERROR_MSG_PERMISSION_ALREADY_DECIDED = '<webview>: ' +
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 objectNode['-internal-persistObject']( 180 objectNode['-internal-persistObject'](
179 window, detail.permission, requestId); 181 window, detail.permission, requestId);
180 182
181 var defaultPrevented = !node.dispatchEvent(evt); 183 var defaultPrevented = !node.dispatchEvent(evt);
182 if (!actionTaken && !defaultPrevented) { 184 if (!actionTaken && !defaultPrevented) {
183 actionTaken = true; 185 actionTaken = true;
184 // The default action is to discard the window. 186 // The default action is to discard the window.
185 objectNode['-internal-setPermission'](requestId, false); 187 objectNode['-internal-setPermission'](requestId, false);
186 } 188 }
187 }); 189 });
190 }
191
192 /**
193 * @private
194 */
195 WebView.prototype.maybeSetupWebRequestEvents_ = function() {
196 var self = this;
197 // Populate the WebRequest events from the API definition.
198 var webRequestDefinition = GetExtensionAPIDefinitions().filter(function(api) {
199 return api.namespace == 'webRequest';
200 })[0];
201 for (var i = 0; i < webRequestDefinition.events.length; ++i) {
202 Object.defineProperty(self.node_, webRequestDefinition.events[i].name, {
203 get: function(webRequestEvent) {
204 return function() {
205 if (!self[webRequestEvent.name + '_']) {
206 self[webRequestEvent.name + '_'] =
207 new WebRequestEvent(
208 'webview.' + webRequestEvent.name,
209 webRequestEvent.parameters,
210 webRequestEvent.extraParameters, null,
211 self.objectNode_.getInstanceId());
212 }
213 return self[webRequestEvent.name + '_'];
214 }
215 }(webRequestDefinition.events[i]),
216 // No setter.
217 enumerable: true
218 });
219 }
188 }; 220 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698