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

Side by Side Diff: extensions/renderer/resources/web_view_events.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 // Event management for WebViewInternal. 5 // Event management for WebViewInternal.
6 6
7 var DeclarativeWebRequestSchema =
8 requireNative('schema_registry').GetSchema('declarativeWebRequest');
9 var EventBindings = require('event_bindings'); 7 var EventBindings = require('event_bindings');
10 var IdGenerator = requireNative('id_generator');
11 var MessagingNatives = requireNative('messaging_natives'); 8 var MessagingNatives = requireNative('messaging_natives');
12 var WebRequestEvent = require('webRequestInternal').WebRequestEvent;
13 var WebRequestSchema =
14 requireNative('schema_registry').GetSchema('webRequest');
15 var WebView = require('webViewInternal').WebView; 9 var WebView = require('webViewInternal').WebView;
16 10
17 var CreateEvent = function(name) { 11 var CreateEvent = function(name) {
18 var eventOpts = {supportsListeners: true, supportsFilters: true}; 12 var eventOpts = {supportsListeners: true, supportsFilters: true};
19 return new EventBindings.Event(name, undefined, eventOpts); 13 return new EventBindings.Event(name, undefined, eventOpts);
20 }; 14 };
21 15
22 var FrameNameChangedEvent = CreateEvent('webViewInternal.onFrameNameChanged'); 16 var FrameNameChangedEvent = CreateEvent('webViewInternal.onFrameNameChanged');
23 var PluginDestroyedEvent = CreateEvent('webViewInternal.onPluginDestroyed'); 17 var PluginDestroyedEvent = CreateEvent('webViewInternal.onPluginDestroyed');
24 var WebRequestMessageEvent = CreateEvent('webViewInternal.onMessage');
25 18
26 // WEB_VIEW_EVENTS is a map of stable <webview> DOM event names to their 19 // WEB_VIEW_EVENTS is a map of stable <webview> DOM event names to their
27 // associated extension event descriptor objects. 20 // associated extension event descriptor objects.
28 // An event listener will be attached to the extension event |evt| specified in 21 // An event listener will be attached to the extension event |evt| specified in
29 // the descriptor. 22 // the descriptor.
30 // |fields| specifies the public-facing fields in the DOM event that are 23 // |fields| specifies the public-facing fields in the DOM event that are
31 // accessible to <webview> developers. 24 // accessible to <webview> developers.
32 // |customHandler| allows a handler function to be called each time an extension 25 // |customHandler| allows a handler function to be called each time an extension
33 // event is caught by its event listener. The DOM event should be dispatched 26 // event is caught by its event listener. The DOM event should be dispatched
34 // within this handler function. With no handler function, the DOM event 27 // within this handler function. With no handler function, the DOM event
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 'unresponsive': { 141 'unresponsive': {
149 evt: CreateEvent('webViewInternal.onUnresponsive'), 142 evt: CreateEvent('webViewInternal.onUnresponsive'),
150 fields: ['processId'] 143 fields: ['processId']
151 }, 144 },
152 'zoomchange': { 145 'zoomchange': {
153 evt: CreateEvent('webViewInternal.onZoomChange'), 146 evt: CreateEvent('webViewInternal.onZoomChange'),
154 fields: ['oldZoomFactor', 'newZoomFactor'] 147 fields: ['oldZoomFactor', 'newZoomFactor']
155 } 148 }
156 }; 149 };
157 150
158 function DeclarativeWebRequestEvent(opt_eventName,
159 opt_argSchemas,
160 opt_eventOptions,
161 opt_webViewInstanceId) {
162 var subEventName = opt_eventName + '/' + IdGenerator.GetNextId();
163 EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions,
164 opt_webViewInstanceId);
165
166 // TODO(lazyboy): When do we dispose this listener?
167 WebRequestMessageEvent.addListener(function() {
168 // Re-dispatch to subEvent's listeners.
169 $Function.apply(this.dispatch, this, $Array.slice(arguments));
170 }.bind(this), {instanceId: opt_webViewInstanceId || 0});
171 }
172
173 DeclarativeWebRequestEvent.prototype = {
174 __proto__: EventBindings.Event.prototype
175 };
176
177 // Constructor. 151 // Constructor.
178 function WebViewEvents(webViewInternal, viewInstanceId) { 152 function WebViewEvents(webViewInternal, viewInstanceId) {
179 this.webViewInternal = webViewInternal; 153 this.webViewInternal = webViewInternal;
180 this.viewInstanceId = viewInstanceId; 154 this.viewInstanceId = viewInstanceId;
181 this.setup(); 155 this.setup();
182 } 156 }
183 157
184 // Sets up events. 158 // Sets up events.
185 WebViewEvents.prototype.setup = function() { 159 WebViewEvents.prototype.setup = function() {
186 this.setupFrameNameChangedEvent(); 160 this.setupFrameNameChangedEvent();
187 this.setupPluginDestroyedEvent(); 161 this.setupPluginDestroyedEvent();
188 this.setupWebRequestEvents(); 162 this.webViewInternal.maybeSetupChromeWebViewEvents();
189 this.webViewInternal.setupExperimentalContextMenus(); 163 this.webViewInternal.setupExperimentalContextMenus();
190 164
191 var events = this.getEvents(); 165 var events = this.getEvents();
192 for (var eventName in events) { 166 for (var eventName in events) {
193 this.setupEvent(eventName, events[eventName]); 167 this.setupEvent(eventName, events[eventName]);
194 } 168 }
195 }; 169 };
196 170
197 WebViewEvents.prototype.setupFrameNameChangedEvent = function() { 171 WebViewEvents.prototype.setupFrameNameChangedEvent = function() {
198 FrameNameChangedEvent.addListener(function(e) { 172 FrameNameChangedEvent.addListener(function(e) {
199 this.webViewInternal.onFrameNameChanged(e.name); 173 this.webViewInternal.onFrameNameChanged(e.name);
200 }.bind(this), {instanceId: this.viewInstanceId}); 174 }.bind(this), {instanceId: this.viewInstanceId});
201 }; 175 };
202 176
203 WebViewEvents.prototype.setupPluginDestroyedEvent = function() { 177 WebViewEvents.prototype.setupPluginDestroyedEvent = function() {
204 PluginDestroyedEvent.addListener(function(e) { 178 PluginDestroyedEvent.addListener(function(e) {
205 this.webViewInternal.onPluginDestroyed(); 179 this.webViewInternal.onPluginDestroyed();
206 }.bind(this), {instanceId: this.viewInstanceId}); 180 }.bind(this), {instanceId: this.viewInstanceId});
207 }; 181 };
208 182
209 WebViewEvents.prototype.setupWebRequestEvents = function() {
210 var request = {};
211 var createWebRequestEvent = function(webRequestEvent) {
212 return function() {
213 if (!this[webRequestEvent.name]) {
214 this[webRequestEvent.name] =
215 new WebRequestEvent(
216 'webViewInternal.' + webRequestEvent.name,
217 webRequestEvent.parameters,
218 webRequestEvent.extraParameters, webRequestEvent.options,
219 this.viewInstanceId);
220 }
221 return this[webRequestEvent.name];
222 }.bind(this);
223 }.bind(this);
224
225 var createDeclarativeWebRequestEvent = function(webRequestEvent) {
226 return function() {
227 if (!this[webRequestEvent.name]) {
228 // The onMessage event gets a special event type because we want
229 // the listener to fire only for messages targeted for this particular
230 // <webview>.
231 var EventClass = webRequestEvent.name === 'onMessage' ?
232 DeclarativeWebRequestEvent : EventBindings.Event;
233 this[webRequestEvent.name] =
234 new EventClass(
235 'webViewInternal.' + webRequestEvent.name,
236 webRequestEvent.parameters,
237 webRequestEvent.options,
238 this.viewInstanceId);
239 }
240 return this[webRequestEvent.name];
241 }.bind(this);
242 }.bind(this);
243
244 for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) {
245 var eventSchema = DeclarativeWebRequestSchema.events[i];
246 var webRequestEvent = createDeclarativeWebRequestEvent(eventSchema);
247 Object.defineProperty(
248 request,
249 eventSchema.name,
250 {
251 get: webRequestEvent,
252 enumerable: true
253 }
254 );
255 }
256
257 // Populate the WebRequest events from the API definition.
258 for (var i = 0; i < WebRequestSchema.events.length; ++i) {
259 var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]);
260 Object.defineProperty(
261 request,
262 WebRequestSchema.events[i].name,
263 {
264 get: webRequestEvent,
265 enumerable: true
266 }
267 );
268 }
269
270 this.webViewInternal.setRequestPropertyOnWebViewNode(request);
271 };
272
273 WebViewEvents.prototype.getEvents = function() { 183 WebViewEvents.prototype.getEvents = function() {
274 var experimentalEvents = this.webViewInternal.maybeGetExperimentalEvents(); 184 var experimentalEvents = this.webViewInternal.maybeGetExperimentalEvents();
275 for (var eventName in experimentalEvents) { 185 for (var eventName in experimentalEvents) {
276 WEB_VIEW_EVENTS[eventName] = experimentalEvents[eventName]; 186 WEB_VIEW_EVENTS[eventName] = experimentalEvents[eventName];
277 } 187 }
278 var chromeEvents = this.webViewInternal.maybeGetChromeWebViewEvents(); 188 var chromeEvents = this.webViewInternal.maybeGetChromeWebViewEvents();
279 for (var eventName in chromeEvents) { 189 for (var eventName in chromeEvents) {
280 WEB_VIEW_EVENTS[eventName] = chromeEvents[eventName]; 190 WEB_VIEW_EVENTS[eventName] = chromeEvents[eventName];
281 } 191 }
282 return WEB_VIEW_EVENTS; 192 return WEB_VIEW_EVENTS;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 } 523 }
614 }; 524 };
615 525
616 WebViewEvents.prototype.handleSizeChangedEvent = function( 526 WebViewEvents.prototype.handleSizeChangedEvent = function(
617 event, webViewEvent) { 527 event, webViewEvent) {
618 this.webViewInternal.onSizeChanged(webViewEvent); 528 this.webViewInternal.onSizeChanged(webViewEvent);
619 }; 529 };
620 530
621 exports.WebViewEvents = WebViewEvents; 531 exports.WebViewEvents = WebViewEvents;
622 exports.CreateEvent = CreateEvent; 532 exports.CreateEvent = CreateEvent;
OLDNEW
« no previous file with comments | « extensions/renderer/resources/web_view.js ('k') | extensions/renderer/resources/web_view_request_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698