OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 Webview (<webview>) as a custom element that wraps a | 5 // This module implements Webview (<webview>) as a custom element that wraps a |
6 // BrowserPlugin object element. The object element is hidden within | 6 // BrowserPlugin object element. The object element is hidden within |
7 // the shadow DOM of the Webview element. | 7 // the shadow DOM of the Webview element. |
8 | 8 |
9 var DocumentNatives = requireNative('document_natives'); | 9 var DocumentNatives = requireNative('document_natives'); |
10 var EventBindings = require('event_bindings'); | 10 var EventBindings = require('event_bindings'); |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
974 WebView.setPermission( | 974 WebView.setPermission( |
975 self.instanceId, requestId, 'default', '', function(allowed) { | 975 self.instanceId, requestId, 'default', '', function(allowed) { |
976 if (allowed) { | 976 if (allowed) { |
977 return; | 977 return; |
978 } | 978 } |
979 showWarningMessage(event.permission); | 979 showWarningMessage(event.permission); |
980 }); | 980 }); |
981 } | 981 } |
982 }; | 982 }; |
983 | 983 |
984 var WebRequestMessageEvent = CreateEvent('webview.onMessage'); | |
985 | |
986 function DeclarativeWebRequestEvent(opt_eventName, | |
987 opt_argSchemas, | |
988 opt_eventOptions, | |
989 opt_webViewInstanceId) { | |
990 var subEventName = opt_eventName + '/' + IdGenerator.GetNextId(); | |
991 EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions, | |
992 opt_webViewInstanceId); | |
993 | |
994 var self = this; | |
995 // TODO(lazyboy): When do we dispose this listener? | |
battre
2014/05/28 15:15:21
Isn't this taken care of by ExtensionWebRequestEve
Fady Samuel
2014/05/29 15:13:27
No. This is a very crude way to do cleanup. These
| |
996 WebRequestMessageEvent.addListener(function() { | |
997 // Re-dispatch to subEvent's listeners. | |
998 $Function.apply(self.dispatch, self, $Array.slice(arguments)); | |
999 }, {instanceId: opt_webViewInstanceId || 0}); | |
battre
2014/05/28 15:15:21
I am lacking the details here, but do you allow on
Fady Samuel
2014/05/29 15:13:27
No. Hence the filter by instance ID. Each webview
| |
1000 } | |
1001 | |
1002 DeclarativeWebRequestEvent.prototype = { | |
1003 __proto__: EventBindings.Event.prototype | |
1004 }; | |
1005 | |
984 /** | 1006 /** |
985 * @private | 1007 * @private |
986 */ | 1008 */ |
987 WebViewInternal.prototype.setupWebRequestEvents = function() { | 1009 WebViewInternal.prototype.setupWebRequestEvents = function() { |
988 var self = this; | 1010 var self = this; |
989 var request = {}; | 1011 var request = {}; |
990 var createWebRequestEvent = function(webRequestEvent) { | 1012 var createWebRequestEvent = function(webRequestEvent) { |
991 return function() { | 1013 return function() { |
992 if (!self[webRequestEvent.name]) { | 1014 if (!self[webRequestEvent.name]) { |
993 self[webRequestEvent.name] = | 1015 self[webRequestEvent.name] = |
994 new WebRequestEvent( | 1016 new WebRequestEvent( |
995 'webview.' + webRequestEvent.name, | 1017 'webview.' + webRequestEvent.name, |
996 webRequestEvent.parameters, | 1018 webRequestEvent.parameters, |
997 webRequestEvent.extraParameters, webRequestEvent.options, | 1019 webRequestEvent.extraParameters, webRequestEvent.options, |
998 self.viewInstanceId); | 1020 self.viewInstanceId); |
999 } | 1021 } |
1000 return self[webRequestEvent.name]; | 1022 return self[webRequestEvent.name]; |
1001 }; | 1023 }; |
1002 }; | 1024 }; |
1003 | 1025 |
1026 var createDeclarativeWebRequestEvent = function(webRequestEvent) { | |
1027 return function() { | |
1028 if (!self[webRequestEvent.name]) { | |
1029 // The onMessage event gets a special event type. | |
battre
2014/05/28 15:15:21
Document why?
Fady Samuel
2014/05/29 15:13:27
Done.
| |
1030 var EventObj = webRequestEvent.name === 'onMessage' ? | |
battre
2014/05/28 15:15:21
EventClass?
Fady Samuel
2014/05/29 15:13:27
Done.
| |
1031 DeclarativeWebRequestEvent : EventBindings.Event; | |
1032 self[webRequestEvent.name] = | |
1033 new EventObj( | |
1034 'webview.' + webRequestEvent.name, | |
1035 webRequestEvent.parameters, | |
1036 webRequestEvent.options, | |
1037 self.viewInstanceId); | |
1038 } | |
1039 return self[webRequestEvent.name]; | |
1040 }; | |
1041 }; | |
1042 | |
1004 for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) { | 1043 for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) { |
1005 var eventSchema = DeclarativeWebRequestSchema.events[i]; | 1044 var eventSchema = DeclarativeWebRequestSchema.events[i]; |
1006 var webRequestEvent = createWebRequestEvent(eventSchema); | 1045 var webRequestEvent = createDeclarativeWebRequestEvent(eventSchema); |
1007 this.maybeAttachWebRequestEventToObject(request, | 1046 Object.defineProperty( |
1008 eventSchema.name, | 1047 request, |
1009 webRequestEvent); | 1048 eventSchema.name, |
1049 { | |
1050 get: webRequestEvent, | |
1051 enumerable: true | |
1052 } | |
1053 ); | |
1010 } | 1054 } |
1011 | 1055 |
1012 // Populate the WebRequest events from the API definition. | 1056 // Populate the WebRequest events from the API definition. |
1013 for (var i = 0; i < WebRequestSchema.events.length; ++i) { | 1057 for (var i = 0; i < WebRequestSchema.events.length; ++i) { |
1014 var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]); | 1058 var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]); |
1015 Object.defineProperty( | 1059 Object.defineProperty( |
1016 request, | 1060 request, |
1017 WebRequestSchema.events[i].name, | 1061 WebRequestSchema.events[i].name, |
1018 { | 1062 { |
1019 get: webRequestEvent, | 1063 get: webRequestEvent, |
1020 enumerable: true | 1064 enumerable: true |
1021 } | 1065 } |
1022 ); | 1066 ); |
1023 this.maybeAttachWebRequestEventToObject(this.webviewNode, | |
1024 WebRequestSchema.events[i].name, | |
1025 webRequestEvent); | |
1026 } | 1067 } |
1027 Object.defineProperty( | 1068 Object.defineProperty( |
1028 this.webviewNode, | 1069 this.webviewNode, |
1029 'request', | 1070 'request', |
1030 { | 1071 { |
1031 value: request, | 1072 value: request, |
1032 enumerable: true | 1073 enumerable: true |
1033 } | 1074 } |
1034 ); | 1075 ); |
1035 }; | 1076 }; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1214 /** | 1255 /** |
1215 * Implemented when the experimental API is available. | 1256 * Implemented when the experimental API is available. |
1216 * @private | 1257 * @private |
1217 */ | 1258 */ |
1218 WebViewInternal.prototype.maybeGetExperimentalEvents = function() {}; | 1259 WebViewInternal.prototype.maybeGetExperimentalEvents = function() {}; |
1219 | 1260 |
1220 /** | 1261 /** |
1221 * Implemented when the experimental API is available. | 1262 * Implemented when the experimental API is available. |
1222 * @private | 1263 * @private |
1223 */ | 1264 */ |
1224 WebViewInternal.prototype.maybeAttachWebRequestEventToObject = function() {}; | |
battre
2014/05/28 15:15:21
I have no idea about this code. It would be great
Fady Samuel
2014/05/29 15:13:27
Yes, will do.
| |
1225 | |
1226 /** | |
1227 * Implemented when the experimental API is available. | |
1228 * @private | |
1229 */ | |
1230 WebViewInternal.prototype.maybeGetExperimentalPermissions = function() { | 1265 WebViewInternal.prototype.maybeGetExperimentalPermissions = function() { |
1231 return []; | 1266 return []; |
1232 }; | 1267 }; |
1233 | 1268 |
1234 /** | 1269 /** |
1235 * Calls to show contextmenu right away instead of dispatching a 'contextmenu' | 1270 * Calls to show contextmenu right away instead of dispatching a 'contextmenu' |
1236 * event. | 1271 * event. |
1237 * This will be overridden in web_view_experimental.js to implement contextmenu | 1272 * This will be overridden in web_view_experimental.js to implement contextmenu |
1238 * API. | 1273 * API. |
1239 * @private | 1274 * @private |
1240 */ | 1275 */ |
1241 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { | 1276 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { |
1242 var requestId = e.requestId; | 1277 var requestId = e.requestId; |
1243 // Setting |params| = undefined will show the context menu unmodified, hence | 1278 // Setting |params| = undefined will show the context menu unmodified, hence |
1244 // the 'contextmenu' API is disabled for stable channel. | 1279 // the 'contextmenu' API is disabled for stable channel. |
1245 var params = undefined; | 1280 var params = undefined; |
1246 WebView.showContextMenu(this.instanceId, requestId, params); | 1281 WebView.showContextMenu(this.instanceId, requestId, params); |
1247 }; | 1282 }; |
1248 | 1283 |
1249 /** | 1284 /** |
1250 * Implemented when the experimental API is available. | 1285 * Implemented when the experimental API is available. |
1251 * @private | 1286 * @private |
1252 */ | 1287 */ |
1253 WebViewInternal.prototype.setupExperimentalContextMenus_ = function() {}; | 1288 WebViewInternal.prototype.setupExperimentalContextMenus_ = function() {}; |
1254 | 1289 |
1255 exports.WebView = WebView; | 1290 exports.WebView = WebView; |
1256 exports.WebViewInternal = WebViewInternal; | 1291 exports.WebViewInternal = WebViewInternal; |
1257 exports.CreateEvent = CreateEvent; | 1292 exports.CreateEvent = CreateEvent; |
OLD | NEW |