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 = false; 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 })(); 54 55 var devtools = devtools || {}; 56 57 devtools.domContentLoaded = function() 58 { 59 WebInspector.setAttachedWindow(WebInspector.queryParamsObject.docked === "true"); 60 if (WebInspector.queryParamsObject.toolbar_color && WebInspector.queryParamsObject.text_color) 61 WebInspector.setToolbarColors(WebInspector.queryParamsObject.toolbar_color, WebInspector.queryParamsObject.text_color); 62 } 63 document.addEventListener("DOMContentLoaded", devtools.domContentLoaded, false); 64 65 66 // FIXME: This needs to be upstreamed. 67 (function InterceptProfilesPanelEvents() 68 { 69 var oldShow = WebInspector.ProfilesPanel.prototype.show; 70 WebInspector.ProfilesPanel.prototype.show = function() 71 { 72 this.enableToggleButton.visible = false; 73 oldShow.call(this); 74 // Show is called on every show event of a panel, so 75 // we only need to intercept it once. 76 WebInspector.ProfilesPanel.prototype.show = oldShow; 77 }; 78 })(); 79 80 81 /* 82 * @override 83 * TODO(mnaganov): Restore l10n when it will be agreed that it is needed. 84 */ 85 WebInspector.UIString = function(string) 86 { 87 return String.vsprintf(string, Array.prototype.slice.call(arguments, 1)); 88 }; 89 90 91 /* 92 * This label must be kept consistent with that in English.lproj/localizedStrings.js 93 * 94 * http://code.google.com/p/chromium/issues/detail?id=61302 requires a custom label for Chromium, 95 * since its behavior is different. 96 */ 97 WebInspector.openLinkExternallyLabel = function() 98 { 99 return WebInspector.UIString("Open Link in New Tab"); 100 }; 101 102 103 /** Pending WebKit upstream by apavlov). Fixes iframe vs drag problem. */ 104 (function() 105 { 106 var originalDragStart = WebInspector.elementDragStart; 107 WebInspector.elementDragStart = function(element) 108 { 109 if (element) { 110 var glassPane = document.createElement("div"); 111 glassPane.style.cssText = "position:absolute;width:100%;height:100%;opacity:0;z-index:1"; 112 glassPane.id = "glass-pane-for-drag"; 113 element.parentElement.appendChild(glassPane); 114 } 115 116 originalDragStart.apply(this, arguments); 117 }; 118 119 var originalDragEnd = WebInspector.elementDragEnd; 120 WebInspector.elementDragEnd = function() 121 { 122 originalDragEnd.apply(this, arguments); 123 124 var glassPane = document.getElementById("glass-pane-for-drag"); 125 if (glassPane) 126 glassPane.parentElement.removeChild(glassPane); 127 }; 128 })(); 129 130 131 132 ///////////////////////////// 133 // Chromium theme support. // 134 ///////////////////////////// 135 136 WebInspector.setToolbarColors = function(backgroundColor, color) 137 { 138 if (!WebInspector._themeStyleElement) { 139 WebInspector._themeStyleElement = document.createElement("style"); 140 document.head.appendChild(WebInspector._themeStyleElement); 141 } 142 WebInspector._themeStyleElement.textContent = 143 "#toolbar {\ 144 background-image: none !important;\ 145 background-color: " + backgroundColor + " !important;\ 146 }\ 147 \ 148 .toolbar-label {\ 149 color: " + color + " !important;\ 150 text-shadow: none;\ 151 }"; 152 } 153 154 WebInspector.resetToolbarColors = function() 155 { 156 if (WebInspector._themeStyleElement) 157 WebInspector._themeStyleElement.textContent = ""; 158 159 } 160 161 //////////////////////////////////////////////////////// 162 // Platform-specific WebInspector extensions support. // 163 //////////////////////////////////////////////////////// 164 165 WebInspector.platformExtensionAPI = function(tabId) 166 { 167 function getTabId() 168 { 169 return tabId; 170 } 171 webInspector.inspectedWindow.__proto__.__defineGetter__("tabId", getTabId); 172 chrome = window.chrome || {}; 173 chrome.devTools = chrome.devTools || {}; 174 for (var property in webInspector) 175 chrome.devTools[property] = webInspector[property]; 176 } 177 178 WebInspector.buildPlatformExtensionAPI = function() 179 { 180 return "(" + WebInspector.platformExtensionAPI + ")(" + WebInspector._inspectedTabId + ");"; 181 } 182 183 WebInspector.setInspectedTabId = function(tabId) 184 { 185 WebInspector._inspectedTabId = tabId; 186 } 187