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 class WebContents; 20 } 21 22 class DevToolsTargetImpl : public content::DevToolsTarget { 23 public: 24 static const char kTargetTypeApp[]; 25 static const char kTargetTypeBackgroundPage[]; 26 static const char kTargetTypePage[]; 27 static const char kTargetTypeWorker[]; 28 static const char kTargetTypeWebView[]; 29 static const char kTargetTypeIFrame[]; 30 static const char kTargetTypeOther[]; 31 static const char kTargetTypeServiceWorker[]; 32 33 explicit DevToolsTargetImpl( 34 scoped_refptr<content::DevToolsAgentHost> agent_host); 35 virtual ~DevToolsTargetImpl(); 36 37 // content::DevToolsTarget overrides: 38 virtual std::string GetId() const OVERRIDE; 39 virtual std::string GetParentId() const OVERRIDE; 40 virtual std::string GetType() const OVERRIDE; 41 virtual std::string GetTitle() const OVERRIDE; 42 virtual std::string GetDescription() const OVERRIDE; 43 virtual GURL GetURL() const OVERRIDE; 44 virtual GURL GetFaviconURL() const OVERRIDE; 45 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE; 46 virtual scoped_refptr<content::DevToolsAgentHost> 47 GetAgentHost() const OVERRIDE; 48 virtual bool IsAttached() const OVERRIDE; 49 virtual bool Activate() const OVERRIDE; 50 virtual bool Close() const OVERRIDE; 51 52 // Returns the WebContents associated with the target on NULL if there is 53 // not any. 54 virtual content::WebContents* GetWebContents() const; 55 56 // Returns the tab id if the target is associated with a tab, -1 otherwise. 57 virtual int GetTabId() const; 58 59 // Returns the extension id if the target is associated with an extension 60 // background page. 61 virtual std::string GetExtensionId() const; 62 63 // Open a new DevTools window or activate the existing one. 64 virtual void Inspect(Profile* profile) const; 65 66 // Reload the target page. 67 virtual void Reload() const; 68 69 // Creates a new target associated with WebContents. 70 static scoped_ptr<DevToolsTargetImpl> CreateForWebContents( 71 content::WebContents* web_contents, 72 bool is_tab); 73 set_parent_id(const std::string & parent_id)74 void set_parent_id(const std::string& parent_id) { parent_id_ = parent_id; } set_type(const std::string & type)75 void set_type(const std::string& type) { type_ = type; } set_title(const std::string & title)76 void set_title(const std::string& title) { title_ = title; } set_description(const std::string & desc)77 void set_description(const std::string& desc) { description_ = desc; } set_url(const GURL & url)78 void set_url(const GURL& url) { url_ = url; } set_favicon_url(const GURL & url)79 void set_favicon_url(const GURL& url) { favicon_url_ = url; } set_last_activity_time(const base::TimeTicks & time)80 void set_last_activity_time(const base::TimeTicks& time) { 81 last_activity_time_ = time; 82 } 83 84 typedef std::vector<DevToolsTargetImpl*> List; 85 typedef base::Callback<void(const List&)> Callback; 86 87 static void EnumerateAllTargets(Callback callback); 88 89 private: 90 scoped_refptr<content::DevToolsAgentHost> agent_host_; 91 std::string parent_id_; 92 std::string type_; 93 std::string title_; 94 std::string description_; 95 GURL url_; 96 GURL favicon_url_; 97 base::TimeTicks last_activity_time_; 98 }; 99 100 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_ 101