Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: content/browser/devtools/devtools_http_handler_impl.cc

Issue 24995003: DevTools: Extract target discovery and manipulation from DevToolsHttpHandlerImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Extracted DevToolsTarget class Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "content/browser/devtools/devtools_http_handler_impl.h" 5 #include "content/browser/devtools/devtools_http_handler_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/lazy_instance.h"
15 #include "base/logging.h" 14 #include "base/logging.h"
16 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/message_loop/message_loop_proxy.h"
17 #include "base/stl_util.h" 16 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/utf_string_conversions.h"
20 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
21 #include "base/values.h" 18 #include "base/values.h"
22 #include "content/browser/devtools/devtools_browser_target.h" 19 #include "content/browser/devtools/devtools_browser_target.h"
23 #include "content/browser/devtools/devtools_protocol.h" 20 #include "content/browser/devtools/devtools_protocol.h"
24 #include "content/browser/devtools/devtools_protocol_constants.h" 21 #include "content/browser/devtools/devtools_protocol_constants.h"
25 #include "content/browser/devtools/devtools_system_info_handler.h" 22 #include "content/browser/devtools/devtools_system_info_handler.h"
26 #include "content/browser/devtools/devtools_tracing_handler.h" 23 #include "content/browser/devtools/devtools_tracing_handler.h"
27 #include "content/browser/devtools/tethering_handler.h" 24 #include "content/browser/devtools/tethering_handler.h"
28 #include "content/browser/web_contents/web_contents_impl.h"
29 #include "content/common/devtools_messages.h" 25 #include "content/common/devtools_messages.h"
30 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/devtools_agent_host.h" 27 #include "content/public/browser/devtools_agent_host.h"
32 #include "content/public/browser/devtools_client_host.h" 28 #include "content/public/browser/devtools_client_host.h"
33 #include "content/public/browser/devtools_http_handler_delegate.h" 29 #include "content/public/browser/devtools_http_handler_delegate.h"
34 #include "content/public/browser/devtools_manager.h" 30 #include "content/public/browser/devtools_manager.h"
35 #include "content/public/browser/favicon_status.h"
36 #include "content/public/browser/navigation_entry.h"
37 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/notification_types.h"
39 #include "content/public/browser/render_view_host.h"
40 #include "content/public/common/content_client.h" 31 #include "content/public/common/content_client.h"
41 #include "content/public/common/url_constants.h" 32 #include "content/public/common/url_constants.h"
42 #include "grit/devtools_resources_map.h" 33 #include "grit/devtools_resources_map.h"
43 #include "net/base/escape.h"
44 #include "net/base/io_buffer.h" 34 #include "net/base/io_buffer.h"
45 #include "net/base/ip_endpoint.h" 35 #include "net/base/ip_endpoint.h"
46 #include "net/server/http_server_request_info.h" 36 #include "net/server/http_server_request_info.h"
47 #include "net/server/http_server_response_info.h" 37 #include "net/server/http_server_response_info.h"
48 #include "ui/base/layout.h"
49 #include "url/gurl.h"
50 #include "webkit/common/user_agent/user_agent.h" 38 #include "webkit/common/user_agent/user_agent.h"
51 #include "webkit/common/user_agent/user_agent_util.h" 39 #include "webkit/common/user_agent/user_agent_util.h"
52 40
53 namespace content { 41 namespace content {
54 42
55 namespace { 43 namespace {
56 44
57 const char kProtocolVersion[] = "1.0"; 45 const char kProtocolVersion[] = "1.0";
58 46
59 const char kDevToolsHandlerThreadName[] = "Chrome_DevToolsHandlerThread"; 47 const char kDevToolsHandlerThreadName[] = "Chrome_DevToolsHandlerThread";
60 48
61 const char kThumbUrlPrefix[] = "/thumb/"; 49 const char kThumbUrlPrefix[] = "/thumb/";
62 const char kPageUrlPrefix[] = "/devtools/page/"; 50 const char kPageUrlPrefix[] = "/devtools/page/";
63 51
64 const char kTargetIdField[] = "id"; 52 const char kTargetIdField[] = "id";
65 const char kTargetTypeField[] = "type"; 53 const char kTargetTypeField[] = "type";
66 const char kTargetTitleField[] = "title"; 54 const char kTargetTitleField[] = "title";
67 const char kTargetDescriptionField[] = "description"; 55 const char kTargetDescriptionField[] = "description";
68 const char kTargetUrlField[] = "url"; 56 const char kTargetUrlField[] = "url";
69 const char kTargetThumbnailUrlField[] = "thumbnailUrl"; 57 const char kTargetThumbnailUrlField[] = "thumbnailUrl";
70 const char kTargetFaviconUrlField[] = "faviconUrl"; 58 const char kTargetFaviconUrlField[] = "faviconUrl";
59 const char kTargetLastActivityTimeField[] = "lastActivityTime";
71 const char kTargetWebSocketDebuggerUrlField[] = "webSocketDebuggerUrl"; 60 const char kTargetWebSocketDebuggerUrlField[] = "webSocketDebuggerUrl";
72 const char kTargetDevtoolsFrontendUrlField[] = "devtoolsFrontendUrl"; 61 const char kTargetDevtoolsFrontendUrlField[] = "devtoolsFrontendUrl";
73 62
74 const char kTargetTypePage[] = "page"; 63 const char kTargetTypePage[] = "page";
75 const char kTargetTypeOther[] = "other"; 64 const char kTargetTypeOther[] = "other";
76 65
77 class DevToolsDefaultBindingHandler
78 : public DevToolsHttpHandler::DevToolsAgentHostBinding {
79 public:
80 DevToolsDefaultBindingHandler() {
81 }
82
83 virtual std::string GetIdentifier(DevToolsAgentHost* agent_host) OVERRIDE {
84 return agent_host->GetId();
85 }
86
87 virtual DevToolsAgentHost* ForIdentifier(const std::string& id) OVERRIDE {
88 return DevToolsAgentHost::GetForId(id).get();
89 }
90 };
91
92 // An internal implementation of DevToolsClientHost that delegates 66 // An internal implementation of DevToolsClientHost that delegates
93 // messages sent for DevToolsClient to a DebuggerShell instance. 67 // messages sent for DevToolsClient to a DebuggerShell instance.
94 class DevToolsClientHostImpl : public DevToolsClientHost { 68 class DevToolsClientHostImpl : public DevToolsClientHost {
95 public: 69 public:
96 DevToolsClientHostImpl(base::MessageLoop* message_loop, 70 DevToolsClientHostImpl(base::MessageLoop* message_loop,
97 net::HttpServer* server, 71 net::HttpServer* server,
98 int connection_id) 72 int connection_id)
99 : message_loop_(message_loop), 73 : message_loop_(message_loop),
100 server_(server), 74 server_(server),
101 connection_id_(connection_id), 75 connection_id_(connection_id),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 116 }
143 117
144 private: 118 private:
145 base::MessageLoop* message_loop_; 119 base::MessageLoop* message_loop_;
146 net::HttpServer* server_; 120 net::HttpServer* server_;
147 int connection_id_; 121 int connection_id_;
148 bool is_closed_; 122 bool is_closed_;
149 std::string detach_reason_; 123 std::string detach_reason_;
150 }; 124 };
151 125
152 static base::TimeTicks GetLastSelectedTime(RenderViewHost* rvh) {
153 WebContents* web_contents = rvh->GetDelegate()->GetAsWebContents();
154 if (!web_contents)
155 return base::TimeTicks();
156
157 return web_contents->GetLastSelectedTime();
158 }
159
160 typedef std::pair<RenderViewHost*, base::TimeTicks> PageInfo;
161
162 static bool TimeComparator(const PageInfo& info1, const PageInfo& info2) {
163 return info1.second > info2.second;
164 }
165
166 } // namespace 126 } // namespace
167 127
168 // static 128 // static
169 bool DevToolsHttpHandler::IsSupportedProtocolVersion( 129 bool DevToolsHttpHandler::IsSupportedProtocolVersion(
170 const std::string& version) { 130 const std::string& version) {
171 return version == kProtocolVersion; 131 return version == kProtocolVersion;
172 } 132 }
173 133
174 // static 134 // static
175 int DevToolsHttpHandler::GetFrontendResourceId(const std::string& name) { 135 int DevToolsHttpHandler::GetFrontendResourceId(const std::string& name) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 196
237 void DevToolsHttpHandlerImpl::Stop() { 197 void DevToolsHttpHandlerImpl::Stop() {
238 if (!thread_) 198 if (!thread_)
239 return; 199 return;
240 BrowserThread::PostTaskAndReply( 200 BrowserThread::PostTaskAndReply(
241 BrowserThread::FILE, FROM_HERE, 201 BrowserThread::FILE, FROM_HERE,
242 base::Bind(&DevToolsHttpHandlerImpl::StopHandlerThread, this), 202 base::Bind(&DevToolsHttpHandlerImpl::StopHandlerThread, this),
243 base::Bind(&DevToolsHttpHandlerImpl::ResetHandlerThreadAndRelease, this)); 203 base::Bind(&DevToolsHttpHandlerImpl::ResetHandlerThreadAndRelease, this));
244 } 204 }
245 205
246 void DevToolsHttpHandlerImpl::SetDevToolsAgentHostBinding(
247 DevToolsAgentHostBinding* binding) {
248 if (binding)
249 binding_ = binding;
250 else
251 binding_ = default_binding_.get();
252 }
253
254 GURL DevToolsHttpHandlerImpl::GetFrontendURL(DevToolsAgentHost* agent_host) { 206 GURL DevToolsHttpHandlerImpl::GetFrontendURL(DevToolsAgentHost* agent_host) {
pfeldman 2013/10/01 14:10:24 nuke agent_host param
Vladislav Kaznacheev 2013/10/01 15:00:16 Done.
255 net::IPEndPoint ip_address; 207 net::IPEndPoint ip_address;
256 if (server_->GetLocalAddress(&ip_address)) 208 if (server_->GetLocalAddress(&ip_address))
257 return GURL(); 209 return GURL();
258 if (!agent_host) { 210 if (!agent_host) {
259 return GURL(std::string("http://") + ip_address.ToString() + 211 return GURL(std::string("http://") + ip_address.ToString() +
260 overridden_frontend_url_); 212 overridden_frontend_url_);
261 } 213 }
262 std::string host = ip_address.ToString(); 214 std::string host = ip_address.ToString();
263 std::string id = binding_->GetIdentifier(agent_host); 215 std::string id = agent_host->GetId();
264 return GURL(std::string("http://") + 216 return GURL(std::string("http://") +
265 ip_address.ToString() + 217 ip_address.ToString() +
266 GetFrontendURLInternal(id, host)); 218 GetFrontendURLInternal(id, host));
267 } 219 }
268 220
269 static std::string PathWithoutParams(const std::string& path) { 221 static std::string PathWithoutParams(const std::string& path) {
270 size_t query_position = path.find("?"); 222 size_t query_position = path.find("?");
271 if (query_position != std::string::npos) 223 if (query_position != std::string::npos)
272 return path.substr(0, query_position); 224 return path.substr(0, query_position);
273 return path; 225 return path;
(...skipping 25 matching lines...) Expand all
299 base::Bind(&DevToolsHttpHandlerImpl::OnJsonRequestUI, 251 base::Bind(&DevToolsHttpHandlerImpl::OnJsonRequestUI,
300 this, 252 this,
301 connection_id, 253 connection_id,
302 info)); 254 info));
303 return; 255 return;
304 } 256 }
305 257
306 if (info.path.find(kThumbUrlPrefix) == 0) { 258 if (info.path.find(kThumbUrlPrefix) == 0) {
307 // Thumbnail request. 259 // Thumbnail request.
308 const std::string target_id = info.path.substr(strlen(kThumbUrlPrefix)); 260 const std::string target_id = info.path.substr(strlen(kThumbUrlPrefix));
309 DevToolsAgentHost* agent_host = binding_->ForIdentifier(target_id); 261 DevToolsTarget* target = GetTarget(target_id);
pfeldman 2013/10/01 14:10:24 scoped_refptr<>
Vladislav Kaznacheev 2013/10/01 15:00:16 Done.
310 GURL page_url; 262 GURL page_url;
311 if (agent_host) { 263 if (target)
312 RenderViewHost* rvh = agent_host->GetRenderViewHost(); 264 page_url = target->GetUrl();
313 if (rvh)
314 page_url = rvh->GetDelegate()->GetURL();
315 }
316 BrowserThread::PostTask( 265 BrowserThread::PostTask(
317 BrowserThread::UI, 266 BrowserThread::UI,
318 FROM_HERE, 267 FROM_HERE,
319 base::Bind(&DevToolsHttpHandlerImpl::OnThumbnailRequestUI, 268 base::Bind(&DevToolsHttpHandlerImpl::OnThumbnailRequestUI,
320 this, 269 this,
321 connection_id, 270 connection_id,
322 page_url)); 271 page_url));
323 return; 272 return;
324 } 273 }
325 274
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 version.SetString("Protocol-Version", kProtocolVersion); 451 version.SetString("Protocol-Version", kProtocolVersion);
503 version.SetString("WebKit-Version", webkit_glue::GetWebKitVersion()); 452 version.SetString("WebKit-Version", webkit_glue::GetWebKitVersion());
504 version.SetString("Browser", content::GetContentClient()->GetProduct()); 453 version.SetString("Browser", content::GetContentClient()->GetProduct());
505 version.SetString("User-Agent", 454 version.SetString("User-Agent",
506 webkit_glue::GetUserAgent(GURL(kAboutBlankURL))); 455 webkit_glue::GetUserAgent(GURL(kAboutBlankURL)));
507 SendJson(connection_id, net::HTTP_OK, &version, std::string()); 456 SendJson(connection_id, net::HTTP_OK, &version, std::string());
508 return; 457 return;
509 } 458 }
510 459
511 if (command == "list") { 460 if (command == "list") {
512 typedef std::vector<PageInfo> PageList;
513 PageList page_list;
514
515 std::vector<RenderViewHost*> rvh_list =
516 DevToolsAgentHost::GetValidRenderViewHosts();
517 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin();
518 it != rvh_list.end(); ++it)
519 page_list.push_back(PageInfo(*it, GetLastSelectedTime(*it)));
520
521 std::sort(page_list.begin(), page_list.end(), TimeComparator);
522
523 base::ListValue* target_list = new base::ListValue();
524 std::string host = info.headers["host"]; 461 std::string host = info.headers["host"];
525 for (PageList::iterator i = page_list.begin(); i != page_list.end(); ++i) 462 delegate_->EnumerateTargets(
526 target_list->Append(SerializePageInfo(i->first, host)); 463 base::Bind(&DevToolsHttpHandlerImpl::OnTargetListReceived,
527 464 this, connection_id, host));
528 AddRef(); // Balanced in SendTargetList.
529 BrowserThread::PostTaskAndReply(
530 BrowserThread::IO,
531 FROM_HERE,
532 base::Bind(&DevToolsHttpHandlerImpl::CollectWorkerInfo,
533 base::Unretained(this),
534 target_list,
535 host),
536 base::Bind(&DevToolsHttpHandlerImpl::SendTargetList,
537 base::Unretained(this),
538 connection_id,
539 target_list));
540 return; 465 return;
541 } 466 }
542 467
543 if (command == "new") { 468 if (command == "new") {
544 RenderViewHost* rvh = delegate_->CreateNewTarget(); 469 scoped_refptr<DevToolsTarget> target = delegate_->CreateNewTarget();
545 if (!rvh) { 470 if (!target) {
546 SendJson(connection_id, 471 SendJson(connection_id,
547 net::HTTP_INTERNAL_SERVER_ERROR, 472 net::HTTP_INTERNAL_SERVER_ERROR,
548 NULL, 473 NULL,
549 "Could not create new page"); 474 "Could not create new page");
550 return; 475 return;
551 } 476 }
552 std::string host = info.headers["host"]; 477 std::string host = info.headers["host"];
553 scoped_ptr<base::DictionaryValue> dictionary(SerializePageInfo(rvh, host)); 478 scoped_ptr<base::DictionaryValue> dictionary(
479 SerializeTarget(*target.get(), host));
554 SendJson(connection_id, net::HTTP_OK, dictionary.get(), std::string()); 480 SendJson(connection_id, net::HTTP_OK, dictionary.get(), std::string());
555 return; 481 return;
556 } 482 }
557 483
558 if (command == "activate" || command == "close") { 484 if (command == "activate" || command == "close") {
559 DevToolsAgentHost* agent_host = binding_->ForIdentifier(target_id); 485 DevToolsTarget* target = GetTarget(target_id);
560 RenderViewHost* rvh = agent_host ? agent_host->GetRenderViewHost() : NULL; 486 if (!target) {
561 if (!rvh) {
562 SendJson(connection_id, 487 SendJson(connection_id,
563 net::HTTP_NOT_FOUND, 488 net::HTTP_NOT_FOUND,
564 NULL, 489 NULL,
565 "No such target id: " + target_id); 490 "No such target id: " + target_id);
566 return; 491 return;
567 } 492 }
568 493
569 if (command == "activate") { 494 if (command == "activate") {
570 rvh->GetDelegate()->Activate(); 495 if (target->Activate())
pfeldman 2013/10/01 14:10:24 {}
Vladislav Kaznacheev 2013/10/01 15:00:16 Done.
571 SendJson(connection_id, net::HTTP_OK, NULL, "Target activated"); 496 SendJson(connection_id, net::HTTP_OK, NULL, "Target activated");
497 else
pfeldman 2013/10/01 14:10:24 {}
Vladislav Kaznacheev 2013/10/01 15:00:16 Done.
498 SendJson(connection_id,
499 net::HTTP_INTERNAL_SERVER_ERROR,
500 NULL,
501 "Could not activate target id: " + target_id);
572 return; 502 return;
573 } 503 }
574 504
575 if (command == "close") { 505 if (command == "close") {
576 rvh->ClosePage(); 506 if (target->Close())
pfeldman 2013/10/01 14:10:24 {}
Vladislav Kaznacheev 2013/10/01 15:00:16 Done.
577 SendJson(connection_id, net::HTTP_OK, NULL, "Target is closing"); 507 SendJson(connection_id, net::HTTP_OK, NULL, "Target is closing");
508 else
pfeldman 2013/10/01 14:10:24 {}
Vladislav Kaznacheev 2013/10/01 15:00:16 Done.
509 SendJson(connection_id,
510 net::HTTP_INTERNAL_SERVER_ERROR,
511 NULL,
512 "Could not close target id: " + target_id);
578 return; 513 return;
579 } 514 }
580 } 515 }
581 SendJson(connection_id, 516 SendJson(connection_id,
582 net::HTTP_NOT_FOUND, 517 net::HTTP_NOT_FOUND,
583 NULL, 518 NULL,
584 "Unknown command: " + command); 519 "Unknown command: " + command);
585 return; 520 return;
586 } 521 }
587 522
588 void DevToolsHttpHandlerImpl::CollectWorkerInfo(base::ListValue* target_list, 523 void DevToolsHttpHandlerImpl::OnTargetListReceived(
589 std::string host) { 524 int connection_id,
590 525 const std::string& host,
591 std::vector<WorkerService::WorkerInfo> worker_info = 526 const DevToolsHttpHandlerDelegate::TargetList& targets) {
592 WorkerService::GetInstance()->GetWorkers(); 527 target_map_.clear();
593 528 base::ListValue list_value;
594 for (size_t i = 0; i < worker_info.size(); ++i) 529 for (DevToolsHttpHandlerDelegate::TargetList::const_iterator it =
595 target_list->Append(SerializeWorkerInfo(worker_info[i], host)); 530 targets.begin(); it != targets.end(); ++it) {
531 scoped_refptr<DevToolsTarget> target = *it;
532 target_map_[target->GetId()] = target;
533 list_value.Append(SerializeTarget(*(target.get()), host));
534 }
535 SendJson(connection_id, net::HTTP_OK, &list_value, std::string());
596 } 536 }
597 537
598 void DevToolsHttpHandlerImpl::SendTargetList(int connection_id, 538 DevToolsTarget* DevToolsHttpHandlerImpl::GetTarget(const std::string& id) {
599 base::ListValue* target_list) { 539 TargetMap::iterator it = target_map_.find(id);
600 SendJson(connection_id, net::HTTP_OK, target_list, std::string()); 540 if (it == target_map_.end())
601 delete target_list; 541 return NULL;
602 Release(); // Balanced OnJsonRequestUI. 542 return it->second.get();
pfeldman 2013/10/01 14:10:24 Restore
Vladislav Kaznacheev 2013/10/01 15:00:16 Done.
603 } 543 }
604 544
605 void DevToolsHttpHandlerImpl::OnThumbnailRequestUI( 545 void DevToolsHttpHandlerImpl::OnThumbnailRequestUI(
606 int connection_id, const GURL& page_url) { 546 int connection_id, const GURL& page_url) {
607 std::string data = delegate_->GetPageThumbnailData(page_url); 547 std::string data = delegate_->GetPageThumbnailData(page_url);
608 if (!data.empty()) 548 if (!data.empty())
609 Send200(connection_id, data, "image/png"); 549 Send200(connection_id, data, "image/png");
610 else 550 else
611 Send404(connection_id); 551 Send404(connection_id);
612 } 552 }
613 553
614 void DevToolsHttpHandlerImpl::OnDiscoveryPageRequestUI(int connection_id) { 554 void DevToolsHttpHandlerImpl::OnDiscoveryPageRequestUI(int connection_id) {
615 std::string response = delegate_->GetDiscoveryPageHTML(); 555 std::string response = delegate_->GetDiscoveryPageHTML();
616 Send200(connection_id, response, "text/html; charset=UTF-8"); 556 Send200(connection_id, response, "text/html; charset=UTF-8");
617 } 557 }
618 558
619 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( 559 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI(
620 int connection_id, 560 int connection_id,
621 const net::HttpServerRequestInfo& request) { 561 const net::HttpServerRequestInfo& request) {
622 if (!thread_) 562 if (!thread_)
623 return; 563 return;
624 564
625 size_t pos = request.path.find(kPageUrlPrefix); 565 size_t pos = request.path.find(kPageUrlPrefix);
626 if (pos != 0) { 566 if (pos != 0) {
627 Send404(connection_id); 567 Send404(connection_id);
628 return; 568 return;
629 } 569 }
630 570
631 std::string page_id = request.path.substr(strlen(kPageUrlPrefix)); 571 std::string page_id = request.path.substr(strlen(kPageUrlPrefix));
632 DevToolsAgentHost* agent = binding_->ForIdentifier(page_id); 572 DevToolsTarget* target = GetTarget(page_id);
573 scoped_refptr<DevToolsAgentHost> agent =
574 target ? target->GetAgentHost() : NULL;
633 if (!agent) { 575 if (!agent) {
634 Send500(connection_id, "No such target id: " + page_id); 576 Send500(connection_id, "No such target id: " + page_id);
635 return; 577 return;
636 } 578 }
637 579
638 if (agent->IsAttached()) { 580 if (agent->IsAttached()) {
639 Send500(connection_id, 581 Send500(connection_id,
640 "Target with given id is being inspected: " + page_id); 582 "Target with given id is being inspected: " + page_id);
641 return; 583 return;
642 } 584 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( 620 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl(
679 const net::StreamListenSocketFactory* socket_factory, 621 const net::StreamListenSocketFactory* socket_factory,
680 const std::string& frontend_url, 622 const std::string& frontend_url,
681 DevToolsHttpHandlerDelegate* delegate) 623 DevToolsHttpHandlerDelegate* delegate)
682 : overridden_frontend_url_(frontend_url), 624 : overridden_frontend_url_(frontend_url),
683 socket_factory_(socket_factory), 625 socket_factory_(socket_factory),
684 delegate_(delegate) { 626 delegate_(delegate) {
685 if (overridden_frontend_url_.empty()) 627 if (overridden_frontend_url_.empty())
686 overridden_frontend_url_ = "/devtools/devtools.html"; 628 overridden_frontend_url_ = "/devtools/devtools.html";
687 629
688 default_binding_.reset(new DevToolsDefaultBindingHandler);
689 binding_ = default_binding_.get();
690
691 // Balanced in ResetHandlerThreadAndRelease(). 630 // Balanced in ResetHandlerThreadAndRelease().
692 AddRef(); 631 AddRef();
693 } 632 }
694 633
695 // Runs on the handler thread 634 // Runs on the handler thread
696 void DevToolsHttpHandlerImpl::Init() { 635 void DevToolsHttpHandlerImpl::Init() {
697 server_ = new net::HttpServer(*socket_factory_.get(), this); 636 server_ = new net::HttpServer(*socket_factory_.get(), this);
698 } 637 }
699 638
700 // Runs on the handler thread 639 // Runs on the handler thread
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 int connection_id, 718 int connection_id,
780 const net::HttpServerRequestInfo& request) { 719 const net::HttpServerRequestInfo& request) {
781 if (!thread_) 720 if (!thread_)
782 return; 721 return;
783 thread_->message_loop()->PostTask( 722 thread_->message_loop()->PostTask(
784 FROM_HERE, 723 FROM_HERE,
785 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), 724 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(),
786 connection_id, request)); 725 connection_id, request));
787 } 726 }
788 727
789 base::DictionaryValue* DevToolsHttpHandlerImpl::SerializePageInfo( 728 base::DictionaryValue* DevToolsHttpHandlerImpl::SerializeTarget(
790 RenderViewHost* rvh, 729 const DevToolsTarget& target,
791 const std::string& host) { 730 const std::string& host) {
792 base::DictionaryValue* dictionary = new base::DictionaryValue; 731 base::DictionaryValue* dictionary = new base::DictionaryValue;
793 732
794 scoped_refptr<DevToolsAgentHost> agent( 733 std::string id = target.GetId();
795 DevToolsAgentHost::GetOrCreateFor(rvh)); 734 dictionary->SetString(kTargetIdField, id);
735 dictionary->SetString(kTargetTypeField, target.GetType());
736 dictionary->SetString(kTargetTitleField, target.GetTitle());
796 737
797 std::string id = binding_->GetIdentifier(agent.get()); 738 GURL url = target.GetUrl();
798 dictionary->SetString(kTargetIdField, id); 739 dictionary->SetString(kTargetUrlField, url.spec());
799 740
800 switch (delegate_->GetTargetType(rvh)) { 741 GURL favicon_url = target.GetFaviconUrl();
801 case DevToolsHttpHandlerDelegate::kTargetTypeTab: 742 if (favicon_url.is_valid())
802 dictionary->SetString(kTargetTypeField, kTargetTypePage); 743 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec());
803 break; 744
804 default: 745 if (!delegate_->GetPageThumbnailData(url).empty())
pfeldman 2013/10/01 14:10:24 {}
Vladislav Kaznacheev 2013/10/01 15:00:16 Done.
805 dictionary->SetString(kTargetTypeField, kTargetTypeOther); 746 dictionary->SetString(kTargetThumbnailUrlField,
747 std::string(kThumbUrlPrefix) + id);
748
749 dictionary->SetDouble(kTargetLastActivityTimeField,
750 target.GetLastActivityTime().ToInternalValue());
751
752 if (!target.IsAttached()) {
753 dictionary->SetString(kTargetWebSocketDebuggerUrlField,
754 base::StringPrintf("ws://%s%s%s",
755 host.c_str(),
756 kPageUrlPrefix,
757 id.c_str()));
758 std::string devtools_frontend_url = GetFrontendURLInternal(
759 id.c_str(),
760 host);
761 dictionary->SetString(
762 kTargetDevtoolsFrontendUrlField, devtools_frontend_url);
806 } 763 }
807 764
808 WebContents* web_contents = rvh->GetDelegate()->GetAsWebContents();
809 if (web_contents) {
810 dictionary->SetString(kTargetTitleField, UTF16ToUTF8(
811 net::EscapeForHTML(web_contents->GetTitle())));
812 dictionary->SetString(kTargetUrlField, web_contents->GetURL().spec());
813 dictionary->SetString(kTargetThumbnailUrlField,
814 std::string(kThumbUrlPrefix) + id);
815
816 NavigationController& controller = web_contents->GetController();
817 NavigationEntry* entry = controller.GetActiveEntry();
818 if (entry != NULL && entry->GetURL().is_valid()) {
819 dictionary->SetString(kTargetFaviconUrlField,
820 entry->GetFavicon().url.spec());
821 }
822 }
823 dictionary->SetString(kTargetDescriptionField,
824 delegate_->GetViewDescription(rvh));
825
826 if (!agent->IsAttached())
827 SerializeDebuggerURLs(dictionary, id, host);
828 return dictionary; 765 return dictionary;
829 } 766 }
830 767
831 base::DictionaryValue* DevToolsHttpHandlerImpl::SerializeWorkerInfo(
832 const WorkerService::WorkerInfo& worker,
833 const std::string& host) {
834 base::DictionaryValue* dictionary = new base::DictionaryValue;
835
836 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetForWorker(
837 worker.process_id, worker.route_id));
838
839 std::string id = binding_->GetIdentifier(agent.get());
840
841 dictionary->SetString(kTargetIdField, id);
842 dictionary->SetString(kTargetTypeField, kTargetTypeOther);
843 dictionary->SetString(kTargetTitleField,
844 UTF16ToUTF8(net::EscapeForHTML(worker.name)));
845 dictionary->SetString(kTargetUrlField, worker.url.spec());
846 dictionary->SetString(kTargetDescriptionField,
847 base::StringPrintf("Worker pid:%d", base::GetProcId(worker.handle)));
848
849 if (!agent->IsAttached())
850 SerializeDebuggerURLs(dictionary, id, host);
851 return dictionary;
852 }
853
854 void DevToolsHttpHandlerImpl::SerializeDebuggerURLs(
855 base::DictionaryValue* dictionary,
856 const std::string& id,
857 const std::string& host) {
858 dictionary->SetString(kTargetWebSocketDebuggerUrlField,
859 base::StringPrintf("ws://%s%s%s",
860 host.c_str(),
861 kPageUrlPrefix,
862 id.c_str()));
863 std::string devtools_frontend_url = GetFrontendURLInternal(
864 id.c_str(),
865 host);
866 dictionary->SetString(kTargetDevtoolsFrontendUrlField, devtools_frontend_url);
867 }
868
869 } // namespace content 768 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698