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? |
| 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}); |
| 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 because we want |
| 1030 // the listener to fire only for messages targeted for this particular |
| 1031 // <webview>. |
| 1032 var EventClass = webRequestEvent.name === 'onMessage' ? |
| 1033 DeclarativeWebRequestEvent : EventBindings.Event; |
| 1034 self[webRequestEvent.name] = |
| 1035 new EventClass( |
| 1036 'webview.' + webRequestEvent.name, |
| 1037 webRequestEvent.parameters, |
| 1038 webRequestEvent.options, |
| 1039 self.viewInstanceId); |
| 1040 } |
| 1041 return self[webRequestEvent.name]; |
| 1042 }; |
| 1043 }; |
| 1044 |
1004 for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) { | 1045 for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) { |
1005 var eventSchema = DeclarativeWebRequestSchema.events[i]; | 1046 var eventSchema = DeclarativeWebRequestSchema.events[i]; |
1006 var webRequestEvent = createWebRequestEvent(eventSchema); | 1047 var webRequestEvent = createDeclarativeWebRequestEvent(eventSchema); |
1007 this.maybeAttachWebRequestEventToObject(request, | 1048 Object.defineProperty( |
1008 eventSchema.name, | 1049 request, |
1009 webRequestEvent); | 1050 eventSchema.name, |
| 1051 { |
| 1052 get: webRequestEvent, |
| 1053 enumerable: true |
| 1054 } |
| 1055 ); |
1010 } | 1056 } |
1011 | 1057 |
1012 // Populate the WebRequest events from the API definition. | 1058 // Populate the WebRequest events from the API definition. |
1013 for (var i = 0; i < WebRequestSchema.events.length; ++i) { | 1059 for (var i = 0; i < WebRequestSchema.events.length; ++i) { |
1014 var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]); | 1060 var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]); |
1015 Object.defineProperty( | 1061 Object.defineProperty( |
1016 request, | 1062 request, |
1017 WebRequestSchema.events[i].name, | 1063 WebRequestSchema.events[i].name, |
1018 { | 1064 { |
1019 get: webRequestEvent, | 1065 get: webRequestEvent, |
1020 enumerable: true | 1066 enumerable: true |
1021 } | 1067 } |
1022 ); | 1068 ); |
1023 this.maybeAttachWebRequestEventToObject(this.webviewNode, | |
1024 WebRequestSchema.events[i].name, | |
1025 webRequestEvent); | |
1026 } | 1069 } |
1027 Object.defineProperty( | 1070 Object.defineProperty( |
1028 this.webviewNode, | 1071 this.webviewNode, |
1029 'request', | 1072 'request', |
1030 { | 1073 { |
1031 value: request, | 1074 value: request, |
1032 enumerable: true | 1075 enumerable: true |
1033 } | 1076 } |
1034 ); | 1077 ); |
1035 }; | 1078 }; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 /** | 1257 /** |
1215 * Implemented when the experimental API is available. | 1258 * Implemented when the experimental API is available. |
1216 * @private | 1259 * @private |
1217 */ | 1260 */ |
1218 WebViewInternal.prototype.maybeGetExperimentalEvents = function() {}; | 1261 WebViewInternal.prototype.maybeGetExperimentalEvents = function() {}; |
1219 | 1262 |
1220 /** | 1263 /** |
1221 * Implemented when the experimental API is available. | 1264 * Implemented when the experimental API is available. |
1222 * @private | 1265 * @private |
1223 */ | 1266 */ |
1224 WebViewInternal.prototype.maybeAttachWebRequestEventToObject = function() {}; | |
1225 | |
1226 /** | |
1227 * Implemented when the experimental API is available. | |
1228 * @private | |
1229 */ | |
1230 WebViewInternal.prototype.maybeGetExperimentalPermissions = function() { | 1267 WebViewInternal.prototype.maybeGetExperimentalPermissions = function() { |
1231 return []; | 1268 return []; |
1232 }; | 1269 }; |
1233 | 1270 |
1234 /** | 1271 /** |
1235 * Calls to show contextmenu right away instead of dispatching a 'contextmenu' | 1272 * Calls to show contextmenu right away instead of dispatching a 'contextmenu' |
1236 * event. | 1273 * event. |
1237 * This will be overridden in web_view_experimental.js to implement contextmenu | 1274 * This will be overridden in web_view_experimental.js to implement contextmenu |
1238 * API. | 1275 * API. |
1239 * @private | 1276 * @private |
1240 */ | 1277 */ |
1241 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { | 1278 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { |
1242 var requestId = e.requestId; | 1279 var requestId = e.requestId; |
1243 // Setting |params| = undefined will show the context menu unmodified, hence | 1280 // Setting |params| = undefined will show the context menu unmodified, hence |
1244 // the 'contextmenu' API is disabled for stable channel. | 1281 // the 'contextmenu' API is disabled for stable channel. |
1245 var params = undefined; | 1282 var params = undefined; |
1246 WebView.showContextMenu(this.instanceId, requestId, params); | 1283 WebView.showContextMenu(this.instanceId, requestId, params); |
1247 }; | 1284 }; |
1248 | 1285 |
1249 /** | 1286 /** |
1250 * Implemented when the experimental API is available. | 1287 * Implemented when the experimental API is available. |
1251 * @private | 1288 * @private |
1252 */ | 1289 */ |
1253 WebViewInternal.prototype.setupExperimentalContextMenus_ = function() {}; | 1290 WebViewInternal.prototype.setupExperimentalContextMenus_ = function() {}; |
1254 | 1291 |
1255 exports.WebView = WebView; | 1292 exports.WebView = WebView; |
1256 exports.WebViewInternal = WebViewInternal; | 1293 exports.WebViewInternal = WebViewInternal; |
1257 exports.CreateEvent = CreateEvent; | 1294 exports.CreateEvent = CreateEvent; |
OLD | NEW |