forked from youtube/cobalt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add debug console command support to devtools. (youtube#536)
* Add debug console command support to devtools. This adds support for debug console commands to the devtools backend and to the Cobalt tab in the frontend. b/251825168 * Update cobalt_agent.cc 2021 -> 2023
- Loading branch information
Showing
7 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2023 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "cobalt/debug/backend/cobalt_agent.h" | ||
|
||
#include <set> | ||
#include <string> | ||
#include <utility> | ||
|
||
#include "base/bind.h" | ||
#include "base/values.h" | ||
#include "cobalt/debug/console/command_manager.h" | ||
#include "cobalt/debug/json_object.h" | ||
|
||
namespace cobalt { | ||
namespace debug { | ||
namespace backend { | ||
|
||
CobaltAgent::CobaltAgent(DebugDispatcher* dispatcher) | ||
: AgentBase("Cobalt", dispatcher) { | ||
commands_["getConsoleCommands"] = | ||
base::Bind(&CobaltAgent::GetConsoleCommands, base::Unretained(this)); | ||
commands_["sendConsoleCommand"] = | ||
base::Bind(&CobaltAgent::SendConsoleCommand, base::Unretained(this)); | ||
// dispatcher_->AddDomain(domain_, commands_.Bind()); | ||
} | ||
|
||
void CobaltAgent::GetConsoleCommands(Command command) { | ||
JSONObject response(new base::DictionaryValue()); | ||
JSONList list(new base::ListValue()); | ||
|
||
console::ConsoleCommandManager* command_manager = | ||
console::ConsoleCommandManager::GetInstance(); | ||
DCHECK(command_manager); | ||
if (command_manager) { | ||
std::set<std::string> commands = command_manager->GetRegisteredCommands(); | ||
for (auto& command_name : commands) { | ||
JSONObject console_command(new base::DictionaryValue()); | ||
console_command->SetString("command", command_name); | ||
console_command->SetString("shortHelp", | ||
command_manager->GetShortHelp(command_name)); | ||
console_command->SetString("longHelp", | ||
command_manager->GetLongHelp(command_name)); | ||
list->Append(std::move(console_command)); | ||
} | ||
} | ||
|
||
JSONObject commands(new base::DictionaryValue()); | ||
commands->Set("commands", std::move(list)); | ||
response->Set("result", std::move(commands)); | ||
command.SendResponse(response); | ||
} | ||
|
||
void CobaltAgent::SendConsoleCommand(Command command) { | ||
JSONObject params = JSONParse(command.GetParams()); | ||
if (params) { | ||
std::string console_command; | ||
if (params->GetString("command", &console_command)) { | ||
std::string message; | ||
params->GetString("message", &message); | ||
console::ConsoleCommandManager* console_command_manager = | ||
console::ConsoleCommandManager::GetInstance(); | ||
DCHECK(console_command_manager); | ||
console_command_manager->HandleCommand(console_command, message); | ||
command.SendResponse(); | ||
return; | ||
} | ||
} | ||
command.SendErrorResponse(Command::kInvalidParams, "Missing command."); | ||
} | ||
|
||
} // namespace backend | ||
} // namespace debug | ||
} // namespace cobalt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2023 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef COBALT_DEBUG_BACKEND_COBALT_AGENT_H_ | ||
#define COBALT_DEBUG_BACKEND_COBALT_AGENT_H_ | ||
|
||
#include "cobalt/debug/backend/agent_base.h" | ||
#include "cobalt/debug/backend/debug_dispatcher.h" | ||
#include "cobalt/debug/command.h" | ||
#include "cobalt/debug/json_object.h" | ||
#include "cobalt/dom/window.h" | ||
|
||
namespace cobalt { | ||
namespace debug { | ||
namespace backend { | ||
|
||
// Implements a small part of the the "Runtime" inspector protocol domain with | ||
// just enough to support console input. When using the V8 JavaScript engine, | ||
// this class is not needed since the V8 inspector implements the Runtime domain | ||
// for us. | ||
// | ||
// https://chromedevtools.github.io/devtools-protocol/tot/Runtime | ||
class CobaltAgent : public AgentBase { | ||
public: | ||
explicit CobaltAgent(DebugDispatcher* dispatcher); | ||
|
||
private: | ||
void GetConsoleCommands(Command command); | ||
void SendConsoleCommand(Command command); | ||
}; | ||
|
||
} // namespace backend | ||
} // namespace debug | ||
} // namespace cobalt | ||
|
||
#endif // COBALT_DEBUG_BACKEND_COBALT_AGENT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters