initial import
[vuplus_webkit] / Source / WebKit / chromium / src / js / DevTools.js
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30
31 /**
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.
36  */
37
38 var context = {};  // Used by WebCore's inspector routines.
39
40 (function () {
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;
59 })();
60
61 // Recognize WebP as a valid image mime type.
62 WebInspector.MIMETypes["image/webp"] = {2: true};
63
64 var devtools = devtools || {};
65
66 devtools.domContentLoaded = function()
67 {
68     if (WebInspector.queryParamsObject.toolbarColor && WebInspector.queryParamsObject.textColor)
69         WebInspector.setToolbarColors(WebInspector.queryParamsObject.toolbarColor, WebInspector.queryParamsObject.textColor);
70 }
71 document.addEventListener("DOMContentLoaded", devtools.domContentLoaded, false);
72
73
74 // FIXME: This needs to be upstreamed.
75 (function InterceptProfilesPanelEvents()
76 {
77     var oldShow = WebInspector.ProfilesPanel.prototype.show;
78     WebInspector.ProfilesPanel.prototype.show = function()
79     {
80         this.enableToggleButton.visible = false;
81         oldShow.call(this);
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;
85     };
86 })();
87
88
89 /*
90  * @override
91  * TODO(mnaganov): Restore l10n when it will be agreed that it is needed.
92  */
93 WebInspector.UIString = function(string)
94 {
95     return String.vsprintf(string, Array.prototype.slice.call(arguments, 1));
96 };
97
98
99 /** Pending WebKit upstream by apavlov). Fixes iframe vs drag problem. */
100 (function()
101 {
102     var originalDragStart = WebInspector.elementDragStart;
103     WebInspector.elementDragStart = function(element)
104     {
105         if (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);
110         }
111
112         originalDragStart.apply(this, arguments);
113     };
114
115     var originalDragEnd = WebInspector.elementDragEnd;
116     WebInspector.elementDragEnd = function()
117     {
118         originalDragEnd.apply(this, arguments);
119
120         var glassPane = document.getElementById("glass-pane-for-drag");
121         if (glassPane)
122             glassPane.parentElement.removeChild(glassPane);
123     };
124 })();
125
126
127
128 /////////////////////////////
129 // Chromium theme support. //
130 /////////////////////////////
131
132 WebInspector.setToolbarColors = function(backgroundColor, color)
133 {
134     if (!WebInspector._themeStyleElement) {
135         WebInspector._themeStyleElement = document.createElement("style");
136         document.head.appendChild(WebInspector._themeStyleElement);
137     }
138     WebInspector._themeStyleElement.textContent =
139         "#toolbar {\
140              background-image: none !important;\
141              background-color: " + backgroundColor + " !important;\
142          }\
143          \
144          .toolbar-label {\
145              color: " + color + " !important;\
146              text-shadow: none;\
147          }";
148 }
149
150 WebInspector.resetToolbarColors = function()
151 {
152     if (WebInspector._themeStyleElement)
153         WebInspector._themeStyleElement.textContent = "";
154
155 }
156
157 ////////////////////////////////////////////////////////
158 // Platform-specific WebInspector extensions support. //
159 ////////////////////////////////////////////////////////
160
161 WebInspector.platformExtensionAPI = function(tabId)
162 {
163     function getTabId()
164     {
165         return tabId;
166     }
167     webInspector.inspectedWindow.__proto__.__defineGetter__("tabId", getTabId);
168     chrome = window.chrome || {};
169     chrome.experimental = chrome.experimental || {};
170     chrome.experimental.devtools = chrome.experimental.devtools || {};
171
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);
176     }
177 }
178
179 WebInspector.buildPlatformExtensionAPI = function()
180 {
181     return "(" + WebInspector.platformExtensionAPI + ")(" + WebInspector._inspectedTabId + ");";
182 }
183
184 WebInspector.setInspectedTabId = function(tabId)
185 {
186     WebInspector._inspectedTabId = tabId;
187 }
188
189 if (WebInspector.InspectorFrontendHostStub) {
190     WebInspector.InspectorFrontendHostStub.prototype.inspectedURLChanged = function(url)
191     {
192         document.title = "Developer Tools - " + url;
193     }
194 }