| Index: chrome/common/extensions/docs/examples/extensions/storage_api_devtools/scripts/devtools.js
|
| ===================================================================
|
| --- chrome/common/extensions/docs/examples/extensions/storage_api_devtools/scripts/devtools.js (revision 0)
|
| +++ chrome/common/extensions/docs/examples/extensions/storage_api_devtools/scripts/devtools.js (revision 0)
|
| @@ -0,0 +1,130 @@
|
| +// Copyright 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.
|
| +
|
| +// See https://bugs.webkit.org/show_bug.cgi?id=106811.
|
| +var supportContentScriptEval = false;
|
| +var chromeVer = navigator.appVersion.match(/Chrome\/\d+\.\d+\.(\d+)\.\d+/);
|
| +if (chromeVer && parseInt(chromeVer[1]) >= 1448)
|
| + supportContentScriptEval = true;
|
| +var createdPanels = {};
|
| +
|
| +function cloneContext(context) {
|
| + var result = {};
|
| + for (var key in context)
|
| + if (key != 'initialized')
|
| + result[key] = context[key];
|
| + return result;
|
| +}
|
| +
|
| +function indexOfContext(context, contexts) {
|
| + for (var i = 0; i < contexts.length; ++i)
|
| + if(contexts[i].type == context.type &&
|
| + contexts[i].securityOrigin == context.securityOrigin)
|
| + return i;
|
| + return -1;
|
| +}
|
| +
|
| +function initContextsForPanel(panelId) {
|
| + var panel = createdPanels[panelId];
|
| + if (!panel.window)
|
| + return;
|
| +
|
| + panel.contexts.forEach(function(context) {
|
| + if (!context.initialized) {
|
| + context.initialized = true;
|
| + panel.window.onContextAdded([cloneContext(context)]);
|
| + }
|
| + });
|
| +}
|
| +
|
| +function initPanels(context)
|
| +{
|
| + PANELS.forEach(function(panel) {
|
| + if (panel.supportedContexts.indexOf(context.type) != -1) {
|
| + var options = {};
|
| + if (supportContentScriptEval && context.type == 'contentScripts')
|
| + options = {scriptExecutionContext: context.securityOrigin};
|
| + evalScript(panel.detectScript, options, null,
|
| + function(result, isException) {
|
| + if (!isException && result) {
|
| + if (createdPanels[panel.id]) {
|
| + if(indexOfContext(context, createdPanels[panel.id].contexts) == -1)
|
| + createdPanels[panel.id].contexts.push(context);
|
| + initContextsForPanel(panel.id);
|
| + } else {
|
| + createdPanels[panel.id] = {contexts: [context]};
|
| + chrome.devtools.panels.create(
|
| + chrome.i18n.getMessage(panel.title_i18n),
|
| + panel.icon,
|
| + panel.page,
|
| + function(extensionPanel) {
|
| + createdPanels[panel.id].extensionPanel = extensionPanel;
|
| + extensionPanel.onShown.addListener(function(win) {
|
| + createdPanels[panel.id].window = win;
|
| + win.devtoolsReload = (function() {
|
| + createdPanels[panel.id].contexts = [];
|
| + initContexts(initPanels);
|
| + });
|
| +
|
| + win.onInspectedWindowUnloaded = (function() {
|
| + createdPanels[panel.id].contexts = [];
|
| + });
|
| +
|
| + initContextsForPanel(panel.id);
|
| + });
|
| + }
|
| + );
|
| + }
|
| + }
|
| + });
|
| + }
|
| + });
|
| +}
|
| +
|
| +function initContexts(callback) {
|
| + var tabId = chrome.devtools.inspectedWindow.tabId;
|
| + // Normal web pages and extensions UI pages have tab ids.
|
| + if (tabId)
|
| + isExtensionTab(tabId, function(result) {
|
| + if (result)
|
| + callback({type: 'extensions'});
|
| + else if (supportContentScriptEval)
|
| + getExtensionIds(function(ids) {
|
| + ids.forEach(function(id) {
|
| + var securityOrigin = 'chrome-extension://' + id;
|
| + chrome.devtools.inspectedWindow.eval('1',
|
| + {scriptExecutionContext: securityOrigin},
|
| + function(result, isException) {
|
| + if (result === 1 && !isException) {
|
| + callback({
|
| + type: 'contentScripts',
|
| + extensionId: id,
|
| + securityOrigin: securityOrigin
|
| + });
|
| + }
|
| + });
|
| + });
|
| + });
|
| + });
|
| + // Extensions background pages and popups do not have tab ids
|
| + else {
|
| + chrome.devtools.inspectedWindow.getResources(function(resources) {
|
| + for (var i = 0; i < resources.length; ++i)
|
| + if (/^chrome-extension:\/\//.test(resources[i].url))
|
| + {
|
| + callback({type: 'extensions'});
|
| + break;
|
| + }
|
| + });
|
| + }
|
| +}
|
| +
|
| +initContexts(initPanels);
|
| +
|
| +chrome.devtools.inspectedWindow.onResourceAdded.addListener(function(res) {
|
| + if (res.url.match(/^chrome-extension:\/\//)) {
|
| + initContexts(initPanels);
|
| + }
|
| +});
|
| +
|
|
|
| Property changes on: chrome/common/extensions/docs/examples/extensions/storage_api_devtools/scripts/devtools.js
|
| ___________________________________________________________________
|
| Added: svn:mime-type
|
| + text/javascript
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|