Update for changes to devtools in Chrome 31
browser/devtools_embedder_message_dispatcher.* came from chrome/browser/devtools, and were modified just enough to compile within brightray.
This commit is contained in:
parent
1da8c37098
commit
265076f19a
5 changed files with 297 additions and 6 deletions
|
@ -35,6 +35,8 @@
|
||||||
'browser/default_web_contents_delegate.cc',
|
'browser/default_web_contents_delegate.cc',
|
||||||
'browser/default_web_contents_delegate.h',
|
'browser/default_web_contents_delegate.h',
|
||||||
'browser/default_web_contents_delegate_mac.mm',
|
'browser/default_web_contents_delegate_mac.mm',
|
||||||
|
'browser/devtools_embedder_message_dispatcher.cc',
|
||||||
|
'browser/devtools_embedder_message_dispatcher.h',
|
||||||
'browser/devtools_ui.cc',
|
'browser/devtools_ui.cc',
|
||||||
'browser/devtools_ui.h',
|
'browser/devtools_ui.h',
|
||||||
'browser/download_manager_delegate.cc',
|
'browser/download_manager_delegate.cc',
|
||||||
|
|
208
brightray/browser/devtools_embedder_message_dispatcher.cc
Normal file
208
brightray/browser/devtools_embedder_message_dispatcher.cc
Normal file
|
@ -0,0 +1,208 @@
|
||||||
|
// Copyright 2013 The Chromium Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE-CHROMIUM file.
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GetValue(const base::ListValue& list, int pos, int& value) {
|
||||||
|
return list.GetInteger(pos, &value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GetValue(const base::ListValue& list, int pos, bool& value) {
|
||||||
|
return list.GetBoolean(pos, &value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct StorageTraits {
|
||||||
|
typedef T StorageType;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct StorageTraits<const T&> {
|
||||||
|
typedef T StorageType;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class A>
|
||||||
|
class Argument {
|
||||||
|
public:
|
||||||
|
typedef typename StorageTraits<A>::StorageType ValueType;
|
||||||
|
|
||||||
|
Argument(const base::ListValue& list, int pos) {
|
||||||
|
valid_ = GetValue(list, pos, value_);
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueType value() const { return value_; }
|
||||||
|
bool valid() const { return valid_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
ValueType value_;
|
||||||
|
bool valid_;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool ParseAndHandle0(const base::Callback<void(void)>& handler,
|
||||||
|
const base::ListValue& list) {
|
||||||
|
handler.Run();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class A1>
|
||||||
|
bool ParseAndHandle1(const base::Callback<void(A1)>& handler,
|
||||||
|
const base::ListValue& list) {
|
||||||
|
if (list.GetSize() != 1)
|
||||||
|
return false;
|
||||||
|
Argument<A1> arg1(list, 0);
|
||||||
|
if (!arg1.valid())
|
||||||
|
return false;
|
||||||
|
handler.Run(arg1.value());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class A1, class A2>
|
||||||
|
bool ParseAndHandle2(const base::Callback<void(A1, A2)>& handler,
|
||||||
|
const base::ListValue& list) {
|
||||||
|
if (list.GetSize() != 2)
|
||||||
|
return false;
|
||||||
|
Argument<A1> arg1(list, 0);
|
||||||
|
if (!arg1.valid())
|
||||||
|
return false;
|
||||||
|
Argument<A2> arg2(list, 1);
|
||||||
|
if (!arg2.valid())
|
||||||
|
return false;
|
||||||
|
handler.Run(arg1.value(), arg2.value());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class A1, class A2, class A3>
|
||||||
|
bool ParseAndHandle3(const base::Callback<void(A1, A2, A3)>& handler,
|
||||||
|
const base::ListValue& list) {
|
||||||
|
if (list.GetSize() != 3)
|
||||||
|
return false;
|
||||||
|
Argument<A1> arg1(list, 0);
|
||||||
|
if (!arg1.valid())
|
||||||
|
return false;
|
||||||
|
Argument<A2> arg2(list, 1);
|
||||||
|
if (!arg2.valid())
|
||||||
|
return false;
|
||||||
|
Argument<A3> arg3(list, 2);
|
||||||
|
if (!arg3.valid())
|
||||||
|
return false;
|
||||||
|
handler.Run(arg1.value(), arg2.value(), arg3.value());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef base::Callback<bool (const base::ListValue&)> ListValueParser;
|
||||||
|
|
||||||
|
ListValueParser BindToListParser(const base::Callback<void()>& handler) {
|
||||||
|
return base::Bind(&ParseAndHandle0, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class A1>
|
||||||
|
ListValueParser BindToListParser(const base::Callback<void(A1)>& handler) {
|
||||||
|
return base::Bind(&ParseAndHandle1<A1>, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class A1, class A2>
|
||||||
|
ListValueParser BindToListParser(const base::Callback<void(A1, A2)>& handler) {
|
||||||
|
return base::Bind(&ParseAndHandle2<A1, A2>, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class A1, class A2, class A3>
|
||||||
|
ListValueParser BindToListParser(
|
||||||
|
const base::Callback<void(A1, A2, A3)>& handler) {
|
||||||
|
return base::Bind(&ParseAndHandle3<A1, A2, A3>, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher(
|
||||||
|
Delegate* delegate) {
|
||||||
|
RegisterHandler("bringToFront",
|
||||||
|
BindToListParser(base::Bind(&Delegate::ActivateWindow,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
RegisterHandler("closeWindow",
|
||||||
|
BindToListParser(base::Bind(&Delegate::CloseWindow,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
RegisterHandler("moveWindowBy",
|
||||||
|
BindToListParser(base::Bind(&Delegate::MoveWindow,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
RegisterHandler("requestSetDockSide",
|
||||||
|
BindToListParser(base::Bind(&Delegate::SetDockSide,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
RegisterHandler("openInNewTab",
|
||||||
|
BindToListParser(base::Bind(&Delegate::OpenInNewTab,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
RegisterHandler("save",
|
||||||
|
BindToListParser(base::Bind(&Delegate::SaveToFile,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
RegisterHandler("append",
|
||||||
|
BindToListParser(base::Bind(&Delegate::AppendToFile,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
RegisterHandler("requestFileSystems",
|
||||||
|
BindToListParser(base::Bind(&Delegate::RequestFileSystems,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
RegisterHandler("addFileSystem",
|
||||||
|
BindToListParser(base::Bind(&Delegate::AddFileSystem,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
RegisterHandler("removeFileSystem",
|
||||||
|
BindToListParser(base::Bind(&Delegate::RemoveFileSystem,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
RegisterHandler("indexPath",
|
||||||
|
BindToListParser(base::Bind(&Delegate::IndexPath,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
RegisterHandler("stopIndexing",
|
||||||
|
BindToListParser(base::Bind(&Delegate::StopIndexing,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
RegisterHandler("searchInPath",
|
||||||
|
BindToListParser(base::Bind(&Delegate::SearchInPath,
|
||||||
|
base::Unretained(delegate))));
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
HandlerMap::iterator it = handlers_.find(method);
|
||||||
|
if (it == handlers_.end()) {
|
||||||
|
LOG(ERROR) << "Unsupported frontend host method: " << message;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!it->second.Run(*params))
|
||||||
|
LOG(ERROR) << "Invalid frontend host message parameters: " << message;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DevToolsEmbedderMessageDispatcher::RegisterHandler(
|
||||||
|
const std::string& method, const Handler& handler) {
|
||||||
|
handlers_[method] = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace brightray
|
68
brightray/browser/devtools_embedder_message_dispatcher.h
Normal file
68
brightray/browser/devtools_embedder_message_dispatcher.h
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
// Copyright 2013 The Chromium Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE-CHROMIUM file.
|
||||||
|
|
||||||
|
#ifndef BRIGHTRAY_BROWSER_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_
|
||||||
|
#define BRIGHTRAY_BROWSER_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "base/callback.h"
|
||||||
|
|
||||||
|
namespace base {
|
||||||
|
class ListValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace brightray {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatcher for messages sent from the DevTools frontend running in an
|
||||||
|
* isolated renderer (on chrome-devtools://) to the embedder in the browser.
|
||||||
|
*
|
||||||
|
* The messages are sent via InspectorFrontendHost.sendMessageToEmbedder method.
|
||||||
|
*/
|
||||||
|
class DevToolsEmbedderMessageDispatcher {
|
||||||
|
public:
|
||||||
|
class Delegate {
|
||||||
|
public:
|
||||||
|
virtual ~Delegate() {}
|
||||||
|
|
||||||
|
virtual void ActivateWindow() = 0;
|
||||||
|
virtual void CloseWindow() = 0;
|
||||||
|
virtual void MoveWindow(int x, int y) = 0;
|
||||||
|
virtual void SetDockSide(const std::string& side) = 0;
|
||||||
|
virtual void OpenInNewTab(const std::string& url) = 0;
|
||||||
|
virtual void SaveToFile(const std::string& url,
|
||||||
|
const std::string& content,
|
||||||
|
bool save_as) = 0;
|
||||||
|
virtual void AppendToFile(const std::string& url,
|
||||||
|
const std::string& content) = 0;
|
||||||
|
virtual void RequestFileSystems() = 0;
|
||||||
|
virtual void AddFileSystem() = 0;
|
||||||
|
virtual void RemoveFileSystem(const std::string& file_system_path) = 0;
|
||||||
|
virtual void IndexPath(int request_id,
|
||||||
|
const std::string& file_system_path) = 0;
|
||||||
|
virtual void StopIndexing(int request_id) = 0;
|
||||||
|
virtual void SearchInPath(int request_id,
|
||||||
|
const std::string& file_system_path,
|
||||||
|
const std::string& query) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit DevToolsEmbedderMessageDispatcher(Delegate* delegate);
|
||||||
|
|
||||||
|
~DevToolsEmbedderMessageDispatcher();
|
||||||
|
|
||||||
|
void Dispatch(const std::string& message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef base::Callback<bool (const base::ListValue&)> Handler;
|
||||||
|
void RegisterHandler(const std::string& method, const Handler& handler);
|
||||||
|
|
||||||
|
typedef std::map<std::string, Handler> HandlerMap;
|
||||||
|
HandlerMap handlers_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace brightray
|
||||||
|
|
||||||
|
#endif // BRIGHTRAY_BROWSER_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_
|
|
@ -61,6 +61,9 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const {
|
||||||
|
|
||||||
void InspectableWebContentsImpl::ShowDevTools() {
|
void InspectableWebContentsImpl::ShowDevTools() {
|
||||||
if (!devtools_web_contents_) {
|
if (!devtools_web_contents_) {
|
||||||
|
embedder_message_dispatcher_.reset(
|
||||||
|
new DevToolsEmbedderMessageDispatcher(this));
|
||||||
|
|
||||||
auto create_params = content::WebContents::CreateParams(
|
auto create_params = content::WebContents::CreateParams(
|
||||||
web_contents_->GetBrowserContext());
|
web_contents_->GetBrowserContext());
|
||||||
devtools_web_contents_.reset(content::WebContents::Create(create_params));
|
devtools_web_contents_.reset(content::WebContents::Create(create_params));
|
||||||
|
@ -103,9 +106,6 @@ void InspectableWebContentsImpl::UpdateFrontendDockSide() {
|
||||||
void InspectableWebContentsImpl::ActivateWindow() {
|
void InspectableWebContentsImpl::ActivateWindow() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::ChangeAttachedWindowHeight(unsigned height) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void InspectableWebContentsImpl::CloseWindow() {
|
void InspectableWebContentsImpl::CloseWindow() {
|
||||||
view_->CloseDevTools();
|
view_->CloseDevTools();
|
||||||
devtools_web_contents_.reset();
|
devtools_web_contents_.reset();
|
||||||
|
@ -162,6 +162,11 @@ void InspectableWebContentsImpl::SearchInPath(
|
||||||
const std::string& query) {
|
const std::string& query) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InspectableWebContentsImpl::DispatchOnEmbedder(
|
||||||
|
const std::string& message) {
|
||||||
|
embedder_message_dispatcher_->Dispatch(message);
|
||||||
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::InspectedContentsClosing() {
|
void InspectableWebContentsImpl::InspectedContentsClosing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
#include "browser/inspectable_web_contents.h"
|
#include "browser/inspectable_web_contents.h"
|
||||||
|
|
||||||
|
#include "browser/devtools_embedder_message_dispatcher.h"
|
||||||
|
|
||||||
#include "content/public/browser/devtools_frontend_host_delegate.h"
|
#include "content/public/browser/devtools_frontend_host_delegate.h"
|
||||||
#include "content/public/browser/web_contents_delegate.h"
|
#include "content/public/browser/web_contents_delegate.h"
|
||||||
#include "content/public/browser/web_contents_observer.h"
|
#include "content/public/browser/web_contents_observer.h"
|
||||||
|
@ -27,7 +29,8 @@ class InspectableWebContentsImpl :
|
||||||
public InspectableWebContents,
|
public InspectableWebContents,
|
||||||
content::DevToolsFrontendHostDelegate,
|
content::DevToolsFrontendHostDelegate,
|
||||||
content::WebContentsObserver,
|
content::WebContentsObserver,
|
||||||
content::WebContentsDelegate {
|
content::WebContentsDelegate,
|
||||||
|
DevToolsEmbedderMessageDispatcher::Delegate {
|
||||||
public:
|
public:
|
||||||
static void RegisterPrefs(PrefRegistrySimple* pref_registry);
|
static void RegisterPrefs(PrefRegistrySimple* pref_registry);
|
||||||
|
|
||||||
|
@ -46,10 +49,9 @@ class InspectableWebContentsImpl :
|
||||||
private:
|
private:
|
||||||
void UpdateFrontendDockSide();
|
void UpdateFrontendDockSide();
|
||||||
|
|
||||||
// content::DevToolsFrontendHostDelegate
|
// DevToolsEmbedderMessageDispacher::Delegate
|
||||||
|
|
||||||
virtual void ActivateWindow() OVERRIDE;
|
virtual void ActivateWindow() OVERRIDE;
|
||||||
virtual void ChangeAttachedWindowHeight(unsigned height) OVERRIDE;
|
|
||||||
virtual void CloseWindow() OVERRIDE;
|
virtual void CloseWindow() OVERRIDE;
|
||||||
virtual void MoveWindow(int x, int y) OVERRIDE;
|
virtual void MoveWindow(int x, int y) OVERRIDE;
|
||||||
virtual void SetDockSide(const std::string& side) OVERRIDE;
|
virtual void SetDockSide(const std::string& side) OVERRIDE;
|
||||||
|
@ -68,6 +70,10 @@ class InspectableWebContentsImpl :
|
||||||
virtual void SearchInPath(int request_id,
|
virtual void SearchInPath(int request_id,
|
||||||
const std::string& file_system_path,
|
const std::string& file_system_path,
|
||||||
const std::string& query) OVERRIDE;
|
const std::string& query) OVERRIDE;
|
||||||
|
|
||||||
|
// content::DevToolsFrontendHostDelegate
|
||||||
|
|
||||||
|
virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE;
|
||||||
virtual void InspectedContentsClosing() OVERRIDE;
|
virtual void InspectedContentsClosing() OVERRIDE;
|
||||||
|
|
||||||
// content::WebContentsObserver
|
// content::WebContentsObserver
|
||||||
|
@ -92,6 +98,8 @@ class InspectableWebContentsImpl :
|
||||||
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
||||||
std::string dock_side_;
|
std::string dock_side_;
|
||||||
|
|
||||||
|
scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl);
|
DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue