OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/device/devtools_android_bridge.h" | 5 #include "chrome/browser/devtools/device/devtools_android_bridge.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 #include "content/public/browser/user_metrics.h" | 48 #include "content/public/browser/user_metrics.h" |
49 #include "net/base/escape.h" | 49 #include "net/base/escape.h" |
50 #include "net/base/host_port_pair.h" | 50 #include "net/base/host_port_pair.h" |
51 #include "net/base/net_errors.h" | 51 #include "net/base/net_errors.h" |
52 | 52 |
53 #if defined(ENABLE_SERVICE_DISCOVERY) | 53 #if defined(ENABLE_SERVICE_DISCOVERY) |
54 #include "chrome/browser/devtools/device/cast_device_provider.h" | 54 #include "chrome/browser/devtools/device/cast_device_provider.h" |
55 #endif | 55 #endif |
56 | 56 |
57 using content::BrowserThread; | 57 using content::BrowserThread; |
58 using content::DevToolsAgentHost; | |
58 | 59 |
59 namespace { | 60 namespace { |
60 | 61 |
61 const char kPageListRequest[] = "/json"; | 62 const char kPageListRequest[] = "/json"; |
62 const char kVersionRequest[] = "/json/version"; | 63 const char kVersionRequest[] = "/json/version"; |
63 const char kClosePageRequest[] = "/json/close/%s"; | 64 const char kClosePageRequest[] = "/json/close/%s"; |
64 const char kNewPageRequestWithURL[] = "/json/new?%s"; | 65 const char kNewPageRequestWithURL[] = "/json/new?%s"; |
65 const char kActivatePageRequest[] = "/json/activate/%s"; | 66 const char kActivatePageRequest[] = "/json/activate/%s"; |
66 const char kBrowserTargetSocket[] = "/devtools/browser"; | 67 const char kBrowserTargetSocket[] = "/devtools/browser"; |
67 const int kAdbPollingIntervalMs = 1000; | 68 const int kAdbPollingIntervalMs = 1000; |
68 | 69 |
69 const char kPageReloadCommand[] = "Page.reload"; | 70 const char kPageReloadCommand[] = "Page.reload"; |
70 | 71 |
71 const char kWebViewSocketPrefix[] = "webview_devtools_remote"; | 72 const char kWebViewSocketPrefix[] = "webview_devtools_remote"; |
72 | 73 |
73 bool BrowserIdFromString(const std::string& browser_id_str, | 74 bool BrowserIdFromString(const std::string& browser_id_str, |
74 DevToolsAndroidBridge::BrowserId* browser_id) { | 75 DevToolsAndroidBridge::BrowserId* browser_id) { |
75 size_t colon_pos = browser_id_str.find(':'); | 76 size_t colon_pos = browser_id_str.find(':'); |
76 if (colon_pos == std::string::npos) | 77 if (colon_pos == std::string::npos) |
77 return false; | 78 return false; |
78 browser_id->first = browser_id_str.substr(0, colon_pos); | 79 browser_id->first = browser_id_str.substr(0, colon_pos); |
79 browser_id->second = browser_id_str.substr(colon_pos + 1); | 80 browser_id->second = browser_id_str.substr(colon_pos + 1); |
80 return true; | 81 return true; |
81 } | 82 } |
82 | 83 |
84 static void NoOp(int, const std::string&) {} | |
85 | |
83 } // namespace | 86 } // namespace |
84 | 87 |
85 // DiscoveryRequest ----------------------------------------------------- | 88 // DiscoveryRequest ----------------------------------------------------- |
86 | 89 |
87 class DevToolsAndroidBridge::DiscoveryRequest | 90 class DevToolsAndroidBridge::DiscoveryRequest |
88 : public base::RefCountedThreadSafe<DiscoveryRequest, | 91 : public base::RefCountedThreadSafe<DiscoveryRequest, |
89 BrowserThread::DeleteOnUIThread> { | 92 BrowserThread::DeleteOnUIThread> { |
90 public: | 93 public: |
91 DiscoveryRequest(AndroidDeviceManager* device_manager, | 94 DiscoveryRequest(AndroidDeviceManager* device_manager, |
92 const DeviceListCallback& callback); | 95 const DeviceListCallback& callback); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 } | 286 } |
284 | 287 |
285 // AgentHostDelegate ---------------------------------------------------------- | 288 // AgentHostDelegate ---------------------------------------------------------- |
286 | 289 |
287 class DevToolsAndroidBridge::AgentHostDelegate | 290 class DevToolsAndroidBridge::AgentHostDelegate |
288 : public content::DevToolsExternalAgentProxyDelegate, | 291 : public content::DevToolsExternalAgentProxyDelegate, |
289 public AndroidDeviceManager::AndroidWebSocket::Delegate { | 292 public AndroidDeviceManager::AndroidWebSocket::Delegate { |
290 public: | 293 public: |
291 static scoped_refptr<content::DevToolsAgentHost> GetOrCreateAgentHost( | 294 static scoped_refptr<content::DevToolsAgentHost> GetOrCreateAgentHost( |
292 DevToolsAndroidBridge* bridge, | 295 DevToolsAndroidBridge* bridge, |
293 const std::string& id, | |
294 const BrowserId& browser_id, | 296 const BrowserId& browser_id, |
295 const std::string& target_path); | 297 const std::string& local_id, |
298 const std::string& target_path, | |
299 const std::string& type, | |
300 base::DictionaryValue* value); | |
296 | 301 |
297 private: | 302 private: |
298 AgentHostDelegate( | 303 AgentHostDelegate( |
299 DevToolsAndroidBridge* bridge, | 304 DevToolsAndroidBridge* bridge, |
300 const std::string& id, | |
301 const BrowserId& browser_id, | 305 const BrowserId& browser_id, |
302 const std::string& target_path); | 306 const std::string& local_id, |
307 const std::string& target_path, | |
308 const std::string& type, | |
309 base::DictionaryValue* value); | |
303 ~AgentHostDelegate() override; | 310 ~AgentHostDelegate() override; |
311 // DevToolsExternalAgentProxyDelegate overrides. | |
304 void Attach(content::DevToolsExternalAgentProxy* proxy) override; | 312 void Attach(content::DevToolsExternalAgentProxy* proxy) override; |
305 void Detach() override; | 313 void Detach() override; |
314 std::string GetType() override; | |
315 std::string GetTitle() override; | |
316 std::string GetDescription() override; | |
317 GURL GetURL() override; | |
318 GURL GetFaviconURL() override; | |
319 bool Activate() override; | |
320 void Inspect() override; | |
321 void Reload() override; | |
322 bool Close() override; | |
306 void SendMessageToBackend(const std::string& message) override; | 323 void SendMessageToBackend(const std::string& message) override; |
324 | |
307 void OnSocketOpened() override; | 325 void OnSocketOpened() override; |
308 void OnFrameRead(const std::string& message) override; | 326 void OnFrameRead(const std::string& message) override; |
309 void OnSocketClosed() override; | 327 void OnSocketClosed() override; |
310 | 328 |
311 std::string id_; | |
312 base::WeakPtr<DevToolsAndroidBridge> bridge_; | 329 base::WeakPtr<DevToolsAndroidBridge> bridge_; |
313 BrowserId browser_id_; | 330 BrowserId browser_id_; |
331 std::string local_id_; | |
314 std::string target_path_; | 332 std::string target_path_; |
333 std::string remote_type_; | |
334 std::string remote_id_; | |
335 std::string frontend_url_; | |
336 std::string title_; | |
337 std::string description_; | |
338 GURL url_; | |
339 GURL favicon_url_; | |
315 bool socket_opened_; | 340 bool socket_opened_; |
316 std::vector<std::string> pending_messages_; | 341 std::vector<std::string> pending_messages_; |
317 scoped_refptr<AndroidDeviceManager::Device> device_; | 342 scoped_refptr<AndroidDeviceManager::Device> device_; |
318 std::unique_ptr<AndroidDeviceManager::AndroidWebSocket> web_socket_; | 343 std::unique_ptr<AndroidDeviceManager::AndroidWebSocket> web_socket_; |
319 content::DevToolsAgentHost* agent_host_; | 344 content::DevToolsAgentHost* agent_host_; |
320 content::DevToolsExternalAgentProxy* proxy_; | 345 content::DevToolsExternalAgentProxy* proxy_; |
321 DISALLOW_COPY_AND_ASSIGN(AgentHostDelegate); | 346 DISALLOW_COPY_AND_ASSIGN(AgentHostDelegate); |
322 }; | 347 }; |
323 | 348 |
349 static std::string GetStringProperty(base::DictionaryValue* value, | |
350 const std::string& name) { | |
351 std::string result; | |
352 value->GetString(name, &result); | |
353 return result; | |
354 } | |
355 | |
356 static std::string BuildUniqueTargetId( | |
357 const DevToolsAndroidBridge::BrowserId& browser_id, | |
358 base::DictionaryValue* value) { | |
359 return base::StringPrintf("%s:%s:%s", browser_id.first.c_str(), | |
360 browser_id.second.c_str(), GetStringProperty(value, "id").c_str()); | |
361 } | |
362 | |
363 static std::string GetFrontendURL(base::DictionaryValue* value) { | |
364 std::string frontend_url = GetStringProperty(value, "devtoolsFrontendUrl"); | |
365 size_t ws_param = frontend_url.find("?ws"); | |
366 if (ws_param != std::string::npos) | |
367 frontend_url = frontend_url.substr(0, ws_param); | |
368 if (base::StartsWith(frontend_url, "http:", base::CompareCase::SENSITIVE)) | |
369 frontend_url = "https:" + frontend_url.substr(5); | |
370 return frontend_url; | |
371 } | |
372 | |
373 static std::string GetTargetPath(base::DictionaryValue* value) { | |
374 std::string target_path = GetStringProperty(value, "webSocketDebuggerUrl"); | |
375 | |
376 if (base::StartsWith(target_path, "ws://", base::CompareCase::SENSITIVE)) { | |
377 size_t pos = target_path.find("/", 5); | |
378 if (pos == std::string::npos) | |
379 pos = 5; | |
380 target_path = target_path.substr(pos); | |
381 } else { | |
382 target_path = std::string(); | |
383 } | |
384 return target_path; | |
385 } | |
386 | |
324 // static | 387 // static |
325 scoped_refptr<content::DevToolsAgentHost> | 388 scoped_refptr<content::DevToolsAgentHost> |
326 DevToolsAndroidBridge::AgentHostDelegate::GetOrCreateAgentHost( | 389 DevToolsAndroidBridge::AgentHostDelegate::GetOrCreateAgentHost( |
327 DevToolsAndroidBridge* bridge, | 390 DevToolsAndroidBridge* bridge, |
328 const std::string& id, | |
329 const BrowserId& browser_id, | 391 const BrowserId& browser_id, |
330 const std::string& target_path) { | 392 const std::string& local_id, |
393 const std::string& target_path, | |
394 const std::string& type, | |
395 base::DictionaryValue* value) { | |
331 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 396 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
332 AgentHostDelegates::iterator it = bridge->host_delegates_.find(id); | 397 AgentHostDelegates::iterator it = bridge->host_delegates_.find(local_id); |
333 if (it != bridge->host_delegates_.end()) | 398 if (it != bridge->host_delegates_.end()) |
334 return it->second->agent_host_; | 399 return it->second->agent_host_; |
335 | 400 |
336 AgentHostDelegate* delegate = | 401 AgentHostDelegate* delegate = new AgentHostDelegate( |
337 new AgentHostDelegate(bridge, id, browser_id, target_path); | 402 bridge, browser_id, local_id, target_path, type, value); |
338 scoped_refptr<content::DevToolsAgentHost> result = | 403 scoped_refptr<content::DevToolsAgentHost> result = |
339 content::DevToolsAgentHost::Create(delegate); | 404 content::DevToolsAgentHost::Create(delegate); |
340 delegate->agent_host_ = result.get(); | 405 delegate->agent_host_ = result.get(); |
341 return result; | 406 return result; |
342 } | 407 } |
343 | 408 |
344 DevToolsAndroidBridge::AgentHostDelegate::AgentHostDelegate( | 409 DevToolsAndroidBridge::AgentHostDelegate::AgentHostDelegate( |
345 DevToolsAndroidBridge* bridge, | 410 DevToolsAndroidBridge* bridge, |
346 const std::string& id, | |
347 const BrowserId& browser_id, | 411 const BrowserId& browser_id, |
348 const std::string& target_path) | 412 const std::string& local_id, |
349 : id_(id), | 413 const std::string& target_path, |
350 bridge_(bridge->AsWeakPtr()), | 414 const std::string& type, |
415 base::DictionaryValue* value) | |
416 : bridge_(bridge->AsWeakPtr()), | |
351 browser_id_(browser_id), | 417 browser_id_(browser_id), |
418 local_id_(local_id), | |
352 target_path_(target_path), | 419 target_path_(target_path), |
420 remote_type_(type), | |
421 remote_id_(value ? GetStringProperty(value, "id") : ""), | |
422 frontend_url_(value ? GetFrontendURL(value) : ""), | |
423 title_(value ? base::UTF16ToUTF8(net::UnescapeForHTML(base::UTF8ToUTF16( | |
424 GetStringProperty(value, "title")))) : ""), | |
425 description_(value ? GetStringProperty(value, "description") : ""), | |
426 url_(GURL(value ? GetStringProperty(value, "url") : "")), | |
427 favicon_url_(GURL(value ? GetStringProperty(value, "faviconUrl") : "")), | |
353 socket_opened_(false), | 428 socket_opened_(false), |
354 agent_host_(NULL), | 429 agent_host_(NULL), |
355 proxy_(NULL) { | 430 proxy_(NULL){ |
dgozman
2016/08/22 23:09:07
space gun!
| |
356 bridge_->host_delegates_[id] = this; | 431 bridge_->host_delegates_[local_id_] = this; |
357 } | 432 } |
358 | 433 |
359 DevToolsAndroidBridge::AgentHostDelegate::~AgentHostDelegate() { | 434 DevToolsAndroidBridge::AgentHostDelegate::~AgentHostDelegate() { |
360 if (bridge_) | 435 if (bridge_) |
361 bridge_->host_delegates_.erase(id_); | 436 bridge_->host_delegates_.erase(local_id_); |
362 } | 437 } |
363 | 438 |
364 void DevToolsAndroidBridge::AgentHostDelegate::Attach( | 439 void DevToolsAndroidBridge::AgentHostDelegate::Attach( |
365 content::DevToolsExternalAgentProxy* proxy) { | 440 content::DevToolsExternalAgentProxy* proxy) { |
366 proxy_ = proxy; | 441 proxy_ = proxy; |
367 content::RecordAction( | 442 content::RecordAction( |
368 base::StartsWith(browser_id_.second, kWebViewSocketPrefix, | 443 base::StartsWith(browser_id_.second, kWebViewSocketPrefix, |
369 base::CompareCase::SENSITIVE) | 444 base::CompareCase::SENSITIVE) |
370 ? base::UserMetricsAction("DevTools_InspectAndroidWebView") | 445 ? base::UserMetricsAction("DevTools_InspectAndroidWebView") |
371 : base::UserMetricsAction("DevTools_InspectAndroidPage")); | 446 : base::UserMetricsAction("DevTools_InspectAndroidPage")); |
372 | 447 |
373 // Retain the device so it's not released until AgentHost is detached. | 448 // Retain the device so it's not released until AgentHost is detached. |
374 if (bridge_) | 449 if (bridge_) |
375 device_ = bridge_->FindDevice(browser_id_.first); | 450 device_ = bridge_->FindDevice(browser_id_.first); |
376 if (!device_.get()) | 451 if (!device_.get()) |
377 return; | 452 return; |
378 | 453 |
379 web_socket_.reset( | 454 web_socket_.reset( |
380 device_->CreateWebSocket(browser_id_.second, target_path_, this)); | 455 device_->CreateWebSocket(browser_id_.second, target_path_, this)); |
381 } | 456 } |
382 | 457 |
383 void DevToolsAndroidBridge::AgentHostDelegate::Detach() { | 458 void DevToolsAndroidBridge::AgentHostDelegate::Detach() { |
384 web_socket_.reset(); | 459 web_socket_.reset(); |
385 device_ = nullptr; | 460 device_ = nullptr; |
386 proxy_ = nullptr; | 461 proxy_ = nullptr; |
387 } | 462 } |
388 | 463 |
464 std::string DevToolsAndroidBridge::AgentHostDelegate::GetType() { | |
465 return remote_type_; | |
466 } | |
467 | |
468 std::string DevToolsAndroidBridge::AgentHostDelegate::GetTitle() { | |
469 return title_; | |
470 } | |
471 | |
472 std::string DevToolsAndroidBridge::AgentHostDelegate::GetDescription() { | |
473 return description_; | |
474 } | |
475 | |
476 GURL DevToolsAndroidBridge::AgentHostDelegate::GetURL() { | |
477 return url_; | |
478 } | |
479 | |
480 GURL DevToolsAndroidBridge::AgentHostDelegate::GetFaviconURL() { | |
481 return favicon_url_; | |
482 } | |
483 | |
484 bool DevToolsAndroidBridge::AgentHostDelegate::Activate() { | |
485 if (!bridge_) | |
486 return false; | |
487 | |
488 std::string request = base::StringPrintf(kActivatePageRequest, | |
489 remote_id_.c_str()); | |
490 bridge_->SendJsonRequest(browser_id_, request, base::Bind(&NoOp)); | |
491 return true; | |
492 } | |
493 | |
494 void DevToolsAndroidBridge::AgentHostDelegate::Inspect() { | |
495 Activate(); | |
496 bool is_worker = remote_type_ == DevToolsAgentHost::kTypeServiceWorker || | |
497 remote_type_ == DevToolsAgentHost::kTypeSharedWorker; | |
498 bool is_v8_only = remote_type_ == "node"; | |
499 DevToolsWindow::OpenExternalFrontend(bridge_->profile_, frontend_url_, | |
500 agent_host_, is_worker, is_v8_only); | |
501 } | |
502 | |
503 void DevToolsAndroidBridge::AgentHostDelegate::Reload() { | |
504 if (!bridge_) | |
505 return; | |
506 | |
507 bridge_->SendProtocolCommand(browser_id_, target_path_, kPageReloadCommand, | |
508 NULL, base::Closure()); | |
dgozman
2016/08/22 23:09:07
nullptr
| |
509 } | |
510 | |
511 bool DevToolsAndroidBridge::AgentHostDelegate::Close() { | |
512 if (!bridge_) | |
513 return false; | |
514 | |
515 std::string request = base::StringPrintf(kClosePageRequest, | |
516 remote_id_.c_str()); | |
517 bridge_->SendJsonRequest(browser_id_, request, base::Bind(&NoOp)); | |
518 return true; | |
519 } | |
520 | |
389 void DevToolsAndroidBridge::AgentHostDelegate::SendMessageToBackend( | 521 void DevToolsAndroidBridge::AgentHostDelegate::SendMessageToBackend( |
390 const std::string& message) { | 522 const std::string& message) { |
391 // We could have detached due to physical connection being closed. | 523 // We could have detached due to physical connection being closed. |
392 if (!proxy_) | 524 if (!proxy_) |
393 return; | 525 return; |
394 if (socket_opened_) | 526 if (socket_opened_) |
395 web_socket_->SendFrame(message); | 527 web_socket_->SendFrame(message); |
396 else | 528 else |
397 pending_messages_.push_back(message); | 529 pending_messages_.push_back(message); |
398 } | 530 } |
(...skipping 15 matching lines...) Expand all Loading... | |
414 | 546 |
415 void DevToolsAndroidBridge::AgentHostDelegate::OnSocketClosed() { | 547 void DevToolsAndroidBridge::AgentHostDelegate::OnSocketClosed() { |
416 if (proxy_) { | 548 if (proxy_) { |
417 std::string message = "{ \"method\": \"Inspector.detached\", " | 549 std::string message = "{ \"method\": \"Inspector.detached\", " |
418 "\"params\": { \"reason\": \"Connection lost.\"} }"; | 550 "\"params\": { \"reason\": \"Connection lost.\"} }"; |
419 proxy_->DispatchOnClientHost(message); | 551 proxy_->DispatchOnClientHost(message); |
420 Detach(); | 552 Detach(); |
421 } | 553 } |
422 } | 554 } |
423 | 555 |
424 //// RemotePageTarget ---------------------------------------------- | |
425 | |
426 class DevToolsAndroidBridge::RemotePageTarget : public DevToolsTargetImpl { | |
427 public: | |
428 RemotePageTarget(DevToolsAndroidBridge* bridge, | |
429 const BrowserId& browser_id, | |
430 const base::DictionaryValue& value); | |
431 ~RemotePageTarget() override; | |
432 | |
433 // DevToolsTargetImpl overrides. | |
434 std::string GetId() const override; | |
435 bool IsAttached() const override; | |
436 bool Activate() const override; | |
437 bool Close() const override; | |
438 void Inspect(Profile* profile) const override; | |
439 void Reload() const override; | |
440 | |
441 private: | |
442 base::WeakPtr<DevToolsAndroidBridge> bridge_; | |
443 BrowserId browser_id_; | |
444 std::string target_path_; | |
445 std::string frontend_url_; | |
446 std::string remote_id_; | |
447 std::string remote_type_; | |
448 std::string local_id_; | |
449 DISALLOW_COPY_AND_ASSIGN(RemotePageTarget); | |
450 }; | |
451 | |
452 static std::string GetStringProperty(const base::DictionaryValue& value, | |
453 const std::string& name) { | |
454 std::string result; | |
455 value.GetString(name, &result); | |
456 return result; | |
457 } | |
458 | |
459 static std::string BuildUniqueTargetId( | |
460 const DevToolsAndroidBridge::BrowserId& browser_id, | |
461 const base::DictionaryValue& value) { | |
462 return base::StringPrintf("%s:%s:%s", browser_id.first.c_str(), | |
463 browser_id.second.c_str(), GetStringProperty(value, "id").c_str()); | |
464 } | |
465 | |
466 static std::string GetFrontendURL(const base::DictionaryValue& value) { | |
467 std::string frontend_url = GetStringProperty(value, "devtoolsFrontendUrl"); | |
468 size_t ws_param = frontend_url.find("?ws"); | |
469 if (ws_param != std::string::npos) | |
470 frontend_url = frontend_url.substr(0, ws_param); | |
471 if (base::StartsWith(frontend_url, "http:", base::CompareCase::SENSITIVE)) | |
472 frontend_url = "https:" + frontend_url.substr(5); | |
473 return frontend_url; | |
474 } | |
475 | |
476 static std::string GetTargetPath(const base::DictionaryValue& value) { | |
477 std::string target_path = GetStringProperty(value, "webSocketDebuggerUrl"); | |
478 | |
479 if (base::StartsWith(target_path, "ws://", base::CompareCase::SENSITIVE)) { | |
480 size_t pos = target_path.find("/", 5); | |
481 if (pos == std::string::npos) | |
482 pos = 5; | |
483 target_path = target_path.substr(pos); | |
484 } else { | |
485 target_path = std::string(); | |
486 } | |
487 return target_path; | |
488 } | |
489 | |
490 DevToolsAndroidBridge::RemotePageTarget::RemotePageTarget( | |
491 DevToolsAndroidBridge* bridge, | |
492 const BrowserId& browser_id, | |
493 const base::DictionaryValue& value) | |
494 : DevToolsTargetImpl(AgentHostDelegate::GetOrCreateAgentHost( | |
495 bridge, | |
496 BuildUniqueTargetId(browser_id, value), | |
497 browser_id, | |
498 GetTargetPath(value))), | |
499 bridge_(bridge->AsWeakPtr()), | |
500 browser_id_(browser_id), | |
501 target_path_(GetTargetPath(value)), | |
502 frontend_url_(GetFrontendURL(value)), | |
503 remote_id_(GetStringProperty(value, "id")), | |
504 remote_type_(GetStringProperty(value, "type")), | |
505 local_id_(BuildUniqueTargetId(browser_id, value)) { | |
506 set_type("adb_page"); | |
507 set_url(GURL(GetStringProperty(value, "url"))); | |
508 set_title(base::UTF16ToUTF8(net::UnescapeForHTML(base::UTF8ToUTF16( | |
509 GetStringProperty(value, "title"))))); | |
510 set_description(GetStringProperty(value, "description")); | |
511 set_favicon_url(GURL(GetStringProperty(value, "faviconUrl"))); | |
512 target_path_ = GetTargetPath(value); | |
513 } | |
514 | |
515 DevToolsAndroidBridge::RemotePageTarget::~RemotePageTarget() { | |
516 } | |
517 | |
518 std::string DevToolsAndroidBridge::RemotePageTarget::GetId() const { | |
519 return local_id_; | |
520 } | |
521 | |
522 bool DevToolsAndroidBridge::RemotePageTarget::IsAttached() const { | |
523 return target_path_.empty(); | |
524 } | |
525 | |
526 static void NoOp(int, const std::string&) {} | |
527 | |
528 void DevToolsAndroidBridge::RemotePageTarget::Inspect(Profile* profile) const { | |
529 Activate(); | |
530 bool is_worker = remote_type_ == kTargetTypeWorker || | |
531 remote_type_ == kTargetTypeServiceWorker; | |
532 bool is_v8_only = remote_type_ == kTargetTypeNode; | |
533 DevToolsWindow::OpenExternalFrontend(profile, frontend_url_, GetAgentHost(), | |
534 is_worker, is_v8_only); | |
535 } | |
536 | |
537 bool DevToolsAndroidBridge::RemotePageTarget::Activate() const { | |
538 if (!bridge_) | |
539 return false; | |
540 | |
541 std::string request = base::StringPrintf(kActivatePageRequest, | |
542 remote_id_.c_str()); | |
543 bridge_->SendJsonRequest(browser_id_, request, base::Bind(&NoOp)); | |
544 return true; | |
545 } | |
546 | |
547 bool DevToolsAndroidBridge::RemotePageTarget::Close() const { | |
548 if (!bridge_) | |
549 return false; | |
550 | |
551 std::string request = base::StringPrintf(kClosePageRequest, | |
552 remote_id_.c_str()); | |
553 bridge_->SendJsonRequest(browser_id_, request, base::Bind(&NoOp)); | |
554 return true; | |
555 } | |
556 | |
557 void DevToolsAndroidBridge::RemotePageTarget::Reload() const { | |
558 if (!bridge_) | |
559 return; | |
560 | |
561 bridge_->SendProtocolCommand(browser_id_, target_path_, kPageReloadCommand, | |
562 NULL, base::Closure()); | |
563 } | |
564 | |
565 // DevToolsAndroidBridge::RemotePage ------------------------------------------ | 556 // DevToolsAndroidBridge::RemotePage ------------------------------------------ |
566 | 557 |
567 DevToolsAndroidBridge::RemotePage::RemotePage(const BrowserId& browser_id, | 558 DevToolsAndroidBridge::RemotePage::RemotePage(const BrowserId& browser_id, |
568 const base::DictionaryValue& dict) | 559 const base::DictionaryValue& dict) |
569 : browser_id_(browser_id), | 560 : browser_id_(browser_id), |
570 frontend_url_(GetFrontendURL(dict)), | |
571 dict_(dict.DeepCopy()) { | 561 dict_(dict.DeepCopy()) { |
572 } | 562 } |
573 | 563 |
574 DevToolsAndroidBridge::RemotePage::~RemotePage() { | 564 DevToolsAndroidBridge::RemotePage::~RemotePage() { |
575 } | 565 } |
576 | 566 |
577 // DevToolsAndroidBridge::RemoteBrowser --------------------------------------- | 567 // DevToolsAndroidBridge::RemoteBrowser --------------------------------------- |
578 | 568 |
579 DevToolsAndroidBridge::RemoteBrowser::RemoteBrowser( | 569 DevToolsAndroidBridge::RemoteBrowser::RemoteBrowser( |
580 const std::string& serial, | 570 const std::string& serial, |
(...skipping 20 matching lines...) Expand all Loading... | |
601 version_, ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { | 591 version_, ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { |
602 int value = 0; | 592 int value = 0; |
603 base::StringToInt(part, &value); | 593 base::StringToInt(part, &value); |
604 result.push_back(value); | 594 result.push_back(value); |
605 } | 595 } |
606 return result; | 596 return result; |
607 } | 597 } |
608 | 598 |
609 DevToolsTargetImpl* | 599 DevToolsTargetImpl* |
610 DevToolsAndroidBridge::CreatePageTarget(scoped_refptr<RemotePage> page) { | 600 DevToolsAndroidBridge::CreatePageTarget(scoped_refptr<RemotePage> page) { |
611 return new RemotePageTarget(this, page->browser_id_, *page->dict_); | 601 std::string local_id = BuildUniqueTargetId(page->browser_id_, |
602 page->dict_.get()); | |
603 std::string target_path = GetTargetPath(page->dict_.get()); | |
604 std::string type = GetStringProperty(page->dict_.get(), "type"); | |
605 scoped_refptr<DevToolsAgentHost> host = | |
606 AgentHostDelegate::GetOrCreateAgentHost(this, page->browser_id_, local_id, | |
607 target_path, type, | |
608 page->dict_.get()); | |
609 return new DevToolsTargetImpl(host); | |
612 } | 610 } |
613 | 611 |
614 void DevToolsAndroidBridge::SendJsonRequest( | 612 void DevToolsAndroidBridge::SendJsonRequest( |
615 const BrowserId& browser_id, | 613 const BrowserId& browser_id, |
616 const std::string& request, | 614 const std::string& request, |
617 const JsonRequestCallback& callback) { | 615 const JsonRequestCallback& callback) { |
618 scoped_refptr<AndroidDeviceManager::Device> device( | 616 scoped_refptr<AndroidDeviceManager::Device> device( |
619 FindDevice(browser_id.first)); | 617 FindDevice(browser_id.first)); |
620 if (!device.get()) { | 618 if (!device.get()) { |
621 callback.Run(net::ERR_FAILED, std::string()); | 619 callback.Run(net::ERR_FAILED, std::string()); |
(...skipping 21 matching lines...) Expand all Loading... | |
643 device, browser_id.second, target_path, | 641 device, browser_id.second, target_path, |
644 DevToolsProtocol::SerializeCommand(1, method, std::move(params)), | 642 DevToolsProtocol::SerializeCommand(1, method, std::move(params)), |
645 callback); | 643 callback); |
646 } | 644 } |
647 | 645 |
648 scoped_refptr<content::DevToolsAgentHost> | 646 scoped_refptr<content::DevToolsAgentHost> |
649 DevToolsAndroidBridge::GetBrowserAgentHost( | 647 DevToolsAndroidBridge::GetBrowserAgentHost( |
650 scoped_refptr<RemoteBrowser> browser) { | 648 scoped_refptr<RemoteBrowser> browser) { |
651 return AgentHostDelegate::GetOrCreateAgentHost( | 649 return AgentHostDelegate::GetOrCreateAgentHost( |
652 this, | 650 this, |
651 browser->browser_id_, | |
653 "adb:" + browser->serial() + ":" + browser->socket(), | 652 "adb:" + browser->serial() + ":" + browser->socket(), |
654 browser->browser_id_, | 653 kBrowserTargetSocket, DevToolsAgentHost::kTypeBrowser, nullptr); |
655 kBrowserTargetSocket); | |
656 } | 654 } |
657 | 655 |
658 void DevToolsAndroidBridge::SendJsonRequest( | 656 void DevToolsAndroidBridge::SendJsonRequest( |
659 const std::string& browser_id_str, | 657 const std::string& browser_id_str, |
660 const std::string& url, | 658 const std::string& url, |
661 const JsonRequestCallback& callback) { | 659 const JsonRequestCallback& callback) { |
662 BrowserId browser_id; | 660 BrowserId browser_id; |
663 if (!BrowserIdFromString(browser_id_str, &browser_id)) { | 661 if (!BrowserIdFromString(browser_id_str, &browser_id)) { |
664 callback.Run(net::ERR_FAILED, std::string()); | 662 callback.Run(net::ERR_FAILED, std::string()); |
665 return; | 663 return; |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
982 StopDeviceListPolling(); | 980 StopDeviceListPolling(); |
983 StartDeviceListPolling(); | 981 StartDeviceListPolling(); |
984 } | 982 } |
985 } | 983 } |
986 | 984 |
987 void DevToolsAndroidBridge::set_tcp_provider_callback_for_test( | 985 void DevToolsAndroidBridge::set_tcp_provider_callback_for_test( |
988 TCPProviderCallback callback) { | 986 TCPProviderCallback callback) { |
989 tcp_provider_callback_ = callback; | 987 tcp_provider_callback_ = callback; |
990 CreateDeviceProviders(); | 988 CreateDeviceProviders(); |
991 } | 989 } |
OLD | NEW |