| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } | 103 } |
| 104 | 104 |
| 105 protected: | 105 protected: |
| 106 explicit TargetBase(WebContents* web_contents) | 106 explicit TargetBase(WebContents* web_contents) |
| 107 : title_(base::UTF16ToUTF8(web_contents->GetTitle())), | 107 : title_(base::UTF16ToUTF8(web_contents->GetTitle())), |
| 108 url_(web_contents->GetURL()), | 108 url_(web_contents->GetURL()), |
| 109 favicon_url_(GetFaviconURLForContents(web_contents)), | 109 favicon_url_(GetFaviconURLForContents(web_contents)), |
| 110 last_activity_time_(web_contents->GetLastActiveTime()) { | 110 last_activity_time_(web_contents->GetLastActiveTime()) { |
| 111 } | 111 } |
| 112 | 112 |
| 113 TargetBase(const base::string16& title, const GURL& url) | 113 TargetBase(const std::string& title, const GURL& url) |
| 114 : title_(base::UTF16ToUTF8(title)), | 114 : title_(title), |
| 115 url_(url) | 115 url_(url) { |
| 116 {} | 116 } |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 const std::string title_; | 119 const std::string title_; |
| 120 const GURL url_; | 120 const GURL url_; |
| 121 const GURL favicon_url_; | 121 const GURL favicon_url_; |
| 122 const base::TimeTicks last_activity_time_; | 122 const base::TimeTicks last_activity_time_; |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 class TabTarget : public TargetBase { | 125 class TabTarget : public TargetBase { |
| 126 public: | 126 public: |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 return true; | 188 return true; |
| 189 } | 189 } |
| 190 | 190 |
| 191 private: | 191 private: |
| 192 TabTarget(int tab_id, WebContents* web_contents) | 192 TabTarget(int tab_id, WebContents* web_contents) |
| 193 : TargetBase(web_contents), | 193 : TargetBase(web_contents), |
| 194 tab_id_(tab_id) { | 194 tab_id_(tab_id) { |
| 195 } | 195 } |
| 196 | 196 |
| 197 TabTarget(int tab_id, const base::string16& title, const GURL& url) | 197 TabTarget(int tab_id, const base::string16& title, const GURL& url) |
| 198 : TargetBase(title, url), | 198 : TargetBase(base::UTF16ToUTF8(title), url), |
| 199 tab_id_(tab_id) { | 199 tab_id_(tab_id) { |
| 200 } | 200 } |
| 201 | 201 |
| 202 bool FindTab(TabModel** model_result, int* index_result) const { | 202 bool FindTab(TabModel** model_result, int* index_result) const { |
| 203 for (TabModelList::const_iterator iter = TabModelList::begin(); | 203 for (TabModelList::const_iterator iter = TabModelList::begin(); |
| 204 iter != TabModelList::end(); ++iter) { | 204 iter != TabModelList::end(); ++iter) { |
| 205 TabModel* model = *iter; | 205 TabModel* model = *iter; |
| 206 for (int i = 0; i < model->GetTabCount(); ++i) { | 206 for (int i = 0; i < model->GetTabCount(); ++i) { |
| 207 TabAndroid* tab = model->GetTabAt(i); | 207 TabAndroid* tab = model->GetTabAt(i); |
| 208 if (tab->GetAndroidId() == tab_id_) { | 208 if (tab->GetAndroidId() == tab_id_) { |
| 209 *model_result = model; | 209 *model_result = model; |
| 210 *index_result = i; | 210 *index_result = i; |
| 211 return true; | 211 return true; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 return false; | 215 return false; |
| 216 } | 216 } |
| 217 | 217 |
| 218 const int tab_id_; | 218 const int tab_id_; |
| 219 }; | 219 }; |
| 220 | 220 |
| 221 class NonTabTarget : public TargetBase { | 221 class NonTabTarget : public TargetBase { |
| 222 public: | 222 public: |
| 223 explicit NonTabTarget(WebContents* web_contents) | 223 explicit NonTabTarget(scoped_refptr<DevToolsAgentHost> agent_host) |
| 224 : TargetBase(web_contents), | 224 : TargetBase("", agent_host->GetURL()), |
| 225 agent_host_(DevToolsAgentHost::GetOrCreateFor(web_contents)) { | 225 agent_host_(agent_host) { |
| 226 } | 226 } |
| 227 | 227 |
| 228 // content::DevToolsTarget implementation: | 228 // content::DevToolsTarget implementation: |
| 229 virtual std::string GetId() const OVERRIDE { | 229 virtual std::string GetId() const OVERRIDE { |
| 230 return agent_host_->GetId(); | 230 return agent_host_->GetId(); |
| 231 } | 231 } |
| 232 | 232 |
| 233 virtual std::string GetType() const OVERRIDE { | 233 virtual std::string GetType() const OVERRIDE { |
| 234 if (TabModelList::begin() == TabModelList::end()) { | 234 if (TabModelList::begin() == TabModelList::end()) { |
| 235 // If there are no tab models we must be running in ChromeShell. | 235 // If there are no tab models we must be running in ChromeShell. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 web_contents)); | 344 web_contents)); |
| 345 } else { | 345 } else { |
| 346 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), | 346 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), |
| 347 tab->GetTitle(), | 347 tab->GetTitle(), |
| 348 tab->GetURL())); | 348 tab->GetURL())); |
| 349 } | 349 } |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 | 352 |
| 353 // Add targets for WebContents not associated with any tabs. | 353 // Add targets for WebContents not associated with any tabs. |
| 354 std::vector<WebContents*> wc_list = | 354 DevToolsAgentHost::List agents = |
| 355 DevToolsAgentHost::GetInspectableWebContents(); | 355 DevToolsAgentHost::GetOrCreateAll(); |
| 356 for (std::vector<WebContents*>::iterator it = wc_list.begin(); | 356 for (DevToolsAgentHost::List::iterator it = agents.begin(); |
| 357 it != wc_list.end(); | 357 it != agents.end(); ++it) { |
| 358 ++it) { | 358 if (WebContents* web_contents = (*it)->GetWebContents()) { |
| 359 if (tab_web_contents.find(*it) != tab_web_contents.end()) | 359 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) |
| 360 continue; | 360 continue; |
| 361 } |
| 361 targets.push_back(new NonTabTarget(*it)); | 362 targets.push_back(new NonTabTarget(*it)); |
| 362 } | 363 } |
| 363 | 364 |
| 364 callback.Run(targets); | 365 callback.Run(targets); |
| 365 } | 366 } |
| 366 | 367 |
| 367 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( | 368 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( |
| 368 net::StreamListenSocket::Delegate* delegate, | 369 net::StreamListenSocket::Delegate* delegate, |
| 369 std::string* name) OVERRIDE { | 370 std::string* name) OVERRIDE { |
| 370 *name = base::StringPrintf( | 371 *name = base::StringPrintf( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 jlong server, | 471 jlong server, |
| 471 jboolean enabled, | 472 jboolean enabled, |
| 472 jboolean allow_debug_permission) { | 473 jboolean allow_debug_permission) { |
| 473 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); | 474 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); |
| 474 if (enabled) { | 475 if (enabled) { |
| 475 devtools_server->Start(allow_debug_permission); | 476 devtools_server->Start(allow_debug_permission); |
| 476 } else { | 477 } else { |
| 477 devtools_server->Stop(); | 478 devtools_server->Stop(); |
| 478 } | 479 } |
| 479 } | 480 } |
| OLD | NEW |