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 <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "base/version.h" | 19 #include "base/version.h" |
20 #include "chrome/browser/devtools/device/devtools_android_bridge.h" | 20 #include "chrome/browser/devtools/device/devtools_android_bridge.h" |
| 21 #include "chrome/browser/devtools/serialize_host_descriptions.h" |
21 #include "content/public/browser/browser_child_process_observer.h" | 22 #include "content/public/browser/browser_child_process_observer.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/child_process_data.h" | 24 #include "content/public/browser/child_process_data.h" |
24 #include "content/public/browser/devtools_agent_host.h" | 25 #include "content/public/browser/devtools_agent_host.h" |
25 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
26 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
27 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
28 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
29 #include "content/public/browser/notification_types.h" | 30 #include "content/public/browser/notification_types.h" |
30 #include "content/public/browser/worker_service.h" | 31 #include "content/public/browser/worker_service.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 base::Unretained(this)), | 227 base::Unretained(this)), |
227 base::TimeDelta::FromMilliseconds(kUpdateDelay))); | 228 base::TimeDelta::FromMilliseconds(kUpdateDelay))); |
228 } | 229 } |
229 | 230 |
230 void LocalTargetsUIHandler::UpdateTargets() { | 231 void LocalTargetsUIHandler::UpdateTargets() { |
231 SendTargets(DevToolsAgentHost::GetOrCreateAll()); | 232 SendTargets(DevToolsAgentHost::GetOrCreateAll()); |
232 } | 233 } |
233 | 234 |
234 void LocalTargetsUIHandler::SendTargets( | 235 void LocalTargetsUIHandler::SendTargets( |
235 const content::DevToolsAgentHost::List& targets) { | 236 const content::DevToolsAgentHost::List& targets) { |
236 base::ListValue list_value; | 237 std::vector<HostDescriptionNode> hosts; |
237 std::map<std::string, base::DictionaryValue*> id_to_descriptor; | 238 hosts.reserve(targets.size()); |
238 | 239 |
239 targets_.clear(); | 240 targets_.clear(); |
240 for (scoped_refptr<DevToolsAgentHost> host : targets) { | 241 for (const scoped_refptr<DevToolsAgentHost>& host : targets) { |
241 targets_[host->GetId()] = host; | 242 targets_[host->GetId()] = host; |
242 id_to_descriptor[host->GetId()] = Serialize(host).release(); | 243 hosts.push_back( |
| 244 {host->GetId(), host->GetParentId(), *Serialize(host.get())}); |
243 } | 245 } |
244 | 246 |
245 for (auto& it : targets_) { | 247 SendSerializedTargets( |
246 scoped_refptr<DevToolsAgentHost> host = it.second; | 248 SerializeHostDescriptions(std::move(hosts), kGuestList)); |
247 base::DictionaryValue* descriptor = id_to_descriptor[host->GetId()]; | |
248 DCHECK(descriptor); | |
249 std::string parent_id = host->GetParentId(); | |
250 if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) { | |
251 list_value.Append(base::WrapUnique(descriptor)); | |
252 } else { | |
253 base::DictionaryValue* parent = id_to_descriptor[parent_id]; | |
254 base::ListValue* guests_weak = NULL; | |
255 if (!parent->GetList(kGuestList, &guests_weak)) { | |
256 auto guests = base::MakeUnique<base::ListValue>(); | |
257 guests_weak = guests.get(); | |
258 parent->Set(kGuestList, std::move(guests)); | |
259 } | |
260 guests_weak->Append(base::WrapUnique(descriptor)); | |
261 } | |
262 } | |
263 | |
264 SendSerializedTargets(list_value); | |
265 } | 249 } |
266 | 250 |
267 // AdbTargetsUIHandler -------------------------------------------------------- | 251 // AdbTargetsUIHandler -------------------------------------------------------- |
268 | 252 |
269 class AdbTargetsUIHandler | 253 class AdbTargetsUIHandler |
270 : public DevToolsTargetsUIHandler, | 254 : public DevToolsTargetsUIHandler, |
271 public DevToolsAndroidBridge::DeviceListListener { | 255 public DevToolsAndroidBridge::DeviceListListener { |
272 public: | 256 public: |
273 AdbTargetsUIHandler(const Callback& callback, Profile* profile); | 257 AdbTargetsUIHandler(const Callback& callback, Profile* profile); |
274 ~AdbTargetsUIHandler() override; | 258 ~AdbTargetsUIHandler() override; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 kAdbBrowserChromeVersionField, | 346 kAdbBrowserChromeVersionField, |
363 browser->IsChrome() && !parsed.empty() ? parsed[0] : 0); | 347 browser->IsChrome() && !parsed.empty() ? parsed[0] : 0); |
364 std::string browser_id = browser->GetId(); | 348 std::string browser_id = browser->GetId(); |
365 browser_data->SetString(kTargetIdField, browser_id); | 349 browser_data->SetString(kTargetIdField, browser_id); |
366 browser_data->SetString(kTargetSourceField, source_id()); | 350 browser_data->SetString(kTargetSourceField, source_id()); |
367 | 351 |
368 auto page_list = base::MakeUnique<base::ListValue>(); | 352 auto page_list = base::MakeUnique<base::ListValue>(); |
369 remote_browsers_[browser_id] = browser; | 353 remote_browsers_[browser_id] = browser; |
370 for (const auto& page : browser->pages()) { | 354 for (const auto& page : browser->pages()) { |
371 scoped_refptr<DevToolsAgentHost> host = page->CreateTarget(); | 355 scoped_refptr<DevToolsAgentHost> host = page->CreateTarget(); |
372 std::unique_ptr<base::DictionaryValue> target_data = Serialize(host); | 356 std::unique_ptr<base::DictionaryValue> target_data = |
| 357 Serialize(host.get()); |
373 // Pass the screen size in the target object to make sure that | 358 // Pass the screen size in the target object to make sure that |
374 // the caching logic does not prevent the target item from updating | 359 // the caching logic does not prevent the target item from updating |
375 // when the screen size changes. | 360 // when the screen size changes. |
376 gfx::Size screen_size = device->screen_size(); | 361 gfx::Size screen_size = device->screen_size(); |
377 target_data->SetInteger(kAdbScreenWidthField, screen_size.width()); | 362 target_data->SetInteger(kAdbScreenWidthField, screen_size.width()); |
378 target_data->SetInteger(kAdbScreenHeightField, screen_size.height()); | 363 target_data->SetInteger(kAdbScreenHeightField, screen_size.height()); |
379 targets_[host->GetId()] = host; | 364 targets_[host->GetId()] = host; |
380 page_list->Append(std::move(target_data)); | 365 page_list->Append(std::move(target_data)); |
381 } | 366 } |
382 browser_data->Set(kAdbPagesList, std::move(page_list)); | 367 browser_data->Set(kAdbPagesList, std::move(page_list)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 void DevToolsTargetsUIHandler::Open(const std::string& browser_id, | 416 void DevToolsTargetsUIHandler::Open(const std::string& browser_id, |
432 const std::string& url) { | 417 const std::string& url) { |
433 } | 418 } |
434 | 419 |
435 scoped_refptr<DevToolsAgentHost> | 420 scoped_refptr<DevToolsAgentHost> |
436 DevToolsTargetsUIHandler::GetBrowserAgentHost(const std::string& browser_id) { | 421 DevToolsTargetsUIHandler::GetBrowserAgentHost(const std::string& browser_id) { |
437 return NULL; | 422 return NULL; |
438 } | 423 } |
439 | 424 |
440 std::unique_ptr<base::DictionaryValue> DevToolsTargetsUIHandler::Serialize( | 425 std::unique_ptr<base::DictionaryValue> DevToolsTargetsUIHandler::Serialize( |
441 scoped_refptr<DevToolsAgentHost> host) { | 426 DevToolsAgentHost* host) { |
442 auto target_data = base::MakeUnique<base::DictionaryValue>(); | 427 auto target_data = base::MakeUnique<base::DictionaryValue>(); |
443 target_data->SetString(kTargetSourceField, source_id_); | 428 target_data->SetString(kTargetSourceField, source_id_); |
444 target_data->SetString(kTargetIdField, host->GetId()); | 429 target_data->SetString(kTargetIdField, host->GetId()); |
445 target_data->SetString(kTargetTypeField, host->GetType()); | 430 target_data->SetString(kTargetTypeField, host->GetType()); |
446 target_data->SetBoolean(kAttachedField, host->IsAttached()); | 431 target_data->SetBoolean(kAttachedField, host->IsAttached()); |
447 target_data->SetString(kUrlField, host->GetURL().spec()); | 432 target_data->SetString(kUrlField, host->GetURL().spec()); |
448 target_data->SetString(kNameField, host->GetTitle()); | 433 target_data->SetString(kNameField, host->GetTitle()); |
449 target_data->SetString(kFaviconUrlField, host->GetFaviconURL().spec()); | 434 target_data->SetString(kFaviconUrlField, host->GetFaviconURL().spec()); |
450 target_data->SetString(kDescriptionField, host->GetDescription()); | 435 target_data->SetString(kDescriptionField, host->GetDescription()); |
451 return target_data; | 436 return target_data; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 device_status_dict->SetString(kPortForwardingBrowserId, | 480 device_status_dict->SetString(kPortForwardingBrowserId, |
496 sit->first->GetId()); | 481 sit->first->GetId()); |
497 | 482 |
498 std::string device_id = base::StringPrintf( | 483 std::string device_id = base::StringPrintf( |
499 kAdbDeviceIdFormat, | 484 kAdbDeviceIdFormat, |
500 sit->first->serial().c_str()); | 485 sit->first->serial().c_str()); |
501 result.Set(device_id, std::move(device_status_dict)); | 486 result.Set(device_id, std::move(device_status_dict)); |
502 } | 487 } |
503 callback_.Run(result); | 488 callback_.Run(result); |
504 } | 489 } |
OLD | NEW |