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 GuestViewInternal = | 10 var GuestViewInternal = |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 }.bind(this)); | 118 }.bind(this)); |
119 }; | 119 }; |
120 | 120 |
121 // Validation helper function for executeScript() and insertCSS(). | 121 // Validation helper function for executeScript() and insertCSS(). |
122 WebView.prototype.validateExecuteCodeCall = function() { | 122 WebView.prototype.validateExecuteCodeCall = function() { |
123 if (!this.guestInstanceId) { | 123 if (!this.guestInstanceId) { |
124 throw new Error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); | 124 throw new Error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); |
125 } | 125 } |
126 }; | 126 }; |
127 | 127 |
128 WebView.prototype.setupAutoSizeProperties = function() { | |
129 $Array.forEach(AUTO_SIZE_ATTRIBUTES, function(attributeName) { | |
130 Object.defineProperty(this.webviewNode, attributeName, { | |
131 get: function() { | |
132 return this.attributes[attributeName].getValue(); | |
133 }.bind(this), | |
134 set: function(value) { | |
135 this.attributes[attributeName].setValue(value); | |
136 }.bind(this), | |
137 enumerable: true | |
138 }); | |
139 }.bind(this), this); | |
140 }; | |
141 | |
142 WebView.prototype.setupWebviewNodeProperties = function() { | 128 WebView.prototype.setupWebviewNodeProperties = function() { |
143 this.setupAutoSizeProperties(); | 129 for (var attributeName in this.attributes) { |
144 | 130 this.attributes[attributeName].define(); |
145 Object.defineProperty(this.webviewNode, | 131 } |
146 WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, { | |
147 get: function() { | |
148 return this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY]. | |
149 getValue(); | |
150 }.bind(this), | |
151 set: function(value) { | |
152 this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY]. | |
153 setValue(value); | |
154 }.bind(this), | |
155 enumerable: true | |
156 }); | |
157 | 132 |
158 // We cannot use {writable: true} property descriptor because we want a | 133 // We cannot use {writable: true} property descriptor because we want a |
159 // dynamic getter value. | 134 // dynamic getter value. |
160 Object.defineProperty(this.webviewNode, 'contentWindow', { | 135 Object.defineProperty(this.webviewNode, 'contentWindow', { |
161 get: function() { | 136 get: function() { |
162 if (this.contentWindow) { | 137 if (this.contentWindow) { |
163 return this.contentWindow; | 138 return this.contentWindow; |
164 } | 139 } |
165 window.console.error( | 140 window.console.error( |
166 WebViewConstants.ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE); | 141 WebViewConstants.ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE); |
167 }.bind(this), | 142 }.bind(this), |
168 // No setter. | 143 // No setter. |
169 enumerable: true | 144 enumerable: true |
170 }); | 145 }); |
171 | |
172 Object.defineProperty(this.webviewNode, WebViewConstants.ATTRIBUTE_NAME, { | |
173 get: function() { | |
174 return this.attributes[WebViewConstants.ATTRIBUTE_NAME].getValue(); | |
175 }.bind(this), | |
176 set: function(value) { | |
177 this.attributes[WebViewConstants.ATTRIBUTE_NAME].setValue(value); | |
178 }.bind(this), | |
179 enumerable: true | |
180 }); | |
181 | |
182 Object.defineProperty(this.webviewNode, | |
183 WebViewConstants.ATTRIBUTE_PARTITION, { | |
184 get: function() { | |
185 return this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].getValue(); | |
186 }.bind(this), | |
187 set: function(value) { | |
188 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].setValue(value); | |
189 }.bind(this), | |
190 enumerable: true | |
191 }); | |
192 | |
193 Object.defineProperty(this.webviewNode, WebViewConstants.ATTRIBUTE_SRC, { | |
194 get: function() { | |
195 return this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); | |
196 }.bind(this), | |
197 set: function(value) { | |
198 this.attributes[WebViewConstants.ATTRIBUTE_SRC].setValue(value); | |
199 }.bind(this), | |
200 enumerable: true | |
201 }); | |
202 }; | 146 }; |
203 | 147 |
204 // The purpose of this mutation observer is to catch assignment to the src | 148 // The purpose of this mutation observer is to catch assignment to the src |
205 // attribute without any changes to its value. This is useful in the case | 149 // attribute without any changes to its value. This is useful in the case |
206 // where the webview guest has crashed and navigating to the same address | 150 // where the webview guest has crashed and navigating to the same address |
207 // spawns off a new process. | 151 // spawns off a new process. |
208 WebView.prototype.setupWebViewSrcAttributeMutationObserver = | 152 WebView.prototype.setupWebViewSrcAttributeMutationObserver = |
209 function() { | 153 function() { |
210 this.srcAndPartitionObserver = new MutationObserver(function(mutations) { | 154 this.srcAndPartitionObserver = new MutationObserver(function(mutations) { |
211 $Array.forEach(mutations, function(mutation) { | 155 $Array.forEach(mutations, function(mutation) { |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 WebView.prototype.maybeGetChromeWebViewEvents = function() {}; | 811 WebView.prototype.maybeGetChromeWebViewEvents = function() {}; |
868 | 812 |
869 // Implemented when the experimental WebView API is available. | 813 // Implemented when the experimental WebView API is available. |
870 WebView.maybeGetExperimentalAPIs = function() {}; | 814 WebView.maybeGetExperimentalAPIs = function() {}; |
871 WebView.prototype.maybeGetExperimentalEvents = function() {}; | 815 WebView.prototype.maybeGetExperimentalEvents = function() {}; |
872 WebView.prototype.setupExperimentalContextMenus = function() {}; | 816 WebView.prototype.setupExperimentalContextMenus = function() {}; |
873 | 817 |
874 // Exports. | 818 // Exports. |
875 exports.WebView = WebView; | 819 exports.WebView = WebView; |
876 exports.WebViewInternal = WebViewInternal; | 820 exports.WebViewInternal = WebViewInternal; |
OLD | NEW |