| 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 // Shim that simulates a <webview> tag via Mutation Observers. | 5 // Shim that simulates a <webview> tag via Mutation Observers. |
| 6 // | 6 // |
| 7 // The actual tag is implemented via the browser plugin. The internals of this | 7 // The actual tag is implemented via the browser plugin. The internals of this |
| 8 // are hidden via Shadow DOM. | 8 // are hidden via Shadow DOM. |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| 11 | 11 |
| 12 var DocumentNatives = requireNative('document_natives'); | 12 var DocumentNatives = requireNative('document_natives'); |
| 13 var EventBindings = require('event_bindings'); | 13 var EventBindings = require('event_bindings'); |
| 14 var IdGenerator = requireNative('id_generator'); |
| 14 var MessagingNatives = requireNative('messaging_natives'); | 15 var MessagingNatives = requireNative('messaging_natives'); |
| 15 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; | 16 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; |
| 16 var WebRequestSchema = | 17 var WebRequestSchema = |
| 17 requireNative('schema_registry').GetSchema('webRequest'); | 18 requireNative('schema_registry').GetSchema('webRequest'); |
| 19 var DeclarativeWebRequestSchema = |
| 20 requireNative('schema_registry').GetSchema('declarativeWebRequest'); |
| 18 var WebView = require('binding').Binding.create('webview').generate(); | 21 var WebView = require('binding').Binding.create('webview').generate(); |
| 19 var idGenerator = requireNative('id_generator'); | |
| 20 | 22 |
| 21 // This secret enables hiding <webview> private members from the outside scope. | 23 // This secret enables hiding <webview> private members from the outside scope. |
| 22 // Outside of this file, |secret| is inaccessible. The only way to access the | 24 // Outside of this file, |secret| is inaccessible. The only way to access the |
| 23 // <webview> element's internal members is via the |secret|. Since it's only | 25 // <webview> element's internal members is via the |secret|. Since it's only |
| 24 // accessible by code here (and in web_view_experimental), only <webview>'s | 26 // accessible by code here (and in web_view_experimental), only <webview>'s |
| 25 // API can access it and not external developers. | 27 // API can access it and not external developers. |
| 26 var secret = {}; | 28 var secret = {}; |
| 27 | 29 |
| 28 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; | 30 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; |
| 29 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; | 31 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 node.style.height = webViewEvent.newHeight + 'px'; | 551 node.style.height = webViewEvent.newHeight + 'px'; |
| 550 } | 552 } |
| 551 node.dispatchEvent(webViewEvent); | 553 node.dispatchEvent(webViewEvent); |
| 552 }; | 554 }; |
| 553 | 555 |
| 554 /** | 556 /** |
| 555 * @private | 557 * @private |
| 556 */ | 558 */ |
| 557 WebViewInternal.prototype.setupWebviewNodeEvents_ = function() { | 559 WebViewInternal.prototype.setupWebviewNodeEvents_ = function() { |
| 558 var self = this; | 560 var self = this; |
| 559 this.viewInstanceId_ = idGenerator.GetNextId(); | 561 this.viewInstanceId_ = IdGenerator.GetNextId(); |
| 560 var onInstanceIdAllocated = function(e) { | 562 var onInstanceIdAllocated = function(e) { |
| 561 var detail = e.detail ? JSON.parse(e.detail) : {}; | 563 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 562 self.instanceId_ = detail.windowId; | 564 self.instanceId_ = detail.windowId; |
| 563 var params = { | 565 var params = { |
| 564 'api': 'webview', | 566 'api': 'webview', |
| 565 'instanceId': self.viewInstanceId_ | 567 'instanceId': self.viewInstanceId_ |
| 566 }; | 568 }; |
| 567 if (self.userAgentOverride_) { | 569 if (self.userAgentOverride_) { |
| 568 params['userAgentOverride'] = self.userAgentOverride_; | 570 params['userAgentOverride'] = self.userAgentOverride_; |
| 569 } | 571 } |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 WebViewInternal.prototype.setupWebRequestEvents_ = function() { | 866 WebViewInternal.prototype.setupWebRequestEvents_ = function() { |
| 865 var self = this; | 867 var self = this; |
| 866 var request = {}; | 868 var request = {}; |
| 867 var createWebRequestEvent = function(webRequestEvent) { | 869 var createWebRequestEvent = function(webRequestEvent) { |
| 868 return function() { | 870 return function() { |
| 869 if (!self[webRequestEvent.name + '_']) { | 871 if (!self[webRequestEvent.name + '_']) { |
| 870 self[webRequestEvent.name + '_'] = | 872 self[webRequestEvent.name + '_'] = |
| 871 new WebRequestEvent( | 873 new WebRequestEvent( |
| 872 'webview.' + webRequestEvent.name, | 874 'webview.' + webRequestEvent.name, |
| 873 webRequestEvent.parameters, | 875 webRequestEvent.parameters, |
| 874 webRequestEvent.extraParameters, null, | 876 webRequestEvent.extraParameters, webRequestEvent.options, |
| 875 self.viewInstanceId_); | 877 self.viewInstanceId_); |
| 876 } | 878 } |
| 877 return self[webRequestEvent.name + '_']; | 879 return self[webRequestEvent.name + '_']; |
| 878 }; | 880 }; |
| 879 }; | 881 }; |
| 880 | 882 |
| 883 for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) { |
| 884 var eventSchema = DeclarativeWebRequestSchema.events[i]; |
| 885 var webRequestEvent = createWebRequestEvent(eventSchema); |
| 886 this.maybeAttachWebRequestEventToObject_(request, |
| 887 eventSchema.name, |
| 888 webRequestEvent); |
| 889 } |
| 890 |
| 881 // Populate the WebRequest events from the API definition. | 891 // Populate the WebRequest events from the API definition. |
| 882 for (var i = 0; i < WebRequestSchema.events.length; ++i) { | 892 for (var i = 0; i < WebRequestSchema.events.length; ++i) { |
| 883 var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]); | 893 var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]); |
| 884 Object.defineProperty( | 894 Object.defineProperty( |
| 885 request, | 895 request, |
| 886 WebRequestSchema.events[i].name, | 896 WebRequestSchema.events[i].name, |
| 887 { | 897 { |
| 888 get: webRequestEvent, | 898 get: webRequestEvent, |
| 889 enumerable: true | 899 enumerable: true |
| 890 } | 900 } |
| 891 ); | 901 ); |
| 892 this.maybeAttachWebRequestEventToWebview_(WebRequestSchema.events[i].name, | 902 this.maybeAttachWebRequestEventToObject_(this.webviewNode_, |
| 893 webRequestEvent); | 903 WebRequestSchema.events[i].name, |
| 904 webRequestEvent); |
| 894 } | 905 } |
| 895 Object.defineProperty( | 906 Object.defineProperty( |
| 896 this.webviewNode_, | 907 this.webviewNode_, |
| 897 'request', | 908 'request', |
| 898 { | 909 { |
| 899 value: request, | 910 value: request, |
| 900 enumerable: true, | 911 enumerable: true, |
| 901 writable: false | 912 writable: false |
| 902 } | 913 } |
| 903 ); | 914 ); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 /** | 1027 /** |
| 1017 * Implemented when the experimental API is available. | 1028 * Implemented when the experimental API is available. |
| 1018 * @private | 1029 * @private |
| 1019 */ | 1030 */ |
| 1020 WebViewInternal.prototype.maybeGetExperimentalEvents_ = function() {}; | 1031 WebViewInternal.prototype.maybeGetExperimentalEvents_ = function() {}; |
| 1021 | 1032 |
| 1022 /** | 1033 /** |
| 1023 * Implemented when the experimental API is available. | 1034 * Implemented when the experimental API is available. |
| 1024 * @private | 1035 * @private |
| 1025 */ | 1036 */ |
| 1026 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {}; | 1037 WebViewInternal.prototype.maybeAttachWebRequestEventToObject_ = function() {}; |
| 1027 | 1038 |
| 1028 /** | 1039 /** |
| 1029 * Implemented when the experimental API is available. | 1040 * Implemented when the experimental API is available. |
| 1030 * @private | 1041 * @private |
| 1031 */ | 1042 */ |
| 1032 WebViewInternal.prototype.maybeGetExperimentalPermissions_ = function() { | 1043 WebViewInternal.prototype.maybeGetExperimentalPermissions_ = function() { |
| 1033 return []; | 1044 return []; |
| 1034 }; | 1045 }; |
| 1035 | 1046 |
| 1036 exports.WebView = WebView; | 1047 exports.WebView = WebView; |
| 1037 exports.WebViewInternal = WebViewInternal; | 1048 exports.WebViewInternal = WebViewInternal; |
| 1038 exports.CreateEvent = CreateEvent; | 1049 exports.CreateEvent = CreateEvent; |
| OLD | NEW |