| Index: chrome/browser/devtools/browser_list_tabcontents_provider.cc
|
| diff --git a/chrome/browser/devtools/browser_list_tabcontents_provider.cc b/chrome/browser/devtools/browser_list_tabcontents_provider.cc
|
| index 1e43a493367bc87d7c4aa332ed9da65c1c5efa31..7d8092e6d3e72de4424b2111148582eb965c3a78 100644
|
| --- a/chrome/browser/devtools/browser_list_tabcontents_provider.cc
|
| +++ b/chrome/browser/devtools/browser_list_tabcontents_provider.cc
|
| @@ -6,6 +6,8 @@
|
|
|
| #include "base/path_service.h"
|
| #include "base/strings/string_number_conversions.h"
|
| +#include "base/strings/stringprintf.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| #include "chrome/browser/extensions/extension_host.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/extensions/extension_system.h"
|
| @@ -20,15 +22,158 @@
|
| #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| #include "chrome/common/chrome_paths.h"
|
| +#include "content/public/browser/browser_thread.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/browser/worker_service.h"
|
| #include "content/public/common/url_constants.h"
|
| #include "grit/devtools_discovery_page_resources.h"
|
| +#include "net/base/escape.h"
|
| #include "net/socket/tcp_listen_socket.h"
|
| #include "net/url_request/url_request_context_getter.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
|
|
| +using content::DevToolsAgentHost;
|
| using content::DevToolsHttpHandlerDelegate;
|
| +using content::DevToolsTarget;
|
| using content::RenderViewHost;
|
| +using content::WebContents;
|
| +
|
| +namespace {
|
| +
|
| +const char kTargetTypePage[] = "page";
|
| +const char kTargetTypeOther[] = "other";
|
| +
|
| +std::string GetExtensionName(WebContents* web_contents) {
|
| + Profile* profile =
|
| + Profile::FromBrowserContext(web_contents->GetBrowserContext());
|
| + if (!profile)
|
| + return std::string();
|
| +
|
| + extensions::ExtensionHost* extension_host =
|
| + extensions::ExtensionSystem::Get(profile)->process_manager()->
|
| + GetBackgroundHostForExtension(web_contents->GetURL().host());
|
| +
|
| + if (!extension_host || extension_host->host_contents() != web_contents)
|
| + return std::string();
|
| +
|
| + return extension_host->extension()->name();
|
| +}
|
| +
|
| +class Target : public content::DevToolsTarget {
|
| + public:
|
| + Target(WebContents* web_contents, bool is_tab);
|
| +
|
| + virtual std::string GetId() const OVERRIDE { return id_; }
|
| + virtual std::string GetType() const OVERRIDE { return type_; }
|
| + virtual std::string GetTitle() const OVERRIDE { return title_; }
|
| + virtual std::string GetDescription() const OVERRIDE { return description_; }
|
| + virtual GURL GetUrl() const OVERRIDE { return url_; }
|
| + virtual GURL GetFaviconUrl() const OVERRIDE { return favicon_url_; }
|
| + virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
|
| + return last_activity_time_;
|
| + }
|
| + virtual bool IsAttached() const OVERRIDE {
|
| + return agent_host_->IsAttached();
|
| + }
|
| + virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
|
| + return agent_host_;
|
| + }
|
| + virtual bool Activate() const OVERRIDE;
|
| + virtual bool Close() const OVERRIDE;
|
| +
|
| + private:
|
| + virtual ~Target() {}
|
| +
|
| + scoped_refptr<DevToolsAgentHost> agent_host_;
|
| + std::string id_;
|
| + std::string type_;
|
| + std::string title_;
|
| + std::string description_;
|
| + GURL url_;
|
| + GURL favicon_url_;
|
| + base::TimeTicks last_activity_time_;
|
| +};
|
| +
|
| +Target::Target(WebContents* web_contents, bool is_tab) {
|
| + agent_host_ =
|
| + DevToolsAgentHost::GetOrCreateFor(web_contents->GetRenderViewHost());
|
| + id_ = agent_host_->GetId();
|
| + type_ = is_tab ? kTargetTypePage : kTargetTypeOther;
|
| + description_ = GetExtensionName(web_contents);
|
| + title_ = UTF16ToUTF8(net::EscapeForHTML(web_contents->GetTitle()));
|
| + url_ = web_contents->GetURL();
|
| + 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->GetLastSelectedTime();
|
| +}
|
| +
|
| +bool Target::Activate() const {
|
| + RenderViewHost* rvh = agent_host_->GetRenderViewHost();
|
| + if (!rvh)
|
| + return false;
|
| + WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
|
| + if (!web_contents)
|
| + return false;
|
| + web_contents->GetDelegate()->ActivateContents(web_contents);
|
| + return true;
|
| +}
|
| +
|
| +bool Target::Close() const {
|
| + RenderViewHost* rvh = agent_host_->GetRenderViewHost();
|
| + if (!rvh)
|
| + return false;
|
| + rvh->ClosePage();
|
| + return true;
|
| +}
|
| +
|
| +class WorkerTarget : public content::DevToolsTarget {
|
| + public:
|
| + explicit WorkerTarget(content::WorkerService::WorkerInfo& worker_info);
|
| +
|
| + virtual std::string GetId() const OVERRIDE { return id_; }
|
| + virtual std::string GetType() const OVERRIDE { return "other"; }
|
| + virtual std::string GetTitle() const OVERRIDE { return title_; }
|
| + virtual std::string GetDescription() const OVERRIDE { return description_; }
|
| + virtual GURL GetUrl() const OVERRIDE { return url_; }
|
| + virtual GURL GetFaviconUrl() const OVERRIDE { return GURL(); }
|
| + virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
|
| + return base::TimeTicks();
|
| + }
|
| + virtual bool IsAttached() const OVERRIDE {
|
| + return agent_host_->IsAttached();
|
| + }
|
| + virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
|
| + return agent_host_;
|
| + }
|
| + virtual bool Activate() const OVERRIDE { return false; }
|
| + virtual bool Close() const OVERRIDE { return false; }
|
| +
|
| + private:
|
| + virtual ~WorkerTarget() {}
|
| +
|
| + scoped_refptr<DevToolsAgentHost> agent_host_;
|
| + std::string id_;
|
| + std::string title_;
|
| + std::string description_;
|
| + GURL url_;
|
| +};
|
| +
|
| +WorkerTarget::WorkerTarget(content::WorkerService::WorkerInfo& worker) {
|
| + agent_host_ =
|
| + DevToolsAgentHost::GetForWorker(worker.process_id, worker.route_id);
|
| + id_ = agent_host_->GetId();
|
| + title_ = UTF16ToUTF8(net::EscapeForHTML(worker.name));
|
| + description_ =
|
| + base::StringPrintf("Worker pid:%d", base::GetProcId(worker.handle));
|
| + url_ = worker.url;
|
| +}
|
| +
|
| +} // namespace
|
|
|
| BrowserListTabContentsProvider::BrowserListTabContentsProvider(
|
| chrome::HostDesktopType host_desktop_type)
|
| @@ -86,54 +231,35 @@ std::string BrowserListTabContentsProvider::GetPageThumbnailData(
|
| return std::string();
|
| }
|
|
|
| -RenderViewHost* BrowserListTabContentsProvider::CreateNewTarget() {
|
| +scoped_refptr<DevToolsTarget>
|
| +BrowserListTabContentsProvider::CreateNewTarget() {
|
| const BrowserList* browser_list =
|
| BrowserList::GetInstance(host_desktop_type_);
|
| -
|
| + WebContents* web_contents;
|
| if (browser_list->empty()) {
|
| chrome::NewEmptyWindow(ProfileManager::GetLastUsedProfile(),
|
| host_desktop_type_);
|
| - return browser_list->empty() ? NULL :
|
| - browser_list->get(0)->tab_strip_model()->GetActiveWebContents()->
|
| - GetRenderViewHost();
|
| - }
|
| -
|
| - content::WebContents* web_contents = chrome::AddSelectedTabWithURL(
|
| + if (browser_list->empty())
|
| + return NULL;
|
| + web_contents =
|
| + browser_list->get(0)->tab_strip_model()->GetActiveWebContents();
|
| + } else {
|
| + web_contents = chrome::AddSelectedTabWithURL(
|
| browser_list->get(0),
|
| GURL(content::kAboutBlankURL),
|
| content::PAGE_TRANSITION_LINK);
|
| - return web_contents->GetRenderViewHost();
|
| + }
|
| + return new Target(web_contents, true);
|
| }
|
| -
|
| -content::DevToolsHttpHandlerDelegate::TargetType
|
| -BrowserListTabContentsProvider::GetTargetType(content::RenderViewHost* rvh) {
|
| - for (TabContentsIterator it; !it.done(); it.Next())
|
| - if (rvh == it->GetRenderViewHost())
|
| - return kTargetTypeTab;
|
| -
|
| - return kTargetTypeOther;
|
| -}
|
| -
|
| -std::string BrowserListTabContentsProvider::GetViewDescription(
|
| - content::RenderViewHost* rvh) {
|
| - content::WebContents* web_contents =
|
| - content::WebContents::FromRenderViewHost(rvh);
|
| - if (!web_contents)
|
| - return std::string();
|
| -
|
| - Profile* profile =
|
| - Profile::FromBrowserContext(web_contents->GetBrowserContext());
|
| - if (!profile)
|
| - return std::string();
|
| -
|
| - extensions::ExtensionHost* extension_host =
|
| - extensions::ExtensionSystem::Get(profile)->process_manager()->
|
| - GetBackgroundHostForExtension(web_contents->GetURL().host());
|
| -
|
| - if (!extension_host || extension_host->host_contents() != web_contents)
|
| - return std::string();
|
| -
|
| - return extension_host->extension()->name();
|
| +void BrowserListTabContentsProvider::EnumerateTargets(TargetCallback callback) {
|
| + content::BrowserThread::PostTaskAndReplyWithResult(
|
| + content::BrowserThread::IO,
|
| + FROM_HERE,
|
| + base::Bind(&BrowserListTabContentsProvider::CollectWorkerTargets,
|
| + base::Unretained(this)),
|
| + base::Bind(&BrowserListTabContentsProvider::RespondWithTargetList,
|
| + base::Unretained(this),
|
| + callback));
|
| }
|
|
|
| #if defined(DEBUG_DEVTOOLS)
|
| @@ -158,3 +284,36 @@ BrowserListTabContentsProvider::CreateSocketForTethering(
|
| return scoped_ptr<net::StreamListenSocket>();
|
| }
|
| #endif // defined(DEBUG_DEVTOOLS)
|
| +
|
| +DevToolsHttpHandlerDelegate::TargetList
|
| +BrowserListTabContentsProvider::CollectWorkerTargets() {
|
| + TargetList targets;
|
| + std::vector<content::WorkerService::WorkerInfo> worker_info =
|
| + content::WorkerService::GetInstance()->GetWorkers();
|
| + for (size_t i = 0; i < worker_info.size(); ++i)
|
| + targets.push_back(new WorkerTarget(worker_info[i]));
|
| + return targets;
|
| +}
|
| +
|
| +void BrowserListTabContentsProvider::RespondWithTargetList(
|
| + TargetCallback callback, const TargetList& worker_targets) {
|
| + std::set<RenderViewHost*> tab_rvhs;
|
| + for (TabContentsIterator it; !it.done(); it.Next())
|
| + tab_rvhs.insert(it->GetRenderViewHost());
|
| +
|
| + TargetList targets;
|
| +
|
| + std::vector<RenderViewHost*> rvh_list =
|
| + content::DevToolsAgentHost::GetValidRenderViewHosts();
|
| + for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin();
|
| + it != rvh_list.end(); ++it) {
|
| + bool is_tab = tab_rvhs.find(*it) != tab_rvhs.end();
|
| + WebContents* web_contents = WebContents::FromRenderViewHost(*it);
|
| + if (web_contents)
|
| + targets.push_back(new Target(web_contents, is_tab));
|
| + }
|
| +
|
| + targets.insert(targets.end(), worker_targets.begin(), worker_targets.end());
|
| +
|
| + callback.Run(targets);
|
| +}
|
|
|