Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/main/Main.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/main/Main.js b/third_party/WebKit/Source/devtools/front_end/main/Main.js |
| index 88677b8a46ae85d4c1d28cf24412e4328419376d..962b8b2abd2a336c20b9b8b399c1b55d67181851 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/main/Main.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/main/Main.js |
| @@ -30,7 +30,6 @@ |
| /** |
| * @constructor |
| - * @implements {InspectorAgent.Dispatcher} |
| * @suppressGlobalPropertiesCheck |
| */ |
| WebInspector.Main = function() |
| @@ -231,7 +230,6 @@ WebInspector.Main.prototype = { |
| WebInspector.inspectorView.createToolbars(); |
| InspectorFrontendHost.loadCompleted(); |
| - InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this); |
| InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.ReloadInspectedPage, this._reloadInspectedPage, this); |
| var extensions = self.runtime.extensions(WebInspector.QueryParamHandler); |
| @@ -253,7 +251,7 @@ WebInspector.Main.prototype = { |
| this._appUIShown = true; |
| if (this._fileSystemManagerInitialized) { |
| // Allow UI cycles to repaint prior to creating connection. |
| - setTimeout(this._createConnection.bind(this), 0); |
| + setTimeout(this._connectAndCreateTarget.bind(this), 0); |
| } |
| }, |
| @@ -261,35 +259,41 @@ WebInspector.Main.prototype = { |
| { |
| this._fileSystemManagerInitialized = true; |
| if (this._appUIShown) |
| - this._createConnection(); |
| + this._connectAndCreateTarget(); |
| }, |
| - _createConnection: function() |
| + _connectAndCreateTarget: function() |
| { |
| - console.timeStamp("Main._createConnection"); |
| - |
| - if (Runtime.queryParam("ws")) { |
| - var ws = "ws://" + Runtime.queryParam("ws"); |
| - WebInspector.WebSocketConnection.Create(ws, this._connectionEstablished.bind(this)); |
| - return; |
| - } |
| - |
| - if (!InspectorFrontendHost.isHostedMode()) { |
| - this._connectionEstablished(new WebInspector.MainConnection()); |
| - return; |
| - } |
| + console.timeStamp("Main._connectAndCreateTarget"); |
| + this._createConnection().then(connection => { |
| + this._createMainTarget(connection); |
| + InspectorFrontendHost.readyForTest(); |
| + WebInspector.targetManager.setMainTargetFactory(this._recreateMainTarget.bind(this)); |
| + // Asynchronously run the extensions. |
| + setTimeout(this._lateInitialization.bind(this), 100); |
| + }); |
| + }, |
| - this._connectionEstablished(new WebInspector.StubConnection()); |
| + _recreateMainTarget: function() |
| + { |
| + this._createConnection().then(this._createMainTarget.bind(this)); |
| }, |
| /** |
| - * @param {!InspectorBackendClass.Connection} connection |
| + * @return {!Promise<!InspectorBackendClass.Connection>} |
| */ |
| - _connectionEstablished: function(connection) |
| + _createConnection: function() |
| { |
| - console.timeStamp("Main._connectionEstablished"); |
| - this._mainConnection = connection; |
| - connection.addEventListener(InspectorBackendClass.Connection.Events.Disconnected, onDisconnected); |
| + if (Runtime.queryParam("ws")) { |
| + var ws = "ws://" + Runtime.queryParam("ws"); |
| + return WebInspector.WebSocketConnection.Create(ws).then(connection => { |
| + connection.addEventListener(InspectorBackendClass.Connection.Events.Disconnected, onDisconnected); |
| + return connection; |
| + }); |
| + } |
| + |
| + return /** @type {!Promise<!InspectorBackendClass.Connection>} */ (Promise.resolve(InspectorFrontendHost.isHostedMode() ? |
| + new WebInspector.StubConnection() : new WebInspector.MainConnection())); |
| /** |
| * @param {!WebInspector.Event} event |
| @@ -300,32 +304,34 @@ WebInspector.Main.prototype = { |
| return; |
| WebInspector.RemoteDebuggingTerminatedScreen.show(event.data.reason); |
| } |
| - |
| - this._createMainTarget(); |
| - InspectorFrontendHost.readyForTest(); |
| - // Asynchronously run the extensions. |
| - setTimeout(this._lateInitialization.bind(this), 100); |
| }, |
| - _createMainTarget: function() |
| + /** |
| + * @param {!InspectorBackendClass.Connection} connection |
| + */ |
| + _createMainTarget: function(connection) |
| { |
| + console.timeStamp("Main._createMainTarget begin"); |
|
dgozman
2016/10/17 17:21:16
time/timeEnd
|
| var capabilities = |
| WebInspector.Target.Capability.Browser | WebInspector.Target.Capability.DOM | |
| WebInspector.Target.Capability.JS | WebInspector.Target.Capability.Log | |
| WebInspector.Target.Capability.Network | WebInspector.Target.Capability.Worker; |
| - if (Runtime.queryParam("isSharedWorker")) |
| + if (Runtime.queryParam("isSharedWorker")) { |
| capabilities = |
| WebInspector.Target.Capability.Browser | WebInspector.Target.Capability.Log | |
| WebInspector.Target.Capability.Network | WebInspector.Target.Capability.Worker; |
| - else if (Runtime.queryParam("v8only")) |
| + } else if (Runtime.queryParam("v8only")) { |
| capabilities = WebInspector.Target.Capability.JS; |
| + } |
| - this._mainTarget = WebInspector.targetManager.createTarget(WebInspector.UIString("Main"), capabilities, this._mainConnection, null); |
| - this._mainTarget.registerInspectorDispatcher(this); |
| - this._mainTarget.runtimeAgent().runIfWaitingForDebugger(); |
| - if (this._mainTarget.hasBrowserCapability()) |
| - this._mainTarget.inspectorAgent().enable(); |
| - console.timeStamp("Main._mainTargetCreated"); |
| + var target = WebInspector.targetManager.createTarget(WebInspector.UIString("Main"), capabilities, connection, null); |
| + target.registerInspectorDispatcher(new WebInspector.Main.InspectorDomainDispatcher(target)); |
| + target.runtimeAgent().runIfWaitingForDebugger(); |
| + if (target.hasBrowserCapability()) |
| + target.inspectorAgent().enable(); |
| + if (Runtime.experiments.isEnabled("nodeDebugging")) |
| + new WebInspector.RemoteLocationManager(target); |
| + console.timeStamp("Main._createMainTarget end"); |
| }, |
| _lateInitialization: function() |
| @@ -333,8 +339,6 @@ WebInspector.Main.prototype = { |
| console.timeStamp("Main._lateInitialization"); |
| this._registerShortcuts(); |
| WebInspector.extensionServer.initializeExtensions(); |
| - if (Runtime.experiments.isEnabled("nodeDebugging")) |
| - new WebInspector.RemoteLocationManager(this._mainTarget); |
| }, |
| _registerForwardedShortcuts: function() |
| @@ -536,6 +540,24 @@ WebInspector.Main.prototype = { |
| WebInspector.Main._reloadPage(hard); |
| }, |
| + _onSuspendStateChanged: function() |
| + { |
| + var suspended = WebInspector.targetManager.allTargetsSuspended(); |
| + WebInspector.inspectorView.onSuspendStateChanged(suspended); |
| + } |
| +} |
| + |
| +/** |
| + * @constructor |
| + * @implements {InspectorAgent.Dispatcher} |
| + * @param {!WebInspector.Target} target |
| + */ |
| +WebInspector.Main.InspectorDomainDispatcher = function(target) |
| +{ |
| + this._target = target; |
| +} |
| + |
| +WebInspector.Main.InspectorDomainDispatcher.prototype = { |
| /** |
| * @override |
| * @param {string} reason |
| @@ -551,45 +573,13 @@ WebInspector.Main.prototype = { |
| */ |
| targetCrashed: function() |
| { |
| - var debuggerModel = WebInspector.DebuggerModel.fromTarget(this._mainTarget); |
| + var debuggerModel = WebInspector.DebuggerModel.fromTarget(this._target); |
| if (debuggerModel) |
| WebInspector.TargetCrashedScreen.show(debuggerModel); |
| - }, |
| - |
| - _onSuspendStateChanged: function() |
| - { |
| - var suspended = WebInspector.targetManager.allTargetsSuspended(); |
| - WebInspector.inspectorView.onSuspendStateChanged(suspended); |
| - }, |
| - |
| - /** |
| - * @param {!WebInspector.Event} event |
| - */ |
| - _evaluateForTestInFrontend: function(event) |
| - { |
| - if (!InspectorFrontendHost.isUnderTest()) |
| - return; |
| - |
| - var callId = /** @type {number} */ (event.data["callId"]); |
| - var script = /** @type {number} */ (event.data["script"]); |
| - |
| - /** |
| - * @suppressGlobalPropertiesCheck |
| - */ |
| - function invokeMethod() |
| - { |
| - try { |
| - script = script + "//# sourceURL=evaluateInWebInspector" + callId + ".js"; |
| - window.eval(script); |
| - } catch (e) { |
| - console.error(e.stack); |
| - } |
| - } |
| - |
| - this._mainConnection.deprecatedRunAfterPendingDispatches(invokeMethod); |
| } |
| } |
| + |
| /** |
| * @constructor |
| * @implements {WebInspector.ActionDelegate} |