Commit 605cb278 authored by Mike Wasserman's avatar Mike Wasserman Committed by Commit Bot

ui_devtools: Encapsulate views server init; use Shell Env for Chrome OS.

Use the ash::Shell aura::Env in single-process mash ui_devtools.
Keep a TODO for initializing ui_devtools in Ash for multi-process Mash.
Encapsulate server init, and the switch and port definitions.

Bug: 896977
Test: ui_devtools works well on Chrome OS single-process Mash.
Change-Id: I3cc285d5f8ee465d45795a3521e7e4eafa354414
Reviewed-on: https://chromium-review.googlesource.com/c/1324373
Commit-Queue: Michael Wasserman <msw@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607408}
parent b7bedaf8
...@@ -1865,6 +1865,7 @@ jumbo_split_static_library("browser") { ...@@ -1865,6 +1865,7 @@ jumbo_split_static_library("browser") {
"//components/translate/content/browser", "//components/translate/content/browser",
"//components/translate/core/browser", "//components/translate/core/browser",
"//components/translate/core/common", "//components/translate/core/common",
"//components/ui_devtools",
"//components/ukm:observers", "//components/ukm:observers",
"//components/undo", "//components/undo",
"//components/unified_consent", "//components/unified_consent",
......
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
#include "components/tracing/common/tracing_switches.h" #include "components/tracing/common/tracing_switches.h"
#include "components/translate/core/browser/translate_prefs.h" #include "components/translate/core/browser/translate_prefs.h"
#include "components/translate/core/browser/translate_ranker_impl.h" #include "components/translate/core/browser/translate_ranker_impl.h"
#include "components/ui_devtools/switches.h"
#include "components/unified_consent/feature.h" #include "components/unified_consent/feature.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#include "components/viz/common/features.h" #include "components/viz/common/features.h"
...@@ -3028,9 +3029,10 @@ const FeatureEntry kFeatureEntries[] = { ...@@ -3028,9 +3029,10 @@ const FeatureEntry kFeatureEntries[] = {
FEATURE_VALUE_TYPE(prerender::kNoStatePrefetchFeature)}, FEATURE_VALUE_TYPE(prerender::kNoStatePrefetchFeature)},
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
{switches::kEnableUiDevTools, flag_descriptions::kUiDevToolsName, {ui_devtools::switches::kEnableUiDevTools,
flag_descriptions::kUiDevToolsName,
flag_descriptions::kUiDevToolsDescription, kOsCrOS, flag_descriptions::kUiDevToolsDescription, kOsCrOS,
SINGLE_VALUE_TYPE(switches::kEnableUiDevTools)}, SINGLE_VALUE_TYPE(ui_devtools::switches::kEnableUiDevTools)},
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
{"enable-autofill-credit-card-ablation-experiment", {"enable-autofill-credit-card-ablation-experiment",
...@@ -4545,7 +4547,7 @@ bool SkipConditionalFeatureEntry(const FeatureEntry& entry) { ...@@ -4545,7 +4547,7 @@ bool SkipConditionalFeatureEntry(const FeatureEntry& entry) {
} }
// enable-ui-devtools is only available on for non Stable channels. // enable-ui-devtools is only available on for non Stable channels.
if (!strcmp(switches::kEnableUiDevTools, entry.internal_name) && if (!strcmp(ui_devtools::switches::kEnableUiDevTools, entry.internal_name) &&
channel == version_info::Channel::STABLE) { channel == version_info::Channel::STABLE) {
return true; return true;
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/chromeos/night_light/night_light_client.h" #include "chrome/browser/chromeos/night_light/night_light_client.h"
#include "chrome/browser/chromeos/policy/display_rotation_default_handler.h" #include "chrome/browser/chromeos/policy/display_rotation_default_handler.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_error_notifier_factory_ash.h" #include "chrome/browser/signin/signin_error_notifier_factory_ash.h"
#include "chrome/browser/sync/sync_error_notifier_factory_ash.h" #include "chrome/browser/sync/sync_error_notifier_factory_ash.h"
...@@ -52,6 +53,7 @@ ...@@ -52,6 +53,7 @@
#include "components/session_manager/core/session_manager.h" #include "components/session_manager/core/session_manager.h"
#include "components/session_manager/core/session_manager_observer.h" #include "components/session_manager/core/session_manager_observer.h"
#include "components/startup_metric_utils/browser/startup_metric_utils.h" #include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "components/ui_devtools/views/devtools_server_util.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
...@@ -63,6 +65,7 @@ ...@@ -63,6 +65,7 @@
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "services/ws/public/mojom/constants.mojom.h" #include "services/ws/public/mojom/constants.mojom.h"
#include "services/ws/public/mojom/user_activity_monitor.mojom.h" #include "services/ws/public/mojom/user_activity_monitor.mojom.h"
#include "ui/aura/env.h"
#include "ui/aura/mus/property_converter.h" #include "ui/aura/mus/property_converter.h"
#include "ui/aura/mus/user_activity_forwarder.h" #include "ui/aura/mus/user_activity_forwarder.h"
#include "ui/base/ime/chromeos/input_method_manager.h" #include "ui/base/ime/chromeos/input_method_manager.h"
...@@ -176,6 +179,21 @@ void ChromeBrowserMainExtraPartsAsh::ServiceManagerConnectionStarted( ...@@ -176,6 +179,21 @@ void ChromeBrowserMainExtraPartsAsh::ServiceManagerConnectionStarted(
} }
void ChromeBrowserMainExtraPartsAsh::PreProfileInit() { void ChromeBrowserMainExtraPartsAsh::PreProfileInit() {
if (ui_devtools::UiDevToolsServer::IsUiDevToolsEnabled()) {
// Start the UI Devtools server using ash::Shell's aura::Env, if possible.
// This can handle events targeting aura::Windows created by Ash and window
// service clients like Chrome. Shell is inaccessible in multi-process Mash.
// Chrome can access the Shell's Env as a workaround in single-process Mash.
// TODO(crbug.com/896977): Init the devtools server in Ash on Chrome OS.
aura::Env* env = aura::Env::GetInstance();
if (!features::IsMultiProcessMash())
env = ash::Shell::Get()->aura_env();
else
LOG(WARNING) << "Chrome cannot handle Ash and mojo app events in Mash.";
devtools_server_ = ui_devtools::CreateUiDevToolsServerForViews(
g_browser_process->system_network_context_manager()->GetContext(), env);
}
// IME driver must be available at login screen, so initialize before profile. // IME driver must be available at login screen, so initialize before profile.
IMEDriver::Register(); IMEDriver::Register();
......
...@@ -27,6 +27,10 @@ namespace ui { ...@@ -27,6 +27,10 @@ namespace ui {
class UserActivityDetector; class UserActivityDetector;
} }
namespace ui_devtools {
class UiDevToolsServer;
}
namespace views { namespace views {
class MusClient; class MusClient;
} }
...@@ -108,6 +112,8 @@ class ChromeBrowserMainExtraPartsAsh : public ChromeBrowserMainExtraParts { ...@@ -108,6 +112,8 @@ class ChromeBrowserMainExtraPartsAsh : public ChromeBrowserMainExtraParts {
// elim chromeos:: namespace. https://crbug.com/798569. // elim chromeos:: namespace. https://crbug.com/798569.
std::unique_ptr<chromeos::NetworkPortalNotificationController> std::unique_ptr<chromeos::NetworkPortalNotificationController>
network_portal_notification_controller_; network_portal_notification_controller_;
// Only used when running in --enable-ui-devtools.
std::unique_ptr<ui_devtools::UiDevToolsServer> devtools_server_;
std::unique_ptr<internal::ChromeLauncherControllerInitializer> std::unique_ptr<internal::ChromeLauncherControllerInitializer>
chrome_launcher_controller_initializer_; chrome_launcher_controller_initializer_;
......
...@@ -20,11 +20,7 @@ ...@@ -20,11 +20,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/net/system_network_context_manager.h" #include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/common/chrome_switches.h" #include "components/ui_devtools/views/devtools_server_util.h"
#include "components/ui_devtools/css_agent.h"
#include "components/ui_devtools/devtools_server.h"
#include "components/ui_devtools/views/dom_agent_aura.h"
#include "components/ui_devtools/views/overlay_agent_aura.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
...@@ -51,12 +47,7 @@ ...@@ -51,12 +47,7 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS) ChromeBrowserMainExtraPartsViews::ChromeBrowserMainExtraPartsViews() {}
#include "ui/base/ui_base_features.h"
#endif
ChromeBrowserMainExtraPartsViews::ChromeBrowserMainExtraPartsViews() {
}
ChromeBrowserMainExtraPartsViews::~ChromeBrowserMainExtraPartsViews() { ChromeBrowserMainExtraPartsViews::~ChromeBrowserMainExtraPartsViews() {
constrained_window::SetConstrainedWindowViewsClient(nullptr); constrained_window::SetConstrainedWindowViewsClient(nullptr);
...@@ -92,34 +83,15 @@ void ChromeBrowserMainExtraPartsViews::PreCreateThreads() { ...@@ -92,34 +83,15 @@ void ChromeBrowserMainExtraPartsViews::PreCreateThreads() {
} }
void ChromeBrowserMainExtraPartsViews::PreProfileInit() { void ChromeBrowserMainExtraPartsViews::PreProfileInit() {
#if defined(USE_AURA) #if defined(USE_AURA) && !defined(OS_CHROMEOS)
// Start devtools server if (ui_devtools::UiDevToolsServer::IsUiDevToolsEnabled()) {
constexpr int kUiDevToolsDefaultPort = 9223; // Start the UI Devtools server using Chrome's local aura::Env instance.
network::mojom::NetworkContext* network_context = // This can only handle events targeting aura::Windows created by Chrome.
g_browser_process->system_network_context_manager()->GetContext(); // ChromeBrowserMainExtraPartsAsh uses ash::Shell's aura::Env to also handle
devtools_server_ = ui_devtools::UiDevToolsServer::CreateForViews( // aura::Windows created by Ash and window service clients (ie. mojo apps).
network_context, switches::kEnableUiDevTools, kUiDevToolsDefaultPort); devtools_server_ = ui_devtools::CreateUiDevToolsServerForViews(
if (devtools_server_) { g_browser_process->system_network_context_manager()->GetContext(),
auto dom_backend = std::make_unique<ui_devtools::DOMAgentAura>(); aura::Env::GetInstance());
#if defined(OS_CHROMEOS)
// OverlayAgentAura intends to handle input events targeting any UI surface,
// and so installs itself as a local aura::Env pre-target ui::EventHandler.
// In multi-process Mash, Chrome's local aura::Env can only handle events
// target Chrome's own aura::Windows, not those targeting Ash or mojo apps.
// TODO(crbug.com/896977): Init the devtools server in Ash on Chrome OS.
LOG_IF(WARNING, features::IsMultiProcessMash())
<< "Chrome cannot handle Ash system ui and mojo app events in Mash.";
#endif
auto overlay_backend =
std::make_unique<ui_devtools::OverlayAgentAura>(dom_backend.get());
auto css_backend =
std::make_unique<ui_devtools::CSSAgent>(dom_backend.get());
auto devtools_client = std::make_unique<ui_devtools::UiDevToolsClient>(
"UiDevToolsClient", devtools_server_.get());
devtools_client->AddAgent(std::move(dom_backend));
devtools_client->AddAgent(std::move(css_backend));
devtools_client->AddAgent(std::move(overlay_backend));
devtools_server_->AttachClient(std::move(devtools_client));
} }
#endif #endif
......
...@@ -43,7 +43,7 @@ class ChromeBrowserMainExtraPartsViews : public ChromeBrowserMainExtraParts { ...@@ -43,7 +43,7 @@ class ChromeBrowserMainExtraPartsViews : public ChromeBrowserMainExtraParts {
std::unique_ptr<views::LayoutProvider> layout_provider_; std::unique_ptr<views::LayoutProvider> layout_provider_;
#if defined(USE_AURA) #if defined(USE_AURA)
// Only used when running in --enable-ui-devtools. // Only used when running in --enable-ui-devtools; not used on Chrome OS.
std::unique_ptr<ui_devtools::UiDevToolsServer> devtools_server_; std::unique_ptr<ui_devtools::UiDevToolsServer> devtools_server_;
std::unique_ptr<wm::WMState> wm_state_; std::unique_ptr<wm::WMState> wm_state_;
......
...@@ -329,10 +329,6 @@ const char kEnablePowerOverlay[] = "enable-power-overlay"; ...@@ -329,10 +329,6 @@ const char kEnablePowerOverlay[] = "enable-power-overlay";
const char kEnablePrintPreviewRegisterPromos[] = const char kEnablePrintPreviewRegisterPromos[] =
"enable-print-preview-register-promos"; "enable-print-preview-register-promos";
// Enables DevTools server for UI (mus, ash, etc). Value should be the port the
// server is started on. Default port is 9223.
const char kEnableUiDevTools[] = "enable-ui-devtools";
// Name of the command line flag to force content verification to be on in one // Name of the command line flag to force content verification to be on in one
// of various modes. // of various modes.
const char kExtensionContentVerification[] = "extension-content-verification"; const char kExtensionContentVerification[] = "extension-content-verification";
......
...@@ -105,7 +105,6 @@ extern const char kEnableOfflineAutoReloadVisibleOnly[]; ...@@ -105,7 +105,6 @@ extern const char kEnableOfflineAutoReloadVisibleOnly[];
extern const char kEnablePotentiallyAnnoyingSecurityFeatures[]; extern const char kEnablePotentiallyAnnoyingSecurityFeatures[];
extern const char kEnablePowerOverlay[]; extern const char kEnablePowerOverlay[];
extern const char kEnablePrintPreviewRegisterPromos[]; extern const char kEnablePrintPreviewRegisterPromos[];
extern const char kEnableUiDevTools[];
extern const char kExtensionContentVerification[]; extern const char kExtensionContentVerification[];
extern const char kExtensionContentVerificationBootstrap[]; extern const char kExtensionContentVerificationBootstrap[];
extern const char kExtensionContentVerificationEnforce[]; extern const char kExtensionContentVerificationEnforce[];
......
...@@ -73,6 +73,8 @@ component("ui_devtools") { ...@@ -73,6 +73,8 @@ component("ui_devtools") {
"root_element.h", "root_element.h",
"string_util.cc", "string_util.cc",
"string_util.h", "string_util.h",
"switches.cc",
"switches.h",
"ui_element.cc", "ui_element.cc",
"ui_element.h", "ui_element.h",
"ui_element_delegate.h", "ui_element_delegate.h",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/values.h" #include "base/values.h"
#include "components/ui_devtools/switches.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/log/net_log.h" #include "net/log/net_log.h"
#include "services/network/public/cpp/server/http_server_request_info.h" #include "services/network/public/cpp/server/http_server_request_info.h"
...@@ -26,12 +27,6 @@ namespace ui_devtools { ...@@ -26,12 +27,6 @@ namespace ui_devtools {
namespace { namespace {
const char kChromeDeveloperToolsPrefix[] = const char kChromeDeveloperToolsPrefix[] =
"chrome-devtools://devtools/bundled/devtools_app.html?ws="; "chrome-devtools://devtools/bundled/devtools_app.html?ws=";
bool IsDevToolsEnabled(const char* enable_devtools_flag) {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
enable_devtools_flag);
}
} // namespace } // namespace
UiDevToolsServer* UiDevToolsServer::devtools_server_ = nullptr; UiDevToolsServer* UiDevToolsServer::devtools_server_ = nullptr;
...@@ -92,20 +87,18 @@ UiDevToolsServer::~UiDevToolsServer() { ...@@ -92,20 +87,18 @@ UiDevToolsServer::~UiDevToolsServer() {
// static // static
std::unique_ptr<UiDevToolsServer> UiDevToolsServer::CreateForViews( std::unique_ptr<UiDevToolsServer> UiDevToolsServer::CreateForViews(
network::mojom::NetworkContext* network_context, network::mojom::NetworkContext* network_context,
const char* enable_devtools_flag, int port) {
int default_port) { DCHECK(IsUiDevToolsEnabled());
std::unique_ptr<UiDevToolsServer> server; DCHECK(!devtools_server_);
if (IsDevToolsEnabled(enable_devtools_flag) && !devtools_server_) {
// TODO(mhashmi): Change port if more than one inspectable clients // TODO(mhashmi): Change port if more than one inspectable clients
int port = GetUiDevToolsPort(enable_devtools_flag, default_port); auto server =
server = base::WrapUnique(new UiDevToolsServer(port, kUIDevtoolsServerTag)); base::WrapUnique(new UiDevToolsServer(port, kUIDevtoolsServerTag));
network::mojom::TCPServerSocketPtr server_socket; network::mojom::TCPServerSocketPtr server_socket;
CreateTCPServerSocket(mojo::MakeRequest(&server_socket), network_context, CreateTCPServerSocket(mojo::MakeRequest(&server_socket), network_context,
port, kUIDevtoolsServerTag, port, kUIDevtoolsServerTag,
base::BindOnce(&UiDevToolsServer::MakeServer, base::BindOnce(&UiDevToolsServer::MakeServer,
server->weak_ptr_factory_.GetWeakPtr(), server->weak_ptr_factory_.GetWeakPtr(),
std::move(server_socket))); std::move(server_socket)));
}
return server; return server;
} }
...@@ -154,16 +147,9 @@ UiDevToolsServer::GetClientNamesAndUrls() { ...@@ -154,16 +147,9 @@ UiDevToolsServer::GetClientNamesAndUrls() {
} }
// static // static
int UiDevToolsServer::GetUiDevToolsPort(const char* enable_devtools_flag, bool UiDevToolsServer::IsUiDevToolsEnabled() {
int default_port) { return base::CommandLine::ForCurrentProcess()->HasSwitch(
DCHECK(IsDevToolsEnabled(enable_devtools_flag)); switches::kEnableUiDevTools);
std::string switch_value =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
enable_devtools_flag);
int port;
if (!base::StringToInt(switch_value, &port))
return default_port;
return port;
} }
void UiDevToolsServer::AttachClient(std::unique_ptr<UiDevToolsClient> client) { void UiDevToolsServer::AttachClient(std::unique_ptr<UiDevToolsClient> client) {
......
...@@ -34,8 +34,7 @@ class UI_DEVTOOLS_EXPORT UiDevToolsServer ...@@ -34,8 +34,7 @@ class UI_DEVTOOLS_EXPORT UiDevToolsServer
// server instance has already been created. // server instance has already been created.
static std::unique_ptr<UiDevToolsServer> CreateForViews( static std::unique_ptr<UiDevToolsServer> CreateForViews(
network::mojom::NetworkContext* network_context, network::mojom::NetworkContext* network_context,
const char* enable_devtools_flag, int port);
int default_port);
// Assumes that the devtools flag is enabled, and was checked when the socket // Assumes that the devtools flag is enabled, and was checked when the socket
// was created. // was created.
...@@ -55,10 +54,8 @@ class UI_DEVTOOLS_EXPORT UiDevToolsServer ...@@ -55,10 +54,8 @@ class UI_DEVTOOLS_EXPORT UiDevToolsServer
using NameUrlPair = std::pair<std::string, std::string>; using NameUrlPair = std::pair<std::string, std::string>;
static std::vector<NameUrlPair> GetClientNamesAndUrls(); static std::vector<NameUrlPair> GetClientNamesAndUrls();
// Returns the port number specified by a command line flag. If a number is // Returns true if UI Devtools is enabled by its commandline switch.
// not specified as a command line argument, returns the |default_port|. static bool IsUiDevToolsEnabled();
static int GetUiDevToolsPort(const char* enable_devtools_flag,
int default_port);
void AttachClient(std::unique_ptr<UiDevToolsClient> client); void AttachClient(std::unique_ptr<UiDevToolsClient> client);
void SendOverWebSocket(int connection_id, const String& message); void SendOverWebSocket(int connection_id, const String& message);
......
// Copyright 2018 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.
#include "components/ui_devtools/switches.h"
namespace ui_devtools {
namespace switches {
// Enables DevTools server for UI (mus, ash, etc). Value should be the port the
// server is started on. Default port is 9223.
const char kEnableUiDevTools[] = "enable-ui-devtools";
} // namespace switches
} // namespace ui_devtools
// Copyright 2018 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.
#ifndef COMPONENTS_UI_DEVTOOLS_SWITCHES_H_
#define COMPONENTS_UI_DEVTOOLS_SWITCHES_H_
#include "components/ui_devtools/devtools_export.h"
namespace ui_devtools {
namespace switches {
UI_DEVTOOLS_EXPORT extern const char kEnableUiDevTools[];
} // namespace switches
} // namespace ui_devtools
#endif // COMPONENTS_UI_DEVTOOLS_SWITCHES_H_
...@@ -11,6 +11,8 @@ source_set("views") { ...@@ -11,6 +11,8 @@ source_set("views") {
} }
sources = [ sources = [
"devtools_server_util.cc",
"devtools_server_util.h",
"dom_agent_aura.cc", "dom_agent_aura.cc",
"dom_agent_aura.h", "dom_agent_aura.h",
"overlay_agent_aura.cc", "overlay_agent_aura.cc",
......
// Copyright 2018 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.
#include "components/ui_devtools/views/devtools_server_util.h"
#include <memory>
#include "base/command_line.h"
#include "components/ui_devtools/css_agent.h"
#include "components/ui_devtools/devtools_server.h"
#include "components/ui_devtools/switches.h"
#include "components/ui_devtools/views/dom_agent_aura.h"
#include "components/ui_devtools/views/overlay_agent_aura.h"
namespace ui_devtools {
namespace {
// Returns the port number specified by the command line flag. If a number is
// not specified as a command line argument, returns the default port (9223).
int GetPort() {
constexpr int kUiDevToolsDefaultPort = 9223;
auto value = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kEnableUiDevTools);
int port = 0;
return base::StringToInt(value, &port) ? port : kUiDevToolsDefaultPort;
}
} // namespace
std::unique_ptr<UiDevToolsServer> CreateUiDevToolsServerForViews(
network::mojom::NetworkContext* network_context,
aura::Env* env) {
auto server = UiDevToolsServer::CreateForViews(network_context, GetPort());
DCHECK(server);
auto client =
std::make_unique<UiDevToolsClient>("UiDevToolsClient", server.get());
auto dom_backend = std::make_unique<DOMAgentAura>(env);
auto* dom_backend_ptr = dom_backend.get();
client->AddAgent(std::move(dom_backend));
client->AddAgent(std::make_unique<CSSAgent>(dom_backend_ptr));
client->AddAgent(std::make_unique<OverlayAgentAura>(dom_backend_ptr, env));
server->AttachClient(std::move(client));
return server;
}
} // namespace ui_devtools
// Copyright 2018 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.
#ifndef COMPONENTS_UI_DEVTOOLS_VIEWS_DEVTOOLS_SERVER_UTIL_H_
#define COMPONENTS_UI_DEVTOOLS_VIEWS_DEVTOOLS_SERVER_UTIL_H_
#include <memory>
#include "components/ui_devtools/devtools_server.h"
namespace aura {
class Env;
}
namespace ui_devtools {
// A factory helper to construct a UiDevToolsServer for Views.
std::unique_ptr<UiDevToolsServer> CreateUiDevToolsServerForViews(
network::mojom::NetworkContext* network_context,
aura::Env* env);
} // namespace ui_devtools
#endif // COMPONENTS_UI_DEVTOOLS_VIEWS_DEVTOOLS_SERVER_UTIL_H_
...@@ -34,14 +34,14 @@ views::Widget* GetWidgetFromWindow(gfx::NativeWindow window) { ...@@ -34,14 +34,14 @@ views::Widget* GetWidgetFromWindow(gfx::NativeWindow window) {
} // namespace } // namespace
DOMAgentAura::DOMAgentAura() { DOMAgentAura::DOMAgentAura(aura::Env* env) : env_(env) {
aura::Env::GetInstance()->AddObserver(this); env_->AddObserver(this);
} }
DOMAgentAura::~DOMAgentAura() { DOMAgentAura::~DOMAgentAura() {
for (aura::Window* window : root_windows_) for (aura::Window* window : root_windows_)
window->RemoveObserver(this); window->RemoveObserver(this);
aura::Env::GetInstance()->RemoveObserver(this); env_->RemoveObserver(this);
} }
void DOMAgentAura::OnHostInitialized(aura::WindowTreeHost* host) { void DOMAgentAura::OnHostInitialized(aura::WindowTreeHost* host) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace aura { namespace aura {
class Env;
class Window; class Window;
} }
...@@ -22,7 +23,7 @@ class DOMAgentAura : public DOMAgent, ...@@ -22,7 +23,7 @@ class DOMAgentAura : public DOMAgent,
public aura::EnvObserver, public aura::EnvObserver,
public aura::WindowObserver { public aura::WindowObserver {
public: public:
DOMAgentAura(); explicit DOMAgentAura(aura::Env* env);
~DOMAgentAura() override; ~DOMAgentAura() override;
const std::vector<gfx::NativeWindow>& root_windows() const { const std::vector<gfx::NativeWindow>& root_windows() const {
...@@ -50,6 +51,7 @@ class DOMAgentAura : public DOMAgent, ...@@ -50,6 +51,7 @@ class DOMAgentAura : public DOMAgent,
std::unique_ptr<protocol::DOM::Node> BuildTreeForUIElement( std::unique_ptr<protocol::DOM::Node> BuildTreeForUIElement(
UIElement* ui_element) override; UIElement* ui_element) override;
aura::Env* env_;
std::vector<aura::Window*> root_windows_; std::vector<aura::Window*> root_windows_;
DISALLOW_COPY_AND_ASSIGN(DOMAgentAura); DISALLOW_COPY_AND_ASSIGN(DOMAgentAura);
......
...@@ -368,8 +368,9 @@ void DrawR1IntersectsR2(const gfx::RectF& pinned_rect_f, ...@@ -368,8 +368,9 @@ void DrawR1IntersectsR2(const gfx::RectF& pinned_rect_f,
} // namespace } // namespace
OverlayAgentAura::OverlayAgentAura(DOMAgentAura* dom_agent) OverlayAgentAura::OverlayAgentAura(DOMAgentAura* dom_agent, aura::Env* env)
: OverlayAgent(dom_agent), : OverlayAgent(dom_agent),
env_(env),
show_size_on_canvas_(false), show_size_on_canvas_(false),
highlight_rect_config_(HighlightRectsConfiguration::NO_DRAW) {} highlight_rect_config_(HighlightRectsConfiguration::NO_DRAW) {}
...@@ -386,10 +387,9 @@ protocol::Response OverlayAgentAura::setInspectMode( ...@@ -386,10 +387,9 @@ protocol::Response OverlayAgentAura::setInspectMode(
protocol::Maybe<protocol::Overlay::HighlightConfig> in_highlightConfig) { protocol::Maybe<protocol::Overlay::HighlightConfig> in_highlightConfig) {
pinned_id_ = 0; pinned_id_ = 0;
if (in_mode.compare("searchForNode") == 0) if (in_mode.compare("searchForNode") == 0)
aura::Env::GetInstance()->AddPreTargetHandler( env_->AddPreTargetHandler(this, ui::EventTarget::Priority::kSystem);
this, ui::EventTarget::Priority::kSystem);
else if (in_mode.compare("none") == 0) else if (in_mode.compare("none") == 0)
aura::Env::GetInstance()->RemovePreTargetHandler(this); env_->RemovePreTargetHandler(this);
return protocol::Response::OK(); return protocol::Response::OK();
} }
...@@ -595,7 +595,7 @@ void OverlayAgentAura::OnKeyEvent(ui::KeyEvent* event) { ...@@ -595,7 +595,7 @@ void OverlayAgentAura::OnKeyEvent(ui::KeyEvent* event) {
// Exit inspect mode by pressing ESC key. // Exit inspect mode by pressing ESC key.
if (event->key_code() == ui::KeyboardCode::VKEY_ESCAPE) { if (event->key_code() == ui::KeyboardCode::VKEY_ESCAPE) {
aura::Env::GetInstance()->RemovePreTargetHandler(this); env_->RemovePreTargetHandler(this);
if (pinned_id_) { if (pinned_id_) {
frontend()->inspectNodeRequested(pinned_id_); frontend()->inspectNodeRequested(pinned_id_);
HighlightNode(pinned_id_, true /* show_size */); HighlightNode(pinned_id_, true /* show_size */);
......
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
#include "ui/events/event_handler.h" #include "ui/events/event_handler.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
namespace aura {
class Env;
}
namespace gfx { namespace gfx {
class RenderText; class RenderText;
} }
...@@ -35,7 +39,7 @@ class OverlayAgentAura : public OverlayAgent, ...@@ -35,7 +39,7 @@ class OverlayAgentAura : public OverlayAgent,
public ui::EventHandler, public ui::EventHandler,
public ui::LayerDelegate { public ui::LayerDelegate {
public: public:
explicit OverlayAgentAura(DOMAgentAura* dom_agent); OverlayAgentAura(DOMAgentAura* dom_agent, aura::Env* env);
~OverlayAgentAura() override; ~OverlayAgentAura() override;
int pinned_id() const { return pinned_id_; }; int pinned_id() const { return pinned_id_; };
void SetPinnedNodeId(int pinned_id); void SetPinnedNodeId(int pinned_id);
...@@ -89,6 +93,7 @@ class OverlayAgentAura : public OverlayAgent, ...@@ -89,6 +93,7 @@ class OverlayAgentAura : public OverlayAgent,
ui::Layer* layer_for_highlighting() { return layer_for_highlighting_.get(); } ui::Layer* layer_for_highlighting() { return layer_for_highlighting_.get(); }
aura::Env* env_;
std::unique_ptr<gfx::RenderText> render_text_; std::unique_ptr<gfx::RenderText> render_text_;
bool show_size_on_canvas_ = false; bool show_size_on_canvas_ = false;
HighlightRectsConfiguration highlight_rect_config_; HighlightRectsConfiguration highlight_rect_config_;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "ui/views/window/non_client_view.h" #include "ui/views/window/non_client_view.h"
#if defined(USE_AURA) #if defined(USE_AURA)
#include "ui/aura/env.h"
#include "ui/aura/test/test_window_delegate.h" #include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#endif #endif
...@@ -42,9 +43,10 @@ class OverlayAgentTest : public views::ViewsTestBase { ...@@ -42,9 +43,10 @@ class OverlayAgentTest : public views::ViewsTestBase {
fake_frontend_channel_ = std::make_unique<FakeFrontendChannel>(); fake_frontend_channel_ = std::make_unique<FakeFrontendChannel>();
uber_dispatcher_ = std::make_unique<protocol::UberDispatcher>( uber_dispatcher_ = std::make_unique<protocol::UberDispatcher>(
fake_frontend_channel_.get()); fake_frontend_channel_.get());
dom_agent_ = std::make_unique<DOMAgentAura>(); aura::Env* env = aura::Env::GetInstance();
dom_agent_ = std::make_unique<DOMAgentAura>(env);
dom_agent_->Init(uber_dispatcher_.get()); dom_agent_->Init(uber_dispatcher_.get());
overlay_agent_ = std::make_unique<OverlayAgentAura>(dom_agent_.get()); overlay_agent_ = std::make_unique<OverlayAgentAura>(dom_agent_.get(), env);
overlay_agent_->Init(uber_dispatcher_.get()); overlay_agent_->Init(uber_dispatcher_.get());
overlay_agent_->enable(); overlay_agent_->enable();
views::ViewsTestBase::SetUp(); views::ViewsTestBase::SetUp();
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "components/ui_devtools/views/widget_element.h" #include "components/ui_devtools/views/widget_element.h"
#include "components/ui_devtools/views/window_element.h" #include "components/ui_devtools/views/window_element.h"
#include "ui/aura/client/window_parenting_client.h" #include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/views/test/views_test_base.h" #include "ui/views/test/views_test_base.h"
#include "ui/views/widget/native_widget_private.h" #include "ui/views/widget/native_widget_private.h"
...@@ -135,12 +136,13 @@ class UIDevToolsTest : public views::ViewsTestBase { ...@@ -135,12 +136,13 @@ class UIDevToolsTest : public views::ViewsTestBase {
fake_frontend_channel_ = std::make_unique<FakeFrontendChannel>(); fake_frontend_channel_ = std::make_unique<FakeFrontendChannel>();
uber_dispatcher_ = uber_dispatcher_ =
std::make_unique<UberDispatcher>(fake_frontend_channel_.get()); std::make_unique<UberDispatcher>(fake_frontend_channel_.get());
dom_agent_ = std::make_unique<DOMAgentAura>(); aura::Env* env = aura::Env::GetInstance();
dom_agent_ = std::make_unique<DOMAgentAura>(env);
dom_agent_->Init(uber_dispatcher_.get()); dom_agent_->Init(uber_dispatcher_.get());
css_agent_ = std::make_unique<CSSAgent>(dom_agent_.get()); css_agent_ = std::make_unique<CSSAgent>(dom_agent_.get());
css_agent_->Init(uber_dispatcher_.get()); css_agent_->Init(uber_dispatcher_.get());
css_agent_->enable(); css_agent_->enable();
overlay_agent_ = std::make_unique<OverlayAgentAura>(dom_agent_.get()); overlay_agent_ = std::make_unique<OverlayAgentAura>(dom_agent_.get(), env);
overlay_agent_->Init(uber_dispatcher_.get()); overlay_agent_->Init(uber_dispatcher_.get());
overlay_agent_->enable(); overlay_agent_->enable();
......
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