Send message ack to devtools.
This commit is contained in:
parent
a5bb24284e
commit
1fbeb11371
3 changed files with 39 additions and 27 deletions
|
@ -5,16 +5,12 @@
|
||||||
#include "browser/devtools_embedder_message_dispatcher.h"
|
#include "browser/devtools_embedder_message_dispatcher.h"
|
||||||
|
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "base/json/json_reader.h"
|
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
static const char kFrontendHostMethod[] = "method";
|
|
||||||
static const char kFrontendHostParams[] = "params";
|
|
||||||
|
|
||||||
bool GetValue(const base::ListValue& list, int pos, std::string& value) {
|
bool GetValue(const base::ListValue& list, int pos, std::string& value) {
|
||||||
return list.GetString(pos, &value);
|
return list.GetString(pos, &value);
|
||||||
}
|
}
|
||||||
|
@ -250,30 +246,15 @@ DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher(
|
||||||
|
|
||||||
DevToolsEmbedderMessageDispatcher::~DevToolsEmbedderMessageDispatcher() {}
|
DevToolsEmbedderMessageDispatcher::~DevToolsEmbedderMessageDispatcher() {}
|
||||||
|
|
||||||
void DevToolsEmbedderMessageDispatcher::Dispatch(const std::string& message) {
|
std::string DevToolsEmbedderMessageDispatcher::Dispatch(
|
||||||
std::string method;
|
const std::string& method, base::ListValue* params) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
HandlerMap::iterator it = handlers_.find(method);
|
HandlerMap::iterator it = handlers_.find(method);
|
||||||
if (it == handlers_.end()) {
|
if (it == handlers_.end())
|
||||||
LOG(ERROR) << "Unsupported frontend host method: " << message;
|
return "Unsupported frontend host method: " + method;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!it->second.Run(*params))
|
if (!it->second.Run(*params))
|
||||||
LOG(ERROR) << "Invalid frontend host message parameters: " << message;
|
return "Invalid frontend host message parameters: " + method;
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevToolsEmbedderMessageDispatcher::RegisterHandler(
|
void DevToolsEmbedderMessageDispatcher::RegisterHandler(
|
||||||
|
|
|
@ -63,7 +63,7 @@ class DevToolsEmbedderMessageDispatcher {
|
||||||
|
|
||||||
~DevToolsEmbedderMessageDispatcher();
|
~DevToolsEmbedderMessageDispatcher();
|
||||||
|
|
||||||
void Dispatch(const std::string& message);
|
std::string Dispatch(const std::string& method, base::ListValue* params);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef base::Callback<bool (const base::ListValue&)> Handler;
|
typedef base::Callback<bool (const base::ListValue&)> Handler;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "browser/inspectable_web_contents_delegate.h"
|
#include "browser/inspectable_web_contents_delegate.h"
|
||||||
#include "browser/inspectable_web_contents_view.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_registry_simple.h"
|
||||||
#include "base/prefs/pref_service.h"
|
#include "base/prefs/pref_service.h"
|
||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
|
@ -21,6 +22,7 @@
|
||||||
#include "content/public/browser/devtools_http_handler.h"
|
#include "content/public/browser/devtools_http_handler.h"
|
||||||
#include "content/public/browser/devtools_manager.h"
|
#include "content/public/browser/devtools_manager.h"
|
||||||
#include "content/public/browser/web_contents_view.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"
|
#include "content/public/browser/render_view_host.h"
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
@ -30,6 +32,10 @@ namespace {
|
||||||
const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?can_dock=true";
|
const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?can_dock=true";
|
||||||
const char kDevToolsBoundsPref[] = "brightray.devtools.bounds";
|
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) {
|
void RectToDictionary(const gfx::Rect& bounds, base::DictionaryValue* dict) {
|
||||||
dict->SetInteger("x", bounds.x());
|
dict->SetInteger("x", bounds.x());
|
||||||
dict->SetInteger("y", bounds.y());
|
dict->SetInteger("y", bounds.y());
|
||||||
|
@ -181,6 +187,8 @@ void InspectableWebContentsImpl::AppendToFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::RequestFileSystems() {
|
void InspectableWebContentsImpl::RequestFileSystems() {
|
||||||
|
devtools_web_contents()->GetMainFrame()->ExecuteJavaScript(
|
||||||
|
base::ASCIIToUTF16("InspectorFrontendAPI.fileSystemsLoaded([])"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::AddFileSystem() {
|
void InspectableWebContentsImpl::AddFileSystem() {
|
||||||
|
@ -218,7 +226,30 @@ void InspectableWebContentsImpl::ResetZoom() {
|
||||||
|
|
||||||
void InspectableWebContentsImpl::DispatchOnEmbedder(
|
void InspectableWebContentsImpl::DispatchOnEmbedder(
|
||||||
const std::string& message) {
|
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() {
|
void InspectableWebContentsImpl::InspectedContentsClosing() {
|
||||||
|
|
Loading…
Reference in a new issue