Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/main/Main.js

Issue 2421913003: DevTools: allow reattaching main target live. (Closed)
Patch Set: link fixed Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). 3 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com).
4 * Copyright (C) 2009 Joseph Pecoraro 4 * Copyright (C) 2009 Joseph Pecoraro
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 12 matching lines...) Expand all
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @implements {InspectorAgent.Dispatcher}
34 * @suppressGlobalPropertiesCheck 33 * @suppressGlobalPropertiesCheck
35 */ 34 */
36 WebInspector.Main = function() 35 WebInspector.Main = function()
37 { 36 {
38 WebInspector.Main._instanceForTest = this; 37 WebInspector.Main._instanceForTest = this;
39 runOnWindowLoad(this._loaded.bind(this)); 38 runOnWindowLoad(this._loaded.bind(this));
40 } 39 }
41 40
42 WebInspector.Main.prototype = { 41 WebInspector.Main.prototype = {
43 _loaded: function() 42 _loaded: function()
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 "securityPanel", 127 "securityPanel",
129 "resolveVariableNames" 128 "resolveVariableNames"
130 ]); 129 ]);
131 }, 130 },
132 131
133 /** 132 /**
134 * @suppressGlobalPropertiesCheck 133 * @suppressGlobalPropertiesCheck
135 */ 134 */
136 _createAppUI: function() 135 _createAppUI: function()
137 { 136 {
138 console.timeStamp("Main._createApp"); 137 console.time("Main._createAppUI");
139 138
140 WebInspector.viewManager = new WebInspector.ViewManager(); 139 WebInspector.viewManager = new WebInspector.ViewManager();
141 140
142 // Request filesystems early, we won't create connections until callback is fired. Things will happen in parallel. 141 // Request filesystems early, we won't create connections until callback is fired. Things will happen in parallel.
143 WebInspector.isolatedFileSystemManager = new WebInspector.IsolatedFileSy stemManager(); 142 WebInspector.isolatedFileSystemManager = new WebInspector.IsolatedFileSy stemManager();
144 WebInspector.isolatedFileSystemManager.waitForFileSystems() 143 WebInspector.isolatedFileSystemManager.waitForFileSystems()
145 .then(this._didInitializeFileSystemManager.bind(this)); 144 .then(this._didInitializeFileSystemManager.bind(this));
146 145
147 var themeSetting = WebInspector.settings.createSetting("uiTheme", "defau lt"); 146 var themeSetting = WebInspector.settings.createSetting("uiTheme", "defau lt");
148 WebInspector.initializeUIUtils(document, themeSetting); 147 WebInspector.initializeUIUtils(document, themeSetting);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 new WebInspector.BackendSettingsSync(); 202 new WebInspector.BackendSettingsSync();
204 WebInspector.domBreakpointsSidebarPane = new WebInspector.DOMBreakpoints SidebarPane(); 203 WebInspector.domBreakpointsSidebarPane = new WebInspector.DOMBreakpoints SidebarPane();
205 204
206 WebInspector.actionRegistry = new WebInspector.ActionRegistry(); 205 WebInspector.actionRegistry = new WebInspector.ActionRegistry();
207 WebInspector.shortcutRegistry = new WebInspector.ShortcutRegistry(WebIns pector.actionRegistry, document); 206 WebInspector.shortcutRegistry = new WebInspector.ShortcutRegistry(WebIns pector.actionRegistry, document);
208 WebInspector.ShortcutsScreen.registerShortcuts(); 207 WebInspector.ShortcutsScreen.registerShortcuts();
209 this._registerForwardedShortcuts(); 208 this._registerForwardedShortcuts();
210 this._registerMessageSinkListener(); 209 this._registerMessageSinkListener();
211 210
212 self.runtime.extension(WebInspector.AppProvider).instance().then(this._s howAppUI.bind(this)); 211 self.runtime.extension(WebInspector.AppProvider).instance().then(this._s howAppUI.bind(this));
212 console.timeEnd("Main._createAppUI");
213 }, 213 },
214 214
215 /** 215 /**
216 * @param {!Object} appProvider 216 * @param {!Object} appProvider
217 * @suppressGlobalPropertiesCheck 217 * @suppressGlobalPropertiesCheck
218 */ 218 */
219 _showAppUI: function(appProvider) 219 _showAppUI: function(appProvider)
220 { 220 {
221 console.time("Main._showAppUI");
221 var app = /** @type {!WebInspector.AppProvider} */ (appProvider).createA pp(); 222 var app = /** @type {!WebInspector.AppProvider} */ (appProvider).createA pp();
222 // It is important to kick controller lifetime after apps are instantiat ed. 223 // It is important to kick controller lifetime after apps are instantiat ed.
223 WebInspector.dockController.initialize(); 224 WebInspector.dockController.initialize();
224 console.timeStamp("Main._presentUI");
225 app.presentUI(document); 225 app.presentUI(document);
226 226
227 var toggleSearchNodeAction = WebInspector.actionRegistry.action("element s.toggle-element-search"); 227 var toggleSearchNodeAction = WebInspector.actionRegistry.action("element s.toggle-element-search");
228 // TODO: we should not access actions from other modules. 228 // TODO: we should not access actions from other modules.
229 if (toggleSearchNodeAction) 229 if (toggleSearchNodeAction)
230 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostA PI.Events.EnterInspectElementMode, toggleSearchNodeAction.execute.bind(toggleSea rchNodeAction), this); 230 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostA PI.Events.EnterInspectElementMode, toggleSearchNodeAction.execute.bind(toggleSea rchNodeAction), this);
231 WebInspector.inspectorView.createToolbars(); 231 WebInspector.inspectorView.createToolbars();
232 InspectorFrontendHost.loadCompleted(); 232 InspectorFrontendHost.loadCompleted();
233 233
234 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E vents.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this);
235 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E vents.ReloadInspectedPage, this._reloadInspectedPage, this); 234 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E vents.ReloadInspectedPage, this._reloadInspectedPage, this);
236 235
237 var extensions = self.runtime.extensions(WebInspector.QueryParamHandler) ; 236 var extensions = self.runtime.extensions(WebInspector.QueryParamHandler) ;
238 for (var extension of extensions) { 237 for (var extension of extensions) {
239 var value = Runtime.queryParam(extension.descriptor()["name"]); 238 var value = Runtime.queryParam(extension.descriptor()["name"]);
240 if (value !== null) 239 if (value !== null)
241 extension.instance().then(handleQueryParam.bind(null, value)); 240 extension.instance().then(handleQueryParam.bind(null, value));
242 } 241 }
243 242
244 /** 243 /**
245 * @param {string} value 244 * @param {string} value
246 * @param {!WebInspector.QueryParamHandler} handler 245 * @param {!WebInspector.QueryParamHandler} handler
247 */ 246 */
248 function handleQueryParam(value, handler) 247 function handleQueryParam(value, handler)
249 { 248 {
250 handler.handleQueryParam(value); 249 handler.handleQueryParam(value);
251 } 250 }
252 251
253 this._appUIShown = true; 252 this._appUIShown = true;
254 if (this._fileSystemManagerInitialized) { 253 if (this._fileSystemManagerInitialized) {
255 // Allow UI cycles to repaint prior to creating connection. 254 // Allow UI cycles to repaint prior to creating connection.
256 setTimeout(this._createConnection.bind(this), 0); 255 setTimeout(this._connectAndCreateTarget.bind(this), 0);
257 } 256 }
257 console.timeEnd("Main._showAppUI");
258 }, 258 },
259 259
260 _didInitializeFileSystemManager: function() 260 _didInitializeFileSystemManager: function()
261 { 261 {
262 this._fileSystemManagerInitialized = true; 262 this._fileSystemManagerInitialized = true;
263 if (this._appUIShown) 263 if (this._appUIShown)
264 this._createConnection(); 264 this._connectAndCreateTarget();
265 }, 265 },
266 266
267 _createConnection: function() 267 _connectAndCreateTarget: function()
268 { 268 {
269 console.timeStamp("Main._createConnection"); 269 console.time("Main._connectAndCreateTarget");
270 this._createConnection().then(connection => {
271 this._createMainTarget(connection);
272 InspectorFrontendHost.readyForTest();
273 WebInspector.targetManager.setMainTargetFactory(this._recreateMainTa rget.bind(this));
274 // Asynchronously run the extensions.
275 console.timeEnd("Main._connectAndCreateTarget");
276 setTimeout(this._lateInitialization.bind(this), 100);
277 });
278 },
270 279
271 if (Runtime.queryParam("ws")) { 280 _recreateMainTarget: function()
272 var ws = "ws://" + Runtime.queryParam("ws"); 281 {
273 WebInspector.WebSocketConnection.Create(ws, this._connectionEstablis hed.bind(this)); 282 this._createConnection().then(this._createMainTarget.bind(this));
274 return;
275 }
276
277 if (!InspectorFrontendHost.isHostedMode()) {
278 this._connectionEstablished(new WebInspector.MainConnection());
279 return;
280 }
281
282 this._connectionEstablished(new WebInspector.StubConnection());
283 }, 283 },
284 284
285 /** 285 /**
286 * @param {!InspectorBackendClass.Connection} connection 286 * @return {!Promise<!InspectorBackendClass.Connection>}
287 */ 287 */
288 _connectionEstablished: function(connection) 288 _createConnection: function()
289 { 289 {
290 console.timeStamp("Main._connectionEstablished"); 290 if (Runtime.queryParam("ws")) {
291 this._mainConnection = connection; 291 var ws = "ws://" + Runtime.queryParam("ws");
292 connection.addEventListener(InspectorBackendClass.Connection.Events.Disc onnected, onDisconnected); 292 return WebInspector.WebSocketConnection.Create(ws).then(connection = > {
293 connection.addEventListener(InspectorBackendClass.Connection.Eve nts.Disconnected, onDisconnected);
294 return connection;
295 });
296 }
297
298 return /** @type {!Promise<!InspectorBackendClass.Connection>} */ (Promi se.resolve(InspectorFrontendHost.isHostedMode() ?
299 new WebInspector.StubConnection() : new WebInspector.MainConnection( )));
293 300
294 /** 301 /**
295 * @param {!WebInspector.Event} event 302 * @param {!WebInspector.Event} event
296 */ 303 */
297 function onDisconnected(event) 304 function onDisconnected(event)
298 { 305 {
299 if (WebInspector._disconnectedScreenWithReasonWasShown) 306 if (WebInspector._disconnectedScreenWithReasonWasShown)
300 return; 307 return;
301 WebInspector.RemoteDebuggingTerminatedScreen.show(event.data.reason) ; 308 WebInspector.RemoteDebuggingTerminatedScreen.show(event.data.reason) ;
302 } 309 }
303
304 this._createMainTarget();
305 InspectorFrontendHost.readyForTest();
306 // Asynchronously run the extensions.
307 setTimeout(this._lateInitialization.bind(this), 100);
308 }, 310 },
309 311
310 _createMainTarget: function() 312 /**
313 * @param {!InspectorBackendClass.Connection} connection
314 */
315 _createMainTarget: function(connection)
311 { 316 {
317 console.time("Main._createMainTarget");
312 var capabilities = 318 var capabilities =
313 WebInspector.Target.Capability.Browser | WebInspector.Target.Capabil ity.DOM | 319 WebInspector.Target.Capability.Browser | WebInspector.Target.Capabil ity.DOM |
314 WebInspector.Target.Capability.JS | WebInspector.Target.Capability.L og | 320 WebInspector.Target.Capability.JS | WebInspector.Target.Capability.L og |
315 WebInspector.Target.Capability.Network | WebInspector.Target.Capabil ity.Worker; 321 WebInspector.Target.Capability.Network | WebInspector.Target.Capabil ity.Worker;
316 if (Runtime.queryParam("isSharedWorker")) 322 if (Runtime.queryParam("isSharedWorker")) {
317 capabilities = 323 capabilities =
318 WebInspector.Target.Capability.Browser | WebInspector.Target.Cap ability.Log | 324 WebInspector.Target.Capability.Browser | WebInspector.Target.Cap ability.Log |
319 WebInspector.Target.Capability.Network | WebInspector.Target.Cap ability.Worker; 325 WebInspector.Target.Capability.Network | WebInspector.Target.Cap ability.Worker;
320 else if (Runtime.queryParam("v8only")) 326 } else if (Runtime.queryParam("v8only")) {
321 capabilities = WebInspector.Target.Capability.JS; 327 capabilities = WebInspector.Target.Capability.JS;
328 }
322 329
323 this._mainTarget = WebInspector.targetManager.createTarget(WebInspector. UIString("Main"), capabilities, this._mainConnection, null); 330 var target = WebInspector.targetManager.createTarget(WebInspector.UIStri ng("Main"), capabilities, connection, null);
324 this._mainTarget.registerInspectorDispatcher(this); 331 target.registerInspectorDispatcher(new WebInspector.Main.InspectorDomain Dispatcher(target));
325 this._mainTarget.runtimeAgent().runIfWaitingForDebugger(); 332 target.runtimeAgent().runIfWaitingForDebugger();
326 if (this._mainTarget.hasBrowserCapability()) 333 if (target.hasBrowserCapability())
327 this._mainTarget.inspectorAgent().enable(); 334 target.inspectorAgent().enable();
328 console.timeStamp("Main._mainTargetCreated"); 335 if (Runtime.experiments.isEnabled("nodeDebugging"))
336 new WebInspector.RemoteLocationManager(target);
337 console.timeEnd("Main._createMainTarget");
329 }, 338 },
330 339
331 _lateInitialization: function() 340 _lateInitialization: function()
332 { 341 {
333 console.timeStamp("Main._lateInitialization"); 342 console.timeStamp("Main._lateInitialization");
334 this._registerShortcuts(); 343 this._registerShortcuts();
335 WebInspector.extensionServer.initializeExtensions(); 344 WebInspector.extensionServer.initializeExtensions();
336 if (Runtime.experiments.isEnabled("nodeDebugging"))
337 new WebInspector.RemoteLocationManager(this._mainTarget);
338 }, 345 },
339 346
340 _registerForwardedShortcuts: function() 347 _registerForwardedShortcuts: function()
341 { 348 {
342 /** @const */ var forwardedActions = ["main.toggle-dock", "debugger.togg le-breakpoints-active", "debugger.toggle-pause", "commandMenu.show"]; 349 /** @const */ var forwardedActions = ["main.toggle-dock", "debugger.togg le-breakpoints-active", "debugger.toggle-pause", "commandMenu.show"];
343 var actionKeys = WebInspector.shortcutRegistry.keysForActions(forwardedA ctions).map(WebInspector.KeyboardShortcut.keyCodeAndModifiersFromKey); 350 var actionKeys = WebInspector.shortcutRegistry.keysForActions(forwardedA ctions).map(WebInspector.KeyboardShortcut.keyCodeAndModifiersFromKey);
344 InspectorFrontendHost.setWhitelistedShortcuts(JSON.stringify(actionKeys) ); 351 InspectorFrontendHost.setWhitelistedShortcuts(JSON.stringify(actionKeys) );
345 }, 352 },
346 353
347 _registerMessageSinkListener: function() 354 _registerMessageSinkListener: function()
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 536
530 /** 537 /**
531 * @param {!WebInspector.Event} event 538 * @param {!WebInspector.Event} event
532 */ 539 */
533 _reloadInspectedPage: function(event) 540 _reloadInspectedPage: function(event)
534 { 541 {
535 var hard = /** @type {boolean} */ (event.data); 542 var hard = /** @type {boolean} */ (event.data);
536 WebInspector.Main._reloadPage(hard); 543 WebInspector.Main._reloadPage(hard);
537 }, 544 },
538 545
546 _onSuspendStateChanged: function()
547 {
548 var suspended = WebInspector.targetManager.allTargetsSuspended();
549 WebInspector.inspectorView.onSuspendStateChanged(suspended);
550 }
551 }
552
553 /**
554 * @constructor
555 * @implements {InspectorAgent.Dispatcher}
556 * @param {!WebInspector.Target} target
557 */
558 WebInspector.Main.InspectorDomainDispatcher = function(target)
559 {
560 this._target = target;
561 }
562
563 WebInspector.Main.InspectorDomainDispatcher.prototype = {
539 /** 564 /**
540 * @override 565 * @override
541 * @param {string} reason 566 * @param {string} reason
542 */ 567 */
543 detached: function(reason) 568 detached: function(reason)
544 { 569 {
545 WebInspector._disconnectedScreenWithReasonWasShown = true; 570 WebInspector._disconnectedScreenWithReasonWasShown = true;
546 WebInspector.RemoteDebuggingTerminatedScreen.show(reason); 571 WebInspector.RemoteDebuggingTerminatedScreen.show(reason);
547 }, 572 },
548 573
549 /** 574 /**
550 * @override 575 * @override
551 */ 576 */
552 targetCrashed: function() 577 targetCrashed: function()
553 { 578 {
554 var debuggerModel = WebInspector.DebuggerModel.fromTarget(this._mainTarg et); 579 var debuggerModel = WebInspector.DebuggerModel.fromTarget(this._target);
555 if (debuggerModel) 580 if (debuggerModel)
556 WebInspector.TargetCrashedScreen.show(debuggerModel); 581 WebInspector.TargetCrashedScreen.show(debuggerModel);
557 },
558
559 _onSuspendStateChanged: function()
560 {
561 var suspended = WebInspector.targetManager.allTargetsSuspended();
562 WebInspector.inspectorView.onSuspendStateChanged(suspended);
563 },
564
565 /**
566 * @param {!WebInspector.Event} event
567 */
568 _evaluateForTestInFrontend: function(event)
569 {
570 if (!InspectorFrontendHost.isUnderTest())
571 return;
572
573 var callId = /** @type {number} */ (event.data["callId"]);
574 var script = /** @type {number} */ (event.data["script"]);
575
576 /**
577 * @suppressGlobalPropertiesCheck
578 */
579 function invokeMethod()
580 {
581 try {
582 script = script + "//# sourceURL=evaluateInWebInspector" + callI d + ".js";
583 window.eval(script);
584 } catch (e) {
585 console.error(e.stack);
586 }
587 }
588
589 this._mainConnection.deprecatedRunAfterPendingDispatches(invokeMethod);
590 } 582 }
591 } 583 }
592 584
585
593 /** 586 /**
594 * @constructor 587 * @constructor
595 * @implements {WebInspector.ActionDelegate} 588 * @implements {WebInspector.ActionDelegate}
596 */ 589 */
597 WebInspector.Main.ReloadActionDelegate = function() 590 WebInspector.Main.ReloadActionDelegate = function()
598 { 591 {
599 } 592 }
600 593
601 WebInspector.Main.ReloadActionDelegate.prototype = { 594 WebInspector.Main.ReloadActionDelegate.prototype = {
602 /** 595 /**
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 * @override 1110 * @override
1118 * @return {?Element} 1111 * @return {?Element}
1119 */ 1112 */
1120 settingElement: function() 1113 settingElement: function()
1121 { 1114 {
1122 return WebInspector.SettingsUI.createSettingCheckbox(WebInspector.UIStri ng("Show rulers"), WebInspector.moduleSetting("showMetricsRulers")); 1115 return WebInspector.SettingsUI.createSettingCheckbox(WebInspector.UIStri ng("Show rulers"), WebInspector.moduleSetting("showMetricsRulers"));
1123 } 1116 }
1124 } 1117 }
1125 1118
1126 new WebInspector.Main(); 1119 new WebInspector.Main();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698