| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return NULL; | 152 return NULL; |
| 153 WebContents* web_contents = model->GetWebContentsAt(index); | 153 WebContents* web_contents = model->GetWebContentsAt(index); |
| 154 if (!web_contents) { | 154 if (!web_contents) { |
| 155 // The tab has been pushed out of memory, pull it back. | 155 // The tab has been pushed out of memory, pull it back. |
| 156 TabAndroid* tab = model->GetTabAt(index); | 156 TabAndroid* tab = model->GetTabAt(index); |
| 157 tab->LoadIfNeeded(); | 157 tab->LoadIfNeeded(); |
| 158 web_contents = model->GetWebContentsAt(index); | 158 web_contents = model->GetWebContentsAt(index); |
| 159 if (!web_contents) | 159 if (!web_contents) |
| 160 return NULL; | 160 return NULL; |
| 161 } | 161 } |
| 162 RenderViewHost* rvh = web_contents->GetRenderViewHost(); | 162 return DevToolsAgentHost::GetOrCreateFor(web_contents); |
| 163 return rvh ? DevToolsAgentHost::GetOrCreateFor(rvh) : NULL; | |
| 164 } | 163 } |
| 165 | 164 |
| 166 virtual bool Activate() const OVERRIDE { | 165 virtual bool Activate() const OVERRIDE { |
| 167 TabModel* model; | 166 TabModel* model; |
| 168 int index; | 167 int index; |
| 169 if (!FindTab(&model, &index)) | 168 if (!FindTab(&model, &index)) |
| 170 return false; | 169 return false; |
| 171 model->SetActiveIndex(index); | 170 model->SetActiveIndex(index); |
| 172 return true; | 171 return true; |
| 173 } | 172 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 return false; | 207 return false; |
| 209 } | 208 } |
| 210 | 209 |
| 211 const int tab_id_; | 210 const int tab_id_; |
| 212 }; | 211 }; |
| 213 | 212 |
| 214 class NonTabTarget : public TargetBase { | 213 class NonTabTarget : public TargetBase { |
| 215 public: | 214 public: |
| 216 explicit NonTabTarget(WebContents* web_contents) | 215 explicit NonTabTarget(WebContents* web_contents) |
| 217 : TargetBase(web_contents), | 216 : TargetBase(web_contents), |
| 218 agent_host_(DevToolsAgentHost::GetOrCreateFor( | 217 agent_host_(DevToolsAgentHost::GetOrCreateFor(web_contents)) { |
| 219 web_contents->GetRenderViewHost())) { | |
| 220 } | 218 } |
| 221 | 219 |
| 222 // content::DevToolsTarget implementation: | 220 // content::DevToolsTarget implementation: |
| 223 virtual std::string GetId() const OVERRIDE { | 221 virtual std::string GetId() const OVERRIDE { |
| 224 return agent_host_->GetId(); | 222 return agent_host_->GetId(); |
| 225 } | 223 } |
| 226 | 224 |
| 227 virtual std::string GetType() const OVERRIDE { | 225 virtual std::string GetType() const OVERRIDE { |
| 228 if (TabModelList::begin() == TabModelList::end()) { | 226 if (TabModelList::begin() == TabModelList::end()) { |
| 229 // If there are no tab models we must be running in ChromeShell. | 227 // If there are no tab models we must be running in ChromeShell. |
| 230 // Return the 'page' target type for backwards compatibility. | 228 // Return the 'page' target type for backwards compatibility. |
| 231 return kTargetTypePage; | 229 return kTargetTypePage; |
| 232 } | 230 } |
| 233 return kTargetTypeOther; | 231 return kTargetTypeOther; |
| 234 } | 232 } |
| 235 | 233 |
| 236 virtual bool IsAttached() const OVERRIDE { | 234 virtual bool IsAttached() const OVERRIDE { |
| 237 return agent_host_->IsAttached(); | 235 return agent_host_->IsAttached(); |
| 238 } | 236 } |
| 239 | 237 |
| 240 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | 238 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { |
| 241 return agent_host_; | 239 return agent_host_; |
| 242 } | 240 } |
| 243 | 241 |
| 244 virtual bool Activate() const OVERRIDE { | 242 virtual bool Activate() const OVERRIDE { |
| 245 RenderViewHost* rvh = agent_host_->GetRenderViewHost(); | 243 WebContents* web_contents = agent_host_->GetWebContents(); |
| 246 if (!rvh) | |
| 247 return false; | |
| 248 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | |
| 249 if (!web_contents) | 244 if (!web_contents) |
| 250 return false; | 245 return false; |
| 251 web_contents->GetDelegate()->ActivateContents(web_contents); | 246 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 252 return true; | 247 return true; |
| 253 } | 248 } |
| 254 | 249 |
| 255 virtual bool Close() const OVERRIDE { | 250 virtual bool Close() const OVERRIDE { |
| 256 RenderViewHost* rvh = agent_host_->GetRenderViewHost(); | 251 WebContents* web_contents = agent_host_->GetWebContents(); |
| 257 if (!rvh) | 252 if (!web_contents) |
| 258 return false; | 253 return false; |
| 259 rvh->ClosePage(); | 254 web_contents->GetRenderViewHost()->ClosePage(); |
| 260 return true; | 255 return true; |
| 261 } | 256 } |
| 262 | 257 |
| 263 private: | 258 private: |
| 264 scoped_refptr<DevToolsAgentHost> agent_host_; | 259 scoped_refptr<DevToolsAgentHost> agent_host_; |
| 265 }; | 260 }; |
| 266 | 261 |
| 267 // Delegate implementation for the devtools http handler on android. A new | 262 // Delegate implementation for the devtools http handler on android. A new |
| 268 // instance of this gets created each time devtools is enabled. | 263 // instance of this gets created each time devtools is enabled. |
| 269 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { | 264 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 web_contents)); | 334 web_contents)); |
| 340 } else { | 335 } else { |
| 341 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), | 336 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), |
| 342 tab->GetTitle(), | 337 tab->GetTitle(), |
| 343 tab->GetURL())); | 338 tab->GetURL())); |
| 344 } | 339 } |
| 345 } | 340 } |
| 346 } | 341 } |
| 347 | 342 |
| 348 // Add targets for WebContents not associated with any tabs. | 343 // Add targets for WebContents not associated with any tabs. |
| 349 std::vector<RenderViewHost*> rvh_list = | 344 std::vector<WebContents*> wc_list = |
| 350 DevToolsAgentHost::GetValidRenderViewHosts(); | 345 DevToolsAgentHost::GetInspectableWebContents(); |
| 351 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin(); | 346 for (std::vector<WebContents*>::iterator it = wc_list.begin(); |
| 352 it != rvh_list.end(); ++it) { | 347 it != wc_list.end(); |
| 353 WebContents* web_contents = WebContents::FromRenderViewHost(*it); | 348 ++it) { |
| 354 if (!web_contents) | 349 if (tab_web_contents.find(*it) != tab_web_contents.end()) |
| 355 continue; | 350 continue; |
| 356 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) | 351 targets.push_back(new NonTabTarget(*it)); |
| 357 continue; | |
| 358 targets.push_back(new NonTabTarget(web_contents)); | |
| 359 } | 352 } |
| 360 | 353 |
| 361 callback.Run(targets); | 354 callback.Run(targets); |
| 362 } | 355 } |
| 363 | 356 |
| 364 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( | 357 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( |
| 365 net::StreamListenSocket::Delegate* delegate, | 358 net::StreamListenSocket::Delegate* delegate, |
| 366 std::string* name) OVERRIDE { | 359 std::string* name) OVERRIDE { |
| 367 *name = base::StringPrintf( | 360 *name = base::StringPrintf( |
| 368 kTetheringSocketName, getpid(), ++last_tethering_socket_); | 361 kTetheringSocketName, getpid(), ++last_tethering_socket_); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 jobject obj, | 465 jobject obj, |
| 473 jlong server, | 466 jlong server, |
| 474 jboolean enabled) { | 467 jboolean enabled) { |
| 475 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); | 468 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); |
| 476 if (enabled) { | 469 if (enabled) { |
| 477 devtools_server->Start(); | 470 devtools_server->Start(); |
| 478 } else { | 471 } else { |
| 479 devtools_server->Stop(); | 472 devtools_server->Stop(); |
| 480 } | 473 } |
| 481 } | 474 } |
| OLD | NEW |