| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | 182 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { |
| 183 TabModel* model; | 183 TabModel* model; |
| 184 int index; | 184 int index; |
| 185 if (!FindTab(&model, &index)) | 185 if (!FindTab(&model, &index)) |
| 186 return NULL; | 186 return NULL; |
| 187 WebContents* web_contents = model->GetWebContentsAt(index); | 187 WebContents* web_contents = model->GetWebContentsAt(index); |
| 188 if (!web_contents) { | 188 if (!web_contents) { |
| 189 // The tab has been pushed out of memory, pull it back. | 189 // The tab has been pushed out of memory, pull it back. |
| 190 TabAndroid* tab = model->GetTabAt(index); | 190 TabAndroid* tab = model->GetTabAt(index); |
| 191 if (!tab) |
| 192 return NULL; |
| 193 |
| 191 tab->LoadIfNeeded(); | 194 tab->LoadIfNeeded(); |
| 192 web_contents = model->GetWebContentsAt(index); | 195 web_contents = model->GetWebContentsAt(index); |
| 193 if (!web_contents) | 196 if (!web_contents) |
| 194 return NULL; | 197 return NULL; |
| 195 } | 198 } |
| 196 return DevToolsAgentHost::GetOrCreateFor(web_contents); | 199 return DevToolsAgentHost::GetOrCreateFor(web_contents); |
| 197 } | 200 } |
| 198 | 201 |
| 199 virtual bool Activate() const OVERRIDE { | 202 virtual bool Activate() const OVERRIDE { |
| 200 TabModel* model; | 203 TabModel* model; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 224 : TargetBase(base::UTF16ToUTF8(title), url), | 227 : TargetBase(base::UTF16ToUTF8(title), url), |
| 225 tab_id_(tab_id) { | 228 tab_id_(tab_id) { |
| 226 } | 229 } |
| 227 | 230 |
| 228 bool FindTab(TabModel** model_result, int* index_result) const { | 231 bool FindTab(TabModel** model_result, int* index_result) const { |
| 229 for (TabModelList::const_iterator iter = TabModelList::begin(); | 232 for (TabModelList::const_iterator iter = TabModelList::begin(); |
| 230 iter != TabModelList::end(); ++iter) { | 233 iter != TabModelList::end(); ++iter) { |
| 231 TabModel* model = *iter; | 234 TabModel* model = *iter; |
| 232 for (int i = 0; i < model->GetTabCount(); ++i) { | 235 for (int i = 0; i < model->GetTabCount(); ++i) { |
| 233 TabAndroid* tab = model->GetTabAt(i); | 236 TabAndroid* tab = model->GetTabAt(i); |
| 234 if (tab->GetAndroidId() == tab_id_) { | 237 if (tab && tab->GetAndroidId() == tab_id_) { |
| 235 *model_result = model; | 238 *model_result = model; |
| 236 *index_result = i; | 239 *index_result = i; |
| 237 return true; | 240 return true; |
| 238 } | 241 } |
| 239 } | 242 } |
| 240 } | 243 } |
| 241 return false; | 244 return false; |
| 242 } | 245 } |
| 243 | 246 |
| 244 const int tab_id_; | 247 const int tab_id_; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 virtual void EnumerateTargets(TargetCallback callback) OVERRIDE { | 359 virtual void EnumerateTargets(TargetCallback callback) OVERRIDE { |
| 357 TargetList targets; | 360 TargetList targets; |
| 358 | 361 |
| 359 // Enumerate existing tabs, including the ones with no WebContents. | 362 // Enumerate existing tabs, including the ones with no WebContents. |
| 360 std::set<WebContents*> tab_web_contents; | 363 std::set<WebContents*> tab_web_contents; |
| 361 for (TabModelList::const_iterator iter = TabModelList::begin(); | 364 for (TabModelList::const_iterator iter = TabModelList::begin(); |
| 362 iter != TabModelList::end(); ++iter) { | 365 iter != TabModelList::end(); ++iter) { |
| 363 TabModel* model = *iter; | 366 TabModel* model = *iter; |
| 364 for (int i = 0; i < model->GetTabCount(); ++i) { | 367 for (int i = 0; i < model->GetTabCount(); ++i) { |
| 365 TabAndroid* tab = model->GetTabAt(i); | 368 TabAndroid* tab = model->GetTabAt(i); |
| 369 if (!tab) |
| 370 continue; |
| 371 |
| 366 WebContents* web_contents = model->GetWebContentsAt(i); | 372 WebContents* web_contents = model->GetWebContentsAt(i); |
| 367 if (web_contents) { | 373 if (web_contents) { |
| 368 tab_web_contents.insert(web_contents); | 374 tab_web_contents.insert(web_contents); |
| 369 targets.push_back(TabTarget::CreateForWebContents(tab->GetAndroidId(), | 375 targets.push_back(TabTarget::CreateForWebContents(tab->GetAndroidId(), |
| 370 web_contents)); | 376 web_contents)); |
| 371 } else { | 377 } else { |
| 372 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), | 378 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), |
| 373 tab->GetTitle(), | 379 tab->GetTitle(), |
| 374 tab->GetURL())); | 380 tab->GetURL())); |
| 375 } | 381 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 jlong server, | 544 jlong server, |
| 539 jboolean enabled, | 545 jboolean enabled, |
| 540 jboolean allow_debug_permission) { | 546 jboolean allow_debug_permission) { |
| 541 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); | 547 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); |
| 542 if (enabled) { | 548 if (enabled) { |
| 543 devtools_server->Start(allow_debug_permission); | 549 devtools_server->Start(allow_debug_permission); |
| 544 } else { | 550 } else { |
| 545 devtools_server->Stop(); | 551 devtools_server->Stop(); |
| 546 } | 552 } |
| 547 } | 553 } |
| OLD | NEW |