Merge pull request #38 from brightray/chrome-31

Update to Chrome 31
This commit is contained in:
Adam Roben 2013-12-02 10:02:21 -08:00
commit 56237a5875
12 changed files with 311 additions and 34 deletions

View file

@ -35,6 +35,8 @@
'browser/default_web_contents_delegate.cc',
'browser/default_web_contents_delegate.h',
'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.h',
'browser/download_manager_delegate.cc',

View 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, &params))) {
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

View 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_

View file

@ -61,6 +61,9 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const {
void InspectableWebContentsImpl::ShowDevTools() {
if (!devtools_web_contents_) {
embedder_message_dispatcher_.reset(
new DevToolsEmbedderMessageDispatcher(this));
auto create_params = content::WebContents::CreateParams(
web_contents_->GetBrowserContext());
devtools_web_contents_.reset(content::WebContents::Create(create_params));
@ -103,9 +106,6 @@ void InspectableWebContentsImpl::UpdateFrontendDockSide() {
void InspectableWebContentsImpl::ActivateWindow() {
}
void InspectableWebContentsImpl::ChangeAttachedWindowHeight(unsigned height) {
}
void InspectableWebContentsImpl::CloseWindow() {
view_->CloseDevTools();
devtools_web_contents_.reset();
@ -162,6 +162,11 @@ void InspectableWebContentsImpl::SearchInPath(
const std::string& query) {
}
void InspectableWebContentsImpl::DispatchOnEmbedder(
const std::string& message) {
embedder_message_dispatcher_->Dispatch(message);
}
void InspectableWebContentsImpl::InspectedContentsClosing() {
}

View file

@ -8,6 +8,8 @@
#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/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
@ -27,7 +29,8 @@ class InspectableWebContentsImpl :
public InspectableWebContents,
content::DevToolsFrontendHostDelegate,
content::WebContentsObserver,
content::WebContentsDelegate {
content::WebContentsDelegate,
DevToolsEmbedderMessageDispatcher::Delegate {
public:
static void RegisterPrefs(PrefRegistrySimple* pref_registry);
@ -46,10 +49,9 @@ class InspectableWebContentsImpl :
private:
void UpdateFrontendDockSide();
// content::DevToolsFrontendHostDelegate
// DevToolsEmbedderMessageDispacher::Delegate
virtual void ActivateWindow() OVERRIDE;
virtual void ChangeAttachedWindowHeight(unsigned height) OVERRIDE;
virtual void CloseWindow() OVERRIDE;
virtual void MoveWindow(int x, int y) OVERRIDE;
virtual void SetDockSide(const std::string& side) OVERRIDE;
@ -68,6 +70,10 @@ class InspectableWebContentsImpl :
virtual void SearchInPath(int request_id,
const std::string& file_system_path,
const std::string& query) OVERRIDE;
// content::DevToolsFrontendHostDelegate
virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE;
virtual void InspectedContentsClosing() OVERRIDE;
// content::WebContentsObserver
@ -92,6 +98,8 @@ class InspectableWebContentsImpl :
scoped_refptr<content::DevToolsAgentHost> agent_host_;
std::string dock_side_;
scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl);
};

View file

@ -9,6 +9,7 @@
#include "browser/network_delegate.h"
#include "base/strings/string_util.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/threading/worker_pool.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/cookie_store_factory.h"
@ -69,6 +70,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
base_path_.Append(FILE_PATH_LITERAL("Cookies")),
false,
nullptr,
nullptr,
nullptr));
storage_->set_server_bound_cert_service(new net::ServerBoundCertService(
new net::DefaultServerBoundCertStore(NULL),
@ -142,7 +144,11 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
job_factory->SetProtocolHandler(
chrome::kDataScheme, new net::DataProtocolHandler);
job_factory->SetProtocolHandler(
chrome::kFileScheme, new net::FileProtocolHandler);
chrome::kFileScheme,
new net::FileProtocolHandler(
content::BrowserThread::GetBlockingPool()->
GetTaskRunnerWithShutdownBehavior(
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
storage_->set_job_factory(job_factory.release());
}

View file

@ -2,13 +2,13 @@
#define BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_
#include "base/memory/weak_ptr.h"
#include "ui/base/win/window_impl.h"
#include "ui/gfx/win/window_impl.h"
namespace brightray {
class InspectableWebContentsViewWin;
class DevToolsWindow : public ui::WindowImpl,
class DevToolsWindow : public gfx::WindowImpl,
public base::SupportsWeakPtr<DevToolsWindow> {
public:
static DevToolsWindow* Create(

View file

@ -5,7 +5,7 @@
#include "browser/win/devtools_window.h"
#include "content/public/browser/web_contents_view.h"
#include "ui/base/win/hwnd_util.h"
#include "ui/gfx/win/hwnd_util.h"
namespace brightray {
@ -44,9 +44,9 @@ void InspectableWebContentsViewWin::ShowDevTools() {
auto contents_view = inspectable_web_contents_->GetWebContents()->GetView();
auto size = contents_view->GetContainerSize();
size.Enlarge(-kWindowInset, -kWindowInset);
ui::CenterAndSizeWindow(contents_view->GetNativeView(),
devtools_window_->hwnd(),
size);
gfx::CenterAndSizeWindow(contents_view->GetNativeView(),
devtools_window_->hwnd(),
size);
ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL);
}

View file

@ -34,7 +34,6 @@ void MainDelegate::PreSandboxStartup() {
#if defined(OS_MACOSX)
OverrideChildProcessPath();
OverrideFrameworkBundlePath();
SetProcessName();
#endif
InitializeResourceBundle();
}

View file

@ -42,7 +42,6 @@ class MainDelegate : public content::ContentMainDelegate {
static base::FilePath GetResourcesPakFilePath();
static void OverrideChildProcessPath();
static void OverrideFrameworkBundlePath();
static void SetProcessName();
#endif
scoped_ptr<ContentClient> content_client_;

View file

@ -11,7 +11,6 @@
#include "base/command_line.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/mac_util.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h"
@ -48,21 +47,4 @@ void MainDelegate::OverrideChildProcessPath() {
PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
}
void MainDelegate::SetProcessName() {
const auto& command_line = *CommandLine::ForCurrentProcess();
auto process_type = command_line.GetSwitchValueASCII(switches::kProcessType);
std::string suffix;
if (process_type == switches::kRendererProcess)
suffix = "Renderer";
else if (process_type == switches::kPluginProcess || process_type == switches::kPpapiPluginProcess)
suffix = "Plug-In Host";
else if (process_type == switches::kUtilityProcess)
suffix = "Utility";
else
return;
auto name = base::SysUTF8ToNSString(base::StringPrintf("%s %s", GetApplicationName().c_str(), suffix.c_str()));
base::mac::SetProcessName(base::mac::NSToCFCast(name));
}
}

@ -1 +1 @@
Subproject commit 7ddba388364ee0b429a2b72555daa55e3270876f
Subproject commit 4252769640884c1964cb936c91521e1a1fb50500