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

Unified Diff: chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/PreprocessorPanel.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
Index: chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/PreprocessorPanel.js
diff --git a/chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/PreprocessorPanel.js b/chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/PreprocessorPanel.js
new file mode 100644
index 0000000000000000000000000000000000000000..b3f4279b0df8c4008e0231d81abdb1da74f1b4da
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/PreprocessorPanel.js
@@ -0,0 +1,68 @@
+// 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.
+
+(function() {
+
+// This function is converted to a string and becomes the preprocessor
+function preprocessor(source, url, listenerName) {
+ url = url ? url : '(eval)';
+ url += listenerName ? '_' + listenerName : '';
+ var prefix = 'window.__preprocessed = window.__preprocessed || [];\n';
+ prefix += 'window.__preprocessed.push(\'' + url +'\');\n';
+ var postfix = '\n//# sourceURL=' + url + '.js\n';
+ return prefix + source + postfix;
+}
+
+function extractPreprocessedFiles(onExtracted) {
+ var expr = 'window.__preprocessed';
+ function onEval(files, isException) {
+ if (isException)
+ throw new Error('Eval failed for ' + expr, isException.value);
+ onExtracted(files);
+ }
+ chrome.devtools.inspectedWindow.eval(expr, onEval);
+}
+
+function reloadWithPreprocessor(injectedScript) {
+ var options = {
+ ignoreCache: true,
+ userAgent: undefined,
+ injectedScript: '(' + injectedScript + ')()',
+ preprocessingScript: '(' + preprocessor + ')'
+ };
+ chrome.devtools.inspectedWindow.reload(options);
+}
+
+function demoPreprocessor() {
+ function onLoaded() {
+ extractPreprocessedFiles(updateUI);
+ }
+ var loadMonitor = new InspectedWindow.LoadMonitor(onLoaded);
+ reloadWithPreprocessor(loadMonitor.injectedScript);
+}
+
+function listen() {
+ var reloadButton = document.querySelector('.reload-button');
+ reloadButton.addEventListener('click', demoPreprocessor);
+}
+
+window.addEventListener('load', listen);
+
+function createRow(url) {
+ var li = document.createElement('li');
+ li.textContent = url;
+ return li;
+}
+
+function updateUI(preprocessedFiles) {
+ var rowContainer = document.querySelector('.js-preprocessed-urls');
+ rowContainer.innerHTML = '';
+ preprocessedFiles.forEach(function(url) {
+ rowContainer.appendChild(createRow(url));
+ });
+}
+
+})();
+
+

Powered by Google App Engine
This is Rietveld 408576698