| 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));
|
| + });
|
| +}
|
| +
|
| +})();
|
| +
|
| +
|
|
|