| Index: extensions/renderer/resources/web_view_events.js
|
| diff --git a/extensions/renderer/resources/web_view_events.js b/extensions/renderer/resources/web_view_events.js
|
| index 13af04c544f941750f79072dc6a8aae9e00f29d6..f02069bd52bbde4b6ac1e40f92ea9ce26f3fdc5e 100644
|
| --- a/extensions/renderer/resources/web_view_events.js
|
| +++ b/extensions/renderer/resources/web_view_events.js
|
| @@ -4,8 +4,14 @@
|
|
|
| // Event management for WebViewInternal.
|
|
|
| +var DeclarativeWebRequestSchema =
|
| + requireNative('schema_registry').GetSchema('declarativeWebRequest');
|
| var EventBindings = require('event_bindings');
|
| +var IdGenerator = requireNative('id_generator');
|
| var MessagingNatives = requireNative('messaging_natives');
|
| +var WebRequestEvent = require('webRequestInternal').WebRequestEvent;
|
| +var WebRequestSchema =
|
| + requireNative('schema_registry').GetSchema('webRequest');
|
| var WebView = require('webViewInternal').WebView;
|
|
|
| var CreateEvent = function(name) {
|
| @@ -15,6 +21,7 @@ var CreateEvent = function(name) {
|
|
|
| var FrameNameChangedEvent = CreateEvent('webViewInternal.onFrameNameChanged');
|
| var PluginDestroyedEvent = CreateEvent('webViewInternal.onPluginDestroyed');
|
| +var WebRequestMessageEvent = CreateEvent('webViewInternal.onMessage');
|
|
|
| // WEB_VIEW_EVENTS is a map of stable <webview> DOM event names to their
|
| // associated extension event descriptor objects.
|
| @@ -148,6 +155,25 @@ var WEB_VIEW_EVENTS = {
|
| }
|
| };
|
|
|
| +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);
|
| +
|
| + // 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
|
| +};
|
| +
|
| // Constructor.
|
| function WebViewEvents(webViewInternal, viewInstanceId) {
|
| this.webViewInternal = webViewInternal;
|
| @@ -159,7 +185,7 @@ function WebViewEvents(webViewInternal, viewInstanceId) {
|
| WebViewEvents.prototype.setup = function() {
|
| this.setupFrameNameChangedEvent();
|
| this.setupPluginDestroyedEvent();
|
| - this.webViewInternal.maybeSetupChromeWebViewEvents();
|
| + this.setupWebRequestEvents();
|
| this.webViewInternal.setupExperimentalContextMenus();
|
|
|
| var events = this.getEvents();
|
| @@ -180,6 +206,70 @@ WebViewEvents.prototype.setupPluginDestroyedEvent = function() {
|
| }.bind(this), {instanceId: this.viewInstanceId});
|
| };
|
|
|
| +WebViewEvents.prototype.setupWebRequestEvents = 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.webViewInternal.setRequestPropertyOnWebViewNode(request);
|
| +};
|
| +
|
| WebViewEvents.prototype.getEvents = function() {
|
| var experimentalEvents = this.webViewInternal.maybeGetExperimentalEvents();
|
| for (var eventName in experimentalEvents) {
|
|
|