Skip to content

Commit

Permalink
Cherry pick PR #567: Update lifecycle console commands and add to dev…
Browse files Browse the repository at this point in the history
…tools. (#640)

* Update lifecycle console commands and add to devtools.

This updates the lifecycle console commands to support all current
lifecycle transitions, and add corresponding buttons to devtools.

b/251825168

* Update lifecycle_console_commands.cc

removed empty line

(cherry picked from commit fdaea56)

Co-authored-by: Jelle Foks <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and jellefoks committed Jun 17, 2023
1 parent c4d8737 commit 1922262
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 36 deletions.
87 changes: 55 additions & 32 deletions cobalt/browser/lifecycle_console_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,41 @@
namespace cobalt {
namespace browser {

const char kPauseCommand[] = "pause";
const char kPauseCommandShortHelp[] = "Sends a request to pause Cobalt.";
const char kPauseCommandLongHelp[] =
"Sends a request to the platform to pause Cobalt, indicating that it is "
const char kBlurCommand[] = "blur";
const char kBlurCommandShortHelp[] = "Sends a request to blur Cobalt.";
const char kBlurCommandLongHelp[] =
"Sends a request to the platform to blur Cobalt, indicating that it is "
"not in focus and sending a blur event to the web application.";

const char kUnpauseCommand[] = "unpause";
const char kUnpauseCommandShortHelp[] = "Sends a request to unpause Cobalt.";
const char kUnpauseCommandLongHelp[] =
"Sends a request to the platform to unpause Cobalt, resulting in a focus "
const char kFocusCommand[] = "focus";
const char kFocusCommandShortHelp[] = "Sends a request to focus Cobalt.";
const char kFocusCommandLongHelp[] =
"Sends a request to the platform to focus Cobalt, resulting in a Focus "
"event being sent to the web application.";

const char kSuspendCommand[] = "suspend";
const char kSuspendCommandShortHelp[] = "Sends a request to suspend Cobalt.";
const char kSuspendCommandLongHelp[] =
"Sends a request to the platform to suspend Cobalt, indicating that it is "
const char kConcealCommand[] = "conceal";
const char kConcealCommandShortHelp[] = "Sends a request to conceal Cobalt.";
const char kConcealCommandLongHelp[] =
"Sends a request to the platform to conceal Cobalt, indicating that it is "
"not visible and sending a hidden event to the web application. Note that "
"Cobalt may become unresponsive after this call and you will need to "
"Cobalt may become unresponsive after this call in which case you will "
"need to resume it in a platform-specific way.";

const char kFreezeCommand[] = "freeze";
const char kFreezeCommandShortHelp[] = "Sends a request to freeze Cobalt.";
const char kFreezeCommandLongHelp[] =
"Sends a request to the platform to freeze Cobalt, indicating that it is "
"not visible, sending a hidden event to the web application, and halt "
"processing. Note that Cobalt may become unresponsive after this call in "
"which case you will need to resume it in a platform-specific way.";

const char kRevealCommand[] = "reveal";
const char kRevealCommandShortHelp[] = "Sends a request to reveal Cobalt.";
const char kRevealCommandLongHelp[] =
"Sends a request to the platform to reveal Cobalt, indicating that it is "
"visible but not focues, and sending a visible event to the web "
"application. Note that "
"Cobalt may be unresponsive in which case you will need to "
"resume it in a platform-specific way.";

const char kQuitCommand[] = "quit";
Expand All @@ -50,31 +67,37 @@ const char kQuitCommandLongHelp[] =
"ending the process (peacefully).";

namespace {
// This is temporary that will be changed in later CLs, for mapping Starboard
// Concealed state support onto Cobalt without Concealed state support to be
// able to test the former.
void OnPause(const std::string& /*message*/) { SbSystemRequestBlur(); }

void OnUnpause(const std::string& /*message*/) { SbSystemRequestFocus(); }

void OnSuspend(const std::string& /*message*/) {
LOG(INFO) << "Concealing Cobalt through the console, but you will need to "
<< "reveal Cobalt using a platform-specific method.";
void OnBlur(const std::string&) { SbSystemRequestBlur(); }
void OnFocus(const std::string&) { SbSystemRequestFocus(); }
void OnConceal(const std::string&) {
LOG(WARNING)
<< "Concealing Cobalt through the console. Note that Cobalt may "
"become unresponsive after this call in which case you will "
"need to resume it in a platform-specific way.";
SbSystemRequestConceal();
}

void OnFreeze(const std::string&) {
LOG(WARNING) << "Freezing Cobalt through the console. Note that Cobalt may "
"become unresponsive after this call in which case you will "
"need to resume it in a platform-specific way.";
SbSystemRequestFreeze();
}
void OnReveal(const std::string&) { SbSystemRequestReveal(); }
void OnQuit(const std::string& /*message*/) { SbSystemRequestStop(0); }
} // namespace

LifecycleConsoleCommands::LifecycleConsoleCommands()
: pause_command_handler_(kPauseCommand, base::Bind(&OnPause),
kPauseCommandShortHelp, kPauseCommandLongHelp),
unpause_command_handler_(kUnpauseCommand, base::Bind(OnUnpause),
kUnpauseCommandShortHelp,
kUnpauseCommandLongHelp),
suspend_command_handler_(kSuspendCommand, base::Bind(OnSuspend),
kSuspendCommandShortHelp,
kSuspendCommandLongHelp),
: blur_command_handler_(kBlurCommand, base::Bind(OnBlur),
kBlurCommandShortHelp, kBlurCommandLongHelp),
focus_command_handler_(kFocusCommand, base::Bind(OnFocus),
kFocusCommandShortHelp, kFocusCommandLongHelp),
conceal_command_handler_(kConcealCommand, base::Bind(OnConceal),
kConcealCommandShortHelp,
kConcealCommandLongHelp),
freeze_command_handler_(kFreezeCommand, base::Bind(OnFreeze),
kFreezeCommandShortHelp, kFreezeCommandLongHelp),
reveal_command_handler_(kRevealCommand, base::Bind(OnReveal),
kRevealCommandShortHelp, kRevealCommandLongHelp),
quit_command_handler_(kQuitCommand, base::Bind(OnQuit),
kQuitCommandShortHelp, kQuitCommandLongHelp) {}

Expand Down
9 changes: 5 additions & 4 deletions cobalt/browser/lifecycle_console_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ class LifecycleConsoleCommands {
LifecycleConsoleCommands();

private:
debug::console::ConsoleCommandManager::CommandHandler pause_command_handler_;
debug::console::ConsoleCommandManager::CommandHandler blur_command_handler_;
debug::console::ConsoleCommandManager::CommandHandler focus_command_handler_;
debug::console::ConsoleCommandManager::CommandHandler
unpause_command_handler_;
debug::console::ConsoleCommandManager::CommandHandler
suspend_command_handler_;
conceal_command_handler_;
debug::console::ConsoleCommandManager::CommandHandler freeze_command_handler_;
debug::console::ConsoleCommandManager::CommandHandler reveal_command_handler_;
debug::console::ConsoleCommandManager::CommandHandler quit_command_handler_;
};

Expand Down
30 changes: 30 additions & 0 deletions third_party/devtools/front_end/cobalt/cobalt.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,36 @@ export default class CobaltPanel extends UI.VBox {
});
}));
});
const debugLogContainer = this.element.createChild('div', 'debug-log-container');
debugLogContainer.appendChild(UI.createTextButton(Common.UIString('DebugLog On'), event => {
this._cobaltAgent.invoke_sendConsoleCommand({
command: 'debug_log', message: 'on'
});
}));
debugLogContainer.appendChild(UI.createTextButton(Common.UIString('DebugLog Off'), event => {
this._cobaltAgent.invoke_sendConsoleCommand({
command: 'debug_log', message: 'off'
});
}));
const lifecycleContainer = this.element.createChild('div', 'lifecycle-container');
lifecycleContainer.appendChild(UI.createTextButton(Common.UIString('Blur'), event => {
this._cobaltAgent.invoke_sendConsoleCommand({ command: 'blur' });
}));
lifecycleContainer.appendChild(UI.createTextButton(Common.UIString('Focus'), event => {
this._cobaltAgent.invoke_sendConsoleCommand({ command: 'focus' });
}));
lifecycleContainer.appendChild(UI.createTextButton(Common.UIString('Conceal'), event => {
this._cobaltAgent.invoke_sendConsoleCommand({ command: 'conceal' });
}));
lifecycleContainer.appendChild(UI.createTextButton(Common.UIString('Freeze'), event => {
this._cobaltAgent.invoke_sendConsoleCommand({ command: 'freeze' });
}));
lifecycleContainer.appendChild(UI.createTextButton(Common.UIString('Reveal'), event => {
this._cobaltAgent.invoke_sendConsoleCommand({ command: 'reveal' });
}));
lifecycleContainer.appendChild(UI.createTextButton(Common.UIString('Quit'), event => {
this._cobaltAgent.invoke_sendConsoleCommand({ command: 'quit' });
}));
const consoleContainer = this.element.createChild('div', 'console-container');
consoleContainer.appendChild(UI.createTextButton(Common.UIString('DebugCommand'), event => {
const outputElement = document.getElementsByClassName('console-output')[0];
Expand Down

0 comments on commit 1922262

Please sign in to comment.