1/* 2 * Copyright (C) 2009 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 * @param {string} methodName 33 */ 34function dispatchMethodByName(methodName) 35{ 36 var callId = ++lastCallId; 37 var argsArray = Array.prototype.slice.call(arguments, 1); 38 var callback = argsArray[argsArray.length - 1]; 39 if (typeof callback === "function") { 40 argsArray.pop(); 41 InspectorFrontendHost._callbacks[callId] = callback; 42 } 43 44 var message = { "id": callId, "method": methodName }; 45 if (argsArray.length) 46 message.params = argsArray; 47 InspectorFrontendHost.sendMessageToEmbedder(JSON.stringify(message)); 48} 49 50if (!window.InspectorFrontendHost) { 51 52/** 53 * @constructor 54 * @implements {InspectorFrontendHostAPI} 55 */ 56WebInspector.InspectorFrontendHostStub = function() 57{ 58 this.isStub = true; 59} 60 61WebInspector.InspectorFrontendHostStub.prototype = { 62 getSelectionBackgroundColor: function() 63 { 64 return "#6e86ff"; 65 }, 66 67 getSelectionForegroundColor: function() 68 { 69 return "#ffffff"; 70 }, 71 72 platform: function() 73 { 74 var match = navigator.userAgent.match(/Windows NT/); 75 if (match) 76 return "windows"; 77 match = navigator.userAgent.match(/Mac OS X/); 78 if (match) 79 return "mac"; 80 return "linux"; 81 }, 82 83 port: function() 84 { 85 return "unknown"; 86 }, 87 88 bringToFront: function() 89 { 90 this._windowVisible = true; 91 }, 92 93 closeWindow: function() 94 { 95 this._windowVisible = false; 96 }, 97 98 requestSetDockSide: function(side) 99 { 100 InspectorFrontendAPI.setDockSide(side); 101 }, 102 103 /** 104 * Requests inspected page to be placed atop of the inspector frontend 105 * with passed insets from the frontend sides. 106 * @param {number} top 107 * @param {number} left 108 * @param {number} bottom 109 * @param {number} right 110 */ 111 setContentsInsets: function(top, left, bottom, right) 112 { 113 }, 114 115 moveWindowBy: function(x, y) 116 { 117 }, 118 119 setInjectedScriptForOrigin: function(origin, script) 120 { 121 }, 122 123 loaded: function() 124 { 125 }, 126 127 localizedStringsURL: function() 128 { 129 }, 130 131 inspectedURLChanged: function(url) 132 { 133 document.title = WebInspector.UIString(Preferences.applicationTitle, url); 134 }, 135 136 copyText: function(text) 137 { 138 WebInspector.log("Clipboard is not enabled in hosted mode. Please inspect using chrome://inspect", WebInspector.ConsoleMessage.MessageLevel.Error, true); 139 }, 140 141 openInNewTab: function(url) 142 { 143 window.open(url, "_blank"); 144 }, 145 146 save: function(url, content, forceSaveAs) 147 { 148 WebInspector.log("Saving files is not enabled in hosted mode. Please inspect using chrome://inspect", WebInspector.ConsoleMessage.MessageLevel.Error, true); 149 WebInspector.fileManager.canceledSaveURL(url); 150 }, 151 152 append: function(url, content) 153 { 154 WebInspector.log("Saving files is not enabled in hosted mode. Please inspect using chrome://inspect", WebInspector.ConsoleMessage.MessageLevel.Error, true); 155 }, 156 157 close: function(url) 158 { 159 }, 160 161 sendMessageToBackend: function(message) 162 { 163 }, 164 165 sendMessageToEmbedder: function(message) 166 { 167 }, 168 169 recordActionTaken: function(actionCode) 170 { 171 }, 172 173 recordPanelShown: function(panelCode) 174 { 175 }, 176 177 recordSettingChanged: function(settingCode) 178 { 179 }, 180 181 supportsFileSystems: function() 182 { 183 return false; 184 }, 185 186 requestFileSystems: function() 187 { 188 }, 189 190 addFileSystem: function() 191 { 192 }, 193 194 removeFileSystem: function(fileSystemPath) 195 { 196 }, 197 198 isolatedFileSystem: function(fileSystemId, registeredName) 199 { 200 return null; 201 }, 202 203 upgradeDraggedFileSystemPermissions: function(domFileSystem) 204 { 205 }, 206 207 indexPath: function(requestId, fileSystemPath) 208 { 209 }, 210 211 stopIndexing: function(requestId) 212 { 213 }, 214 215 searchInPath: function(requestId, fileSystemPath, query) 216 { 217 }, 218 219 setZoomFactor: function(zoom) 220 { 221 }, 222 223 isUnderTest: function() 224 { 225 return false; 226 } 227} 228 229InspectorFrontendHost = new WebInspector.InspectorFrontendHostStub(); 230 231} else if (InspectorFrontendHost.sendMessageToEmbedder) { 232 // Install message-based handlers with callbacks. 233 var lastCallId = 0; 234 InspectorFrontendHost._callbacks = []; 235 236 /** 237 * @param {number} id 238 * @param {?string} error 239 */ 240 InspectorFrontendHost.embedderMessageAck = function(id, error) 241 { 242 var callback = InspectorFrontendHost._callbacks[id]; 243 delete InspectorFrontendHost._callbacks[id]; 244 if (callback) 245 callback(error); 246 } 247 248 var methodList = [ 249 "addFileSystem", 250 "append", 251 "bringToFront", 252 "closeWindow", 253 "indexPath", 254 "moveWindowBy", 255 "openInNewTab", 256 "removeFileSystem", 257 "requestFileSystems", 258 "requestSetDockSide", 259 "save", 260 "searchInPath", 261 "setContentsInsets", 262 "stopIndexing" 263 ]; 264 265 for (var i = 0; i < methodList.length; ++i) 266 InspectorFrontendHost[methodList[i]] = dispatchMethodByName.bind(null, methodList[i]); 267} 268 269/** 270 * @constructor 271 * @extends {WebInspector.HelpScreen} 272 */ 273WebInspector.RemoteDebuggingTerminatedScreen = function(reason) 274{ 275 WebInspector.HelpScreen.call(this, WebInspector.UIString("Detached from the target")); 276 var p = this.contentElement.createChild("p"); 277 p.classList.add("help-section"); 278 p.createChild("span").textContent = "Remote debugging has been terminated with reason: "; 279 p.createChild("span", "error-message").textContent = reason; 280 p.createChild("br"); 281 p.createChild("span").textContent = "Please re-attach to the new target."; 282} 283 284WebInspector.RemoteDebuggingTerminatedScreen.prototype = { 285 __proto__: WebInspector.HelpScreen.prototype 286} 287