Chromium Code Reviews| Index: chrome/renderer/resources/extensions/chrome_web_view.js |
| diff --git a/chrome/renderer/resources/extensions/chrome_web_view.js b/chrome/renderer/resources/extensions/chrome_web_view.js |
| index badbf62d70f555c26dadceec38ba3d1b0c360a70..bf3ec707ffeb9df2f2d1344814ffc29d83c8d27c 100644 |
| --- a/chrome/renderer/resources/extensions/chrome_web_view.js |
| +++ b/chrome/renderer/resources/extensions/chrome_web_view.js |
| @@ -4,11 +4,19 @@ |
| // This module implements chrome-specific <webview> API. |
| +var DeclarativeWebRequestSchema = |
|
lazyboy
2014/09/12 17:03:57
Sort these.
lfg
2014/09/12 17:18:57
Done.
|
| + requireNative('schema_registry').GetSchema('declarativeWebRequest'); |
| var ChromeWebView = require('chromeWebViewInternal').ChromeWebView; |
| var CreateEvent = require('webViewEvents').CreateEvent; |
| var EventBindings = require('event_bindings'); |
| +var IdGenerator = requireNative('id_generator'); |
| +var WebRequestEvent = require('webRequestInternal').WebRequestEvent; |
| +var WebRequestSchema = |
| + requireNative('schema_registry').GetSchema('webRequest'); |
| var WebViewInternal = require('webView').WebViewInternal |
|
lazyboy
2014/09/12 17:03:57
nit: remove empty line.
lazyboy
2014/09/12 17:17:25
Wrong comment.
|
| +var WebRequestMessageEvent = CreateEvent('webViewInternal.onMessage'); |
| + |
| var CHROME_WEB_VIEW_EVENTS = { |
| 'contextmenu': { |
| evt: CreateEvent('chromeWebViewInternal.contextmenu'), |
| @@ -41,3 +49,86 @@ WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { |
| var params = undefined; |
| ChromeWebView.showContextMenu(this.guestInstanceId, requestId, params); |
| }; |
| + |
| +function DeclarativeWebRequestEvent(opt_eventName, |
|
lazyboy
2014/09/12 17:03:57
nit: move this and line 68 around to top block of
lfg
2014/09/12 17:18:57
Done.
|
| + opt_argSchemas, |
| + opt_eventOptions, |
| + opt_webViewInstanceId) { |
| + var subEventName = opt_eventName + '/' + IdGenerator.GetNextId(); |
| + EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions, |
| + opt_webViewInstanceId); |
| + |
| + // TODO(lazyboy): When do we dispose this listener? |
| + WebRequestMessageEvent.addListener(function() { |
| + // Re-dispatch to subEvent's listeners. |
| + $Function.apply(this.dispatch, this, $Array.slice(arguments)); |
| + }.bind(this), {instanceId: opt_webViewInstanceId || 0}); |
| +} |
| + |
| +DeclarativeWebRequestEvent.prototype = { |
| + __proto__: EventBindings.Event.prototype |
| +}; |
| + |
| +WebViewInternal.prototype.maybeSetupChromeWebViewEvents = function() { |
| + var request = {}; |
| + var createWebRequestEvent = function(webRequestEvent) { |
| + return function() { |
| + if (!this[webRequestEvent.name]) { |
| + this[webRequestEvent.name] = |
| + new WebRequestEvent( |
| + 'webViewInternal.' + webRequestEvent.name, |
| + webRequestEvent.parameters, |
| + webRequestEvent.extraParameters, webRequestEvent.options, |
| + this.viewInstanceId); |
| + } |
| + return this[webRequestEvent.name]; |
| + }.bind(this); |
| + }.bind(this); |
| + |
| + var createDeclarativeWebRequestEvent = function(webRequestEvent) { |
| + return function() { |
| + if (!this[webRequestEvent.name]) { |
| + // The onMessage event gets a special event type because we want |
| + // the listener to fire only for messages targeted for this particular |
| + // <webview>. |
| + var EventClass = webRequestEvent.name === 'onMessage' ? |
| + DeclarativeWebRequestEvent : EventBindings.Event; |
| + this[webRequestEvent.name] = |
| + new EventClass( |
| + 'webViewInternal.' + webRequestEvent.name, |
| + webRequestEvent.parameters, |
| + webRequestEvent.options, |
| + this.viewInstanceId); |
| + } |
| + return this[webRequestEvent.name]; |
| + }.bind(this); |
| + }.bind(this); |
| + |
| + for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) { |
| + var eventSchema = DeclarativeWebRequestSchema.events[i]; |
| + var webRequestEvent = createDeclarativeWebRequestEvent(eventSchema); |
| + Object.defineProperty( |
| + request, |
| + eventSchema.name, |
| + { |
| + get: webRequestEvent, |
| + enumerable: true |
| + } |
| + ); |
| + } |
| + |
| + // Populate the WebRequest events from the API definition. |
| + for (var i = 0; i < WebRequestSchema.events.length; ++i) { |
| + var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]); |
| + Object.defineProperty( |
| + request, |
| + WebRequestSchema.events[i].name, |
| + { |
| + get: webRequestEvent, |
| + enumerable: true |
| + } |
| + ); |
| + } |
| + |
| + this.setRequestPropertyOnWebViewNode(request); |
| +}; |