Commit a183c611 authored by sergeyv@chromium.org's avatar sergeyv@chromium.org

DevTools: Use TargetsToolbar instead of ThreadToolbar

BUG=

Review URL: https://codereview.chromium.org/338283004

git-svn-id: svn://svn.chromium.org/blink/trunk@176508 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent fa551a02
......@@ -374,7 +374,7 @@
'front_end/sources/UISourceCodeFrame.js',
'front_end/sources/WatchExpressionsSidebarPane.js',
'front_end/sources/WorkersSidebarPane.js',
'front_end/sources/ThreadsToolbar.js',
'front_end/sources/TargetsToolbar.js',
],
'devtools_timeline_js_files': [
'front_end/timeline/CountersGraph.js',
......
......@@ -6,8 +6,11 @@
* @constructor
* @implements {WebInspector.TargetManager.Observer}
*/
WebInspector.ExecutionContextSelector = function() {
WebInspector.ExecutionContextSelector = function()
{
WebInspector.targetManager.observeTargets(this);
WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this._executionContextChanged, this);
WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targetChanged, this);
}
WebInspector.ExecutionContextSelector.prototype = {
......@@ -17,6 +20,9 @@ WebInspector.ExecutionContextSelector.prototype = {
*/
targetAdded: function(target)
{
if (!WebInspector.context.flavor(WebInspector.Target))
WebInspector.context.setFlavor(WebInspector.Target, target);
target.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.ExecutionContextCreated, this._onExecutionContextCreated, this);
target.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.ExecutionContextDestroyed, this._onExecutionContextDestroyed, this);
},
......@@ -28,8 +34,46 @@ WebInspector.ExecutionContextSelector.prototype = {
{
target.runtimeModel.removeEventListener(WebInspector.RuntimeModel.Events.ExecutionContextCreated, this._onExecutionContextCreated, this);
target.runtimeModel.removeEventListener(WebInspector.RuntimeModel.Events.ExecutionContextDestroyed, this._onExecutionContextDestroyed, this);
if (WebInspector.context.flavor(WebInspector.ExecutionContext).target() === target)
var currentExecutionContext = WebInspector.context.flavor(WebInspector.Target);
if (currentExecutionContext && currentExecutionContext.target() === target)
this._currentExecutionContextGone();
var targets = WebInspector.targetManager.targets();
if (WebInspector.context.flavor(WebInspector.Target) === target && targets.length)
WebInspector.context.setFlavor(WebInspector.Target, targets[0]);
},
/**
* @param {!WebInspector.Event} event
*/
_executionContextChanged: function(event)
{
var newContext = /** @type {?WebInspector.ExecutionContext} */ (event.data);
if (newContext)
WebInspector.context.setFlavor(WebInspector.Target, newContext.target());
},
/**
* @param {!WebInspector.Event} event
*/
_targetChanged: function(event)
{
var newTarget = /** @type {?WebInspector.Target} */(event.data);
var currentContext = WebInspector.context.flavor(WebInspector.ExecutionContext);
if (!newTarget || (currentContext && currentContext.target() === newTarget))
return;
var executionContexts = newTarget.runtimeModel.executionContexts();
if (!executionContexts.length)
return;
var newContext = executionContexts[0];
for (var i = 1; i < executionContexts.length; ++i) {
if (executionContexts[i].isMainWorldContext)
newContext = executionContexts[i];
}
WebInspector.context.setFlavor(WebInspector.ExecutionContext, newContext);
},
/**
......
......@@ -140,6 +140,7 @@ WebInspector.ConsoleView = function(hideContextSelector)
this._registerWithMessageSink();
WebInspector.targetManager.observeTargets(this);
WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this._executionContextChangedExternally, this);
}
WebInspector.ConsoleView.prototype = {
......@@ -318,6 +319,8 @@ WebInspector.ConsoleView.prototype = {
}
}
this._executionContextSelector.selectElement().insertBefore(newOption, insertBeforeOption);
if (executionContext === WebInspector.context.flavor(WebInspector.ExecutionContext))
this._executionContextSelector.select(newOption);
},
/**
......@@ -339,6 +342,22 @@ WebInspector.ConsoleView.prototype = {
this._updateMessageList();
},
/**
* @param {!WebInspector.Event} event
*/
_executionContextChangedExternally: function(event)
{
var executionContext = /** @type {?WebInspector.ExecutionContext} */ (event.data);
if (!executionContext)
return;
var options = this._executionContextSelector.selectElement().options;
for (var i = 0; i < options.length; ++i) {
if (options[i].__executionContext === executionContext)
this._executionContextSelector.select(options[i]);
}
},
/**
* @return {?WebInspector.ExecutionContext}
*/
......
......@@ -266,7 +266,7 @@ WebInspector.Main.prototype = {
WebInspector.setToolbarColors(WebInspector.queryParam("toolbarColor"), WebInspector.queryParam("textColor"));
WebInspector.targetManager = new WebInspector.TargetManager();
WebInspector.targetManager.createTarget(connection, this._doLoadedDoneWithCapabilities.bind(this));
WebInspector.targetManager.createTarget(WebInspector.UIString("Main"), connection, this._doLoadedDoneWithCapabilities.bind(this));
WebInspector.isolatedFileSystemManager = new WebInspector.IsolatedFileSystemManager();
WebInspector.isolatedFileSystemDispatcher = new WebInspector.IsolatedFileSystemDispatcher(WebInspector.isolatedFileSystemManager);
WebInspector.workspace = new WebInspector.Workspace(WebInspector.isolatedFileSystemManager.mapping());
......@@ -805,7 +805,7 @@ WebInspector.Main._addWebSocketTarget = function(ws)
*/
function callback(connection)
{
WebInspector.targetManager.createTarget(connection);
WebInspector.targetManager.createTarget(ws, connection);
}
new InspectorBackendClass.WebSocketConnection(ws, callback);
}
......
......@@ -7,12 +7,14 @@
/**
* @constructor
* @extends {Protocol.Agents}
* @param {string} name
* @param {!InspectorBackendClass.Connection} connection
* @param {function(!WebInspector.Target)=} callback
*/
WebInspector.Target = function(connection, callback)
WebInspector.Target = function(name, connection, callback)
{
Protocol.Agents.call(this, connection.agentsMap());
this._name = name;
this._connection = connection;
/** @type {boolean} */
this.isMainFrontend = false;
......@@ -46,6 +48,15 @@ WebInspector.Target.prototype = {
return this._id;
},
/**
*
* @return {string}
*/
name: function()
{
return this._name;
},
/**
* @param {string} name
* @param {function()|null} callback
......@@ -244,12 +255,13 @@ WebInspector.TargetManager.prototype = {
},
/**
* @param {string} name
* @param {!InspectorBackendClass.Connection} connection
* @param {function(!WebInspector.Target)=} callback
*/
createTarget: function(connection, callback)
createTarget: function(name, connection, callback)
{
var target = new WebInspector.Target(connection, callbackWrapper.bind(this));
var target = new WebInspector.Target(name, connection, callbackWrapper.bind(this));
/**
* @this {WebInspector.TargetManager}
......
......@@ -31,7 +31,7 @@ WebInspector.WorkerTargetManager.prototype = {
*/
function onConnectionReady(connection)
{
this._targetManager.createTarget(connection)
this._targetManager.createTarget(event.data.url, connection)
}
}
......
......@@ -42,7 +42,7 @@ importScript("StyleSheetOutlineDialog.js");
importScript("TabbedEditorContainer.js");
importScript("WatchExpressionsSidebarPane.js");
importScript("WorkersSidebarPane.js");
importScript("ThreadsToolbar.js");
importScript("TargetsToolbar.js");
importScript("ScriptFormatterEditorAction.js");
importScript("InplaceFormatterEditorAction.js");
importScript("ScriptFormatter.js");
......@@ -69,7 +69,7 @@ WebInspector.SourcesPanel = function(workspaceForTest)
var helpSection = WebInspector.shortcutsScreen.section(WebInspector.UIString("Sources Panel"));
this.debugToolbar = this._createDebugToolbar();
this._debugToolbarDrawer = this._createDebugToolbarDrawer();
this.threadsToolbar = new WebInspector.ThreadsToolbar();
this._targetsToolbar = new WebInspector.TargetsToolbar();
const initialDebugSidebarWidth = 225;
this._splitView = new WebInspector.SplitView(true, true, "sourcesPanelSplitViewState", initialDebugSidebarWidth);
......@@ -1052,7 +1052,7 @@ WebInspector.SourcesPanel.prototype = {
var vbox = new WebInspector.VBox();
vbox.element.appendChild(this._debugToolbarDrawer);
vbox.element.appendChild(this.debugToolbar);
vbox.element.appendChild(this.threadsToolbar.element);
vbox.element.appendChild(this._targetsToolbar.element);
vbox.setMinimumAndPreferredSizes(25, 25, WebInspector.SourcesPanel.minToolbarWidth, 100);
var sidebarPaneStack = new WebInspector.SidebarPaneStack();
sidebarPaneStack.element.classList.add("flex-auto");
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @constructor
* @implements {WebInspector.TargetManager.Observer}
*/
WebInspector.TargetsToolbar = function()
{
this.element = document.createElement("div");
this.element.className = "status-bar scripts-debug-toolbar targets-toolbar hidden";
this._comboBox = new WebInspector.StatusBarComboBox(this._onComboBoxSelectionChange.bind(this));
this.element.appendChild(this._comboBox.element);
/** @type {!Map.<!WebInspector.Target, !Element>} */
this._targetToOption = new Map();
if (!WebInspector.experimentsSettings.workersInMainWindow.isEnabled())
return;
WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targetChangedExternally, this);
WebInspector.targetManager.observeTargets(this);
}
WebInspector.TargetsToolbar.prototype = {
/**
* @param {!WebInspector.Target} target
*/
targetAdded: function(target)
{
var option = this._comboBox.createOption(target.name());
option.__target = target;
this._targetToOption.put(target, option);
if (WebInspector.context.flavor(WebInspector.Target) === target)
this._comboBox.select(option);
this._updateVisibility();
},
/**
* @param {!WebInspector.Target} target
*/
targetRemoved: function(target)
{
var option = this._targetToOption.remove(target);
this._comboBox.removeOption(option);
this._updateVisibility();
},
_onComboBoxSelectionChange: function()
{
var selectedOption = this._comboBox.selectedOption();
if (!selectedOption)
return;
WebInspector.context.setFlavor(WebInspector.Target, selectedOption.__target);
},
_updateVisibility: function()
{
var hidden = this._comboBox.size() === 1;
this.element.classList.toggle("hidden", hidden);
},
/**
* @param {!WebInspector.Event} event
*/
_targetChangedExternally: function(event)
{
var target = /** @type {?WebInspector.Target} */ (event.data);
if (target) {
var option = /** @type {!Element} */ (this._targetToOption.get(target));
this._comboBox.select(option);
}
}
}
/*
* Copyright (C) 2014 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @constructor
*/
WebInspector.ThreadsToolbar = function()
{
this.element = document.createElement("div");
this.element.className = "status-bar scripts-debug-toolbar threads-toolbar hidden";
this._comboBox = new WebInspector.StatusBarComboBox(this._onComboBoxSelectionChange.bind(this));
this.element.appendChild(this._comboBox.element);
this._reset();
if (WebInspector.experimentsSettings.workersInMainWindow.isEnabled()) {
WebInspector.workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerAdded, this._workerAdded, this);
WebInspector.workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerRemoved, this._workerRemoved, this);
WebInspector.workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkersCleared, this._workersCleared, this);
}
}
WebInspector.ThreadsToolbar.prototype = {
_reset: function()
{
if (!WebInspector.experimentsSettings.workersInMainWindow.isEnabled())
return;
this._threadIdToOption = {};
var connectedThreads = WebInspector.workerManager.threadsList();
for (var i = 0; i < connectedThreads.length; ++i) {
var threadId = connectedThreads[i];
this._addOption(threadId, WebInspector.workerManager.threadUrl(threadId));
}
this._alterVisibility();
this._comboBox.select(this._threadIdToOption[WebInspector.workerManager.selectedThreadId()]);
},
/**
* @param {number} workerId
* @param {string} url
*/
_addOption: function(workerId, url)
{
var option = this._comboBox.createOption(url, "", String(workerId));
this._threadIdToOption[workerId] = option;
},
/**
* @param {!WebInspector.Event} event
*/
_workerAdded: function(event)
{
var data = /** @type {{workerId: number, url: string}} */ (event.data);
this._addOption(data.workerId, data.url);
this._alterVisibility();
},
/**
* @param {!WebInspector.Event} event
*/
_workerRemoved: function(event)
{
var data = /** @type {{workerId: number, url: string}} */ (event.data);
this._comboBox.removeOption(this._threadIdToOption[data.workerId]);
delete this._threadIdToOption[data.workerId];
this._alterVisibility();
},
_workersCleared: function()
{
this._comboBox.removeOptions();
this._reset();
},
_onComboBoxSelectionChange: function()
{
var selectedOption = this._comboBox.selectedOption();
if (!selectedOption)
return;
WebInspector.workerManager.setSelectedThreadId(parseInt(selectedOption.value, 10));
},
_alterVisibility: function()
{
var hidden = this._comboBox.size() === 1;
this.element.classList.toggle("hidden", hidden);
}
}
......@@ -202,7 +202,7 @@ a.worker-item:hover {
overflow: auto;
}
.threads-toolbar {
.targets-toolbar {
padding-left: 10px;
margin-top: -1px;
}
......
......@@ -293,7 +293,7 @@
"sources/UISourceCodeFrame.js",
"sources/WatchExpressionsSidebarPane.js",
"sources/WorkersSidebarPane.js",
"sources/ThreadsToolbar.js"
"sources/TargetsToolbar.js"
]
},
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment