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

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: Profile* => void* 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 console.warn('<webview>: A new window was blocked.'); 188 console.warn('<webview>: A new window was blocked.');
187 } 189 }
188 }); 190 });
191 }
192
193 /**
194 * @private
195 */
196 WebView.prototype.maybeSetupWebRequestEvents_ = function() {
197 var self = this;
198 // Populate the WebRequest events from the API definition.
199 var webRequestDefinition = GetExtensionAPIDefinitions().filter(function(api) {
200 return api.namespace == 'webRequest';
201 })[0];
202 for (var i = 0; i < webRequestDefinition.events.length; ++i) {
203 Object.defineProperty(self.node_, webRequestDefinition.events[i].name, {
204 get: function(webRequestEvent) {
205 return function() {
206 if (!self[webRequestEvent.name + '_']) {
207 self[webRequestEvent.name + '_'] =
208 new WebRequestEvent(
209 'webview.' + webRequestEvent.name,
210 webRequestEvent.parameters,
211 webRequestEvent.extraParameters, null,
212 self.objectNode_.getInstanceId());
213 }
214 return self[webRequestEvent.name + '_'];
215 }
216 }(webRequestDefinition.events[i]),
217 // No setter.
218 enumerable: true
219 });
220 }
189 }; 221 };
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/web_view.js ('k') | chrome/test/data/extensions/platform_apps/web_view/shim/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698