зеркало из https://github.com/electron/electron.git
Send message ack to devtools.
This commit is contained in:
Родитель
a5bb24284e
Коммит
1fbeb11371
|
@ -5,16 +5,12 @@
|
|||
#include "browser/devtools_embedder_message_dispatcher.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/json/json_reader.h"
|
||||
#include "base/values.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
namespace {
|
||||
|
||||
static const char kFrontendHostMethod[] = "method";
|
||||
static const char kFrontendHostParams[] = "params";
|
||||
|
||||
bool GetValue(const base::ListValue& list, int pos, std::string& value) {
|
||||
return list.GetString(pos, &value);
|
||||
}
|
||||
|
@ -250,30 +246,15 @@ DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher(
|
|||
|
||||
DevToolsEmbedderMessageDispatcher::~DevToolsEmbedderMessageDispatcher() {}
|
||||
|
||||
void DevToolsEmbedderMessageDispatcher::Dispatch(const std::string& message) {
|
||||
std::string method;
|
||||
base::ListValue empty_params;
|
||||
base::ListValue* params = &empty_params;
|
||||
|
||||
base::DictionaryValue* dict;
|
||||
scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
|
||||
if (!parsed_message ||
|
||||
!parsed_message->GetAsDictionary(&dict) ||
|
||||
!dict->GetString(kFrontendHostMethod, &method) ||
|
||||
(dict->HasKey(kFrontendHostParams) &&
|
||||
!dict->GetList(kFrontendHostParams, ¶ms))) {
|
||||
LOG(ERROR) << "Cannot parse frontend host message: " << message;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string DevToolsEmbedderMessageDispatcher::Dispatch(
|
||||
const std::string& method, base::ListValue* params) {
|
||||
HandlerMap::iterator it = handlers_.find(method);
|
||||
if (it == handlers_.end()) {
|
||||
LOG(ERROR) << "Unsupported frontend host method: " << message;
|
||||
return;
|
||||
}
|
||||
if (it == handlers_.end())
|
||||
return "Unsupported frontend host method: " + method;
|
||||
|
||||
if (!it->second.Run(*params))
|
||||
LOG(ERROR) << "Invalid frontend host message parameters: " << message;
|
||||
return "Invalid frontend host message parameters: " + method;
|
||||
return "";
|
||||
}
|
||||
|
||||
void DevToolsEmbedderMessageDispatcher::RegisterHandler(
|
||||
|
|
|
@ -63,7 +63,7 @@ class DevToolsEmbedderMessageDispatcher {
|
|||
|
||||
~DevToolsEmbedderMessageDispatcher();
|
||||
|
||||
void Dispatch(const std::string& message);
|
||||
std::string Dispatch(const std::string& method, base::ListValue* params);
|
||||
|
||||
private:
|
||||
typedef base::Callback<bool (const base::ListValue&)> Handler;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "browser/inspectable_web_contents_delegate.h"
|
||||
#include "browser/inspectable_web_contents_view.h"
|
||||
|
||||
#include "base/json/json_reader.h"
|
||||
#include "base/prefs/pref_registry_simple.h"
|
||||
#include "base/prefs/pref_service.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
|
@ -21,6 +22,7 @@
|
|||
#include "content/public/browser/devtools_http_handler.h"
|
||||
#include "content/public/browser/devtools_manager.h"
|
||||
#include "content/public/browser/web_contents_view.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
|
||||
namespace brightray {
|
||||
|
@ -30,6 +32,10 @@ namespace {
|
|||
const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?can_dock=true";
|
||||
const char kDevToolsBoundsPref[] = "brightray.devtools.bounds";
|
||||
|
||||
const char kFrontendHostId[] = "id";
|
||||
const char kFrontendHostMethod[] = "method";
|
||||
const char kFrontendHostParams[] = "params";
|
||||
|
||||
void RectToDictionary(const gfx::Rect& bounds, base::DictionaryValue* dict) {
|
||||
dict->SetInteger("x", bounds.x());
|
||||
dict->SetInteger("y", bounds.y());
|
||||
|
@ -181,6 +187,8 @@ void InspectableWebContentsImpl::AppendToFile(
|
|||
}
|
||||
|
||||
void InspectableWebContentsImpl::RequestFileSystems() {
|
||||
devtools_web_contents()->GetMainFrame()->ExecuteJavaScript(
|
||||
base::ASCIIToUTF16("InspectorFrontendAPI.fileSystemsLoaded([])"));
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::AddFileSystem() {
|
||||
|
@ -218,7 +226,30 @@ void InspectableWebContentsImpl::ResetZoom() {
|
|||
|
||||
void InspectableWebContentsImpl::DispatchOnEmbedder(
|
||||
const std::string& message) {
|
||||
embedder_message_dispatcher_->Dispatch(message);
|
||||
std::string method;
|
||||
base::ListValue empty_params;
|
||||
base::ListValue* params = &empty_params;
|
||||
|
||||
base::DictionaryValue* dict = NULL;
|
||||
scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
|
||||
if (!parsed_message ||
|
||||
!parsed_message->GetAsDictionary(&dict) ||
|
||||
!dict->GetString(kFrontendHostMethod, &method) ||
|
||||
(dict->HasKey(kFrontendHostParams) &&
|
||||
!dict->GetList(kFrontendHostParams, ¶ms))) {
|
||||
LOG(ERROR) << "Invalid message was sent to embedder: " << message;
|
||||
return;
|
||||
}
|
||||
|
||||
int id = 0;
|
||||
dict->GetInteger(kFrontendHostId, &id);
|
||||
|
||||
std::string error = embedder_message_dispatcher_->Dispatch(method, params);
|
||||
if (id) {
|
||||
std::string ack = base::StringPrintf(
|
||||
"InspectorFrontendAPI.embedderMessageAck(%d, \"%s\");", id, error.c_str());
|
||||
devtools_web_contents()->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(ack));
|
||||
}
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::InspectedContentsClosing() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче