OSDN Git Service

am 1fc015f0: (-s ours) am 4741f411: Do not merge.
[android-x86/external-webkit.git] / 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.debuggerAlwaysEnabled = true;
45     Preferences.profilerAlwaysEnabled = true;
46     Preferences.canEditScriptSource = true;
47     Preferences.onlineDetectionEnabled = false;
48     Preferences.nativeInstrumentationEnabled = true;
49     Preferences.fileSystemEnabled = false;
50 })();
51
52 var devtools = devtools || {};
53
54 devtools.domContentLoaded = function()
55 {
56     WebInspector.setAttachedWindow(WebInspector.queryParamsObject.docked === "true");
57     if (WebInspector.queryParamsObject.toolbar_color && WebInspector.queryParamsObject.text_color)
58         WebInspector.setToolbarColors(WebInspector.queryParamsObject.toolbar_color, WebInspector.queryParamsObject.text_color);
59 }
60 document.addEventListener("DOMContentLoaded", devtools.domContentLoaded, false);
61
62
63 // FIXME: This needs to be upstreamed.
64 (function InterceptProfilesPanelEvents()
65 {
66     var oldShow = WebInspector.ProfilesPanel.prototype.show;
67     WebInspector.ProfilesPanel.prototype.show = function()
68     {
69         this.enableToggleButton.visible = false;
70         oldShow.call(this);
71         // Show is called on every show event of a panel, so
72         // we only need to intercept it once.
73         WebInspector.ProfilesPanel.prototype.show = oldShow;
74     };
75 })();
76
77
78 /*
79  * @override
80  * TODO(mnaganov): Restore l10n when it will be agreed that it is needed.
81  */
82 WebInspector.UIString = function(string)
83 {
84     return String.vsprintf(string, Array.prototype.slice.call(arguments, 1));
85 };
86
87
88 /** Pending WebKit upstream by apavlov). Fixes iframe vs drag problem. */
89 (function()
90 {
91     var originalDragStart = WebInspector.elementDragStart;
92     WebInspector.elementDragStart = function(element)
93     {
94         if (element) {
95             var glassPane = document.createElement("div");
96             glassPane.style.cssText = "position:absolute;width:100%;height:100%;opacity:0;z-index:1";
97             glassPane.id = "glass-pane-for-drag";
98             element.parentElement.appendChild(glassPane);
99         }
100
101         originalDragStart.apply(this, arguments);
102     };
103
104     var originalDragEnd = WebInspector.elementDragEnd;
105     WebInspector.elementDragEnd = function()
106     {
107         originalDragEnd.apply(this, arguments);
108
109         var glassPane = document.getElementById("glass-pane-for-drag");
110         if (glassPane)
111             glassPane.parentElement.removeChild(glassPane);
112     };
113 })();
114
115
116
117 ///////////////////////////////////////////
118 // Chromium layout test harness support. //
119 ///////////////////////////////////////////
120
121 WebInspector.runAfterPendingDispatchesQueue = [];
122
123 WebInspector.TestController.prototype.runAfterPendingDispatches = function(callback)
124 {
125     WebInspector.runAfterPendingDispatchesQueue.push(callback);
126 };
127
128 WebInspector.queuesAreEmpty = function()
129 {
130     var copy = this.runAfterPendingDispatchesQueue.slice();
131     this.runAfterPendingDispatchesQueue = [];
132     for (var i = 0; i < copy.length; ++i)
133         copy[i].call(this);
134 };
135
136
137 /////////////////////////////
138 // Chromium theme support. //
139 /////////////////////////////
140
141 WebInspector.setToolbarColors = function(backgroundColor, color)
142 {
143     if (!WebInspector._themeStyleElement) {
144         WebInspector._themeStyleElement = document.createElement("style");
145         document.head.appendChild(WebInspector._themeStyleElement);
146     }
147     WebInspector._themeStyleElement.textContent =
148         "#toolbar {\
149              background-image: none !important;\
150              background-color: " + backgroundColor + " !important;\
151          }\
152          \
153          .toolbar-label {\
154              color: " + color + " !important;\
155              text-shadow: none;\
156          }";
157 }
158
159 WebInspector.resetToolbarColors = function()
160 {
161     if (WebInspector._themeStyleElement)
162         WebInspector._themeStyleElement.textContent = "";
163
164 }
165
166 ////////////////////////////////////////////////////////
167 // Platform-specific WebInspector extensions support. //
168 ////////////////////////////////////////////////////////
169
170 WebInspector.platformExtensionAPI = function(tabId)
171 {
172     function getTabId()
173     {
174         return tabId;
175     }
176     webInspector.inspectedWindow.__proto__.__defineGetter__("tabId", getTabId);
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 }