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

Unified Diff: chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/InspectedWindowLoadMonitor.js

Issue 23892003: Sample Extension for chrome.devtools.inspectedWindow.reload preprocessor option (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Retry license Created 7 years, 3 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/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/PreprocessorPanel.css » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/InspectedWindowLoadMonitor.js
diff --git a/chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/InspectedWindowLoadMonitor.js b/chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/InspectedWindowLoadMonitor.js
new file mode 100644
index 0000000000000000000000000000000000000000..80421f58c27cda6cc53f0015f5221e167812786c
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/InspectedWindowLoadMonitor.js
@@ -0,0 +1,53 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/** @fileoverview The chrome.devtools API does not support notifications from
+ * within a Web page nor does it report on events occuring in the page. For now
+ * we poll the page to determine a reasonable time to report the scripts.
+ */
+
+(function() {
+ /*
+ * @param {function} Called after the 'load' event on the inspected window
+ * @return {function} A function to be injected into the inspected window.
+ */
+ function LoadMonitor(onLoadedCallback) {
+
+ function checkForLoad() {
+ var expr = 'window.__inspectedWindowLoaded';
+ function onEval(isLoaded, isException) {
+ if (isException)
+ throw new Error('Eval failed for ' + expr, isException.value);
+ if (isLoaded)
+ onLoadedCallback();
+ else
+ pollForLoad();
+ }
+ chrome.devtools.inspectedWindow.eval(expr, onEval);
+ }
+
+ function pollForLoad() {
+ setTimeout(checkForLoad, 200);
+ }
+
+ pollForLoad();
+ }
+
+ LoadMonitor.prototype = {
+ // This function should be converted to a string and run in the Web page
+ injectedScript: function() {
+ // Initialize a secret data structure.
+ window.__inspectedWindowLoaded = false;
+ window.addEventListener('load', function() {
+ window.__inspectedWindowLoaded = true;
+ console.log('loaded');
+ });
+ }
+ };
+
+ window.InspectedWindow = window.InspectedWindow || {};
+ InspectedWindow.LoadMonitor = LoadMonitor;
+})();
+
+
« no previous file with comments | « no previous file | chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/PreprocessorPanel.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698