| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | |
| 3 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). | |
| 4 * Copyright (C) 2009 Joseph Pecoraro | |
| 5 * | |
| 6 * Redistribution and use in source and binary forms, with or without | |
| 7 * modification, are permitted provided that the following conditions | |
| 8 * are met: | |
| 9 * | |
| 10 * 1. Redistributions of source code must retain the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer. | |
| 12 * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 * notice, this list of conditions and the following disclaimer in the | |
| 14 * documentation and/or other materials provided with the distribution. | |
| 15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
| 16 * its contributors may be used to endorse or promote products derived | |
| 17 * from this software without specific prior written permission. | |
| 18 * | |
| 19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 /** | |
| 32 * @constructor | |
| 33 * @implements {InspectorAgent.Dispatcher} | |
| 34 */ | |
| 35 WebInspector.Main = function() | |
| 36 { | |
| 37 var boundListener = windowLoaded.bind(this); | |
| 38 | |
| 39 /** | |
| 40 * @this {WebInspector.Main} | |
| 41 */ | |
| 42 function windowLoaded() | |
| 43 { | |
| 44 this._loaded(); | |
| 45 window.removeEventListener("DOMContentLoaded", boundListener, false); | |
| 46 } | |
| 47 window.addEventListener("DOMContentLoaded", boundListener, false); | |
| 48 } | |
| 49 | |
| 50 WebInspector.Main.prototype = { | |
| 51 _registerModules: function() | |
| 52 { | |
| 53 var configuration; | |
| 54 if (!Capabilities.isMainFrontend) { | |
| 55 configuration = ["sources", "timeline", "profiles", "console", "code
mirror"]; | |
| 56 } else { | |
| 57 configuration = ["elements", "network", "sources", "timeline", "prof
iles", "resources", "audits", "console", "codemirror", "extensions"]; | |
| 58 if (WebInspector.experimentsSettings.layersPanel.isEnabled()) | |
| 59 configuration.push("layers"); | |
| 60 } | |
| 61 WebInspector.moduleManager.registerModules(configuration); | |
| 62 }, | |
| 63 | |
| 64 _createGlobalStatusBarItems: function() | |
| 65 { | |
| 66 if (WebInspector.inspectElementModeController) | |
| 67 WebInspector.inspectorView.appendToLeftToolbar(WebInspector.inspectE
lementModeController.toggleSearchButton.element); | |
| 68 | |
| 69 WebInspector.inspectorView.appendToRightToolbar(WebInspector.settingsCon
troller.statusBarItem); | |
| 70 if (WebInspector.dockController.element) | |
| 71 WebInspector.inspectorView.appendToRightToolbar(WebInspector.dockCon
troller.element); | |
| 72 | |
| 73 if (WebInspector._screencastController) | |
| 74 WebInspector.inspectorView.appendToRightToolbar(WebInspector._screen
castController.statusBarItem()); | |
| 75 }, | |
| 76 | |
| 77 _createRootView: function() | |
| 78 { | |
| 79 var rootView = new WebInspector.RootView(); | |
| 80 | |
| 81 this._rootSplitView = new WebInspector.SplitView(false, true, WebInspect
or.dockController.canDock() ? "InspectorView.splitViewState" : "InspectorView.du
mmySplitViewState", 300, 300); | |
| 82 this._rootSplitView.show(rootView.element); | |
| 83 this._rootSplitView.setSidebarElementConstraints(180, 50); | |
| 84 this._rootSplitView.setMainElementConstraints(WebInspector.InspectedPage
Placeholder.Constraints.Width, WebInspector.InspectedPagePlaceholder.Constraints
.Height); | |
| 85 | |
| 86 WebInspector.inspectorView.show(this._rootSplitView.sidebarElement()); | |
| 87 | |
| 88 var inspectedPagePlaceholder = new WebInspector.InspectedPagePlaceholder
(); | |
| 89 inspectedPagePlaceholder.show(this._rootSplitView.mainElement()); | |
| 90 | |
| 91 WebInspector.dockController.addEventListener(WebInspector.DockController
.Events.DockSideChanged, this._updateRootSplitViewOnDockSideChange, this); | |
| 92 this._updateRootSplitViewOnDockSideChange(); | |
| 93 | |
| 94 rootView.show(document.body); | |
| 95 }, | |
| 96 | |
| 97 _updateRootSplitViewOnDockSideChange: function() | |
| 98 { | |
| 99 var dockSide = WebInspector.dockController.dockSide(); | |
| 100 if (dockSide === WebInspector.DockController.State.Undocked) { | |
| 101 this._rootSplitView.toggleResizer(this._rootSplitView.resizerElement
(), false); | |
| 102 this._rootSplitView.toggleResizer(WebInspector.inspectorView.topResi
zerElement(), false); | |
| 103 this._rootSplitView.hideMain(); | |
| 104 return; | |
| 105 } | |
| 106 | |
| 107 this._rootSplitView.setVertical(dockSide === WebInspector.DockController
.State.DockedToLeft || dockSide === WebInspector.DockController.State.DockedToRi
ght); | |
| 108 this._rootSplitView.setSecondIsSidebar(dockSide === WebInspector.DockCon
troller.State.DockedToRight || dockSide === WebInspector.DockController.State.Do
ckedToBottom); | |
| 109 this._rootSplitView.toggleResizer(this._rootSplitView.resizerElement(),
true); | |
| 110 this._rootSplitView.toggleResizer(WebInspector.inspectorView.topResizerE
lement(), dockSide === WebInspector.DockController.State.DockedToBottom); | |
| 111 this._rootSplitView.showBoth(); | |
| 112 }, | |
| 113 | |
| 114 _calculateWorkerInspectorTitle: function() | |
| 115 { | |
| 116 var expression = "location.href"; | |
| 117 if (WebInspector.queryParam("isSharedWorker")) | |
| 118 expression += " + (this.name ? ' (' + this.name + ')' : '')"; | |
| 119 RuntimeAgent.invoke_evaluate({expression:expression, doNotPauseOnExcepti
onsAndMuteConsole:true, returnByValue: true}, evalCallback); | |
| 120 | |
| 121 /** | |
| 122 * @param {?Protocol.Error} error | |
| 123 * @param {!RuntimeAgent.RemoteObject} result | |
| 124 * @param {boolean=} wasThrown | |
| 125 */ | |
| 126 function evalCallback(error, result, wasThrown) | |
| 127 { | |
| 128 if (error || wasThrown) { | |
| 129 console.error(error); | |
| 130 return; | |
| 131 } | |
| 132 InspectorFrontendHost.inspectedURLChanged(result.value); | |
| 133 } | |
| 134 }, | |
| 135 | |
| 136 _loadCompletedForWorkers: function() | |
| 137 { | |
| 138 // Make sure script execution of dedicated worker is resumed and then pa
used | |
| 139 // on the first script statement in case we autoattached to it. | |
| 140 if (WebInspector.queryParam("workerPaused")) { | |
| 141 DebuggerAgent.pause(); | |
| 142 RuntimeAgent.run(calculateTitle.bind(this)); | |
| 143 } else if (!Capabilities.isMainFrontend) { | |
| 144 calculateTitle.call(this); | |
| 145 } | |
| 146 | |
| 147 /** | |
| 148 * @this {WebInspector.Main} | |
| 149 */ | |
| 150 function calculateTitle() | |
| 151 { | |
| 152 this._calculateWorkerInspectorTitle(); | |
| 153 } | |
| 154 }, | |
| 155 | |
| 156 _resetErrorAndWarningCounts: function() | |
| 157 { | |
| 158 WebInspector.inspectorView.setErrorAndWarningCounts(0, 0); | |
| 159 }, | |
| 160 | |
| 161 _updateErrorAndWarningCounts: function() | |
| 162 { | |
| 163 var errors = WebInspector.console.errors; | |
| 164 var warnings = WebInspector.console.warnings; | |
| 165 WebInspector.inspectorView.setErrorAndWarningCounts(errors, warnings); | |
| 166 }, | |
| 167 | |
| 168 _debuggerPaused: function() | |
| 169 { | |
| 170 WebInspector.debuggerModel.removeEventListener(WebInspector.DebuggerMode
l.Events.DebuggerPaused, this._debuggerPaused, this); | |
| 171 WebInspector.inspectorView.showPanel("sources"); | |
| 172 }, | |
| 173 | |
| 174 _loaded: function() | |
| 175 { | |
| 176 if (!InspectorFrontendHost.sendMessageToEmbedder) { | |
| 177 var helpScreen = new WebInspector.HelpScreen(WebInspector.UIString("
Incompatible Chrome version")); | |
| 178 var p = helpScreen.contentElement.createChild("p", "help-section"); | |
| 179 p.textContent = WebInspector.UIString("Please upgrade to a newer Chr
ome version (you might need a Dev or Canary build)."); | |
| 180 helpScreen.showModal(); | |
| 181 return; | |
| 182 } | |
| 183 | |
| 184 InspectorBackend.loadFromJSONIfNeeded("../protocol.json"); | |
| 185 WebInspector.dockController = new WebInspector.DockController(!!WebInspe
ctor.queryParam("can_dock")); | |
| 186 | |
| 187 var onConnectionReady = this._doLoadedDone.bind(this); | |
| 188 | |
| 189 var workerId = WebInspector.queryParam("dedicatedWorkerId"); | |
| 190 if (workerId) { | |
| 191 new WebInspector.WorkerConnection(workerId, onConnectionReady); | |
| 192 return; | |
| 193 } | |
| 194 | |
| 195 var ws; | |
| 196 if (WebInspector.queryParam("ws")) { | |
| 197 ws = "ws://" + WebInspector.queryParam("ws"); | |
| 198 } else if (WebInspector.queryParam("page")) { | |
| 199 var page = WebInspector.queryParam("page"); | |
| 200 var host = WebInspector.queryParam("host") || window.location.host; | |
| 201 ws = "ws://" + host + "/devtools/page/" + page; | |
| 202 } | |
| 203 | |
| 204 if (ws) { | |
| 205 document.body.classList.add("remote"); | |
| 206 new InspectorBackendClass.WebSocketConnection(ws, onConnectionReady)
; | |
| 207 return; | |
| 208 } | |
| 209 | |
| 210 if (!InspectorFrontendHost.isStub) { | |
| 211 new InspectorBackendClass.MainConnection(onConnectionReady); | |
| 212 return; | |
| 213 } | |
| 214 | |
| 215 InspectorFrontendAPI.dispatchQueryParameters(WebInspector.queryParam("di
spatch")); | |
| 216 new InspectorBackendClass.StubConnection(onConnectionReady); | |
| 217 }, | |
| 218 | |
| 219 /** | |
| 220 * @param {!InspectorBackendClass.Connection} connection | |
| 221 */ | |
| 222 _doLoadedDone: function(connection) | |
| 223 { | |
| 224 connection.addEventListener(InspectorBackendClass.Connection.Events.Disc
onnected, onDisconnected); | |
| 225 | |
| 226 /** | |
| 227 * @param {!WebInspector.Event} event | |
| 228 */ | |
| 229 function onDisconnected(event) | |
| 230 { | |
| 231 if (WebInspector._disconnectedScreenWithReasonWasShown) | |
| 232 return; | |
| 233 new WebInspector.RemoteDebuggingTerminatedScreen(event.data.reason).
showModal(); | |
| 234 } | |
| 235 | |
| 236 InspectorBackend.setConnection(connection); | |
| 237 | |
| 238 // Install styles and themes | |
| 239 WebInspector.installPortStyles(); | |
| 240 | |
| 241 if (WebInspector.queryParam("toolbarColor") && WebInspector.queryParam("
textColor")) | |
| 242 WebInspector.setToolbarColors(WebInspector.queryParam("toolbarColor"
), WebInspector.queryParam("textColor")); | |
| 243 | |
| 244 WebInspector.targetManager = new WebInspector.TargetManager(); | |
| 245 WebInspector.targetManager.createTarget(connection, this._doLoadedDoneWi
thCapabilities.bind(this)); | |
| 246 }, | |
| 247 | |
| 248 _doLoadedDoneWithCapabilities: function(mainTarget) | |
| 249 { | |
| 250 new WebInspector.VersionController().updateVersion(); | |
| 251 WebInspector.shortcutsScreen = new WebInspector.ShortcutsScreen(); | |
| 252 this._registerShortcuts(); | |
| 253 | |
| 254 // set order of some sections explicitly | |
| 255 WebInspector.shortcutsScreen.section(WebInspector.UIString("Console")); | |
| 256 WebInspector.shortcutsScreen.section(WebInspector.UIString("Elements Pan
el")); | |
| 257 WebInspector.ShortcutsScreen.registerShortcuts(); | |
| 258 | |
| 259 WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.C
onsoleCleared, this._resetErrorAndWarningCounts, this); | |
| 260 WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.M
essageAdded, this._updateErrorAndWarningCounts, this); | |
| 261 WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.R
epeatCountUpdated, this._updateErrorAndWarningCounts, this); | |
| 262 | |
| 263 WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.E
vents.DebuggerPaused, this._debuggerPaused, this); | |
| 264 WebInspector.networkLog = new WebInspector.NetworkLog(); | |
| 265 | |
| 266 WebInspector.zoomManager = new WebInspector.ZoomManager(); | |
| 267 | |
| 268 WebInspector.advancedSearchController = new WebInspector.AdvancedSearchC
ontroller(); | |
| 269 | |
| 270 InspectorBackend.registerInspectorDispatcher(this); | |
| 271 | |
| 272 WebInspector.isolatedFileSystemManager = new WebInspector.IsolatedFileSy
stemManager(); | |
| 273 WebInspector.isolatedFileSystemDispatcher = new WebInspector.IsolatedFil
eSystemDispatcher(WebInspector.isolatedFileSystemManager); | |
| 274 WebInspector.workspace = new WebInspector.Workspace(WebInspector.isolate
dFileSystemManager.mapping()); | |
| 275 | |
| 276 WebInspector.cssModel = new WebInspector.CSSStyleModel(WebInspector.work
space); | |
| 277 WebInspector.timelineManager = new WebInspector.TimelineManager(); | |
| 278 WebInspector.tracingAgent = new WebInspector.TracingAgent(); | |
| 279 | |
| 280 if (Capabilities.isMainFrontend) { | |
| 281 WebInspector.inspectElementModeController = new WebInspector.Inspect
ElementModeController(); | |
| 282 WebInspector.workerFrontendManager = new WebInspector.WorkerFrontend
Manager(); | |
| 283 } else { | |
| 284 mainTarget.workerManager.addEventListener(WebInspector.WorkerManager
.Events.WorkerDisconnected, onWorkerDisconnected); | |
| 285 } | |
| 286 | |
| 287 function onWorkerDisconnected() | |
| 288 { | |
| 289 var screen = new WebInspector.WorkerTerminatedScreen(); | |
| 290 var listener = hideScreen.bind(null, screen); | |
| 291 mainTarget.debuggerModel.addEventListener(WebInspector.DebuggerModel
.Events.GlobalObjectCleared, listener); | |
| 292 | |
| 293 /** | |
| 294 * @param {!WebInspector.WorkerTerminatedScreen} screen | |
| 295 */ | |
| 296 function hideScreen(screen) | |
| 297 { | |
| 298 mainTarget.debuggerModel.removeEventListener(WebInspector.Debugg
erModel.Events.GlobalObjectCleared, listener); | |
| 299 screen.hide(); | |
| 300 } | |
| 301 | |
| 302 screen.showModal(); | |
| 303 } | |
| 304 | |
| 305 WebInspector.settingsController = new WebInspector.SettingsController(); | |
| 306 | |
| 307 WebInspector.domBreakpointsSidebarPane = new WebInspector.DOMBreakpoints
SidebarPane(); | |
| 308 | |
| 309 var autoselectPanel = WebInspector.UIString("a panel chosen automaticall
y"); | |
| 310 var openAnchorLocationSetting = WebInspector.settings.createSetting("ope
nLinkHandler", autoselectPanel); | |
| 311 WebInspector.openAnchorLocationRegistry = new WebInspector.HandlerRegist
ry(openAnchorLocationSetting); | |
| 312 WebInspector.openAnchorLocationRegistry.registerHandler(autoselectPanel,
function() { return false; }); | |
| 313 WebInspector.Linkifier.setLinkHandler(new WebInspector.HandlerRegistry.L
inkHandler()); | |
| 314 | |
| 315 new WebInspector.WorkspaceController(WebInspector.workspace); | |
| 316 | |
| 317 WebInspector.fileSystemWorkspaceProvider = new WebInspector.FileSystemWo
rkspaceProvider(WebInspector.isolatedFileSystemManager, WebInspector.workspace); | |
| 318 | |
| 319 WebInspector.networkWorkspaceProvider = new WebInspector.SimpleWorkspace
Provider(WebInspector.workspace, WebInspector.projectTypes.Network); | |
| 320 new WebInspector.NetworkUISourceCodeProvider(WebInspector.networkWorkspa
ceProvider, WebInspector.workspace); | |
| 321 | |
| 322 WebInspector.breakpointManager = new WebInspector.BreakpointManager(WebI
nspector.settings.breakpoints, WebInspector.debuggerModel, WebInspector.workspac
e); | |
| 323 | |
| 324 WebInspector.scriptSnippetModel = new WebInspector.ScriptSnippetModel(We
bInspector.workspace); | |
| 325 | |
| 326 WebInspector.overridesSupport = new WebInspector.OverridesSupport(); | |
| 327 WebInspector.overridesSupport.applyInitialOverrides(); | |
| 328 | |
| 329 new WebInspector.DebuggerScriptMapping(WebInspector.debuggerModel, WebIn
spector.workspace, WebInspector.networkWorkspaceProvider); | |
| 330 WebInspector.liveEditSupport = new WebInspector.LiveEditSupport(WebInspe
ctor.workspace); | |
| 331 new WebInspector.CSSStyleSheetMapping(WebInspector.cssModel, WebInspecto
r.workspace, WebInspector.networkWorkspaceProvider); | |
| 332 new WebInspector.PresentationConsoleMessageHelper(WebInspector.workspace
); | |
| 333 | |
| 334 // Create settings before loading modules. | |
| 335 WebInspector.settings.initializeBackendSettings(); | |
| 336 | |
| 337 this._registerModules(); | |
| 338 | |
| 339 WebInspector.panels = {}; | |
| 340 WebInspector.inspectorView = new WebInspector.InspectorView(); | |
| 341 // Screencast controller creates a root view itself. | |
| 342 if (mainTarget.canScreencast) | |
| 343 this._screencastController = new WebInspector.ScreencastController()
; | |
| 344 else | |
| 345 this._createRootView(); | |
| 346 this._createGlobalStatusBarItems(); | |
| 347 | |
| 348 this._addMainEventListeners(document); | |
| 349 | |
| 350 function onResize() | |
| 351 { | |
| 352 if (WebInspector.settingsController) | |
| 353 WebInspector.settingsController.resize(); | |
| 354 } | |
| 355 window.addEventListener("resize", onResize, true); | |
| 356 | |
| 357 var errorWarningCount = document.getElementById("error-warning-count"); | |
| 358 | |
| 359 function showConsole() | |
| 360 { | |
| 361 WebInspector.console.show(); | |
| 362 } | |
| 363 errorWarningCount.addEventListener("click", showConsole, false); | |
| 364 this._updateErrorAndWarningCounts(); | |
| 365 | |
| 366 WebInspector.extensionServerProxy.setFrontendReady(); | |
| 367 | |
| 368 WebInspector.console.enableAgent(); | |
| 369 | |
| 370 WebInspector.databaseModel = new WebInspector.DatabaseModel(); | |
| 371 WebInspector.domStorageModel = new WebInspector.DOMStorageModel(); | |
| 372 WebInspector.cpuProfilerModel = new WebInspector.CPUProfilerModel(); | |
| 373 | |
| 374 InspectorAgent.enable(inspectorAgentEnableCallback.bind(this)); | |
| 375 | |
| 376 /** | |
| 377 * @this {WebInspector.Main} | |
| 378 */ | |
| 379 function inspectorAgentEnableCallback() | |
| 380 { | |
| 381 WebInspector.inspectorView.showInitialPanel(); | |
| 382 | |
| 383 if (WebInspector.overridesSupport.hasActiveOverrides()) { | |
| 384 if (!WebInspector.settings.showEmulationViewInDrawer.get()) | |
| 385 WebInspector.settings.showEmulationViewInDrawer.set(true); | |
| 386 WebInspector.inspectorView.showViewInDrawer("emulation", true); | |
| 387 } | |
| 388 | |
| 389 if (WebInspector.settings.showPaintRects.get() || WebInspector.setti
ngs.showDebugBorders.get() || WebInspector.settings.continuousPainting.get() || | |
| 390 WebInspector.settings.showFPSCounter.get() || WebInspector.s
ettings.showScrollBottleneckRects.get()) { | |
| 391 WebInspector.settings.showRenderingViewInDrawer.set(true); | |
| 392 } | |
| 393 | |
| 394 WebInspector.settings.showMetricsRulers.addChangeListener(showRulers
Changed); | |
| 395 function showRulersChanged() | |
| 396 { | |
| 397 PageAgent.setShowViewportSizeOnResize(true, WebInspector.setting
s.showMetricsRulers.get()); | |
| 398 } | |
| 399 showRulersChanged(); | |
| 400 | |
| 401 if (this._screencastController) | |
| 402 this._screencastController.initialize(); | |
| 403 } | |
| 404 | |
| 405 this._loadCompletedForWorkers(); | |
| 406 InspectorFrontendAPI.loadCompleted(); | |
| 407 WebInspector.notifications.dispatchEventToListeners(WebInspector.Notific
ationService.Events.InspectorLoaded); | |
| 408 }, | |
| 409 | |
| 410 _documentClick: function(event) | |
| 411 { | |
| 412 var anchor = event.target.enclosingNodeOrSelfWithNodeName("a"); | |
| 413 if (!anchor || !anchor.href || (anchor.target === "_blank")) | |
| 414 return; | |
| 415 | |
| 416 // Prevent the link from navigating, since we don't do any navigation by
following links normally. | |
| 417 event.consume(true); | |
| 418 | |
| 419 function followLink() | |
| 420 { | |
| 421 if (WebInspector.isBeingEdited(event.target)) | |
| 422 return; | |
| 423 if (WebInspector.openAnchorLocationRegistry.dispatch({ url: anchor.h
ref, lineNumber: anchor.lineNumber})) | |
| 424 return; | |
| 425 | |
| 426 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(anchor.
href); | |
| 427 if (uiSourceCode) { | |
| 428 WebInspector.Revealer.reveal(new WebInspector.UILocation(uiSourc
eCode, anchor.lineNumber || 0, anchor.columnNumber || 0)); | |
| 429 return; | |
| 430 } | |
| 431 | |
| 432 var resource = WebInspector.resourceForURL(anchor.href); | |
| 433 if (resource) { | |
| 434 WebInspector.Revealer.reveal(resource); | |
| 435 return; | |
| 436 } | |
| 437 | |
| 438 var request = WebInspector.networkLog.requestForURL(anchor.href); | |
| 439 if (request) { | |
| 440 WebInspector.Revealer.reveal(request); | |
| 441 return; | |
| 442 } | |
| 443 InspectorFrontendHost.openInNewTab(anchor.href); | |
| 444 } | |
| 445 | |
| 446 if (WebInspector.followLinkTimeout) | |
| 447 clearTimeout(WebInspector.followLinkTimeout); | |
| 448 | |
| 449 if (anchor.preventFollowOnDoubleClick) { | |
| 450 // Start a timeout if this is the first click, if the timeout is can
celed | |
| 451 // before it fires, then a double clicked happened or another link w
as clicked. | |
| 452 if (event.detail === 1) | |
| 453 WebInspector.followLinkTimeout = setTimeout(followLink, 333); | |
| 454 return; | |
| 455 } | |
| 456 | |
| 457 followLink(); | |
| 458 }, | |
| 459 | |
| 460 _registerShortcuts: function() | |
| 461 { | |
| 462 var shortcut = WebInspector.KeyboardShortcut; | |
| 463 var section = WebInspector.shortcutsScreen.section(WebInspector.UIString
("All Panels")); | |
| 464 var keys = [ | |
| 465 shortcut.makeDescriptor("[", shortcut.Modifiers.CtrlOrMeta), | |
| 466 shortcut.makeDescriptor("]", shortcut.Modifiers.CtrlOrMeta) | |
| 467 ]; | |
| 468 section.addRelatedKeys(keys, WebInspector.UIString("Go to the panel to t
he left/right")); | |
| 469 | |
| 470 keys = [ | |
| 471 shortcut.makeDescriptor("[", shortcut.Modifiers.CtrlOrMeta | shortcu
t.Modifiers.Alt), | |
| 472 shortcut.makeDescriptor("]", shortcut.Modifiers.CtrlOrMeta | shortcu
t.Modifiers.Alt) | |
| 473 ]; | |
| 474 section.addRelatedKeys(keys, WebInspector.UIString("Go back/forward in p
anel history")); | |
| 475 | |
| 476 var toggleConsoleLabel = WebInspector.UIString("Show console"); | |
| 477 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Tilde, shortcut.Mod
ifiers.Ctrl), toggleConsoleLabel); | |
| 478 var doNotOpenDrawerOnEsc = WebInspector.experimentsSettings.doNotOpenDra
werOnEsc.isEnabled(); | |
| 479 var toggleDrawerLabel = doNotOpenDrawerOnEsc ? WebInspector.UIString("Hi
de drawer") : WebInspector.UIString("Toggle drawer"); | |
| 480 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Esc), toggleDrawerL
abel); | |
| 481 section.addKey(shortcut.makeDescriptor("f", shortcut.Modifiers.CtrlOrMet
a), WebInspector.UIString("Search")); | |
| 482 | |
| 483 var advancedSearchShortcut = WebInspector.AdvancedSearchController.creat
eShortcut(); | |
| 484 section.addKey(advancedSearchShortcut, WebInspector.UIString("Search acr
oss all sources")); | |
| 485 | |
| 486 var inspectElementModeShortcut = WebInspector.InspectElementModeControll
er.createShortcut(); | |
| 487 section.addKey(inspectElementModeShortcut, WebInspector.UIString("Select
node to inspect")); | |
| 488 | |
| 489 var openResourceShortcut = WebInspector.KeyboardShortcut.makeDescriptor(
"o", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta); | |
| 490 section.addKey(openResourceShortcut, WebInspector.UIString("Go to source
")); | |
| 491 | |
| 492 if (WebInspector.isMac()) { | |
| 493 keys = [ | |
| 494 shortcut.makeDescriptor("g", shortcut.Modifiers.Meta), | |
| 495 shortcut.makeDescriptor("g", shortcut.Modifiers.Meta | shortcut.
Modifiers.Shift) | |
| 496 ]; | |
| 497 section.addRelatedKeys(keys, WebInspector.UIString("Find next/previo
us")); | |
| 498 } | |
| 499 }, | |
| 500 | |
| 501 /** | |
| 502 * @param {?Event} event | |
| 503 * @return {boolean} | |
| 504 */ | |
| 505 _handleZoomEvent: function(event) | |
| 506 { | |
| 507 switch (event.keyCode) { | |
| 508 case 107: // + | |
| 509 case 187: // + | |
| 510 InspectorFrontendHost.zoomIn(); | |
| 511 return true; | |
| 512 case 109: // - | |
| 513 case 189: // - | |
| 514 InspectorFrontendHost.zoomOut(); | |
| 515 return true; | |
| 516 case 48: // 0 | |
| 517 case 96: // Numpad 0 | |
| 518 // Zoom reset shortcut does not allow "Shift" when handled by the br
owser. | |
| 519 if (!event.shiftKey) { | |
| 520 InspectorFrontendHost.resetZoom(); | |
| 521 return true; | |
| 522 } | |
| 523 break; | |
| 524 } | |
| 525 return false; | |
| 526 }, | |
| 527 | |
| 528 _postDocumentKeyDown: function(event) | |
| 529 { | |
| 530 if (event.handled) | |
| 531 return; | |
| 532 | |
| 533 if (WebInspector.inspectorView.currentPanel()) { | |
| 534 WebInspector.inspectorView.currentPanel().handleShortcut(event); | |
| 535 if (event.handled) { | |
| 536 event.consume(true); | |
| 537 return; | |
| 538 } | |
| 539 } | |
| 540 | |
| 541 if (WebInspector.advancedSearchController.handleShortcut(event)) | |
| 542 return; | |
| 543 if (WebInspector.inspectElementModeController && WebInspector.inspectEle
mentModeController.handleShortcut(event)) | |
| 544 return; | |
| 545 | |
| 546 switch (event.keyIdentifier) { | |
| 547 case "U+004F": // O key | |
| 548 case "U+0050": // P key | |
| 549 if (!event.shiftKey && !event.altKey && WebInspector.KeyboardSho
rtcut.eventHasCtrlOrMeta(event)) { | |
| 550 // FIXME: Dependency violation. Introduce pluggable global s
hortcuts. | |
| 551 /** @type {!WebInspector.SourcesPanel} */ (WebInspector.insp
ectorView.showPanel("sources")).showGoToSourceDialog(); | |
| 552 event.consume(true); | |
| 553 } | |
| 554 break; | |
| 555 case "U+0052": // R key | |
| 556 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event)) { | |
| 557 WebInspector.debuggerModel.skipAllPauses(true, true); | |
| 558 WebInspector.resourceTreeModel.reloadPage(event.shiftKey); | |
| 559 event.consume(true); | |
| 560 } | |
| 561 if (window.DEBUG && event.altKey) { | |
| 562 WebInspector.reload(); | |
| 563 return; | |
| 564 } | |
| 565 break; | |
| 566 case "F5": | |
| 567 if (!WebInspector.isMac()) { | |
| 568 WebInspector.resourceTreeModel.reloadPage(event.ctrlKey || e
vent.shiftKey); | |
| 569 event.consume(true); | |
| 570 } | |
| 571 break; | |
| 572 } | |
| 573 | |
| 574 var isValidZoomShortcut = WebInspector.KeyboardShortcut.eventHasCtrlOrMe
ta(event) && | |
| 575 !event.altKey && | |
| 576 !InspectorFrontendHost.isStub; | |
| 577 if (isValidZoomShortcut && this._handleZoomEvent(event)) { | |
| 578 event.consume(true); | |
| 579 return; | |
| 580 } | |
| 581 | |
| 582 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.F1.code || | |
| 583 (event.keyCode === WebInspector.KeyboardShortcut.Keys.QuestionMark.c
ode && event.shiftKey && (!WebInspector.isBeingEdited(event.target) || event.met
aKey))) { | |
| 584 WebInspector.settingsController.showSettingsScreen(WebInspector.Sett
ingsScreen.Tabs.General); | |
| 585 event.consume(true); | |
| 586 return; | |
| 587 } | |
| 588 | |
| 589 var Esc = "U+001B"; | |
| 590 var doNotOpenDrawerOnEsc = WebInspector.experimentsSettings.doNotOpenDra
werOnEsc.isEnabled(); | |
| 591 if (event.keyIdentifier === Esc) { | |
| 592 if (WebInspector.inspectorView.drawerVisible()) | |
| 593 WebInspector.inspectorView.closeDrawer(); | |
| 594 else if (!doNotOpenDrawerOnEsc) | |
| 595 WebInspector.inspectorView.showDrawer(); | |
| 596 } | |
| 597 | |
| 598 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Tilde.code && e
vent.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) | |
| 599 WebInspector.console.show(); | |
| 600 }, | |
| 601 | |
| 602 _documentCanCopy: function(event) | |
| 603 { | |
| 604 if (WebInspector.inspectorView.currentPanel() && WebInspector.inspectorV
iew.currentPanel()["handleCopyEvent"]) | |
| 605 event.preventDefault(); | |
| 606 }, | |
| 607 | |
| 608 _documentCopy: function(event) | |
| 609 { | |
| 610 if (WebInspector.inspectorView.currentPanel() && WebInspector.inspectorV
iew.currentPanel()["handleCopyEvent"]) | |
| 611 WebInspector.inspectorView.currentPanel()["handleCopyEvent"](event); | |
| 612 }, | |
| 613 | |
| 614 _contextMenuEventFired: function(event) | |
| 615 { | |
| 616 if (event.handled || event.target.classList.contains("popup-glasspane")) | |
| 617 event.preventDefault(); | |
| 618 }, | |
| 619 | |
| 620 _inspectNodeRequested: function(event) | |
| 621 { | |
| 622 this._updateFocusedNode(event.data); | |
| 623 }, | |
| 624 | |
| 625 _updateFocusedNode: function(nodeId) | |
| 626 { | |
| 627 var node = WebInspector.domAgent.nodeForId(nodeId); | |
| 628 console.assert(node); | |
| 629 WebInspector.Revealer.reveal(node); | |
| 630 }, | |
| 631 | |
| 632 _addMainEventListeners: function(doc) | |
| 633 { | |
| 634 doc.addEventListener("keydown", this._postDocumentKeyDown.bind(this), fa
lse); | |
| 635 doc.addEventListener("beforecopy", this._documentCanCopy.bind(this), tru
e); | |
| 636 doc.addEventListener("copy", this._documentCopy.bind(this), false); | |
| 637 doc.addEventListener("contextmenu", this._contextMenuEventFired.bind(thi
s), true); | |
| 638 doc.addEventListener("click", this._documentClick.bind(this), false); | |
| 639 }, | |
| 640 | |
| 641 /** | |
| 642 * @override | |
| 643 * @param {!RuntimeAgent.RemoteObject} payload | |
| 644 * @param {!Object=} hints | |
| 645 */ | |
| 646 inspect: function(payload, hints) | |
| 647 { | |
| 648 var object = WebInspector.RemoteObject.fromPayload(payload); | |
| 649 if (object.subtype === "node") { | |
| 650 object.pushNodeToFrontend(callback); | |
| 651 var elementsPanel = /** @type {!WebInspector.ElementsPanel} */ (WebI
nspector.inspectorView.panel("elements")); | |
| 652 elementsPanel.omitDefaultSelection(); | |
| 653 WebInspector.inspectorView.setCurrentPanel(elementsPanel); | |
| 654 return; | |
| 655 } | |
| 656 | |
| 657 function callback(nodeId) | |
| 658 { | |
| 659 elementsPanel.stopOmittingDefaultSelection(); | |
| 660 WebInspector.Revealer.reveal(WebInspector.domAgent.nodeForId(nodeId)
); | |
| 661 if (!WebInspector.inspectorView.drawerVisible() && !WebInspector._no
tFirstInspectElement) | |
| 662 InspectorFrontendHost.inspectElementCompleted(); | |
| 663 WebInspector._notFirstInspectElement = true; | |
| 664 object.release(); | |
| 665 } | |
| 666 | |
| 667 if (object.type === "function") { | |
| 668 /** | |
| 669 * @param {?Protocol.Error} error | |
| 670 * @param {!DebuggerAgent.FunctionDetails} response | |
| 671 */ | |
| 672 DebuggerAgent.getFunctionDetails(object.objectId, didGetDetails); | |
| 673 return; | |
| 674 } | |
| 675 | |
| 676 function didGetDetails(error, response) | |
| 677 { | |
| 678 object.release(); | |
| 679 | |
| 680 if (error) { | |
| 681 console.error(error); | |
| 682 return; | |
| 683 } | |
| 684 | |
| 685 var uiLocation = WebInspector.debuggerModel.rawLocationToUILocation(
response.location); | |
| 686 if (!uiLocation) | |
| 687 return; | |
| 688 | |
| 689 // FIXME: Dependency violation. | |
| 690 /** @type {!WebInspector.SourcesPanel} */ (WebInspector.inspectorVie
w.panel("sources")).showUILocation(uiLocation, true); | |
| 691 } | |
| 692 | |
| 693 if (hints.copyToClipboard) | |
| 694 InspectorFrontendHost.copyText(object.value); | |
| 695 object.release(); | |
| 696 }, | |
| 697 | |
| 698 /** | |
| 699 * @override | |
| 700 * @param {string} reason | |
| 701 */ | |
| 702 detached: function(reason) | |
| 703 { | |
| 704 WebInspector._disconnectedScreenWithReasonWasShown = true; | |
| 705 new WebInspector.RemoteDebuggingTerminatedScreen(reason).showModal(); | |
| 706 }, | |
| 707 | |
| 708 /** | |
| 709 * @override | |
| 710 */ | |
| 711 targetCrashed: function() | |
| 712 { | |
| 713 (new WebInspector.HelpScreenUntilReload( | |
| 714 WebInspector.UIString("Inspected target crashed"), | |
| 715 WebInspector.UIString("Inspected target has crashed. Once it reloads
we will attach to it automatically."))).showModal(); | |
| 716 }, | |
| 717 | |
| 718 /** | |
| 719 * @override | |
| 720 * @param {number} callId | |
| 721 * @param {string} script | |
| 722 */ | |
| 723 evaluateForTestInFrontend: function(callId, script) | |
| 724 { | |
| 725 WebInspector.evaluateForTestInFrontend(callId, script); | |
| 726 } | |
| 727 } | |
| 728 | |
| 729 WebInspector.reload = function() | |
| 730 { | |
| 731 InspectorAgent.reset(); | |
| 732 window.location.reload(); | |
| 733 } | |
| 734 | |
| 735 new WebInspector.Main(); | |
| 736 | |
| 737 window.DEBUG = true; | |
| OLD | NEW |