1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_ 6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_ 7 8 #include <vector> 9 10 #include "base/callback.h" 11 #include "content/public/browser/devtools_target.h" 12 #include "content/public/browser/worker_service.h" 13 14 class Profile; 15 16 namespace content { 17 class DevToolsAgentHost; 18 class RenderViewHost; 19 } 20 21 class DevToolsTargetImpl : public content::DevToolsTarget { 22 public: 23 explicit DevToolsTargetImpl( 24 scoped_refptr<content::DevToolsAgentHost> agent_host); 25 virtual ~DevToolsTargetImpl(); 26 27 // content::DevToolsTarget overrides: 28 virtual std::string GetId() const OVERRIDE; 29 virtual std::string GetParentId() const OVERRIDE; 30 virtual std::string GetType() const OVERRIDE; 31 virtual std::string GetTitle() const OVERRIDE; 32 virtual std::string GetDescription() const OVERRIDE; 33 virtual GURL GetURL() const OVERRIDE; 34 virtual GURL GetFaviconURL() const OVERRIDE; 35 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE; 36 virtual scoped_refptr<content::DevToolsAgentHost> 37 GetAgentHost() const OVERRIDE; 38 virtual bool IsAttached() const OVERRIDE; 39 virtual bool Activate() const OVERRIDE; 40 virtual bool Close() const OVERRIDE; 41 42 // Returns the RenderViewHost associated with the target on NULL if there is 43 // not any. 44 virtual content::RenderViewHost* GetRenderViewHost() const; 45 46 // Returns the tab id if the target is associated with a tab, -1 otherwise. 47 virtual int GetTabId() const; 48 49 // Returns the extension id if the target is associated with an extension 50 // background page. 51 virtual std::string GetExtensionId() const; 52 53 // Open a new DevTools window or activate the existing one. 54 virtual void Inspect(Profile* profile) const; 55 56 // Reload the target page. 57 virtual void Reload() const; 58 59 // Creates a new target associated with RenderViewHost. 60 static scoped_ptr<DevToolsTargetImpl> CreateForRenderViewHost( 61 content::RenderViewHost*, bool is_tab); 62 set_parent_id(const std::string & parent_id)63 void set_parent_id(const std::string& parent_id) { parent_id_ = parent_id; } set_type(const std::string & type)64 void set_type(const std::string& type) { type_ = type; } set_title(const std::string & title)65 void set_title(const std::string& title) { title_ = title; } set_description(const std::string & desc)66 void set_description(const std::string& desc) { description_ = desc; } set_url(const GURL & url)67 void set_url(const GURL& url) { url_ = url; } set_favicon_url(const GURL & url)68 void set_favicon_url(const GURL& url) { favicon_url_ = url; } set_last_activity_time(const base::TimeTicks & time)69 void set_last_activity_time(const base::TimeTicks& time) { 70 last_activity_time_ = time; 71 } 72 73 typedef std::vector<DevToolsTargetImpl*> List; 74 typedef base::Callback<void(const List&)> Callback; 75 76 static List EnumerateRenderViewHostTargets(); 77 static void EnumerateWorkerTargets(Callback callback); 78 static void EnumerateAllTargets(Callback callback); 79 80 private: 81 scoped_refptr<content::DevToolsAgentHost> agent_host_; 82 std::string parent_id_; 83 std::string type_; 84 std::string title_; 85 std::string description_; 86 GURL url_; 87 GURL favicon_url_; 88 base::TimeTicks last_activity_time_; 89 }; 90 91 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_ 92