Chromium Code Reviews| 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 // This module implements chrome-specific <webview> API. | 5 // This module implements chrome-specific <webview> API. |
| 6 | 6 |
| 7 var DeclarativeWebRequestSchema = | |
|
lazyboy
2014/09/12 17:03:57
Sort these.
lfg
2014/09/12 17:18:57
Done.
| |
| 8 requireNative('schema_registry').GetSchema('declarativeWebRequest'); | |
| 7 var ChromeWebView = require('chromeWebViewInternal').ChromeWebView; | 9 var ChromeWebView = require('chromeWebViewInternal').ChromeWebView; |
| 8 var CreateEvent = require('webViewEvents').CreateEvent; | 10 var CreateEvent = require('webViewEvents').CreateEvent; |
| 9 var EventBindings = require('event_bindings'); | 11 var EventBindings = require('event_bindings'); |
| 12 var IdGenerator = requireNative('id_generator'); | |
| 13 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; | |
| 14 var WebRequestSchema = | |
| 15 requireNative('schema_registry').GetSchema('webRequest'); | |
| 10 var WebViewInternal = require('webView').WebViewInternal | 16 var WebViewInternal = require('webView').WebViewInternal |
| 11 | 17 |
|
lazyboy
2014/09/12 17:03:57
nit: remove empty line.
lazyboy
2014/09/12 17:17:25
Wrong comment.
| |
| 18 var WebRequestMessageEvent = CreateEvent('webViewInternal.onMessage'); | |
| 19 | |
| 12 var CHROME_WEB_VIEW_EVENTS = { | 20 var CHROME_WEB_VIEW_EVENTS = { |
| 13 'contextmenu': { | 21 'contextmenu': { |
| 14 evt: CreateEvent('chromeWebViewInternal.contextmenu'), | 22 evt: CreateEvent('chromeWebViewInternal.contextmenu'), |
| 15 cancelable: true, | 23 cancelable: true, |
| 16 customHandler: function(handler, event, webViewEvent) { | 24 customHandler: function(handler, event, webViewEvent) { |
| 17 handler.webViewInternal.maybeHandleContextMenu(event, webViewEvent); | 25 handler.webViewInternal.maybeHandleContextMenu(event, webViewEvent); |
| 18 }, | 26 }, |
| 19 fields: ['items'] | 27 fields: ['items'] |
| 20 } | 28 } |
| 21 }; | 29 }; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 34 * This will be overridden in chrome_web_view_experimental.js to implement | 42 * This will be overridden in chrome_web_view_experimental.js to implement |
| 35 * contextmenu API. | 43 * contextmenu API. |
| 36 */ | 44 */ |
| 37 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { | 45 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { |
| 38 var requestId = e.requestId; | 46 var requestId = e.requestId; |
| 39 // Setting |params| = undefined will show the context menu unmodified, hence | 47 // Setting |params| = undefined will show the context menu unmodified, hence |
| 40 // the 'contextmenu' API is disabled for stable channel. | 48 // the 'contextmenu' API is disabled for stable channel. |
| 41 var params = undefined; | 49 var params = undefined; |
| 42 ChromeWebView.showContextMenu(this.guestInstanceId, requestId, params); | 50 ChromeWebView.showContextMenu(this.guestInstanceId, requestId, params); |
| 43 }; | 51 }; |
| 52 | |
| 53 function DeclarativeWebRequestEvent(opt_eventName, | |
|
lazyboy
2014/09/12 17:03:57
nit: move this and line 68 around to top block of
lfg
2014/09/12 17:18:57
Done.
| |
| 54 opt_argSchemas, | |
| 55 opt_eventOptions, | |
| 56 opt_webViewInstanceId) { | |
| 57 var subEventName = opt_eventName + '/' + IdGenerator.GetNextId(); | |
| 58 EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions, | |
| 59 opt_webViewInstanceId); | |
| 60 | |
| 61 // TODO(lazyboy): When do we dispose this listener? | |
| 62 WebRequestMessageEvent.addListener(function() { | |
| 63 // Re-dispatch to subEvent's listeners. | |
| 64 $Function.apply(this.dispatch, this, $Array.slice(arguments)); | |
| 65 }.bind(this), {instanceId: opt_webViewInstanceId || 0}); | |
| 66 } | |
| 67 | |
| 68 DeclarativeWebRequestEvent.prototype = { | |
| 69 __proto__: EventBindings.Event.prototype | |
| 70 }; | |
| 71 | |
| 72 WebViewInternal.prototype.maybeSetupChromeWebViewEvents = function() { | |
| 73 var request = {}; | |
| 74 var createWebRequestEvent = function(webRequestEvent) { | |
| 75 return function() { | |
| 76 if (!this[webRequestEvent.name]) { | |
| 77 this[webRequestEvent.name] = | |
| 78 new WebRequestEvent( | |
| 79 'webViewInternal.' + webRequestEvent.name, | |
| 80 webRequestEvent.parameters, | |
| 81 webRequestEvent.extraParameters, webRequestEvent.options, | |
| 82 this.viewInstanceId); | |
| 83 } | |
| 84 return this[webRequestEvent.name]; | |
| 85 }.bind(this); | |
| 86 }.bind(this); | |
| 87 | |
| 88 var createDeclarativeWebRequestEvent = function(webRequestEvent) { | |
| 89 return function() { | |
| 90 if (!this[webRequestEvent.name]) { | |
| 91 // The onMessage event gets a special event type because we want | |
| 92 // the listener to fire only for messages targeted for this particular | |
| 93 // <webview>. | |
| 94 var EventClass = webRequestEvent.name === 'onMessage' ? | |
| 95 DeclarativeWebRequestEvent : EventBindings.Event; | |
| 96 this[webRequestEvent.name] = | |
| 97 new EventClass( | |
| 98 'webViewInternal.' + webRequestEvent.name, | |
| 99 webRequestEvent.parameters, | |
| 100 webRequestEvent.options, | |
| 101 this.viewInstanceId); | |
| 102 } | |
| 103 return this[webRequestEvent.name]; | |
| 104 }.bind(this); | |
| 105 }.bind(this); | |
| 106 | |
| 107 for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) { | |
| 108 var eventSchema = DeclarativeWebRequestSchema.events[i]; | |
| 109 var webRequestEvent = createDeclarativeWebRequestEvent(eventSchema); | |
| 110 Object.defineProperty( | |
| 111 request, | |
| 112 eventSchema.name, | |
| 113 { | |
| 114 get: webRequestEvent, | |
| 115 enumerable: true | |
| 116 } | |
| 117 ); | |
| 118 } | |
| 119 | |
| 120 // Populate the WebRequest events from the API definition. | |
| 121 for (var i = 0; i < WebRequestSchema.events.length; ++i) { | |
| 122 var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]); | |
| 123 Object.defineProperty( | |
| 124 request, | |
| 125 WebRequestSchema.events[i].name, | |
| 126 { | |
| 127 get: webRequestEvent, | |
| 128 enumerable: true | |
| 129 } | |
| 130 ); | |
| 131 } | |
| 132 | |
| 133 this.setRequestPropertyOnWebViewNode(request); | |
| 134 }; | |
| OLD | NEW |