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