Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick PR #3989: Don't start DebugConsole with debug_console=off. #3996

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions cobalt/browser/browser_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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(
Expand All @@ -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;
}

Expand All @@ -1189,6 +1197,7 @@ void BrowserModule::OnDebugConsoleRenderTreeProduced(
}

SubmitCurrentRenderTreeToRenderer();
#endif
}

void BrowserModule::OnNavigateTimedTrace(const std::string& time) {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -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();
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 @@ -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);
Expand Down
Loading