mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Update source files for bracket style
This commit is contained in:
@ -31,8 +31,9 @@ CefDevToolsController::~CefDevToolsController() {
|
||||
bool CefDevToolsController::SendDevToolsMessage(
|
||||
const base::StringPiece& message) {
|
||||
CEF_REQUIRE_UIT();
|
||||
if (!EnsureAgentHost())
|
||||
if (!EnsureAgentHost()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
agent_host_->DispatchProtocolMessage(
|
||||
this, base::as_bytes(base::make_span(message)));
|
||||
@ -44,25 +45,29 @@ int CefDevToolsController::ExecuteDevToolsMethod(
|
||||
const std::string& method,
|
||||
const base::DictionaryValue* params) {
|
||||
CEF_REQUIRE_UIT();
|
||||
if (!EnsureAgentHost())
|
||||
if (!EnsureAgentHost()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Message IDs must always be increasing and unique.
|
||||
int message_id = suggested_message_id;
|
||||
if (message_id < next_message_id_)
|
||||
if (message_id < next_message_id_) {
|
||||
message_id = next_message_id_++;
|
||||
else
|
||||
} else {
|
||||
next_message_id_ = message_id + 1;
|
||||
}
|
||||
|
||||
base::DictionaryValue message;
|
||||
message.SetIntKey("id", message_id);
|
||||
message.SetStringKey("method", method);
|
||||
if (params)
|
||||
if (params) {
|
||||
message.SetKey("params", params->Clone());
|
||||
}
|
||||
|
||||
std::string protocol_message;
|
||||
if (!base::JSONWriter::Write(message, &protocol_message))
|
||||
if (!base::JSONWriter::Write(message, &protocol_message)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
agent_host_->DispatchProtocolMessage(
|
||||
this, base::as_bytes(base::make_span(protocol_message)));
|
||||
@ -91,8 +96,9 @@ void CefDevToolsController::RemoveObserver(Observer* observer) {
|
||||
void CefDevToolsController::DispatchProtocolMessage(
|
||||
content::DevToolsAgentHost* agent_host,
|
||||
base::span<const uint8_t> message) {
|
||||
if (observers_.empty())
|
||||
if (observers_.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
base::StringPiece str_message(reinterpret_cast<const char*>(message.data()),
|
||||
message.size());
|
||||
|
@ -82,8 +82,9 @@ void CefDevToolsFileManager::Save(const std::string& url,
|
||||
|
||||
if (const base::Value* path_value = file_map.Find(base::MD5String(url))) {
|
||||
absl::optional<base::FilePath> path = base::ValueToFilePath(*path_value);
|
||||
if (path)
|
||||
if (path) {
|
||||
initial_path = std::move(*path);
|
||||
}
|
||||
}
|
||||
|
||||
if (initial_path.empty()) {
|
||||
@ -91,8 +92,9 @@ void CefDevToolsFileManager::Save(const std::string& url,
|
||||
std::string suggested_file_name =
|
||||
gurl.is_valid() ? gurl.ExtractFileName() : url;
|
||||
|
||||
if (suggested_file_name.length() > 64)
|
||||
if (suggested_file_name.length() > 64) {
|
||||
suggested_file_name = suggested_file_name.substr(0, 64);
|
||||
}
|
||||
|
||||
if (!g_last_save_path.Pointer()->empty()) {
|
||||
initial_path = g_last_save_path.Pointer()->DirName().AppendASCII(
|
||||
@ -167,8 +169,9 @@ void CefDevToolsFileManager::Append(const std::string& url,
|
||||
const std::string& content,
|
||||
AppendCallback callback) {
|
||||
auto it = saved_files_.find(url);
|
||||
if (it == saved_files_.end())
|
||||
if (it == saved_files_.end()) {
|
||||
return;
|
||||
}
|
||||
std::move(callback).Run();
|
||||
file_task_runner_->PostTask(
|
||||
FROM_HERE, base::BindOnce(&::AppendToFile, it->second, content));
|
||||
|
@ -98,8 +98,9 @@ base::DictionaryValue BuildObjectForResponse(const net::HttpResponseHeaders* rh,
|
||||
std::string value;
|
||||
// TODO(caseq): this probably needs to handle duplicate header names
|
||||
// correctly by folding them.
|
||||
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value))
|
||||
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value)) {
|
||||
headers->SetString(name, value);
|
||||
}
|
||||
|
||||
response.Set("headers", std::move(headers));
|
||||
return response;
|
||||
@ -135,8 +136,9 @@ void LogProtocolMessage(const base::FilePath& log_file,
|
||||
std::string to_log) {
|
||||
// Track if logging has failed, in which case we don't keep trying.
|
||||
static bool log_error = false;
|
||||
if (log_error)
|
||||
if (log_error) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (storage::NativeFileUtil::EnsureFileExists(log_file, nullptr) !=
|
||||
base::File::FILE_OK) {
|
||||
@ -289,10 +291,12 @@ void CefDevToolsFrontend::Focus() {
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::InspectElementAt(int x, int y) {
|
||||
if (inspect_element_at_.x != x || inspect_element_at_.y != y)
|
||||
if (inspect_element_at_.x != x || inspect_element_at_.y != y) {
|
||||
inspect_element_at_.Set(x, y);
|
||||
if (agent_host_)
|
||||
}
|
||||
if (agent_host_) {
|
||||
agent_host_->InspectElement(inspected_contents_->GetFocusedFrame(), x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::Close() {
|
||||
@ -334,8 +338,9 @@ void CefDevToolsFrontend::ReadyToCommitNavigation(
|
||||
std::string origin =
|
||||
navigation_handle->GetURL().DeprecatedGetOriginAsURL().spec();
|
||||
auto it = extensions_api_.find(origin);
|
||||
if (it == extensions_api_.end())
|
||||
if (it == extensions_api_.end()) {
|
||||
return;
|
||||
}
|
||||
std::string script = base::StringPrintf("%s(\"%s\")", it->second.c_str(),
|
||||
base::GenerateGUID().c_str());
|
||||
content::DevToolsFrontendHost::SetupExtensionsAPI(frame, script);
|
||||
@ -348,8 +353,9 @@ void CefDevToolsFrontend::PrimaryMainDocumentElementAvailable() {
|
||||
scoped_refptr<content::DevToolsAgentHost> agent_host =
|
||||
content::DevToolsAgentHost::GetOrCreateFor(inspected_contents_);
|
||||
if (agent_host != agent_host_) {
|
||||
if (agent_host_)
|
||||
if (agent_host_) {
|
||||
agent_host_->DetachClient(this);
|
||||
}
|
||||
agent_host_ = agent_host;
|
||||
agent_host_->AttachClient(this);
|
||||
if (!inspect_element_at_.IsEmpty()) {
|
||||
@ -371,8 +377,9 @@ void CefDevToolsFrontend::WebContentsDestroyed() {
|
||||
void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
|
||||
base::Value::Dict message) {
|
||||
const std::string* method = message.FindString("method");
|
||||
if (!method)
|
||||
if (!method) {
|
||||
return;
|
||||
}
|
||||
|
||||
int request_id = message.FindInt("id").value_or(0);
|
||||
base::Value::List* params_value = message.FindList("params");
|
||||
@ -384,11 +391,13 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
|
||||
}
|
||||
|
||||
if (*method == "dispatchProtocolMessage") {
|
||||
if (params.size() < 1)
|
||||
if (params.size() < 1) {
|
||||
return;
|
||||
}
|
||||
const std::string* protocol_message = params[0].GetIfString();
|
||||
if (!agent_host_ || !protocol_message)
|
||||
if (!agent_host_ || !protocol_message) {
|
||||
return;
|
||||
}
|
||||
if (ProtocolLoggingEnabled()) {
|
||||
LogProtocolMessage(ProtocolMessageType::METHOD, *protocol_message);
|
||||
}
|
||||
@ -398,8 +407,9 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
|
||||
web_contents()->GetPrimaryMainFrame()->ExecuteJavaScriptForTests(
|
||||
u"DevToolsAPI.setUseSoftMenu(true);", base::NullCallback());
|
||||
} else if (*method == "loadNetworkResource") {
|
||||
if (params.size() < 3)
|
||||
if (params.size() < 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(pfeldman): handle some of the embedder messages in content.
|
||||
const std::string* url = params[0].GetIfString();
|
||||
@ -486,62 +496,73 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
|
||||
base::Value(GetPrefs()->GetDict(prefs::kDevToolsPreferences).Clone()));
|
||||
return;
|
||||
} else if (*method == "setPreference") {
|
||||
if (params.size() < 2)
|
||||
if (params.size() < 2) {
|
||||
return;
|
||||
}
|
||||
const std::string* name = params[0].GetIfString();
|
||||
|
||||
// We're just setting params[1] as a value anyways, so just make sure it's
|
||||
// the type we want, but don't worry about getting it.
|
||||
if (!name || !params[1].is_string())
|
||||
if (!name || !params[1].is_string()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DictionaryPrefUpdate update(GetPrefs(), prefs::kDevToolsPreferences);
|
||||
update.Get()->SetKey(*name, std::move(params[1]));
|
||||
} else if (*method == "removePreference") {
|
||||
const std::string* name = params[0].GetIfString();
|
||||
if (!name)
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
DictionaryPrefUpdate update(GetPrefs(), prefs::kDevToolsPreferences);
|
||||
update.Get()->RemoveKey(*name);
|
||||
} else if (*method == "requestFileSystems") {
|
||||
web_contents()->GetPrimaryMainFrame()->ExecuteJavaScriptForTests(
|
||||
u"DevToolsAPI.fileSystemsLoaded([]);", base::NullCallback());
|
||||
} else if (*method == "reattach") {
|
||||
if (!agent_host_)
|
||||
if (!agent_host_) {
|
||||
return;
|
||||
}
|
||||
agent_host_->DetachClient(this);
|
||||
agent_host_->AttachClient(this);
|
||||
} else if (*method == "registerExtensionsAPI") {
|
||||
if (params.size() < 2)
|
||||
if (params.size() < 2) {
|
||||
return;
|
||||
}
|
||||
const std::string* origin = params[0].GetIfString();
|
||||
const std::string* script = params[1].GetIfString();
|
||||
if (!origin || !script)
|
||||
if (!origin || !script) {
|
||||
return;
|
||||
}
|
||||
extensions_api_[*origin + "/"] = *script;
|
||||
} else if (*method == "save") {
|
||||
if (params.size() < 3)
|
||||
if (params.size() < 3) {
|
||||
return;
|
||||
}
|
||||
const std::string* url = params[0].GetIfString();
|
||||
const std::string* content = params[1].GetIfString();
|
||||
absl::optional<bool> save_as = params[2].GetIfBool();
|
||||
if (!url || !content || !save_as.has_value())
|
||||
if (!url || !content || !save_as.has_value()) {
|
||||
return;
|
||||
}
|
||||
file_manager_.SaveToFile(*url, *content, *save_as);
|
||||
} else if (*method == "append") {
|
||||
if (params.size() < 2)
|
||||
if (params.size() < 2) {
|
||||
return;
|
||||
}
|
||||
const std::string* url = params[0].GetIfString();
|
||||
const std::string* content = params[1].GetIfString();
|
||||
if (!url || !content)
|
||||
if (!url || !content) {
|
||||
return;
|
||||
}
|
||||
file_manager_.AppendToFile(*url, *content);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (request_id)
|
||||
if (request_id) {
|
||||
SendMessageAck(request_id, base::Value());
|
||||
}
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::DispatchProtocolMessage(
|
||||
|
@ -30,8 +30,9 @@ class CefDevToolsRegistrationImpl : public CefRegistration,
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
// May be null if OnDevToolsControllerDestroyed was called.
|
||||
if (!controller_)
|
||||
if (!controller_) {
|
||||
return;
|
||||
}
|
||||
|
||||
controller_->RemoveObserver(this);
|
||||
}
|
||||
@ -132,8 +133,9 @@ void CefDevToolsManager::ShowDevTools(const CefWindowInfo& windowInfo,
|
||||
|
||||
void CefDevToolsManager::CloseDevTools() {
|
||||
CEF_REQUIRE_UIT();
|
||||
if (!devtools_frontend_)
|
||||
if (!devtools_frontend_) {
|
||||
return;
|
||||
}
|
||||
devtools_frontend_->Close();
|
||||
}
|
||||
|
||||
@ -145,11 +147,13 @@ bool CefDevToolsManager::HasDevTools() {
|
||||
bool CefDevToolsManager::SendDevToolsMessage(const void* message,
|
||||
size_t message_size) {
|
||||
CEF_REQUIRE_UIT();
|
||||
if (!message || message_size == 0)
|
||||
if (!message || message_size == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!EnsureController())
|
||||
if (!EnsureController()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return devtools_controller_->SendDevToolsMessage(
|
||||
base::StringPiece(static_cast<const char*>(message), message_size));
|
||||
@ -160,11 +164,13 @@ int CefDevToolsManager::ExecuteDevToolsMethod(
|
||||
const CefString& method,
|
||||
CefRefPtr<CefDictionaryValue> params) {
|
||||
CEF_REQUIRE_UIT();
|
||||
if (method.empty())
|
||||
if (method.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!EnsureController())
|
||||
if (!EnsureController()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (params && params->IsValid()) {
|
||||
CefDictionaryValueImpl* impl =
|
||||
@ -189,8 +195,9 @@ void CefDevToolsManager::InitializeRegistrationOnUIThread(
|
||||
CefRefPtr<CefRegistration> registration) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
if (!EnsureController())
|
||||
if (!EnsureController()) {
|
||||
return;
|
||||
}
|
||||
|
||||
static_cast<CefDevToolsRegistrationImpl*>(registration.get())
|
||||
->Initialize(inspected_browser_, devtools_controller_->GetWeakPtr());
|
||||
|
@ -51,8 +51,10 @@ class TCPServerSocketFactory : public content::DevToolsSocketFactory {
|
||||
std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
|
||||
std::unique_ptr<net::ServerSocket> socket(
|
||||
new net::TCPServerSocket(nullptr, net::NetLogSource()));
|
||||
if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK)
|
||||
if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) !=
|
||||
net::OK) {
|
||||
return std::unique_ptr<net::ServerSocket>();
|
||||
}
|
||||
return socket;
|
||||
}
|
||||
|
||||
@ -85,8 +87,9 @@ std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() {
|
||||
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
|
||||
}
|
||||
}
|
||||
if (port == 0)
|
||||
if (port == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::unique_ptr<content::DevToolsSocketFactory>(
|
||||
new TCPServerSocketFactory("127.0.0.1", port));
|
||||
}
|
||||
@ -100,8 +103,9 @@ void CefDevToolsManagerDelegate::StartHttpHandler(
|
||||
content::BrowserContext* browser_context) {
|
||||
std::unique_ptr<content::DevToolsSocketFactory> socket_factory =
|
||||
CreateSocketFactory();
|
||||
if (!socket_factory)
|
||||
if (!socket_factory) {
|
||||
return;
|
||||
}
|
||||
content::DevToolsAgentHost::StartRemoteDebuggingServer(
|
||||
std::move(socket_factory), browser_context->GetPath(), base::FilePath());
|
||||
|
||||
|
@ -25,16 +25,19 @@ bool ParseEvent(const base::StringPiece& message,
|
||||
static const char kMethodEnd[] = "\"";
|
||||
static const char kParamsStart[] = ",\"params\":";
|
||||
|
||||
if (!base::StartsWith(message, kMethodStart))
|
||||
if (!base::StartsWith(message, kMethodStart)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t method_start = sizeof(kMethodStart) - 1;
|
||||
const size_t method_end = message.find(kMethodEnd, method_start);
|
||||
if (method_end == base::StringPiece::npos)
|
||||
if (method_end == base::StringPiece::npos) {
|
||||
return false;
|
||||
}
|
||||
method = message.substr(method_start, method_end - method_start);
|
||||
if (method.empty())
|
||||
if (method.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t remainder_start = method_end + sizeof(kMethodEnd) - 1;
|
||||
if (remainder_start == message.size() - 1) {
|
||||
@ -52,8 +55,9 @@ bool ParseEvent(const base::StringPiece& message,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsValidDictionary(params, /*allow_empty=*/true))
|
||||
if (!IsValidDictionary(params, /*allow_empty=*/true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -72,16 +76,19 @@ bool ParseResult(const base::StringPiece& message,
|
||||
static const char kResultStart[] = "\"result\":";
|
||||
static const char kErrorStart[] = "\"error\":";
|
||||
|
||||
if (!base::StartsWith(message, kIdStart))
|
||||
if (!base::StartsWith(message, kIdStart)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t id_start = sizeof(kIdStart) - 1;
|
||||
const size_t id_end = message.find(kIdEnd, id_start);
|
||||
if (id_end == base::StringPiece::npos)
|
||||
if (id_end == base::StringPiece::npos) {
|
||||
return false;
|
||||
}
|
||||
const base::StringPiece& id_str = message.substr(id_start, id_end - id_start);
|
||||
if (id_str.empty() || !base::StringToInt(id_str, &message_id))
|
||||
if (id_str.empty() || !base::StringToInt(id_str, &message_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t remainder_start = id_end + sizeof(kIdEnd) - 1;
|
||||
const base::StringPiece& remainder = message.substr(remainder_start);
|
||||
@ -102,8 +109,9 @@ bool ParseResult(const base::StringPiece& message,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsValidDictionary(result, /*allow_empty=*/true))
|
||||
if (!IsValidDictionary(result, /*allow_empty=*/true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -116,8 +124,9 @@ bool ProtocolParser::IsValidMessage(const base::StringPiece& message) {
|
||||
}
|
||||
|
||||
bool ProtocolParser::Initialize(const base::StringPiece& message) {
|
||||
if (status_ != UNINITIALIZED)
|
||||
if (status_ != UNINITIALIZED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ParseEvent(message, method_, params_)) {
|
||||
status_ = EVENT;
|
||||
|
Reference in New Issue
Block a user