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