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

(cherry picked from commit a9495fe)
  • Loading branch information
jellefoks authored and anonymous1-me committed Aug 15, 2024
1 parent c6647d4 commit 6347575
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
62 changes: 60 additions & 2 deletions cobalt/browser/browser_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,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
if (command_line->HasSwitch(browser::switches::kQrCodeOverlay)) {
qr_overlay_info_layer_ =
Expand Down Expand Up @@ -411,6 +414,7 @@ BrowserModule::BrowserModule(const GURL& url,
}

#if defined(ENABLE_DEBUGGER)
<<<<<<< HEAD
debug_console_.reset(new DebugConsole(
application_state_,
base::Bind(&BrowserModule::QueueOnDebugConsoleRenderTreeProduced,
Expand All @@ -419,6 +423,19 @@ BrowserModule::BrowserModule(const GURL& url,
kLayoutMaxRefreshFrequencyInHz,
base::Bind(&BrowserModule::CreateDebugClient, 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());
}
>>>>>>> a9495fedb6e (Don't start DebugConsole with debug_console=off. (#3989))
#endif // defined(ENABLE_DEBUGGER)
if (command_line->HasSwitch(switches::kEnableMapToMeshRectanglar)) {
Expand Down Expand Up @@ -1031,6 +1048,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 @@ -1039,14 +1057,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::kApplicationStatePreloading) {
=======
DCHECK(task_runner_->RunsTasksInCurrentSequence());
if (!debug_console_ ||
(application_state_ == base::kApplicationStateConcealed)) {
>>>>>>> a9495fedb6e (Don't start DebugConsole with debug_console=off. (#3989))
return;
}
Expand All @@ -1063,6 +1089,7 @@ void BrowserModule::OnDebugConsoleRenderTreeProduced(
}
SubmitCurrentRenderTreeToRenderer();
#endif
}
#endif // defined(ENABLE_DEBUGGER)
Expand All @@ -1081,12 +1108,18 @@ void BrowserModule::OnOnScreenKeyboardInputEventProduced(
}
#if defined(ENABLE_DEBUGGER)
<<<<<<< HEAD
// If the debug console is fully visible, it gets the next chance to handle
// input events.
if (debug_console_->GetMode() >= debug::console::DebugHub::kDebugConsoleOn) {
if (!debug_console_->InjectOnScreenKeyboardInputEvent(type, event)) {
return;
}
=======
if (debug_console_ &&
!debug_console_->FilterOnScreenKeyboardInputEvent(type, event)) {
return;
>>>>>>> a9495fedb6e (Don't start DebugConsole with debug_console=off. (#3989))
}
#endif // defined(ENABLE_DEBUGGER)

Expand Down Expand Up @@ -1123,12 +1156,17 @@ void BrowserModule::OnPointerEventProduced(base::Token type,
}

#if defined(ENABLE_DEBUGGER)
<<<<<<< HEAD
// If the debug console is fully visible, it gets the next chance to handle
// pointer events.
if (debug_console_->GetMode() >= debug::console::DebugHub::kDebugConsoleOn) {
if (!debug_console_->FilterPointerEvent(type, event)) {
return;
}
=======
if (debug_console_ && !debug_console_->FilterPointerEvent(type, event)) {
return;
>>>>>>> a9495fedb6e (Don't start DebugConsole with debug_console=off. (#3989))
}
#endif // defined(ENABLE_DEBUGGER)
Expand All @@ -1148,12 +1186,17 @@ void BrowserModule::OnWheelEventProduced(base::Token type,
}
#if defined(ENABLE_DEBUGGER)
<<<<<<< HEAD
// If the debug console is fully visible, it gets the next chance to handle
// wheel events.
if (debug_console_->GetMode() >= debug::console::DebugHub::kDebugConsoleOn) {
if (!debug_console_->FilterWheelEvent(type, event)) {
return;
}
=======
if (debug_console_ && !debug_console_->FilterWheelEvent(type, event)) {
return;
>>>>>>> a9495fedb6e (Don't start DebugConsole with debug_console=off. (#3989))
}

#endif // defined(ENABLE_DEBUGGER)
Expand Down Expand Up @@ -1278,24 +1321,37 @@ bool BrowserModule::FilterKeyEvent(base::Token type,
}

#if defined(ENABLE_DEBUGGER)
<<<<<<< HEAD
// If the debug console is fully visible, it gets the next chance to handle
// key events.
if (debug_console_->GetMode() >= debug::console::DebugHub::kDebugConsoleOn) {
if (!debug_console_->FilterKeyEvent(type, event)) {
return false;
}
=======
if (debug_console_ && !debug_console_->FilterKeyEvent(type, event)) {
return false;
>>>>>>> a9495fedb6e (Don't start DebugConsole with debug_console=off. (#3989))
}
#endif // defined(ENABLE_DEBUGGER)
return true;
}
bool BrowserModule::FilterKeyEventForHotkeys(
<<<<<<< HEAD
base::Token type, const dom::KeyboardEventInit& event) {
#if !defined(ENABLE_DEBUGGER)
#else
if (event.key_code() == dom::keycode::kF1 ||
(event.ctrl_key() && event.key_code() == dom::keycode::kO)) {
=======
base_token::Token type, const dom::KeyboardEventInit& event) {
#if defined(ENABLE_DEBUGGER)
if (debug_console_ &&
(event.key_code() == dom::keycode::kF1 ||
(event.ctrl_key() && event.key_code() == dom::keycode::kO))) {
>>>>>>> a9495fedb6e (Don't start DebugConsole with debug_console=off. (#3989))
if (type == base::Tokens::keydown()) {
// Ctrl+O toggles the debug console display.
debug_console_->CycleMode();
Expand Down Expand Up @@ -1685,7 +1741,9 @@ void BrowserModule::SuspendInternal(bool is_start) {
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
26 changes: 26 additions & 0 deletions cobalt/browser/debug_console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,33 @@ DebugConsole::DebugConsole(

DebugConsole::~DebugConsole() {}

<<<<<<< HEAD
bool DebugConsole::FilterKeyEvent(base::Token type,
=======
// 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:
case debug::console::kDebugConsoleModeHud:
return false;
default:
return true;
}
}

bool DebugConsole::FilterKeyEvent(base_token::Token type,
>>>>>>> a9495fedb6e (Don't start DebugConsole with debug_console=off. (#3989))
const dom::KeyboardEventInit& event) {
// Assume here the full debug console is visible - pass all events to its
// web module, and return false to indicate the event has been consumed.
Expand Down
13 changes: 13 additions & 0 deletions cobalt/browser/debug_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,22 @@ class DebugConsole : public LifecycleObserver {
// Returns the currently set debug console visibility mode.
int GetMode();

<<<<<<< HEAD
void SetSize(const cssom::ViewportSize& window_dimensions,
float video_pixel_ratio) {
web_module_->SetSize(window_dimensions, video_pixel_ratio);
=======
// 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);
}

void SetSize(const cssom::ViewportSize& viewport_size) {
web_module_->SetSize(viewport_size);
>>>>>>> a9495fedb6e (Don't start DebugConsole with debug_console=off. (#3989))
}
// LifecycleObserver implementation.
Expand Down

0 comments on commit 6347575

Please sign in to comment.