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

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: review comments addressed. 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 console.timeStamp("Main._presentUI"); 223 console.timeStamp("Main._presentUI");
225 app.presentUI(document); 224 app.presentUI(document);
226 225
227 var toggleSearchNodeAction = WebInspector.actionRegistry.action("element s.toggle-element-search"); 226 var toggleSearchNodeAction = WebInspector.actionRegistry.action("element s.toggle-element-search");
228 // TODO: we should not access actions from other modules. 227 // TODO: we should not access actions from other modules.
229 if (toggleSearchNodeAction) 228 if (toggleSearchNodeAction)
230 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostA PI.Events.EnterInspectElementMode, toggleSearchNodeAction.execute.bind(toggleSea rchNodeAction), this); 229 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostA PI.Events.EnterInspectElementMode, toggleSearchNodeAction.execute.bind(toggleSea rchNodeAction), this);
231 WebInspector.inspectorView.createToolbars(); 230 WebInspector.inspectorView.createToolbars();
232 InspectorFrontendHost.loadCompleted(); 231 InspectorFrontendHost.loadCompleted();
233 232
234 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E vents.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this);
235 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E vents.ReloadInspectedPage, this._reloadInspectedPage, this); 233 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E vents.ReloadInspectedPage, this._reloadInspectedPage, this);
236 234
237 var extensions = self.runtime.extensions(WebInspector.QueryParamHandler) ; 235 var extensions = self.runtime.extensions(WebInspector.QueryParamHandler) ;
238 for (var extension of extensions) { 236 for (var extension of extensions) {
239 var value = Runtime.queryParam(extension.descriptor()["name"]); 237 var value = Runtime.queryParam(extension.descriptor()["name"]);
240 if (value !== null) 238 if (value !== null)
241 extension.instance().then(handleQueryParam.bind(null, value)); 239 extension.instance().then(handleQueryParam.bind(null, value));
242 } 240 }
243 241
244 /** 242 /**
245 * @param {string} value 243 * @param {string} value
246 * @param {!WebInspector.QueryParamHandler} handler 244 * @param {!WebInspector.QueryParamHandler} handler
247 */ 245 */
248 function handleQueryParam(value, handler) 246 function handleQueryParam(value, handler)
249 { 247 {
250 handler.handleQueryParam(value); 248 handler.handleQueryParam(value);
251 } 249 }
252 250
253 this._appUIShown = true; 251 this._appUIShown = true;
254 if (this._fileSystemManagerInitialized) { 252 if (this._fileSystemManagerInitialized) {
255 // Allow UI cycles to repaint prior to creating connection. 253 // Allow UI cycles to repaint prior to creating connection.
256 setTimeout(this._createConnection.bind(this), 0); 254 setTimeout(this._connectAndCreateTarget.bind(this), 0);
257 } 255 }
258 }, 256 },
259 257
260 _didInitializeFileSystemManager: function() 258 _didInitializeFileSystemManager: function()
261 { 259 {
262 this._fileSystemManagerInitialized = true; 260 this._fileSystemManagerInitialized = true;
263 if (this._appUIShown) 261 if (this._appUIShown)
264 this._createConnection(); 262 this._connectAndCreateTarget();
265 }, 263 },
266 264
267 _createConnection: function() 265 _connectAndCreateTarget: function()
268 { 266 {
269 console.timeStamp("Main._createConnection"); 267 console.timeStamp("Main._connectAndCreateTarget");
268 this._createConnection().then(connection => {
269 this._createMainTarget(connection);
270 InspectorFrontendHost.readyForTest();
271 WebInspector.targetManager.setMainTargetFactory(this._recreateMainTa rget.bind(this));
272 // Asynchronously run the extensions.
273 setTimeout(this._lateInitialization.bind(this), 100);
274 });
275 },
270 276
271 if (Runtime.queryParam("ws")) { 277 _recreateMainTarget: function()
272 var ws = "ws://" + Runtime.queryParam("ws"); 278 {
273 WebInspector.WebSocketConnection.Create(ws, this._connectionEstablis hed.bind(this)); 279 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 }, 280 },
284 281
285 /** 282 /**
286 * @param {!InspectorBackendClass.Connection} connection 283 * @return {!Promise<!InspectorBackendClass.Connection>}
287 */ 284 */
288 _connectionEstablished: function(connection) 285 _createConnection: function()
289 { 286 {
290 console.timeStamp("Main._connectionEstablished"); 287 if (Runtime.queryParam("ws")) {
291 this._mainConnection = connection; 288 var ws = "ws://" + Runtime.queryParam("ws");
292 connection.addEventListener(InspectorBackendClass.Connection.Events.Disc onnected, onDisconnected); 289 return WebInspector.WebSocketConnection.Create(ws).then(connection = > {
290 connection.addEventListener(InspectorBackendClass.Connection.Eve nts.Disconnected, onDisconnected);
291 return connection;
292 });
293 }
294
295 return /** @type {!Promise<!InspectorBackendClass.Connection>} */ (Promi se.resolve(InspectorFrontendHost.isHostedMode() ?
296 new WebInspector.StubConnection() : new WebInspector.MainConnection( )));
293 297
294 /** 298 /**
295 * @param {!WebInspector.Event} event 299 * @param {!WebInspector.Event} event
296 */ 300 */
297 function onDisconnected(event) 301 function onDisconnected(event)
298 { 302 {
299 if (WebInspector._disconnectedScreenWithReasonWasShown) 303 if (WebInspector._disconnectedScreenWithReasonWasShown)
300 return; 304 return;
301 WebInspector.RemoteDebuggingTerminatedScreen.show(event.data.reason) ; 305 WebInspector.RemoteDebuggingTerminatedScreen.show(event.data.reason) ;
302 } 306 }
303
304 this._createMainTarget();
305 InspectorFrontendHost.readyForTest();
306 // Asynchronously run the extensions.
307 setTimeout(this._lateInitialization.bind(this), 100);
308 }, 307 },
309 308
310 _createMainTarget: function() 309 /**
310 * @param {!InspectorBackendClass.Connection} connection
311 */
312 _createMainTarget: function(connection)
311 { 313 {
314 console.timeStamp("Main._createMainTarget begin");
dgozman 2016/10/17 17:21:16 time/timeEnd
312 var capabilities = 315 var capabilities =
313 WebInspector.Target.Capability.Browser | WebInspector.Target.Capabil ity.DOM | 316 WebInspector.Target.Capability.Browser | WebInspector.Target.Capabil ity.DOM |
314 WebInspector.Target.Capability.JS | WebInspector.Target.Capability.L og | 317 WebInspector.Target.Capability.JS | WebInspector.Target.Capability.L og |
315 WebInspector.Target.Capability.Network | WebInspector.Target.Capabil ity.Worker; 318 WebInspector.Target.Capability.Network | WebInspector.Target.Capabil ity.Worker;
316 if (Runtime.queryParam("isSharedWorker")) 319 if (Runtime.queryParam("isSharedWorker")) {
317 capabilities = 320 capabilities =
318 WebInspector.Target.Capability.Browser | WebInspector.Target.Cap ability.Log | 321 WebInspector.Target.Capability.Browser | WebInspector.Target.Cap ability.Log |
319 WebInspector.Target.Capability.Network | WebInspector.Target.Cap ability.Worker; 322 WebInspector.Target.Capability.Network | WebInspector.Target.Cap ability.Worker;
320 else if (Runtime.queryParam("v8only")) 323 } else if (Runtime.queryParam("v8only")) {
321 capabilities = WebInspector.Target.Capability.JS; 324 capabilities = WebInspector.Target.Capability.JS;
325 }
322 326
323 this._mainTarget = WebInspector.targetManager.createTarget(WebInspector. UIString("Main"), capabilities, this._mainConnection, null); 327 var target = WebInspector.targetManager.createTarget(WebInspector.UIStri ng("Main"), capabilities, connection, null);
324 this._mainTarget.registerInspectorDispatcher(this); 328 target.registerInspectorDispatcher(new WebInspector.Main.InspectorDomain Dispatcher(target));
325 this._mainTarget.runtimeAgent().runIfWaitingForDebugger(); 329 target.runtimeAgent().runIfWaitingForDebugger();
326 if (this._mainTarget.hasBrowserCapability()) 330 if (target.hasBrowserCapability())
327 this._mainTarget.inspectorAgent().enable(); 331 target.inspectorAgent().enable();
328 console.timeStamp("Main._mainTargetCreated"); 332 if (Runtime.experiments.isEnabled("nodeDebugging"))
333 new WebInspector.RemoteLocationManager(target);
334 console.timeStamp("Main._createMainTarget end");
329 }, 335 },
330 336
331 _lateInitialization: function() 337 _lateInitialization: function()
332 { 338 {
333 console.timeStamp("Main._lateInitialization"); 339 console.timeStamp("Main._lateInitialization");
334 this._registerShortcuts(); 340 this._registerShortcuts();
335 WebInspector.extensionServer.initializeExtensions(); 341 WebInspector.extensionServer.initializeExtensions();
336 if (Runtime.experiments.isEnabled("nodeDebugging"))
337 new WebInspector.RemoteLocationManager(this._mainTarget);
338 }, 342 },
339 343
340 _registerForwardedShortcuts: function() 344 _registerForwardedShortcuts: function()
341 { 345 {
342 /** @const */ var forwardedActions = ["main.toggle-dock", "debugger.togg le-breakpoints-active", "debugger.toggle-pause", "commandMenu.show"]; 346 /** @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); 347 var actionKeys = WebInspector.shortcutRegistry.keysForActions(forwardedA ctions).map(WebInspector.KeyboardShortcut.keyCodeAndModifiersFromKey);
344 InspectorFrontendHost.setWhitelistedShortcuts(JSON.stringify(actionKeys) ); 348 InspectorFrontendHost.setWhitelistedShortcuts(JSON.stringify(actionKeys) );
345 }, 349 },
346 350
347 _registerMessageSinkListener: function() 351 _registerMessageSinkListener: function()
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 533
530 /** 534 /**
531 * @param {!WebInspector.Event} event 535 * @param {!WebInspector.Event} event
532 */ 536 */
533 _reloadInspectedPage: function(event) 537 _reloadInspectedPage: function(event)
534 { 538 {
535 var hard = /** @type {boolean} */ (event.data); 539 var hard = /** @type {boolean} */ (event.data);
536 WebInspector.Main._reloadPage(hard); 540 WebInspector.Main._reloadPage(hard);
537 }, 541 },
538 542
543 _onSuspendStateChanged: function()
544 {
545 var suspended = WebInspector.targetManager.allTargetsSuspended();
546 WebInspector.inspectorView.onSuspendStateChanged(suspended);
547 }
548 }
549
550 /**
551 * @constructor
552 * @implements {InspectorAgent.Dispatcher}
553 * @param {!WebInspector.Target} target
554 */
555 WebInspector.Main.InspectorDomainDispatcher = function(target)
556 {
557 this._target = target;
558 }
559
560 WebInspector.Main.InspectorDomainDispatcher.prototype = {
539 /** 561 /**
540 * @override 562 * @override
541 * @param {string} reason 563 * @param {string} reason
542 */ 564 */
543 detached: function(reason) 565 detached: function(reason)
544 { 566 {
545 WebInspector._disconnectedScreenWithReasonWasShown = true; 567 WebInspector._disconnectedScreenWithReasonWasShown = true;
546 WebInspector.RemoteDebuggingTerminatedScreen.show(reason); 568 WebInspector.RemoteDebuggingTerminatedScreen.show(reason);
547 }, 569 },
548 570
549 /** 571 /**
550 * @override 572 * @override
551 */ 573 */
552 targetCrashed: function() 574 targetCrashed: function()
553 { 575 {
554 var debuggerModel = WebInspector.DebuggerModel.fromTarget(this._mainTarg et); 576 var debuggerModel = WebInspector.DebuggerModel.fromTarget(this._target);
555 if (debuggerModel) 577 if (debuggerModel)
556 WebInspector.TargetCrashedScreen.show(debuggerModel); 578 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 } 579 }
591 } 580 }
592 581
582
593 /** 583 /**
594 * @constructor 584 * @constructor
595 * @implements {WebInspector.ActionDelegate} 585 * @implements {WebInspector.ActionDelegate}
596 */ 586 */
597 WebInspector.Main.ReloadActionDelegate = function() 587 WebInspector.Main.ReloadActionDelegate = function()
598 { 588 {
599 } 589 }
600 590
601 WebInspector.Main.ReloadActionDelegate.prototype = { 591 WebInspector.Main.ReloadActionDelegate.prototype = {
602 /** 592 /**
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 * @override 1107 * @override
1118 * @return {?Element} 1108 * @return {?Element}
1119 */ 1109 */
1120 settingElement: function() 1110 settingElement: function()
1121 { 1111 {
1122 return WebInspector.SettingsUI.createSettingCheckbox(WebInspector.UIStri ng("Show rulers"), WebInspector.moduleSetting("showMetricsRulers")); 1112 return WebInspector.SettingsUI.createSettingCheckbox(WebInspector.UIStri ng("Show rulers"), WebInspector.moduleSetting("showMetricsRulers"));
1123 } 1113 }
1124 } 1114 }
1125 1115
1126 new WebInspector.Main(); 1116 new WebInspector.Main();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698