Skip to content

Commit

Permalink
Don't start DebugConsole with debug_console=off. (#3989)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jellefoks authored Aug 15, 2024
1 parent d4f1e95 commit a9495fe
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 18 deletions.
50 changes: 32 additions & 18 deletions cobalt/browser/browser_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,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;
Expand Down Expand Up @@ -367,15 +370,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 =
Expand Down Expand Up @@ -1095,6 +1100,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(
Expand All @@ -1103,14 +1109,17 @@ void BrowserModule::QueueOnDebugConsoleRenderTreeProduced(
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(task_runner_->RunsTasksInCurrentSequence());
if (application_state_ == base::kApplicationStateConcealed) {
if (!debug_console_ ||
(application_state_ == base::kApplicationStateConcealed)) {
return;
}

Expand All @@ -1127,6 +1136,7 @@ void BrowserModule::OnDebugConsoleRenderTreeProduced(
}

SubmitCurrentRenderTreeToRenderer();
#endif
}

void BrowserModule::OnNavigateTimedTrace(const std::string& time) {
Expand All @@ -1151,7 +1161,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)
Expand Down Expand Up @@ -1188,7 +1199,7 @@ void BrowserModule::OnPointerEventProduced(base_token::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)
Expand All @@ -1214,7 +1225,7 @@ void BrowserModule::OnWheelEventProduced(base_token::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)
Expand Down Expand Up @@ -1348,7 +1359,7 @@ bool BrowserModule::FilterKeyEvent(base_token::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)
Expand All @@ -1359,8 +1370,9 @@ bool BrowserModule::FilterKeyEvent(base_token::Token type,
bool BrowserModule::FilterKeyEventForHotkeys(
base_token::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();
Expand Down Expand Up @@ -1754,7 +1766,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();
Expand Down
12 changes: 12 additions & 0 deletions cobalt/browser/debug_console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions cobalt/browser/debug_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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);
Expand Down

0 comments on commit a9495fe

Please sign in to comment.