diff --git a/cobalt/browser/browser_module.cc b/cobalt/browser/browser_module.cc index f168f1b3bf45..0f4a567cb03e 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,22 @@ 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()"); +<<<<<<< HEAD DCHECK_EQ(base::MessageLoop::current(), self_message_loop_); if (application_state_ == base::kApplicationStateConcealed) { +======= + DCHECK(task_runner_->RunsTasksInCurrentSequence()); + if (!debug_console_ || + (application_state_ == base::kApplicationStateConcealed)) { +>>>>>>> a9495fedb6e (Don't start DebugConsole with debug_console=off. (#3989)) return; } @@ -1189,6 +1203,7 @@ void BrowserModule::OnDebugConsoleRenderTreeProduced( } SubmitCurrentRenderTreeToRenderer(); +#endif } void BrowserModule::OnNavigateTimedTrace(const std::string& time) { @@ -1213,7 +1228,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 +1266,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 +1292,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 +1430,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 +1441,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 +1878,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);