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

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: same 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 /**
(...skipping 18 matching lines...) Expand all
263 if (this._appUIShown) 261 if (this._appUIShown)
264 this._createConnection(); 262 this._createConnection();
265 }, 263 },
266 264
267 _createConnection: function() 265 _createConnection: function()
268 { 266 {
269 console.timeStamp("Main._createConnection"); 267 console.timeStamp("Main._createConnection");
270 268
271 if (Runtime.queryParam("ws")) { 269 if (Runtime.queryParam("ws")) {
272 var ws = "ws://" + Runtime.queryParam("ws"); 270 var ws = "ws://" + Runtime.queryParam("ws");
273 WebInspector.WebSocketConnection.Create(ws, this._connectionEstablis hed.bind(this)); 271 WebInspector.WebSocketConnection.Create(ws, connection => {
272 connection.addEventListener(InspectorBackendClass.Connection.Eve nts.Disconnected, onDisconnected);
273 this._connectionEstablished(connection);
274 });
274 return; 275 return;
275 } 276 }
276 277
277 if (!InspectorFrontendHost.isHostedMode()) { 278 if (!InspectorFrontendHost.isHostedMode()) {
278 this._connectionEstablished(new WebInspector.MainConnection()); 279 this._connectionEstablished(new WebInspector.MainConnection());
280 WebInspector.targetManager.setMainTargetFactory(this._createMainTarg etOverMainConnection.bind(this));
279 return; 281 return;
280 } 282 }
281 283
282 this._connectionEstablished(new WebInspector.StubConnection()); 284 this._connectionEstablished(new WebInspector.StubConnection());
283 },
284
285 /**
286 * @param {!InspectorBackendClass.Connection} connection
287 */
288 _connectionEstablished: function(connection)
289 {
290 console.timeStamp("Main._connectionEstablished");
291 this._mainConnection = connection;
292 connection.addEventListener(InspectorBackendClass.Connection.Events.Disc onnected, onDisconnected);
293 285
294 /** 286 /**
295 * @param {!WebInspector.Event} event 287 * @param {!WebInspector.Event} event
296 */ 288 */
297 function onDisconnected(event) 289 function onDisconnected(event)
298 { 290 {
299 if (WebInspector._disconnectedScreenWithReasonWasShown) 291 if (WebInspector._disconnectedScreenWithReasonWasShown)
300 return; 292 return;
301 WebInspector.RemoteDebuggingTerminatedScreen.show(event.data.reason) ; 293 WebInspector.RemoteDebuggingTerminatedScreen.show(event.data.reason) ;
302 } 294 }
295 },
303 296
304 this._createMainTarget(); 297 _createMainTargetOverMainConnection()
298 {
299 this._createMainTarget(new WebInspector.MainConnection());
300 },
301
302 /**
303 * @param {!InspectorBackendClass.Connection} connection
304 */
305 _connectionEstablished: function(connection)
306 {
307 console.timeStamp("Main._connectionEstablished");
308
309 this._createMainTarget(connection);
305 InspectorFrontendHost.readyForTest(); 310 InspectorFrontendHost.readyForTest();
306 // Asynchronously run the extensions. 311 // Asynchronously run the extensions.
307 setTimeout(this._lateInitialization.bind(this), 100); 312 setTimeout(this._lateInitialization.bind(this), 100);
308 }, 313 },
309 314
310 _createMainTarget: function() 315 /**
316 * @param {!InspectorBackendClass.Connection} connection
317 */
318 _createMainTarget: function(connection)
311 { 319 {
312 var capabilities = 320 var capabilities =
313 WebInspector.Target.Capability.Browser | WebInspector.Target.Capabil ity.DOM | 321 WebInspector.Target.Capability.Browser | WebInspector.Target.Capabil ity.DOM |
314 WebInspector.Target.Capability.JS | WebInspector.Target.Capability.L og | 322 WebInspector.Target.Capability.JS | WebInspector.Target.Capability.L og |
315 WebInspector.Target.Capability.Network | WebInspector.Target.Capabil ity.Worker; 323 WebInspector.Target.Capability.Network | WebInspector.Target.Capabil ity.Worker;
316 if (Runtime.queryParam("isSharedWorker")) 324 if (Runtime.queryParam("isSharedWorker")) {
317 capabilities = 325 capabilities =
318 WebInspector.Target.Capability.Browser | WebInspector.Target.Cap ability.Log | 326 WebInspector.Target.Capability.Browser | WebInspector.Target.Cap ability.Log |
319 WebInspector.Target.Capability.Network | WebInspector.Target.Cap ability.Worker; 327 WebInspector.Target.Capability.Network | WebInspector.Target.Cap ability.Worker;
320 else if (Runtime.queryParam("v8only")) 328 } else if (Runtime.queryParam("v8only")) {
321 capabilities = WebInspector.Target.Capability.JS; 329 capabilities = WebInspector.Target.Capability.JS;
330 }
322 331
323 this._mainTarget = WebInspector.targetManager.createTarget(WebInspector. UIString("Main"), capabilities, this._mainConnection, null); 332 var target = WebInspector.targetManager.createTarget(WebInspector.UIStri ng("Main"), capabilities, connection, null);
324 this._mainTarget.registerInspectorDispatcher(this); 333 target.registerInspectorDispatcher(new WebInspector.Main.InspectorDomain Dispatcher(target));
325 this._mainTarget.runtimeAgent().runIfWaitingForDebugger(); 334 target.runtimeAgent().runIfWaitingForDebugger();
326 if (this._mainTarget.hasBrowserCapability()) 335 if (target.hasBrowserCapability())
327 this._mainTarget.inspectorAgent().enable(); 336 target.inspectorAgent().enable();
337 if (Runtime.experiments.isEnabled("nodeDebugging"))
338 new WebInspector.RemoteLocationManager(target);
328 console.timeStamp("Main._mainTargetCreated"); 339 console.timeStamp("Main._mainTargetCreated");
329 }, 340 },
330 341
331 _lateInitialization: function() 342 _lateInitialization: function()
332 { 343 {
333 console.timeStamp("Main._lateInitialization"); 344 console.timeStamp("Main._lateInitialization");
334 this._registerShortcuts(); 345 this._registerShortcuts();
335 WebInspector.extensionServer.initializeExtensions(); 346 WebInspector.extensionServer.initializeExtensions();
336 if (Runtime.experiments.isEnabled("nodeDebugging"))
337 new WebInspector.RemoteLocationManager(this._mainTarget);
338 }, 347 },
339 348
340 _registerForwardedShortcuts: function() 349 _registerForwardedShortcuts: function()
341 { 350 {
342 /** @const */ var forwardedActions = ["main.toggle-dock", "debugger.togg le-breakpoints-active", "debugger.toggle-pause", "commandMenu.show"]; 351 /** @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); 352 var actionKeys = WebInspector.shortcutRegistry.keysForActions(forwardedA ctions).map(WebInspector.KeyboardShortcut.keyCodeAndModifiersFromKey);
344 InspectorFrontendHost.setWhitelistedShortcuts(JSON.stringify(actionKeys) ); 353 InspectorFrontendHost.setWhitelistedShortcuts(JSON.stringify(actionKeys) );
345 }, 354 },
346 355
347 _registerMessageSinkListener: function() 356 _registerMessageSinkListener: function()
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 538
530 /** 539 /**
531 * @param {!WebInspector.Event} event 540 * @param {!WebInspector.Event} event
532 */ 541 */
533 _reloadInspectedPage: function(event) 542 _reloadInspectedPage: function(event)
534 { 543 {
535 var hard = /** @type {boolean} */ (event.data); 544 var hard = /** @type {boolean} */ (event.data);
536 WebInspector.Main._reloadPage(hard); 545 WebInspector.Main._reloadPage(hard);
537 }, 546 },
538 547
548 _onSuspendStateChanged: function()
549 {
550 var suspended = WebInspector.targetManager.allTargetsSuspended();
551 WebInspector.inspectorView.onSuspendStateChanged(suspended);
552 }
553 }
554
555 /**
556 * @constructor
557 * @implements {InspectorAgent.Dispatcher}
558 * @param {!WebInspector.Target} target
559 */
560 WebInspector.Main.InspectorDomainDispatcher = function(target)
561 {
562 this._target = target;
563 }
564
565 WebInspector.Main.InspectorDomainDispatcher.prototype = {
539 /** 566 /**
540 * @override 567 * @override
541 * @param {string} reason 568 * @param {string} reason
542 */ 569 */
543 detached: function(reason) 570 detached: function(reason)
544 { 571 {
545 WebInspector._disconnectedScreenWithReasonWasShown = true; 572 WebInspector._disconnectedScreenWithReasonWasShown = true;
546 WebInspector.RemoteDebuggingTerminatedScreen.show(reason); 573 WebInspector.RemoteDebuggingTerminatedScreen.show(reason);
547 }, 574 },
548 575
549 /** 576 /**
550 * @override 577 * @override
551 */ 578 */
552 targetCrashed: function() 579 targetCrashed: function()
553 { 580 {
554 var debuggerModel = WebInspector.DebuggerModel.fromTarget(this._mainTarg et); 581 var debuggerModel = WebInspector.DebuggerModel.fromTarget(this._target);
555 if (debuggerModel) 582 if (debuggerModel)
556 WebInspector.TargetCrashedScreen.show(debuggerModel); 583 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 } 584 }
591 } 585 }
592 586
587
593 /** 588 /**
594 * @constructor 589 * @constructor
595 * @implements {WebInspector.ActionDelegate} 590 * @implements {WebInspector.ActionDelegate}
596 */ 591 */
597 WebInspector.Main.ReloadActionDelegate = function() 592 WebInspector.Main.ReloadActionDelegate = function()
598 { 593 {
599 } 594 }
600 595
601 WebInspector.Main.ReloadActionDelegate.prototype = { 596 WebInspector.Main.ReloadActionDelegate.prototype = {
602 /** 597 /**
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 * @override 1112 * @override
1118 * @return {?Element} 1113 * @return {?Element}
1119 */ 1114 */
1120 settingElement: function() 1115 settingElement: function()
1121 { 1116 {
1122 return WebInspector.SettingsUI.createSettingCheckbox(WebInspector.UIStri ng("Show rulers"), WebInspector.moduleSetting("showMetricsRulers")); 1117 return WebInspector.SettingsUI.createSettingCheckbox(WebInspector.UIStri ng("Show rulers"), WebInspector.moduleSetting("showMetricsRulers"));
1123 } 1118 }
1124 } 1119 }
1125 1120
1126 new WebInspector.Main(); 1121 new WebInspector.Main();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698