| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Event management for WebView. | 5 // Event management for WebView. |
| 6 | 6 |
| 7 var CreateEvent = require('guestViewEvents').CreateEvent; | 7 var CreateEvent = require('guestViewEvents').CreateEvent; |
| 8 var DeclarativeWebRequestSchema = | 8 var DeclarativeWebRequestSchema = |
| 9 requireNative('schema_registry').GetSchema('declarativeWebRequest'); | 9 requireNative('schema_registry').GetSchema('declarativeWebRequest'); |
| 10 var GuestViewEvents = require('guestViewEvents').GuestViewEvents; | 10 var GuestViewEvents = require('guestViewEvents').GuestViewEvents; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 function createCustomDeclarativeEvent(name, schema, options, webviewId) { | 29 function createCustomDeclarativeEvent(name, schema, options, webviewId) { |
| 30 if (bindingUtil) { | 30 if (bindingUtil) { |
| 31 return bindingUtil.createCustomDeclarativeEvent( | 31 return bindingUtil.createCustomDeclarativeEvent( |
| 32 name, options.actions, options.conditions, webviewId || 0); | 32 name, options.actions, options.conditions, webviewId || 0); |
| 33 } | 33 } |
| 34 if (!jsEvent) | 34 if (!jsEvent) |
| 35 jsEvent = require('event_bindings').Event; | 35 jsEvent = require('event_bindings').Event; |
| 36 return new jsEvent(name, schema, options, webviewId); | 36 return new jsEvent(name, schema, options, webviewId); |
| 37 } | 37 } |
| 38 | 38 |
| 39 function createCustomEvent(name, schema, options) { |
| 40 if (bindingUtil) |
| 41 return bindingUtil.createCustomEvent(name, undefined, false); |
| 42 if (!jsEvent) |
| 43 jsEvent = require('event_bindings').Event; |
| 44 return new jsEvent(name, schema, options); |
| 45 } |
| 46 |
| 39 function createOnMessageEvent(name, schema, options, webviewId) { | 47 function createOnMessageEvent(name, schema, options, webviewId) { |
| 40 var subEventName = name + '/' + IdGenerator.GetNextId(); | 48 var subEventName = name + '/' + IdGenerator.GetNextId(); |
| 41 var newEvent = createCustomDeclarativeEvent(subEventName, | 49 var newEvent = createCustomEvent(subEventName, schema, options); |
| 42 schema, | |
| 43 options, | |
| 44 webviewId); | |
| 45 | 50 |
| 46 var view = GuestViewInternalNatives.GetViewFromID(webviewId || 0); | 51 var view = GuestViewInternalNatives.GetViewFromID(webviewId || 0); |
| 47 if (view) { | 52 if (view) { |
| 48 view.events.addScopedListener( | 53 view.events.addScopedListener( |
| 49 WebRequestMessageEvent, | 54 WebRequestMessageEvent, |
| 50 $Function.bind(function() { | 55 $Function.bind(function() { |
| 51 // Re-dispatch to subEvent's listeners. | 56 // Re-dispatch to subEvent's listeners. |
| 52 $Function.apply(newEvent.dispatch, newEvent, $Array.slice(arguments)); | 57 $Function.apply(newEvent.dispatch, newEvent, $Array.slice(arguments)); |
| 53 }, newEvent), | 58 }, newEvent), |
| 54 {instanceId: webviewId || 0}); | 59 {instanceId: webviewId || 0}); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 314 } |
| 310 }; | 315 }; |
| 311 | 316 |
| 312 WebViewEvents.prototype.handleSizeChangedEvent = function(event, eventName) { | 317 WebViewEvents.prototype.handleSizeChangedEvent = function(event, eventName) { |
| 313 var webViewEvent = this.makeDomEvent(event, eventName); | 318 var webViewEvent = this.makeDomEvent(event, eventName); |
| 314 this.view.onSizeChanged(webViewEvent); | 319 this.view.onSizeChanged(webViewEvent); |
| 315 }; | 320 }; |
| 316 | 321 |
| 317 // Exports. | 322 // Exports. |
| 318 exports.$set('WebViewEvents', WebViewEvents); | 323 exports.$set('WebViewEvents', WebViewEvents); |
| OLD | NEW |