Chromium Code Reviews| 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 forEach = require('utils').forEach; | 12 var forEach = require('utils').forEach; |
| 11 var watchForTag = require('tagWatcher').watchForTag; | 13 var watchForTag = require('tagWatcher').watchForTag; |
| 12 | 14 |
| 13 /** @type {Array.<string>} */ | 15 /** @type {Array.<string>} */ |
| 14 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight', | 16 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight', |
| 15 'minwidth', 'maxheight', 'maxwidth']; | 17 'minwidth', 'maxheight', 'maxwidth']; |
| 16 | 18 |
| 17 | 19 |
| 18 // All exposed api methods for <webview>, these are forwarded to the browser | 20 // All exposed api methods for <webview>, these are forwarded to the browser |
| 19 // plugin. | 21 // plugin. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 37 'loadabort' : ['url', 'isTopLevel', 'reason'], | 39 'loadabort' : ['url', 'isTopLevel', 'reason'], |
| 38 'loadcommit' : ['url', 'isTopLevel'], | 40 'loadcommit' : ['url', 'isTopLevel'], |
| 39 'loadredirect' : ['oldUrl', 'newUrl', 'isTopLevel'], | 41 'loadredirect' : ['oldUrl', 'newUrl', 'isTopLevel'], |
| 40 'loadstart' : ['url', 'isTopLevel'], | 42 'loadstart' : ['url', 'isTopLevel'], |
| 41 'loadstop' : [], | 43 'loadstop' : [], |
| 42 'responsive' : ['processId'], | 44 'responsive' : ['processId'], |
| 43 'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'], | 45 'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'], |
| 44 'unresponsive' : ['processId'] | 46 'unresponsive' : ['processId'] |
| 45 }; | 47 }; |
| 46 | 48 |
| 47 window.addEventListener('DOMContentLoaded', function() { | 49 var documentA = document; |
| 48 watchForTag('WEBVIEW', function(addedNode) { new WebView(addedNode); }); | 50 renderViewObserverNatives.OnDocumentCreatedForCurrentContext(function() { |
| 51 var documentB = document; | |
| 52 if (documentA == documentB) { | |
|
adamk
2013/06/18 22:26:49
This only makes sense to me if documentA is undefi
lazyboy
2013/06/18 22:54:47
Surprisingly it is not, I tried to addEventListene
| |
| 53 window.console.log('both document are equal'); | |
| 54 } else { | |
| 55 window.console.log('documents are different'); | |
| 56 } | |
| 57 // At this point we have a new document where app's content would go | |
| 58 // (document.readyState == 'loading'), run watchForTag() once document's | |
| 59 // OnDOMContentLoaded fires. | |
| 60 document.addEventListener('DOMContentLoaded', function(e) { | |
| 61 window.console.log('shim: document.DOMContentLoaded'); | |
| 62 watchForTag('WEBVIEW', function(addedNode) { new WebView(addedNode); }); | |
| 63 }); | |
| 49 }); | 64 }); |
| 50 | 65 |
| 51 /** | 66 /** |
| 52 * @constructor | 67 * @constructor |
| 53 */ | 68 */ |
| 54 function WebView(webviewNode) { | 69 function WebView(webviewNode) { |
| 55 this.webviewNode_ = webviewNode; | 70 this.webviewNode_ = webviewNode; |
| 56 this.browserPluginNode_ = this.createBrowserPluginNode_(); | 71 this.browserPluginNode_ = this.createBrowserPluginNode_(); |
| 57 var shadowRoot = this.webviewNode_.webkitCreateShadowRoot(); | 72 var shadowRoot = this.webviewNode_.webkitCreateShadowRoot(); |
| 58 shadowRoot.appendChild(this.browserPluginNode_); | 73 shadowRoot.appendChild(this.browserPluginNode_); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 } | 392 } |
| 378 }; | 393 }; |
| 379 | 394 |
| 380 /** | 395 /** |
| 381 * Implemented when the experimental API is available. | 396 * Implemented when the experimental API is available. |
| 382 * @private | 397 * @private |
| 383 */ | 398 */ |
| 384 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; | 399 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; |
| 385 | 400 |
| 386 exports.WebView = WebView; | 401 exports.WebView = WebView; |
| OLD | NEW |