OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/android/dev_tools_server.h" | 5 #include "chrome/browser/android/dev_tools_server.h" |
6 | 6 |
7 #include <pwd.h> | 7 #include <pwd.h> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 | 96 |
97 protected: | 97 protected: |
98 explicit TargetBase(WebContents* web_contents) | 98 explicit TargetBase(WebContents* web_contents) |
99 : title_(base::UTF16ToUTF8(web_contents->GetTitle())), | 99 : title_(base::UTF16ToUTF8(web_contents->GetTitle())), |
100 url_(web_contents->GetURL()), | 100 url_(web_contents->GetURL()), |
101 favicon_url_(GetFaviconURLForContents(web_contents)), | 101 favicon_url_(GetFaviconURLForContents(web_contents)), |
102 last_activity_time_(web_contents->GetLastActiveTime()) { | 102 last_activity_time_(web_contents->GetLastActiveTime()) { |
103 } | 103 } |
104 | 104 |
105 TargetBase(const base::string16& title, const GURL& url) | 105 TargetBase(const std::string& title, const GURL& url) |
106 : title_(base::UTF16ToUTF8(title)), | 106 : title_(title), |
107 url_(url) | 107 url_(url) |
108 {} | 108 {} |
109 | 109 |
110 private: | 110 private: |
111 const std::string title_; | 111 const std::string title_; |
112 const GURL url_; | 112 const GURL url_; |
113 const GURL favicon_url_; | 113 const GURL favicon_url_; |
114 const base::TimeTicks last_activity_time_; | 114 const base::TimeTicks last_activity_time_; |
115 }; | 115 }; |
116 | 116 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 return true; | 181 return true; |
182 } | 182 } |
183 | 183 |
184 private: | 184 private: |
185 TabTarget(int tab_id, WebContents* web_contents) | 185 TabTarget(int tab_id, WebContents* web_contents) |
186 : TargetBase(web_contents), | 186 : TargetBase(web_contents), |
187 tab_id_(tab_id) { | 187 tab_id_(tab_id) { |
188 } | 188 } |
189 | 189 |
190 TabTarget(int tab_id, const base::string16& title, const GURL& url) | 190 TabTarget(int tab_id, const base::string16& title, const GURL& url) |
191 : TargetBase(title, url), | 191 : TargetBase(base::UTF16ToUTF8(title), url), |
192 tab_id_(tab_id) { | 192 tab_id_(tab_id) { |
193 } | 193 } |
194 | 194 |
195 bool FindTab(TabModel** model_result, int* index_result) const { | 195 bool FindTab(TabModel** model_result, int* index_result) const { |
196 for (TabModelList::const_iterator iter = TabModelList::begin(); | 196 for (TabModelList::const_iterator iter = TabModelList::begin(); |
197 iter != TabModelList::end(); ++iter) { | 197 iter != TabModelList::end(); ++iter) { |
198 TabModel* model = *iter; | 198 TabModel* model = *iter; |
199 for (int i = 0; i < model->GetTabCount(); ++i) { | 199 for (int i = 0; i < model->GetTabCount(); ++i) { |
200 TabAndroid* tab = model->GetTabAt(i); | 200 TabAndroid* tab = model->GetTabAt(i); |
201 if (tab->GetAndroidId() == tab_id_) { | 201 if (tab->GetAndroidId() == tab_id_) { |
202 *model_result = model; | 202 *model_result = model; |
203 *index_result = i; | 203 *index_result = i; |
204 return true; | 204 return true; |
205 } | 205 } |
206 } | 206 } |
207 } | 207 } |
208 return false; | 208 return false; |
209 } | 209 } |
210 | 210 |
211 const int tab_id_; | 211 const int tab_id_; |
212 }; | 212 }; |
213 | 213 |
214 class NonTabTarget : public TargetBase { | 214 class NonTabTarget : public TargetBase { |
215 public: | 215 public: |
216 explicit NonTabTarget(WebContents* web_contents) | 216 explicit NonTabTarget(scoped_refptr<DevToolsAgentHost> agent_host) |
217 : TargetBase(web_contents), | 217 : TargetBase("Service Worker", agent_host->GetURL()), |
218 agent_host_(DevToolsAgentHost::GetOrCreateFor( | 218 agent_host_(agent_host) { |
219 web_contents->GetRenderViewHost())) { | |
220 } | 219 } |
221 | 220 |
222 // content::DevToolsTarget implementation: | 221 // content::DevToolsTarget implementation: |
223 virtual std::string GetId() const OVERRIDE { | 222 virtual std::string GetId() const OVERRIDE { |
224 return agent_host_->GetId(); | 223 return agent_host_->GetId(); |
225 } | 224 } |
226 | 225 |
227 virtual std::string GetType() const OVERRIDE { | 226 virtual std::string GetType() const OVERRIDE { |
228 if (TabModelList::begin() == TabModelList::end()) { | 227 if (TabModelList::begin() == TabModelList::end()) { |
229 // If there are no tab models we must be running in ChromeShell. | 228 // If there are no tab models we must be running in ChromeShell. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 | 315 |
317 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | 316 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
318 if (!tab) | 317 if (!tab) |
319 return scoped_ptr<content::DevToolsTarget>(); | 318 return scoped_ptr<content::DevToolsTarget>(); |
320 | 319 |
321 return scoped_ptr<content::DevToolsTarget>( | 320 return scoped_ptr<content::DevToolsTarget>( |
322 TabTarget::CreateForWebContents(tab->GetAndroidId(), web_contents)); | 321 TabTarget::CreateForWebContents(tab->GetAndroidId(), web_contents)); |
323 } | 322 } |
324 | 323 |
325 virtual void EnumerateTargets(TargetCallback callback) OVERRIDE { | 324 virtual void EnumerateTargets(TargetCallback callback) OVERRIDE { |
| 325 DevToolsAgentHost::GetOrCreateAllHosts( |
| 326 base::Bind(&DevToolsServerDelegate::CreateAllTargets, callback)); |
| 327 } |
| 328 |
| 329 static void CreateAllTargets(const TargetCallback& callback, |
| 330 const DevToolsAgentHost::List& agent_hosts) { |
326 TargetList targets; | 331 TargetList targets; |
327 | 332 |
328 // Enumerate existing tabs, including the ones with no WebContents. | 333 // Enumerate existing tabs, including the ones with no WebContents. |
329 std::set<WebContents*> tab_web_contents; | 334 std::set<WebContents*> tab_web_contents; |
330 for (TabModelList::const_iterator iter = TabModelList::begin(); | 335 for (TabModelList::const_iterator iter = TabModelList::begin(); |
331 iter != TabModelList::end(); ++iter) { | 336 iter != TabModelList::end(); ++iter) { |
332 TabModel* model = *iter; | 337 TabModel* model = *iter; |
333 for (int i = 0; i < model->GetTabCount(); ++i) { | 338 for (int i = 0; i < model->GetTabCount(); ++i) { |
334 TabAndroid* tab = model->GetTabAt(i); | 339 TabAndroid* tab = model->GetTabAt(i); |
335 WebContents* web_contents = model->GetWebContentsAt(i); | 340 WebContents* web_contents = model->GetWebContentsAt(i); |
336 if (web_contents) { | 341 if (web_contents) { |
337 tab_web_contents.insert(web_contents); | 342 tab_web_contents.insert(web_contents); |
338 targets.push_back(TabTarget::CreateForWebContents(tab->GetAndroidId(), | 343 targets.push_back(TabTarget::CreateForWebContents(tab->GetAndroidId(), |
339 web_contents)); | 344 web_contents)); |
340 } else { | 345 } else { |
341 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), | 346 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), |
342 tab->GetTitle(), | 347 tab->GetTitle(), |
343 tab->GetURL())); | 348 tab->GetURL())); |
344 } | 349 } |
345 } | 350 } |
346 } | 351 } |
347 | 352 |
348 // Add targets for WebContents not associated with any tabs. | 353 // Add targets for WebContents not associated with any tabs. |
349 std::vector<RenderViewHost*> rvh_list = | 354 for (DevToolsAgentHost::List::const_iterator it = agent_hosts.begin(); |
350 DevToolsAgentHost::GetValidRenderViewHosts(); | 355 it != agent_hosts.end(); ++it) { |
351 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin(); | 356 if (RenderViewHost* rvh = (*it)->GetRenderViewHost()) { |
352 it != rvh_list.end(); ++it) { | 357 if (WebContents* web_contents = WebContents::FromRenderViewHost(rvh)) { |
353 WebContents* web_contents = WebContents::FromRenderViewHost(*it); | 358 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) |
354 if (!web_contents) | 359 continue; |
355 continue; | 360 } |
356 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) | 361 } |
357 continue; | 362 targets.push_back(new NonTabTarget(*it)); |
358 targets.push_back(new NonTabTarget(web_contents)); | |
359 } | 363 } |
360 | 364 |
361 callback.Run(targets); | 365 callback.Run(targets); |
362 } | 366 } |
363 | 367 |
364 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( | 368 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( |
365 net::StreamListenSocket::Delegate* delegate, | 369 net::StreamListenSocket::Delegate* delegate, |
366 std::string* name) OVERRIDE { | 370 std::string* name) OVERRIDE { |
367 *name = base::StringPrintf( | 371 *name = base::StringPrintf( |
368 kTetheringSocketName, getpid(), ++last_tethering_socket_); | 372 kTetheringSocketName, getpid(), ++last_tethering_socket_); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 jobject obj, | 475 jobject obj, |
472 jlong server, | 476 jlong server, |
473 jboolean enabled) { | 477 jboolean enabled) { |
474 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); | 478 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); |
475 if (enabled) { | 479 if (enabled) { |
476 devtools_server->Start(); | 480 devtools_server->Start(); |
477 } else { | 481 } else { |
478 devtools_server->Stop(); | 482 devtools_server->Stop(); |
479 } | 483 } |
480 } | 484 } |
OLD | NEW |