Chromium Code Reviews| Index: chrome/renderer/resources/extensions/web_view.js |
| diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js |
| index 77bc1a433ce395b36a6da4cb29b393cdc6999db8..f0578f7ae76c0d5be08fe63fa17a66c46c24723f 100644 |
| --- a/chrome/renderer/resources/extensions/web_view.js |
| +++ b/chrome/renderer/resources/extensions/web_view.js |
| @@ -981,6 +981,28 @@ WebViewInternal.prototype.handlePermissionEvent = |
| } |
| }; |
| +var WebRequestMessageEvent = CreateEvent('webview.onMessage'); |
| + |
| +function DeclarativeWebRequestEvent(opt_eventName, |
| + opt_argSchemas, |
| + opt_eventOptions, |
| + opt_webViewInstanceId) { |
| + var subEventName = opt_eventName + '/' + IdGenerator.GetNextId(); |
| + EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions, |
| + opt_webViewInstanceId); |
| + |
| + var self = this; |
| + // TODO(lazyboy): When do we dispose this listener? |
| + WebRequestMessageEvent.addListener(function() { |
| + // Re-dispatch to subEvent's listeners. |
| + $Function.apply(self.dispatch, self, $Array.slice(arguments)); |
| + }, {instanceId: opt_webViewInstanceId || 0}); |
| +} |
| + |
| +DeclarativeWebRequestEvent.prototype = { |
| + __proto__: EventBindings.Event.prototype |
| +}; |
| + |
| /** |
| * @private |
| */ |
| @@ -1001,12 +1023,36 @@ WebViewInternal.prototype.setupWebRequestEvents = function() { |
| }; |
| }; |
| + var createDeclarativeWebRequestEvent = function(webRequestEvent) { |
| + return function() { |
| + if (!self[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; |
| + self[webRequestEvent.name] = |
| + new EventClass( |
| + 'webview.' + webRequestEvent.name, |
| + webRequestEvent.parameters, |
| + webRequestEvent.options, |
| + self.viewInstanceId); |
| + } |
| + return self[webRequestEvent.name]; |
| + }; |
| + }; |
| + |
| for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) { |
| var eventSchema = DeclarativeWebRequestSchema.events[i]; |
| - var webRequestEvent = createWebRequestEvent(eventSchema); |
| - this.maybeAttachWebRequestEventToObject(request, |
| - eventSchema.name, |
| - webRequestEvent); |
| + var webRequestEvent = createDeclarativeWebRequestEvent(eventSchema); |
| + Object.defineProperty( |
| + request, |
|
lazyboy
2014/05/29 17:50:14
Doesn't this need to go to web_view_experimental?
Fady Samuel
2014/05/29 18:44:45
This will be used by products that will presumably
lazyboy
2014/05/29 19:01:40
Ok.
|
| + eventSchema.name, |
| + { |
| + get: webRequestEvent, |
| + enumerable: true |
| + } |
| + ); |
| } |
| // Populate the WebRequest events from the API definition. |
| @@ -1020,9 +1066,6 @@ WebViewInternal.prototype.setupWebRequestEvents = function() { |
| enumerable: true |
| } |
| ); |
| - this.maybeAttachWebRequestEventToObject(this.webviewNode, |
| - WebRequestSchema.events[i].name, |
| - webRequestEvent); |
| } |
| Object.defineProperty( |
| this.webviewNode, |
| @@ -1221,12 +1264,6 @@ WebViewInternal.prototype.maybeGetExperimentalEvents = function() {}; |
| * Implemented when the experimental API is available. |
| * @private |
| */ |
| -WebViewInternal.prototype.maybeAttachWebRequestEventToObject = function() {}; |
| - |
| -/** |
| - * Implemented when the experimental API is available. |
| - * @private |
| - */ |
| WebViewInternal.prototype.maybeGetExperimentalPermissions = function() { |
| return []; |
| }; |