2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * FIXME: change field naming style to use trailing underscore.
33 * @fileoverview Tools is a main class that wires all components of the
34 * DevTools frontend together. It is also responsible for overriding existing
35 * WebInspector functionality while it is getting upstreamed into WebCore.
38 var context = {}; // Used by WebCore's inspector routines.
41 Preferences.ignoreWhitespace = false;
42 Preferences.samplingCPUProfiler = true;
43 Preferences.heapProfilerPresent = true;
44 Preferences.detailedHeapProfiles = true;
45 Preferences.debuggerAlwaysEnabled = true;
46 Preferences.profilerAlwaysEnabled = true;
47 Preferences.canEditScriptSource = true;
48 Preferences.onlineDetectionEnabled = false;
49 Preferences.nativeInstrumentationEnabled = true;
50 Preferences.fileSystemEnabled = false;
51 Preferences.showTimingTab = true;
52 Preferences.showCookiesTab = true;
53 Preferences.saveAsAvailable = true;
54 Preferences.useLowerCaseMenuTitlesOnWindows = true;
55 Preferences.canInspectWorkers = true;
56 Preferences.canClearCacheAndCookies = true;
57 Preferences.canDisableCache = true;
58 Preferences.showNetworkPanelInitiatorColumn = true;
61 // Recognize WebP as a valid image mime type.
62 WebInspector.MIMETypes["image/webp"] = {2: true};
64 var devtools = devtools || {};
66 devtools.domContentLoaded = function()
68 if (WebInspector.queryParamsObject.toolbarColor && WebInspector.queryParamsObject.textColor)
69 WebInspector.setToolbarColors(WebInspector.queryParamsObject.toolbarColor, WebInspector.queryParamsObject.textColor);
71 document.addEventListener("DOMContentLoaded", devtools.domContentLoaded, false);
74 // FIXME: This needs to be upstreamed.
75 (function InterceptProfilesPanelEvents()
77 var oldShow = WebInspector.ProfilesPanel.prototype.show;
78 WebInspector.ProfilesPanel.prototype.show = function()
80 this.enableToggleButton.visible = false;
82 // Show is called on every show event of a panel, so
83 // we only need to intercept it once.
84 WebInspector.ProfilesPanel.prototype.show = oldShow;
91 * TODO(mnaganov): Restore l10n when it will be agreed that it is needed.
93 WebInspector.UIString = function(string)
95 return String.vsprintf(string, Array.prototype.slice.call(arguments, 1));
99 /** Pending WebKit upstream by apavlov). Fixes iframe vs drag problem. */
102 var originalDragStart = WebInspector.elementDragStart;
103 WebInspector.elementDragStart = function(element)
106 var glassPane = document.createElement("div");
107 glassPane.style.cssText = "position:absolute;width:100%;height:100%;opacity:0;z-index:1";
108 glassPane.id = "glass-pane-for-drag";
109 element.parentElement.appendChild(glassPane);
112 originalDragStart.apply(this, arguments);
115 var originalDragEnd = WebInspector.elementDragEnd;
116 WebInspector.elementDragEnd = function()
118 originalDragEnd.apply(this, arguments);
120 var glassPane = document.getElementById("glass-pane-for-drag");
122 glassPane.parentElement.removeChild(glassPane);
128 /////////////////////////////
129 // Chromium theme support. //
130 /////////////////////////////
132 WebInspector.setToolbarColors = function(backgroundColor, color)
134 if (!WebInspector._themeStyleElement) {
135 WebInspector._themeStyleElement = document.createElement("style");
136 document.head.appendChild(WebInspector._themeStyleElement);
138 WebInspector._themeStyleElement.textContent =
140 background-image: none !important;\
141 background-color: " + backgroundColor + " !important;\
145 color: " + color + " !important;\
150 WebInspector.resetToolbarColors = function()
152 if (WebInspector._themeStyleElement)
153 WebInspector._themeStyleElement.textContent = "";
157 ////////////////////////////////////////////////////////
158 // Platform-specific WebInspector extensions support. //
159 ////////////////////////////////////////////////////////
161 WebInspector.platformExtensionAPI = function(tabId)
167 webInspector.inspectedWindow.__proto__.__defineGetter__("tabId", getTabId);
168 chrome = window.chrome || {};
169 chrome.experimental = chrome.experimental || {};
170 chrome.experimental.devtools = chrome.experimental.devtools || {};
172 var properties = Object.getOwnPropertyNames(webInspector);
173 for (var i = 0; i < properties.length; ++i) {
174 var descriptor = Object.getOwnPropertyDescriptor(webInspector, properties[i]);
175 Object.defineProperty(chrome.experimental.devtools, properties[i], descriptor);
179 WebInspector.buildPlatformExtensionAPI = function()
181 return "(" + WebInspector.platformExtensionAPI + ")(" + WebInspector._inspectedTabId + ");";
184 WebInspector.setInspectedTabId = function(tabId)
186 WebInspector._inspectedTabId = tabId;
189 if (WebInspector.InspectorFrontendHostStub) {
190 WebInspector.InspectorFrontendHostStub.prototype.inspectedURLChanged = function(url)
192 document.title = "Developer Tools - " + url;