| 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..17c2aed9cdbeca8ed2ad52b445970eefd2af201b 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,34 @@ WebViewInternal.prototype.setupWebRequestEvents = function() {
|
| };
|
| };
|
|
|
| + var createDeclarativeWebRequestEvent = function(webRequestEvent) {
|
| + return function() {
|
| + if (!self[webRequestEvent.name]) {
|
| + // The onMessage event gets a special event type.
|
| + var EventObj = webRequestEvent.name === 'onMessage' ?
|
| + DeclarativeWebRequestEvent : EventBindings.Event;
|
| + self[webRequestEvent.name] =
|
| + new EventObj(
|
| + '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,
|
| + eventSchema.name,
|
| + {
|
| + get: webRequestEvent,
|
| + enumerable: true
|
| + }
|
| + );
|
| }
|
|
|
| // Populate the WebRequest events from the API definition.
|
| @@ -1020,9 +1064,6 @@ WebViewInternal.prototype.setupWebRequestEvents = function() {
|
| enumerable: true
|
| }
|
| );
|
| - this.maybeAttachWebRequestEventToObject(this.webviewNode,
|
| - WebRequestSchema.events[i].name,
|
| - webRequestEvent);
|
| }
|
| Object.defineProperty(
|
| this.webviewNode,
|
| @@ -1221,12 +1262,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 [];
|
| };
|
|
|