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/chrome_web_view.js

Issue 620623002: Revert "Allow declarative webrequest and webrequest in extensions." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // This module implements chrome-specific <webview> API. 5 // This module implements chrome-specific <webview> API.
6 6
7 var ChromeWebView = require('chromeWebViewInternal').ChromeWebView; 7 var ChromeWebView = require('chromeWebViewInternal').ChromeWebView;
8 var CreateEvent = require('webViewEvents').CreateEvent; 8 var CreateEvent = require('webViewEvents').CreateEvent;
9 var DeclarativeWebRequestSchema =
10 requireNative('schema_registry').GetSchema('declarativeWebRequest');
9 var EventBindings = require('event_bindings'); 11 var EventBindings = require('event_bindings');
12 var IdGenerator = requireNative('id_generator');
13 var WebRequestEvent = require('webRequestInternal').WebRequestEvent;
14 var WebRequestSchema =
15 requireNative('schema_registry').GetSchema('webRequest');
10 var WebViewInternal = require('webView').WebViewInternal 16 var WebViewInternal = require('webView').WebViewInternal
11 17
18 var WebRequestMessageEvent = CreateEvent('webViewInternal.onMessage');
19
12 var CHROME_WEB_VIEW_EVENTS = { 20 var CHROME_WEB_VIEW_EVENTS = {
13 'contextmenu': { 21 'contextmenu': {
14 evt: CreateEvent('chromeWebViewInternal.contextmenu'), 22 evt: CreateEvent('chromeWebViewInternal.contextmenu'),
15 cancelable: true, 23 cancelable: true,
16 customHandler: function(handler, event, webViewEvent) { 24 customHandler: function(handler, event, webViewEvent) {
17 handler.webViewInternal.maybeHandleContextMenu(event, webViewEvent); 25 handler.webViewInternal.maybeHandleContextMenu(event, webViewEvent);
18 }, 26 },
19 fields: ['items'] 27 fields: ['items']
20 } 28 }
21 }; 29 };
22 30
31 function DeclarativeWebRequestEvent(opt_eventName,
32 opt_argSchemas,
33 opt_eventOptions,
34 opt_webViewInstanceId) {
35 var subEventName = opt_eventName + '/' + IdGenerator.GetNextId();
36 EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions,
37 opt_webViewInstanceId);
38
39 // TODO(lazyboy): When do we dispose this listener?
40 WebRequestMessageEvent.addListener(function() {
41 // Re-dispatch to subEvent's listeners.
42 $Function.apply(this.dispatch, this, $Array.slice(arguments));
43 }.bind(this), {instanceId: opt_webViewInstanceId || 0});
44 }
45
46 DeclarativeWebRequestEvent.prototype = {
47 __proto__: EventBindings.Event.prototype
48 };
49
23 /** 50 /**
24 * Implemented when the ChromeWebView API is available. 51 * Implemented when the ChromeWebView API is available.
25 * @private 52 * @private
26 */ 53 */
27 WebViewInternal.prototype.maybeGetChromeWebViewEvents = function() { 54 WebViewInternal.prototype.maybeGetChromeWebViewEvents = function() {
28 return CHROME_WEB_VIEW_EVENTS; 55 return CHROME_WEB_VIEW_EVENTS;
29 }; 56 };
30 57
31 /** 58 /**
32 * Calls to show contextmenu right away instead of dispatching a 'contextmenu' 59 * Calls to show contextmenu right away instead of dispatching a 'contextmenu'
33 * event. 60 * event.
34 * This will be overridden in chrome_web_view_experimental.js to implement 61 * This will be overridden in chrome_web_view_experimental.js to implement
35 * contextmenu API. 62 * contextmenu API.
36 */ 63 */
37 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { 64 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) {
38 var requestId = e.requestId; 65 var requestId = e.requestId;
39 // Setting |params| = undefined will show the context menu unmodified, hence 66 // Setting |params| = undefined will show the context menu unmodified, hence
40 // the 'contextmenu' API is disabled for stable channel. 67 // the 'contextmenu' API is disabled for stable channel.
41 var params = undefined; 68 var params = undefined;
42 ChromeWebView.showContextMenu(this.guestInstanceId, requestId, params); 69 ChromeWebView.showContextMenu(this.guestInstanceId, requestId, params);
43 }; 70 };
71
72 WebViewInternal.prototype.maybeSetupChromeWebViewEvents = function() {
73 var request = {};
74 var createWebRequestEvent = function(webRequestEvent) {
75 return function() {
76 if (!this[webRequestEvent.name]) {
77 this[webRequestEvent.name] =
78 new WebRequestEvent(
79 'webViewInternal.' + webRequestEvent.name,
80 webRequestEvent.parameters,
81 webRequestEvent.extraParameters, webRequestEvent.options,
82 this.viewInstanceId);
83 }
84 return this[webRequestEvent.name];
85 }.bind(this);
86 }.bind(this);
87
88 var createDeclarativeWebRequestEvent = function(webRequestEvent) {
89 return function() {
90 if (!this[webRequestEvent.name]) {
91 // The onMessage event gets a special event type because we want
92 // the listener to fire only for messages targeted for this particular
93 // <webview>.
94 var EventClass = webRequestEvent.name === 'onMessage' ?
95 DeclarativeWebRequestEvent : EventBindings.Event;
96 this[webRequestEvent.name] =
97 new EventClass(
98 'webViewInternal.' + webRequestEvent.name,
99 webRequestEvent.parameters,
100 webRequestEvent.options,
101 this.viewInstanceId);
102 }
103 return this[webRequestEvent.name];
104 }.bind(this);
105 }.bind(this);
106
107 for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) {
108 var eventSchema = DeclarativeWebRequestSchema.events[i];
109 var webRequestEvent = createDeclarativeWebRequestEvent(eventSchema);
110 Object.defineProperty(
111 request,
112 eventSchema.name,
113 {
114 get: webRequestEvent,
115 enumerable: true
116 }
117 );
118 }
119
120 // Populate the WebRequest events from the API definition.
121 for (var i = 0; i < WebRequestSchema.events.length; ++i) {
122 var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]);
123 Object.defineProperty(
124 request,
125 WebRequestSchema.events[i].name,
126 {
127 get: webRequestEvent,
128 enumerable: true
129 }
130 );
131 }
132
133 this.setRequestPropertyOnWebViewNode(request);
134 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698