| 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 "chrome/browser/devtools/devtools_targets_ui.h" | 5 #include "chrome/browser/devtools/devtools_targets_ui.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 SendTargets(DevToolsTargetImpl::EnumerateAll()); | 229 SendTargets(DevToolsTargetImpl::EnumerateAll()); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void LocalTargetsUIHandler::SendTargets( | 232 void LocalTargetsUIHandler::SendTargets( |
| 233 const std::vector<DevToolsTargetImpl*>& targets) { | 233 const std::vector<DevToolsTargetImpl*>& targets) { |
| 234 base::ListValue list_value; | 234 base::ListValue list_value; |
| 235 std::map<std::string, base::DictionaryValue*> id_to_descriptor; | 235 std::map<std::string, base::DictionaryValue*> id_to_descriptor; |
| 236 | 236 |
| 237 base::STLDeleteValues(&targets_); | 237 base::STLDeleteValues(&targets_); |
| 238 for (DevToolsTargetImpl* target : targets) { | 238 for (DevToolsTargetImpl* target : targets) { |
| 239 targets_[target->GetId()] = target; | 239 scoped_refptr<content::DevToolsAgentHost> host = target->GetAgentHost(); |
| 240 id_to_descriptor[target->GetId()] = Serialize(*target); | 240 targets_[host->GetId()] = target; |
| 241 id_to_descriptor[host->GetId()] = Serialize(*target); |
| 241 } | 242 } |
| 242 | 243 |
| 243 for (TargetMap::iterator it(targets_.begin()); it != targets_.end(); ++it) { | 244 for (TargetMap::iterator it(targets_.begin()); it != targets_.end(); ++it) { |
| 244 DevToolsTargetImpl* target = it->second; | 245 DevToolsTargetImpl* target = it->second; |
| 245 base::DictionaryValue* descriptor = id_to_descriptor[target->GetId()]; | 246 scoped_refptr<content::DevToolsAgentHost> host = target->GetAgentHost(); |
| 246 std::string parent_id = target->GetParentId(); | 247 base::DictionaryValue* descriptor = id_to_descriptor[host->GetId()]; |
| 248 std::string parent_id = host->GetParentId(); |
| 247 if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) { | 249 if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) { |
| 248 list_value.Append(descriptor); | 250 list_value.Append(descriptor); |
| 249 } else { | 251 } else { |
| 250 base::DictionaryValue* parent = id_to_descriptor[parent_id]; | 252 base::DictionaryValue* parent = id_to_descriptor[parent_id]; |
| 251 base::ListValue* guests = NULL; | 253 base::ListValue* guests = NULL; |
| 252 if (!parent->GetList(kGuestList, &guests)) { | 254 if (!parent->GetList(kGuestList, &guests)) { |
| 253 guests = new base::ListValue(); | 255 guests = new base::ListValue(); |
| 254 parent->Set(kGuestList, guests); | 256 parent->Set(kGuestList, guests); |
| 255 } | 257 } |
| 256 guests->Append(descriptor); | 258 guests->Append(descriptor); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 browser->IsChrome() && !parsed.empty() ? parsed[0] : 0); | 362 browser->IsChrome() && !parsed.empty() ? parsed[0] : 0); |
| 361 std::string browser_id = browser->GetId(); | 363 std::string browser_id = browser->GetId(); |
| 362 browser_data->SetString(kTargetIdField, browser_id); | 364 browser_data->SetString(kTargetIdField, browser_id); |
| 363 browser_data->SetString(kTargetSourceField, source_id()); | 365 browser_data->SetString(kTargetSourceField, source_id()); |
| 364 | 366 |
| 365 base::ListValue* page_list = new base::ListValue(); | 367 base::ListValue* page_list = new base::ListValue(); |
| 366 remote_browsers_[browser_id] = browser; | 368 remote_browsers_[browser_id] = browser; |
| 367 browser_data->Set(kAdbPagesList, page_list); | 369 browser_data->Set(kAdbPagesList, page_list); |
| 368 for (const auto& page : browser->pages()) { | 370 for (const auto& page : browser->pages()) { |
| 369 DevToolsTargetImpl* target = android_bridge_->CreatePageTarget(page); | 371 DevToolsTargetImpl* target = android_bridge_->CreatePageTarget(page); |
| 372 scoped_refptr<content::DevToolsAgentHost> host = target->GetAgentHost(); |
| 370 base::DictionaryValue* target_data = Serialize(*target); | 373 base::DictionaryValue* target_data = Serialize(*target); |
| 371 target_data->SetBoolean( | 374 target_data->SetBoolean( |
| 372 kAdbAttachedForeignField, | 375 kAdbAttachedForeignField, |
| 373 target->IsAttached() && | 376 host->IsAttached() && |
| 374 !android_bridge_->HasDevToolsWindow(target->GetId())); | 377 !android_bridge_->HasDevToolsWindow(host->GetId())); |
| 375 // Pass the screen size in the target object to make sure that | 378 // Pass the screen size in the target object to make sure that |
| 376 // the caching logic does not prevent the target item from updating | 379 // the caching logic does not prevent the target item from updating |
| 377 // when the screen size changes. | 380 // when the screen size changes. |
| 378 gfx::Size screen_size = device->screen_size(); | 381 gfx::Size screen_size = device->screen_size(); |
| 379 target_data->SetInteger(kAdbScreenWidthField, screen_size.width()); | 382 target_data->SetInteger(kAdbScreenWidthField, screen_size.width()); |
| 380 target_data->SetInteger(kAdbScreenHeightField, screen_size.height()); | 383 target_data->SetInteger(kAdbScreenHeightField, screen_size.height()); |
| 381 targets_[target->GetId()] = target; | 384 targets_[host->GetId()] = target; |
| 382 page_list->Append(target_data); | 385 page_list->Append(target_data); |
| 383 } | 386 } |
| 384 browser_list->Append(std::move(browser_data)); | 387 browser_list->Append(std::move(browser_data)); |
| 385 } | 388 } |
| 386 | 389 |
| 387 device_list.Append(std::move(device_data)); | 390 device_list.Append(std::move(device_data)); |
| 388 } | 391 } |
| 389 SendSerializedTargets(device_list); | 392 SendSerializedTargets(device_list); |
| 390 } | 393 } |
| 391 | 394 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 437 } |
| 435 | 438 |
| 436 scoped_refptr<content::DevToolsAgentHost> | 439 scoped_refptr<content::DevToolsAgentHost> |
| 437 DevToolsTargetsUIHandler::GetBrowserAgentHost(const std::string& browser_id) { | 440 DevToolsTargetsUIHandler::GetBrowserAgentHost(const std::string& browser_id) { |
| 438 return NULL; | 441 return NULL; |
| 439 } | 442 } |
| 440 | 443 |
| 441 base::DictionaryValue* DevToolsTargetsUIHandler::Serialize( | 444 base::DictionaryValue* DevToolsTargetsUIHandler::Serialize( |
| 442 const DevToolsTargetImpl& target) { | 445 const DevToolsTargetImpl& target) { |
| 443 base::DictionaryValue* target_data = new base::DictionaryValue(); | 446 base::DictionaryValue* target_data = new base::DictionaryValue(); |
| 447 scoped_refptr<content::DevToolsAgentHost> host = target.GetAgentHost(); |
| 444 target_data->SetString(kTargetSourceField, source_id_); | 448 target_data->SetString(kTargetSourceField, source_id_); |
| 445 target_data->SetString(kTargetIdField, target.GetId()); | 449 target_data->SetString(kTargetIdField, host->GetId()); |
| 446 target_data->SetString(kTargetTypeField, target.GetType()); | 450 target_data->SetString(kTargetTypeField, host->GetType()); |
| 447 target_data->SetBoolean(kAttachedField, target.IsAttached()); | 451 target_data->SetBoolean(kAttachedField, host->IsAttached()); |
| 448 target_data->SetString(kUrlField, target.GetURL().spec()); | 452 target_data->SetString(kUrlField, host->GetURL().spec()); |
| 449 target_data->SetString(kNameField, target.GetTitle()); | 453 target_data->SetString(kNameField, host->GetTitle()); |
| 450 target_data->SetString(kFaviconUrlField, target.GetFaviconURL().spec()); | 454 target_data->SetString(kFaviconUrlField, host->GetFaviconURL().spec()); |
| 451 target_data->SetString(kDescriptionField, target.GetDescription()); | 455 target_data->SetString(kDescriptionField, host->GetDescription()); |
| 452 return target_data; | 456 return target_data; |
| 453 } | 457 } |
| 454 | 458 |
| 455 void DevToolsTargetsUIHandler::SendSerializedTargets( | 459 void DevToolsTargetsUIHandler::SendSerializedTargets( |
| 456 const base::ListValue& list) { | 460 const base::ListValue& list) { |
| 457 callback_.Run(source_id_, list); | 461 callback_.Run(source_id_, list); |
| 458 } | 462 } |
| 459 | 463 |
| 460 void DevToolsTargetsUIHandler::ForceUpdate() { | 464 void DevToolsTargetsUIHandler::ForceUpdate() { |
| 461 } | 465 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 device_status_dict->SetString(kPortForwardingBrowserId, | 500 device_status_dict->SetString(kPortForwardingBrowserId, |
| 497 sit->first->GetId()); | 501 sit->first->GetId()); |
| 498 | 502 |
| 499 std::string device_id = base::StringPrintf( | 503 std::string device_id = base::StringPrintf( |
| 500 kAdbDeviceIdFormat, | 504 kAdbDeviceIdFormat, |
| 501 sit->first->serial().c_str()); | 505 sit->first->serial().c_str()); |
| 502 result.Set(device_id, device_status_dict); | 506 result.Set(device_id, device_status_dict); |
| 503 } | 507 } |
| 504 callback_.Run(result); | 508 callback_.Run(result); |
| 505 } | 509 } |
| OLD | NEW |