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 #include "content/shell/browser/shell_devtools_delegate.h" | 5 #include "content/shell/browser/shell_devtools_delegate.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 using content::RenderViewHost; | 36 using content::RenderViewHost; |
37 using content::WebContents; | 37 using content::WebContents; |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 #if defined(OS_ANDROID) | 41 #if defined(OS_ANDROID) |
42 const char kFrontEndURL[] = | 42 const char kFrontEndURL[] = |
43 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; | 43 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; |
44 #endif | 44 #endif |
45 const char kTargetTypePage[] = "page"; | 45 const char kTargetTypePage[] = "page"; |
| 46 const char kTargetTypeServiceWorker[] = "service_worker"; |
| 47 const char kTargetTypeOther[] = "other"; |
46 | 48 |
47 net::StreamListenSocketFactory* CreateSocketFactory() { | 49 net::StreamListenSocketFactory* CreateSocketFactory() { |
48 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 50 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
49 #if defined(OS_ANDROID) | 51 #if defined(OS_ANDROID) |
50 std::string socket_name = "content_shell_devtools_remote"; | 52 std::string socket_name = "content_shell_devtools_remote"; |
51 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { | 53 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { |
52 socket_name = command_line.GetSwitchValueASCII( | 54 socket_name = command_line.GetSwitchValueASCII( |
53 switches::kRemoteDebuggingSocketName); | 55 switches::kRemoteDebuggingSocketName); |
54 } | 56 } |
55 return new net::deprecated:: | 57 return new net::deprecated:: |
(...skipping 13 matching lines...) Expand all Loading... |
69 } else { | 71 } else { |
70 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; | 72 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; |
71 } | 73 } |
72 } | 74 } |
73 return new net::TCPListenSocketFactory("127.0.0.1", port); | 75 return new net::TCPListenSocketFactory("127.0.0.1", port); |
74 #endif | 76 #endif |
75 } | 77 } |
76 | 78 |
77 class Target : public content::DevToolsTarget { | 79 class Target : public content::DevToolsTarget { |
78 public: | 80 public: |
79 explicit Target(WebContents* web_contents); | 81 explicit Target(scoped_refptr<DevToolsAgentHost> agent_host); |
80 | 82 |
81 virtual std::string GetId() const OVERRIDE { return id_; } | 83 virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); } |
82 virtual std::string GetParentId() const OVERRIDE { return std::string(); } | 84 virtual std::string GetParentId() const OVERRIDE { return std::string(); } |
83 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } | 85 virtual std::string GetType() const OVERRIDE { |
84 virtual std::string GetTitle() const OVERRIDE { return title_; } | 86 switch (agent_host_->GetType()) { |
| 87 case DevToolsAgentHost::AGENT_HOST_WEB_CONTENTS: |
| 88 return kTargetTypePage; |
| 89 case DevToolsAgentHost::AGENT_HOST_SERVICE_WORKER: |
| 90 return kTargetTypeServiceWorker; |
| 91 default: |
| 92 {} // Do nothing. |
| 93 } |
| 94 return kTargetTypeOther; |
| 95 } |
| 96 virtual std::string GetTitle() const OVERRIDE { |
| 97 return agent_host_->GetTitle(); |
| 98 } |
85 virtual std::string GetDescription() const OVERRIDE { return std::string(); } | 99 virtual std::string GetDescription() const OVERRIDE { return std::string(); } |
86 virtual GURL GetURL() const OVERRIDE { return url_; } | 100 virtual GURL GetURL() const OVERRIDE { return agent_host_->GetURL(); } |
87 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } | 101 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } |
88 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { | 102 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { |
89 return last_activity_time_; | 103 return last_activity_time_; |
90 } | 104 } |
91 virtual bool IsAttached() const OVERRIDE { | 105 virtual bool IsAttached() const OVERRIDE { |
92 return agent_host_->IsAttached(); | 106 return agent_host_->IsAttached(); |
93 } | 107 } |
94 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | 108 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { |
95 return agent_host_; | 109 return agent_host_; |
96 } | 110 } |
97 virtual bool Activate() const OVERRIDE; | 111 virtual bool Activate() const OVERRIDE; |
98 virtual bool Close() const OVERRIDE; | 112 virtual bool Close() const OVERRIDE; |
99 | 113 |
100 private: | 114 private: |
101 scoped_refptr<DevToolsAgentHost> agent_host_; | 115 scoped_refptr<DevToolsAgentHost> agent_host_; |
102 std::string id_; | |
103 std::string title_; | |
104 GURL url_; | |
105 GURL favicon_url_; | 116 GURL favicon_url_; |
106 base::TimeTicks last_activity_time_; | 117 base::TimeTicks last_activity_time_; |
107 }; | 118 }; |
108 | 119 |
109 Target::Target(WebContents* web_contents) { | 120 Target::Target(scoped_refptr<DevToolsAgentHost> agent_host) |
110 agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents); | 121 : agent_host_(agent_host) { |
111 id_ = agent_host_->GetId(); | 122 if (WebContents* web_contents = agent_host_->GetWebContents()) { |
112 title_ = base::UTF16ToUTF8(web_contents->GetTitle()); | 123 content::NavigationController& controller = web_contents->GetController(); |
113 url_ = web_contents->GetURL(); | 124 content::NavigationEntry* entry = controller.GetActiveEntry(); |
114 content::NavigationController& controller = web_contents->GetController(); | 125 if (entry != NULL && entry->GetURL().is_valid()) |
115 content::NavigationEntry* entry = controller.GetActiveEntry(); | 126 favicon_url_ = entry->GetFavicon().url; |
116 if (entry != NULL && entry->GetURL().is_valid()) | 127 last_activity_time_ = web_contents->GetLastActiveTime(); |
117 favicon_url_ = entry->GetFavicon().url; | 128 } |
118 last_activity_time_ = web_contents->GetLastActiveTime(); | |
119 } | 129 } |
120 | 130 |
121 bool Target::Activate() const { | 131 bool Target::Activate() const { |
122 WebContents* web_contents = agent_host_->GetWebContents(); | 132 return agent_host_->Activate(); |
123 if (!web_contents) | |
124 return false; | |
125 web_contents->GetDelegate()->ActivateContents(web_contents); | |
126 return true; | |
127 } | 133 } |
128 | 134 |
129 bool Target::Close() const { | 135 bool Target::Close() const { |
130 WebContents* web_contents = agent_host_->GetWebContents(); | 136 return agent_host_->Close(); |
131 if (!web_contents) | |
132 return false; | |
133 web_contents->GetRenderViewHost()->ClosePage(); | |
134 return true; | |
135 } | 137 } |
136 | 138 |
137 } // namespace | 139 } // namespace |
138 | 140 |
139 namespace content { | 141 namespace content { |
140 | 142 |
141 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context) | 143 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context) |
142 : browser_context_(browser_context) { | 144 : browser_context_(browser_context) { |
143 std::string frontend_url; | 145 std::string frontend_url; |
144 #if defined(OS_ANDROID) | 146 #if defined(OS_ANDROID) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 return std::string(); | 184 return std::string(); |
183 } | 185 } |
184 | 186 |
185 scoped_ptr<DevToolsTarget> | 187 scoped_ptr<DevToolsTarget> |
186 ShellDevToolsDelegate::CreateNewTarget(const GURL& url) { | 188 ShellDevToolsDelegate::CreateNewTarget(const GURL& url) { |
187 Shell* shell = Shell::CreateNewWindow(browser_context_, | 189 Shell* shell = Shell::CreateNewWindow(browser_context_, |
188 url, | 190 url, |
189 NULL, | 191 NULL, |
190 MSG_ROUTING_NONE, | 192 MSG_ROUTING_NONE, |
191 gfx::Size()); | 193 gfx::Size()); |
192 return scoped_ptr<DevToolsTarget>(new Target(shell->web_contents())); | 194 return scoped_ptr<DevToolsTarget>( |
| 195 new Target(DevToolsAgentHost::GetOrCreateFor(shell->web_contents()))); |
193 } | 196 } |
194 | 197 |
195 void ShellDevToolsDelegate::EnumerateTargets(TargetCallback callback) { | 198 void ShellDevToolsDelegate::EnumerateTargets(TargetCallback callback) { |
196 TargetList targets; | 199 TargetList targets; |
197 std::vector<WebContents*> wc_list = | 200 content::DevToolsAgentHost::List agents = |
198 content::DevToolsAgentHost::GetInspectableWebContents(); | 201 content::DevToolsAgentHost::GetOrCreateAll(); |
199 for (std::vector<WebContents*>::iterator it = wc_list.begin(); | 202 for (content::DevToolsAgentHost::List::iterator it = agents.begin(); |
200 it != wc_list.end(); | 203 it != agents.end(); ++it) { |
201 ++it) { | |
202 targets.push_back(new Target(*it)); | 204 targets.push_back(new Target(*it)); |
203 } | 205 } |
204 callback.Run(targets); | 206 callback.Run(targets); |
205 } | 207 } |
206 | 208 |
207 scoped_ptr<net::StreamListenSocket> | 209 scoped_ptr<net::StreamListenSocket> |
208 ShellDevToolsDelegate::CreateSocketForTethering( | 210 ShellDevToolsDelegate::CreateSocketForTethering( |
209 net::StreamListenSocket::Delegate* delegate, | 211 net::StreamListenSocket::Delegate* delegate, |
210 std::string* name) { | 212 std::string* name) { |
211 return scoped_ptr<net::StreamListenSocket>(); | 213 return scoped_ptr<net::StreamListenSocket>(); |
212 } | 214 } |
213 | 215 |
214 } // namespace content | 216 } // namespace content |
OLD | NEW |