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

Unified Diff: chrome/common/extensions/docs/examples/extensions/storage_api_devtools/scripts/devtools.js

Issue 12760009: Write a devtools extension to inspect chrome.storage data Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: small fixes Created 7 years, 8 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/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

Powered by Google App Engine
This is Rietveld 408576698