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 GuestView = require('guestView').GuestView; | 10 var GuestView = require('guestView').GuestView; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 element.style.width = newWidth + 'px'; | 130 element.style.width = newWidth + 'px'; |
131 element.style.height = newHeight + 'px'; | 131 element.style.height = newHeight + 'px'; |
132 // Only fire the DOM event if the size of the <webview> has actually | 132 // Only fire the DOM event if the size of the <webview> has actually |
133 // changed. | 133 // changed. |
134 this.dispatchEvent(webViewEvent); | 134 this.dispatchEvent(webViewEvent); |
135 } | 135 } |
136 }; | 136 }; |
137 | 137 |
138 WebViewImpl.prototype.createGuest = function() { | 138 WebViewImpl.prototype.createGuest = function() { |
139 this.guest.create(this.buildParams(), function() { | 139 this.guest.create(this.buildParams(), function() { |
140 this.attachWindow(); | 140 this.attachWindow$(); |
141 }.bind(this)); | 141 }.bind(this)); |
142 }; | 142 }; |
143 | 143 |
144 WebViewImpl.prototype.onFrameNameChanged = function(name) { | 144 WebViewImpl.prototype.onFrameNameChanged = function(name) { |
145 this.attributes[WebViewConstants.ATTRIBUTE_NAME].setValueIgnoreMutation(name); | 145 this.attributes[WebViewConstants.ATTRIBUTE_NAME].setValueIgnoreMutation(name); |
146 }; | 146 }; |
147 | 147 |
148 // Updates state upon loadcommit. | 148 // Updates state upon loadcommit. |
149 WebViewImpl.prototype.onLoadCommit = function( | 149 WebViewImpl.prototype.onLoadCommit = function( |
150 baseUrlForDataUrl, currentEntryIndex, entryCount, | 150 baseUrlForDataUrl, currentEntryIndex, entryCount, |
(...skipping 20 matching lines...) Expand all Loading... |
171 var params = { 'initialZoomFactor': this.cachedZoomFactor, | 171 var params = { 'initialZoomFactor': this.cachedZoomFactor, |
172 'userAgentOverride': this.userAgentOverride }; | 172 'userAgentOverride': this.userAgentOverride }; |
173 for (var i in this.attributes) { | 173 for (var i in this.attributes) { |
174 var value = this.attributes[i].getValueIfDirty(); | 174 var value = this.attributes[i].getValueIfDirty(); |
175 if (value) | 175 if (value) |
176 params[i] = value; | 176 params[i] = value; |
177 } | 177 } |
178 return params; | 178 return params; |
179 }; | 179 }; |
180 | 180 |
181 WebViewImpl.prototype.attachWindow = function(opt_guestInstanceId) { | 181 WebViewImpl.prototype.attachWindow$ = function(opt_guestInstanceId) { |
182 // If |opt_guestInstanceId| was provided, then a different existing guest is | 182 // If |opt_guestInstanceId| was provided, then a different existing guest is |
183 // being attached to this webview, and the current one will get destroyed. | 183 // being attached to this webview, and the current one will get destroyed. |
184 if (opt_guestInstanceId) { | 184 if (opt_guestInstanceId) { |
185 if (this.guest.getId() == opt_guestInstanceId) { | 185 if (this.guest.getId() == opt_guestInstanceId) { |
186 return true; | 186 return true; |
187 } | 187 } |
188 this.guest.destroy(); | 188 this.guest.destroy(); |
189 this.guest = new GuestView('webview', opt_guestInstanceId); | 189 this.guest = new GuestView('webview', opt_guestInstanceId); |
190 } | 190 } |
191 | 191 |
192 return GuestViewContainer.prototype.attachWindow.call(this); | 192 return GuestViewContainer.prototype.attachWindow$.call(this); |
193 }; | 193 }; |
194 | 194 |
195 // Shared implementation of executeScript() and insertCSS(). | 195 // Shared implementation of executeScript() and insertCSS(). |
196 WebViewImpl.prototype.executeCode = function(func, args) { | 196 WebViewImpl.prototype.executeCode = function(func, args) { |
197 if (!this.guest.getId()) { | 197 if (!this.guest.getId()) { |
198 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); | 198 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); |
199 return false; | 199 return false; |
200 } | 200 } |
201 | 201 |
202 var webviewSrc = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); | 202 var webviewSrc = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); |
(...skipping 14 matching lines...) Expand all Loading... |
217 }.bind(this)); | 217 }.bind(this)); |
218 }; | 218 }; |
219 | 219 |
220 // Implemented when the ChromeWebView API is available. | 220 // Implemented when the ChromeWebView API is available. |
221 WebViewImpl.prototype.maybeSetupContextMenus = function() {}; | 221 WebViewImpl.prototype.maybeSetupContextMenus = function() {}; |
222 | 222 |
223 GuestViewContainer.registerElement(WebViewImpl); | 223 GuestViewContainer.registerElement(WebViewImpl); |
224 | 224 |
225 // Exports. | 225 // Exports. |
226 exports.WebViewImpl = WebViewImpl; | 226 exports.WebViewImpl = WebViewImpl; |
OLD | NEW |