From 7d22da516941ea821c7c428fd12eebadb138110f Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 23 Jul 2015 18:18:03 +0800 Subject: [PATCH] Fix API changes in DevToolsManagerDelegate. --- .../browser/devtools_manager_delegate.cc | 135 ++++-------------- brightray/browser/devtools_manager_delegate.h | 9 +- brightray/common/content_client.cc | 18 ++- brightray/common/content_client.h | 2 + 4 files changed, 48 insertions(+), 116 deletions(-) diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index ec660d08ce03..0491d8aa859c 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -12,27 +12,21 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" -#include "browser/browser_context.h" +#include "common/content_client.h" +#include "components/devtools_discovery/basic_target_descriptor.h" +#include "components/devtools_http_handler/devtools_http_handler.h" #include "content/public/browser/devtools_agent_host.h" -#include "content/public/browser/devtools_http_handler.h" -#include "content/public/browser/devtools_target.h" +#include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/favicon_status.h" #include "content/public/browser/navigation_entry.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/web_contents.h" #include "content/public/common/content_switches.h" #include "content/public/common/url_constants.h" #include "content/public/common/user_agent.h" +#include "net/base/net_errors.h" #include "net/socket/tcp_server_socket.h" #include "net/socket/stream_socket.h" #include "ui/base/resource/resource_bundle.h" -using content::DevToolsAgentHost; -using content::RenderViewHost; -using content::WebContents; -using content::BrowserContext; -using content::DevToolsTarget; -using content::DevToolsHttpHandler; namespace brightray { @@ -43,12 +37,8 @@ namespace { // since libcontentchromium doesn't expose content_shell resources. const int kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE = 25500; -const char kTargetTypePage[] = "page"; -const char kTargetTypeServiceWorker[] = "service_worker"; -const char kTargetTypeOther[] = "other"; - class TCPServerSocketFactory - : public content::DevToolsHttpHandler::ServerSocketFactory { + : public devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory { public: TCPServerSocketFactory(const std::string& address, int port) : address_(address), port_(port) { @@ -71,7 +61,7 @@ class TCPServerSocketFactory DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); }; -scoped_ptr +scoped_ptr CreateSocketFactory() { auto& command_line = *base::CommandLine::ForCurrentProcess(); // See if the user specified a port on the command line (useful for @@ -88,77 +78,24 @@ CreateSocketFactory() { DLOG(WARNING) << "Invalid http debugger port number " << temp_port; } } - return scoped_ptr( - new TCPServerSocketFactory("127.0.0.1", port)); + return scoped_ptr< + devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory>( + new TCPServerSocketFactory("127.0.0.1", port)); } -class Target : public content::DevToolsTarget { - public: - explicit Target(scoped_refptr agent_host); - - std::string GetId() const override { return agent_host_->GetId(); } - std::string GetParentId() const override { return std::string(); } - std::string GetType() const override { - switch (agent_host_->GetType()) { - case DevToolsAgentHost::TYPE_WEB_CONTENTS: - return kTargetTypePage; - case DevToolsAgentHost::TYPE_SERVICE_WORKER: - return kTargetTypeServiceWorker; - default: - break; - } - return kTargetTypeOther; - } - std::string GetTitle() const override { return agent_host_->GetTitle(); } - std::string GetDescription() const override { return std::string(); } - GURL GetURL() const override { return agent_host_->GetURL(); } - GURL GetFaviconURL() const override { return favicon_url_; } - base::TimeTicks GetLastActivityTime() const override { - return last_activity_time_; - } - bool IsAttached() const override { return agent_host_->IsAttached(); } - scoped_refptr GetAgentHost() const override { - return agent_host_; - } - bool Activate() const override; - bool Close() const override; - - private: - scoped_refptr agent_host_; - GURL favicon_url_; - base::TimeTicks last_activity_time_; -}; - -Target::Target(scoped_refptr agent_host) - : agent_host_(agent_host) { - if (WebContents* web_contents = agent_host_->GetWebContents()) { - content::NavigationController& controller = web_contents->GetController(); - content::NavigationEntry* entry = controller.GetActiveEntry(); - if (entry != NULL && entry->GetURL().is_valid()) - favicon_url_ = entry->GetFavicon().url; - last_activity_time_ = web_contents->GetLastActiveTime(); - } -} - -bool Target::Activate() const { - return agent_host_->Activate(); -} - -bool Target::Close() const { - return agent_host_->Close(); -} // DevToolsDelegate -------------------------------------------------------- -class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { +class DevToolsDelegate : + public devtools_http_handler::DevToolsHttpHandlerDelegate { public: DevToolsDelegate(); virtual ~DevToolsDelegate(); - // content::DevToolsHttpHandlerDelegate. + // devtools_http_handler::DevToolsHttpHandlerDelegate. std::string GetDiscoveryPageHTML() override; - bool BundlesFrontendResources() override; - base::FilePath GetDebugFrontendDir() override; + std::string GetFrontendResource(const std::string& path) override; + std::string GetPageThumbnailData(const GURL& url) override; private: DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate); @@ -175,12 +112,14 @@ std::string DevToolsDelegate::GetDiscoveryPageHTML() { kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); } -bool DevToolsDelegate::BundlesFrontendResources() { - return true; + +std::string DevToolsDelegate::GetFrontendResource( + const std::string& path) { + return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); } -base::FilePath DevToolsDelegate::GetDebugFrontendDir() { - return base::FilePath(); +std::string DevToolsDelegate::GetPageThumbnailData(const GURL& url) { + return std::string(); } } // namespace @@ -188,12 +127,16 @@ base::FilePath DevToolsDelegate::GetDebugFrontendDir() { // DevToolsManagerDelegate --------------------------------------------------- // static -content::DevToolsHttpHandler* +devtools_http_handler::DevToolsHttpHandler* DevToolsManagerDelegate::CreateHttpHandler() { - return DevToolsHttpHandler::Start(CreateSocketFactory(), - std::string(), - new DevToolsDelegate, - base::FilePath()); + return new devtools_http_handler::DevToolsHttpHandler( + CreateSocketFactory(), + std::string(), + new DevToolsDelegate, + base::FilePath(), + base::FilePath(), + std::string(), + GetBrightrayUserAgent()); } DevToolsManagerDelegate::DevToolsManagerDelegate() { @@ -208,22 +151,4 @@ base::DictionaryValue* DevToolsManagerDelegate::HandleCommand( return NULL; } -std::string DevToolsManagerDelegate::GetPageThumbnailData( - const GURL& url) { - return std::string(); -} - -scoped_ptr -DevToolsManagerDelegate::CreateNewTarget(const GURL& url) { - return scoped_ptr(); -} - -void DevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) { - TargetList targets; - for (const auto& agent_host : DevToolsAgentHost::GetOrCreateAll()) { - targets.push_back(new Target(agent_host)); - } - callback.Run(targets); -} - } // namespace brightray diff --git a/brightray/browser/devtools_manager_delegate.h b/brightray/browser/devtools_manager_delegate.h index 529f1ff7b895..154ea9ccbf75 100644 --- a/brightray/browser/devtools_manager_delegate.h +++ b/brightray/browser/devtools_manager_delegate.h @@ -7,10 +7,10 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "content/public/browser/devtools_http_handler_delegate.h" +#include "components/devtools_http_handler/devtools_http_handler_delegate.h" #include "content/public/browser/devtools_manager_delegate.h" -namespace content { +namespace devtools_http_handler { class DevToolsHttpHandler; } @@ -18,7 +18,7 @@ namespace brightray { class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { public: - static content::DevToolsHttpHandler* CreateHttpHandler(); + static devtools_http_handler::DevToolsHttpHandler* CreateHttpHandler(); DevToolsManagerDelegate(); virtual ~DevToolsManagerDelegate(); @@ -30,9 +30,6 @@ class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { bool attached) override {} base::DictionaryValue* HandleCommand(content::DevToolsAgentHost* agent_host, base::DictionaryValue* command) override; - scoped_ptr CreateNewTarget(const GURL& url) override; - void EnumerateTargets(TargetCallback callback) override; - std::string GetPageThumbnailData(const GURL& url) override; private: DISALLOW_COPY_AND_ASSIGN(DevToolsManagerDelegate); diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index 3867ed6fe3fb..b13fc73ef900 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -14,6 +14,17 @@ namespace brightray { +std::string GetProductInternal() { + auto name = GetApplicationName(); + base::RemoveChars(name, base::kWhitespaceASCII, &name); + return base::StringPrintf("%s/%s", + name.c_str(), GetApplicationVersion().c_str()); +} + +std::string GetBrightrayUserAgent() { + return content::BuildUserAgentFromProduct(GetProductInternal()); +} + ContentClient::ContentClient() { } @@ -21,14 +32,11 @@ ContentClient::~ContentClient() { } std::string ContentClient::GetProduct() const { - auto name = GetApplicationName(); - base::RemoveChars(name, base::kWhitespaceASCII, &name); - return base::StringPrintf("%s/%s", - name.c_str(), GetApplicationVersion().c_str()); + return GetProductInternal(); } std::string ContentClient::GetUserAgent() const { - return content::BuildUserAgentFromProduct(GetProduct()); + return GetBrightrayUserAgent(); } base::string16 ContentClient::GetLocalizedString(int message_id) const { diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h index f0e4449e251d..d54cf5df7301 100644 --- a/brightray/common/content_client.h +++ b/brightray/common/content_client.h @@ -10,6 +10,8 @@ namespace brightray { +std::string GetBrightrayUserAgent(); + class ContentClient : public content::ContentClient { public: ContentClient();