Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5064)

Unified Diff: chrome/renderer/resources/extensions/web_view.js

Issue 16975007: Run shim's watchForTag on document.DOMContentLoaded (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from kalman@ Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view/document_ready/embedder.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/resources/extensions/web_view.js
diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js
index 833778252c2a2e2d01028b770a2d04c0de37484f..333ec128cbc90323c069b9061804fe72c9eed1fb 100644
--- a/chrome/renderer/resources/extensions/web_view.js
+++ b/chrome/renderer/resources/extensions/web_view.js
@@ -43,9 +43,22 @@ var WEB_VIEW_EVENTS = {
'unresponsive' : ['processId']
};
-window.addEventListener('DOMContentLoaded', function() {
- watchForTag('WEBVIEW', function(addedNode) { new WebView(addedNode); });
-});
+// The <webview> tags we wish to watch for (watchForTag) does not belong to the
+// current scope's "document" reference. We need to wait until the document
+// begins loading, since only then will the "document" reference
+// point to the page's document (it will be reset between now and then).
+// We can't listen for the "readystatechange" event on the document (because
+// the object that it's dispatched on doesn't exist yet), but we can instead
+// do it at the window level in the capturing phase.
+window.addEventListener('readystatechange', function(e) {
+ if (document.readyState != 'loading') {
+ return;
+ }
+
+ document.addEventListener('DOMContentLoaded', function(e) {
+ watchForTag('WEBVIEW', function(addedNode) { new WebView(addedNode); });
+ });
+}, true /* useCapture */);
/**
* @constructor
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view/document_ready/embedder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698