From 05e73c418f49d33e8a84f2800fb58cc5a68f244d Mon Sep 17 00:00:00 2001 From: cobalt-github-releaser-bot <95661244+cobalt-github-releaser-bot@users.noreply.github.com> Date: Thu, 15 Aug 2024 14:59:06 -0700 Subject: [PATCH] Cherry pick PR #3989: Don't start DebugConsole with debug_console=off. (#3996) Refer to the original PR: https://github.com/youtube/cobalt/pull/3989 When started with `--debug_console=off`, don't start the DebugConsole at all. Note: The web debugger (devtools) still works but no longer will show overlay changes. To also disable the web debugger, also start with `--disable_web_debugger`. b/205134049 --------- Co-authored-by: Jelle Foks --- cobalt/browser/browser_module.cc | 49 ++++++++++++++++++++------------ cobalt/browser/debug_console.cc | 12 ++++++++ cobalt/browser/debug_console.h | 3 ++ 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/cobalt/browser/browser_module.cc b/cobalt/browser/browser_module.cc index f168f1b3bf45..1464470f3a0b 100644 --- a/cobalt/browser/browser_module.cc +++ b/cobalt/browser/browser_module.cc @@ -331,7 +331,10 @@ BrowserModule::BrowserModule(const GURL& url, splash_screen_layer_ = render_tree_combiner_.CreateLayer(kSplashScreenZIndex); // Create the debug console layer. #if defined(ENABLE_DEBUGGER) - debug_console_layer_ = render_tree_combiner_.CreateLayer(kDebugConsoleZIndex); + if (DebugConsole::IsEnabled()) { + debug_console_layer_ = + render_tree_combiner_.CreateLayer(kDebugConsoleZIndex); + } #endif int qr_code_overlay_slots = 4; @@ -408,15 +411,17 @@ BrowserModule::BrowserModule(const GURL& url, resource_provider_stub_.emplace(true /*allocate_image_data*/); #if defined(ENABLE_DEBUGGER) - debug_console_.reset(new DebugConsole( - platform_info_.get(), application_state_, - base::Bind(&BrowserModule::QueueOnDebugConsoleRenderTreeProduced, - base::Unretained(this)), - &web_settings_, network_module_, GetViewportSize(), GetResourceProvider(), - kLayoutMaxRefreshFrequencyInHz, - base::Bind(&BrowserModule::CreateDebugClient, base::Unretained(this)), - base::Bind(&BrowserModule::OnMaybeFreeze, base::Unretained(this)))); - lifecycle_observers_.AddObserver(debug_console_.get()); + if (debug_console_layer_) { + debug_console_.reset(new DebugConsole( + platform_info_.get(), application_state_, + base::Bind(&BrowserModule::QueueOnDebugConsoleRenderTreeProduced, + base::Unretained(this)), + &web_settings_, network_module_, GetViewportSize(), + GetResourceProvider(), kLayoutMaxRefreshFrequencyInHz, + base::Bind(&BrowserModule::CreateDebugClient, base::Unretained(this)), + base::Bind(&BrowserModule::OnMaybeFreeze, base::Unretained(this)))); + lifecycle_observers_.AddObserver(debug_console_.get()); + } #endif // defined(ENABLE_DEBUGGER) const renderer::Pipeline* pipeline = @@ -1157,6 +1162,7 @@ void BrowserModule::OnDisableMediaCodecs(const std::string& codecs) { void BrowserModule::QueueOnDebugConsoleRenderTreeProduced( const browser::WebModule::LayoutResults& layout_results) { +#if defined(ENABLE_DEBUGGER) TRACE_EVENT0("cobalt::browser", "BrowserModule::QueueOnDebugConsoleRenderTreeProduced()"); render_tree_submission_queue_.AddMessage( @@ -1165,14 +1171,16 @@ void BrowserModule::QueueOnDebugConsoleRenderTreeProduced( self_message_loop_->task_runner()->PostTask( FROM_HERE, base::Bind(&BrowserModule::ProcessRenderTreeSubmissionQueue, weak_this_)); +#endif } void BrowserModule::OnDebugConsoleRenderTreeProduced( const browser::WebModule::LayoutResults& layout_results) { +#if defined(ENABLE_DEBUGGER) TRACE_EVENT0("cobalt::browser", "BrowserModule::OnDebugConsoleRenderTreeProduced()"); DCHECK_EQ(base::MessageLoop::current(), self_message_loop_); - if (application_state_ == base::kApplicationStateConcealed) { + if (!debug_console_ || (application_state_ == base::kApplicationStateConcealed)) { return; } @@ -1189,6 +1197,7 @@ void BrowserModule::OnDebugConsoleRenderTreeProduced( } SubmitCurrentRenderTreeToRenderer(); +#endif } void BrowserModule::OnNavigateTimedTrace(const std::string& time) { @@ -1213,7 +1222,8 @@ void BrowserModule::OnOnScreenKeyboardInputEventProduced( } #if defined(ENABLE_DEBUGGER) - if (!debug_console_->FilterOnScreenKeyboardInputEvent(type, event)) { + if (debug_console_ && + !debug_console_->FilterOnScreenKeyboardInputEvent(type, event)) { return; } #endif // defined(ENABLE_DEBUGGER) @@ -1250,7 +1260,7 @@ void BrowserModule::OnPointerEventProduced(base::Token type, } #if defined(ENABLE_DEBUGGER) - if (!debug_console_->FilterPointerEvent(type, event)) { + if (debug_console_ && !debug_console_->FilterPointerEvent(type, event)) { return; } #endif // defined(ENABLE_DEBUGGER) @@ -1276,7 +1286,7 @@ void BrowserModule::OnWheelEventProduced(base::Token type, } #if defined(ENABLE_DEBUGGER) - if (!debug_console_->FilterWheelEvent(type, event)) { + if (debug_console_ && !debug_console_->FilterWheelEvent(type, event)) { return; } #endif // defined(ENABLE_DEBUGGER) @@ -1414,7 +1424,7 @@ bool BrowserModule::FilterKeyEvent(base::Token type, } #if defined(ENABLE_DEBUGGER) - if (!debug_console_->FilterKeyEvent(type, event)) { + if (debug_console_ && !debug_console_->FilterKeyEvent(type, event)) { return false; } #endif // defined(ENABLE_DEBUGGER) @@ -1425,8 +1435,9 @@ bool BrowserModule::FilterKeyEvent(base::Token type, bool BrowserModule::FilterKeyEventForHotkeys( base::Token type, const dom::KeyboardEventInit& event) { #if defined(ENABLE_DEBUGGER) - if (event.key_code() == dom::keycode::kF1 || - (event.ctrl_key() && event.key_code() == dom::keycode::kO)) { + if (debug_console_ && + (event.key_code() == dom::keycode::kF1 || + (event.ctrl_key() && event.key_code() == dom::keycode::kO))) { if (type == base::Tokens::keydown()) { // F1 or Ctrl+O cycles the debug console display. debug_console_->CycleMode(); @@ -1861,7 +1872,9 @@ void BrowserModule::ResetResources() { main_web_module_layer_->Reset(); splash_screen_layer_->Reset(); #if defined(ENABLE_DEBUGGER) - debug_console_layer_->Reset(); + if (debug_console_layer_) { + debug_console_layer_->Reset(); + } #endif // defined(ENABLE_DEBUGGER) if (qr_overlay_info_layer_) { qr_overlay_info_layer_->Reset(); diff --git a/cobalt/browser/debug_console.cc b/cobalt/browser/debug_console.cc index f540eec8f6eb..6e999cae0fd4 100644 --- a/cobalt/browser/debug_console.cc +++ b/cobalt/browser/debug_console.cc @@ -157,6 +157,18 @@ DebugConsole::DebugConsole( DebugConsole::~DebugConsole() {} +// static +bool DebugConsole::IsEnabled() { +#if defined(ENABLE_DEBUGGER) + // The debug console is not enabled when it's turned off from the + // command-line. + return GetDebugConsoleModeFromCommandLine() != + debug::console::kDebugConsoleModeOff; +#else + return false; +#endif +} + bool DebugConsole::ShouldInjectInputEvents() { switch (GetMode()) { case debug::console::kDebugConsoleModeOff: diff --git a/cobalt/browser/debug_console.h b/cobalt/browser/debug_console.h index c77e1eca6479..368b8ecf90de 100644 --- a/cobalt/browser/debug_console.h +++ b/cobalt/browser/debug_console.h @@ -85,6 +85,9 @@ class DebugConsole : public LifecycleObserver { // Cycles through each different possible debug console visibility mode. void CycleMode(); + // Returns true if the debug console is enabled. + static bool IsEnabled(); + // Returns true iff the console is in a mode that is visible. bool IsVisible() { return (GetMode() != debug::console::kDebugConsoleModeOff);