| 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 var renderViewObserverNatives = requireNative('renderViewObserverNatives'); |
| 11 |
| 10 var watchForTag = require('tagWatcher').watchForTag; | 12 var watchForTag = require('tagWatcher').watchForTag; |
| 11 | 13 |
| 12 /** @type {Array.<string>} */ | 14 /** @type {Array.<string>} */ |
| 13 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight', | 15 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight', |
| 14 'minwidth', 'maxheight', 'maxwidth']; | 16 'minwidth', 'maxheight', 'maxwidth']; |
| 15 | 17 |
| 16 | 18 |
| 17 // All exposed api methods for <webview>, these are forwarded to the browser | 19 // All exposed api methods for <webview>, these are forwarded to the browser |
| 18 // plugin. | 20 // plugin. |
| 19 var WEB_VIEW_API_METHODS = [ | 21 var WEB_VIEW_API_METHODS = [ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 36 'loadabort' : ['url', 'isTopLevel', 'reason'], | 38 'loadabort' : ['url', 'isTopLevel', 'reason'], |
| 37 'loadcommit' : ['url', 'isTopLevel'], | 39 'loadcommit' : ['url', 'isTopLevel'], |
| 38 'loadredirect' : ['oldUrl', 'newUrl', 'isTopLevel'], | 40 'loadredirect' : ['oldUrl', 'newUrl', 'isTopLevel'], |
| 39 'loadstart' : ['url', 'isTopLevel'], | 41 'loadstart' : ['url', 'isTopLevel'], |
| 40 'loadstop' : [], | 42 'loadstop' : [], |
| 41 'responsive' : ['processId'], | 43 'responsive' : ['processId'], |
| 42 'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'], | 44 'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'], |
| 43 'unresponsive' : ['processId'] | 45 'unresponsive' : ['processId'] |
| 44 }; | 46 }; |
| 45 | 47 |
| 46 window.addEventListener('DOMContentLoaded', function() { | 48 var documentA = document; |
| 47 watchForTag('WEBVIEW', function(addedNode) { new WebView(addedNode); }); | 49 renderViewObserverNatives.OnDocumentCreatedForCurrentContext(function() { |
| 50 var documentB = document; |
| 51 window.console.log('old document: ' + documentA); |
| 52 window.console.log('new document: ' + documentB); |
| 53 if (documentA == documentB) { |
| 54 window.console.log('both document are equal'); |
| 55 } else { |
| 56 window.console.log('documents are different'); |
| 57 } |
| 58 // At this point we have a new document where app's content would go |
| 59 // (document.readyState == 'loading'), run watchForTag() once document's |
| 60 // OnDOMContentLoaded fires. |
| 61 document.addEventListener('DOMContentLoaded', function(e) { |
| 62 window.console.log('shim: document.DOMContentLoaded'); |
| 63 watchForTag('WEBVIEW', function(addedNode) { new WebView(addedNode); }); |
| 64 }); |
| 48 }); | 65 }); |
| 49 | 66 |
| 50 /** | 67 /** |
| 51 * @constructor | 68 * @constructor |
| 52 */ | 69 */ |
| 53 function WebView(webviewNode) { | 70 function WebView(webviewNode) { |
| 54 this.webviewNode_ = webviewNode; | 71 this.webviewNode_ = webviewNode; |
| 55 this.browserPluginNode_ = this.createBrowserPluginNode_(); | 72 this.browserPluginNode_ = this.createBrowserPluginNode_(); |
| 56 var shadowRoot = this.webviewNode_.webkitCreateShadowRoot(); | 73 var shadowRoot = this.webviewNode_.webkitCreateShadowRoot(); |
| 57 shadowRoot.appendChild(this.browserPluginNode_); | 74 shadowRoot.appendChild(this.browserPluginNode_); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 403 } |
| 387 }; | 404 }; |
| 388 | 405 |
| 389 /** | 406 /** |
| 390 * Implemented when the experimental API is available. | 407 * Implemented when the experimental API is available. |
| 391 * @private | 408 * @private |
| 392 */ | 409 */ |
| 393 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; | 410 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; |
| 394 | 411 |
| 395 exports.WebView = WebView; | 412 exports.WebView = WebView; |
| OLD | NEW |