| Index: extensions/renderer/resources/guest_view/web_view/web_view_events.js
|
| diff --git a/extensions/renderer/resources/guest_view/web_view/web_view_events.js b/extensions/renderer/resources/guest_view/web_view/web_view_events.js
|
| index 5cf5036930301f8da8fb98b2b6bd936d315c32d4..b413af3f72cdbea9617958d51ff6fb9f836847c7 100644
|
| --- a/extensions/renderer/resources/guest_view/web_view/web_view_events.js
|
| +++ b/extensions/renderer/resources/guest_view/web_view/web_view_events.js
|
| @@ -7,7 +7,6 @@
|
| var CreateEvent = require('guestViewEvents').CreateEvent;
|
| var DeclarativeWebRequestSchema =
|
| requireNative('schema_registry').GetSchema('declarativeWebRequest');
|
| -var EventBindings = require('event_bindings');
|
| var GuestViewEvents = require('guestViewEvents').GuestViewEvents;
|
| var GuestViewInternalNatives = requireNative('guest_view_internal');
|
| var IdGenerator = requireNative('id_generator');
|
| @@ -26,6 +25,38 @@ function WebViewEvents(webViewImpl) {
|
| this.view.maybeSetupContextMenus();
|
| }
|
|
|
| +var jsEvent;
|
| +function createCustomDeclarativeEvent(name, schema, options, webviewId) {
|
| + if (bindingUtil) {
|
| + return bindingUtil.createCustomDeclarativeEvent(
|
| + name, options.actions, options.conditions, webviewId || 0);
|
| + }
|
| + if (!jsEvent)
|
| + jsEvent = require('event_bindings').Event;
|
| + return new jsEvent(name, schema, options, webviewId);
|
| +}
|
| +
|
| +function createOnMessageEvent(name, schema, options, webviewId) {
|
| + var subEventName = name + '/' + IdGenerator.GetNextId();
|
| + var newEvent = createCustomDeclarativeEvent(subEventName,
|
| + schema,
|
| + options,
|
| + webviewId);
|
| +
|
| + var view = GuestViewInternalNatives.GetViewFromID(webviewId || 0);
|
| + if (view) {
|
| + view.events.addScopedListener(
|
| + WebRequestMessageEvent,
|
| + $Function.bind(function() {
|
| + // Re-dispatch to subEvent's listeners.
|
| + $Function.apply(newEvent.dispatch, newEvent, $Array.slice(arguments));
|
| + }, newEvent),
|
| + {instanceId: webviewId || 0});
|
| + }
|
| +
|
| + return newEvent;
|
| +}
|
| +
|
| WebViewEvents.prototype.__proto__ = GuestViewEvents.prototype;
|
|
|
| // A dictionary of <webview> extension events to be listened for. This
|
| @@ -169,17 +200,25 @@ WebViewEvents.prototype.setupWebRequestEvents = function() {
|
| $Function.bind(function(webRequestEvent) {
|
| return this.weakWrapper(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.declarativeWebRequest.' + webRequestEvent.name,
|
| - webRequestEvent.parameters,
|
| - webRequestEvent.options,
|
| - this.view.viewInstanceId);
|
| + var newEvent;
|
| + var eventName =
|
| + 'webViewInternal.declarativeWebRequest.' + webRequestEvent.name;
|
| + if (webRequestEvent.name === 'onMessage') {
|
| + // The onMessage event gets a special event type because we want the
|
| + // listener to fire only for messages targeted for this particular
|
| + // <webview>.
|
| + newEvent = createOnMessageEvent(eventName,
|
| + webRequestEvent.parameters,
|
| + webRequestEvent.options,
|
| + this.view.viewInstanceId);
|
| + } else {
|
| + newEvent =
|
| + createCustomDeclarativeEvent(eventName,
|
| + webRequestEvent.parameters,
|
| + webRequestEvent.options,
|
| + this.view.viewInstanceId);
|
| + }
|
| + this[webRequestEvent.name] = newEvent;
|
| }
|
| return this[webRequestEvent.name];
|
| });
|
| @@ -275,30 +314,5 @@ WebViewEvents.prototype.handleSizeChangedEvent = function(event, eventName) {
|
| this.view.onSizeChanged(webViewEvent);
|
| };
|
|
|
| -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 view = GuestViewInternalNatives.GetViewFromID(opt_webViewInstanceId || 0);
|
| - if (!view) {
|
| - return;
|
| - }
|
| - view.events.addScopedListener(
|
| - WebRequestMessageEvent,
|
| - $Function.bind(function() {
|
| - // Re-dispatch to subEvent's listeners.
|
| - $Function.apply(this.dispatch, this, $Array.slice(arguments));
|
| - }, this), {instanceId: opt_webViewInstanceId || 0});
|
| -}
|
| -
|
| -DeclarativeWebRequestEvent.prototype.__proto__ = EventBindings.Event.prototype;
|
| -
|
| // Exports.
|
| exports.$set('WebViewEvents', WebViewEvents);
|
|
|