OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 << filename | 388 << filename |
389 << " text/plain will be returned"; | 389 << " text/plain will be returned"; |
390 NOTREACHED(); | 390 NOTREACHED(); |
391 return "text/plain"; | 391 return "text/plain"; |
392 } | 392 } |
393 | 393 |
394 void ServerWrapper::OnHttpRequest(int connection_id, | 394 void ServerWrapper::OnHttpRequest(int connection_id, |
395 const net::HttpServerRequestInfo& info) { | 395 const net::HttpServerRequestInfo& info) { |
396 server_->SetSendBufferSize(connection_id, kSendBufferSizeForDevTools); | 396 server_->SetSendBufferSize(connection_id, kSendBufferSizeForDevTools); |
397 | 397 |
398 if (info.path.find("/json") == 0) { | 398 if (base::StartsWith(info.path, "/json", base::CompareCase::SENSITIVE)) { |
399 BrowserThread::PostTask( | 399 BrowserThread::PostTask( |
400 BrowserThread::UI, | 400 BrowserThread::UI, |
401 FROM_HERE, | 401 FROM_HERE, |
402 base::Bind(&DevToolsHttpHandler::OnJsonRequest, | 402 base::Bind(&DevToolsHttpHandler::OnJsonRequest, |
403 handler_, | 403 handler_, |
404 connection_id, | 404 connection_id, |
405 info)); | 405 info)); |
406 return; | 406 return; |
407 } | 407 } |
408 | 408 |
409 if (info.path.find(kThumbUrlPrefix) == 0) { | 409 if (base::StartsWith(info.path, kThumbUrlPrefix, |
| 410 base::CompareCase::SENSITIVE)) { |
410 // Thumbnail request. | 411 // Thumbnail request. |
411 const std::string target_id = info.path.substr(strlen(kThumbUrlPrefix)); | 412 const std::string target_id = info.path.substr(strlen(kThumbUrlPrefix)); |
412 BrowserThread::PostTask( | 413 BrowserThread::PostTask( |
413 BrowserThread::UI, | 414 BrowserThread::UI, |
414 FROM_HERE, | 415 FROM_HERE, |
415 base::Bind(&DevToolsHttpHandler::OnThumbnailRequest, | 416 base::Bind(&DevToolsHttpHandler::OnThumbnailRequest, |
416 handler_, | 417 handler_, |
417 connection_id, | 418 connection_id, |
418 target_id)); | 419 target_id)); |
419 return; | 420 return; |
420 } | 421 } |
421 | 422 |
422 if (info.path.empty() || info.path == "/") { | 423 if (info.path.empty() || info.path == "/") { |
423 // Discovery page request. | 424 // Discovery page request. |
424 BrowserThread::PostTask( | 425 BrowserThread::PostTask( |
425 BrowserThread::UI, | 426 BrowserThread::UI, |
426 FROM_HERE, | 427 FROM_HERE, |
427 base::Bind(&DevToolsHttpHandler::OnDiscoveryPageRequest, | 428 base::Bind(&DevToolsHttpHandler::OnDiscoveryPageRequest, |
428 handler_, | 429 handler_, |
429 connection_id)); | 430 connection_id)); |
430 return; | 431 return; |
431 } | 432 } |
432 | 433 |
433 if (info.path.find("/devtools/") != 0) { | 434 if (!base::StartsWith(info.path, "/devtools/", |
| 435 base::CompareCase::SENSITIVE)) { |
434 server_->Send404(connection_id); | 436 server_->Send404(connection_id); |
435 return; | 437 return; |
436 } | 438 } |
437 | 439 |
438 std::string filename = PathWithoutParams(info.path.substr(10)); | 440 std::string filename = PathWithoutParams(info.path.substr(10)); |
439 std::string mime_type = GetMimeType(filename); | 441 std::string mime_type = GetMimeType(filename); |
440 | 442 |
441 if (!frontend_dir_.empty()) { | 443 if (!frontend_dir_.empty()) { |
442 base::FilePath path = frontend_dir_.AppendASCII(filename); | 444 base::FilePath path = frontend_dir_.AppendASCII(filename); |
443 std::string data; | 445 std::string data; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 const std::string& path, | 512 const std::string& path, |
511 std::string* command, | 513 std::string* command, |
512 std::string* target_id) { | 514 std::string* target_id) { |
513 | 515 |
514 // Fall back to list in case of empty query. | 516 // Fall back to list in case of empty query. |
515 if (path.empty()) { | 517 if (path.empty()) { |
516 *command = "list"; | 518 *command = "list"; |
517 return true; | 519 return true; |
518 } | 520 } |
519 | 521 |
520 if (path.find("/") != 0) { | 522 if (!base::StartsWith(path, "/", base::CompareCase::SENSITIVE)) { |
521 // Malformed command. | 523 // Malformed command. |
522 return false; | 524 return false; |
523 } | 525 } |
524 *command = path.substr(1); | 526 *command = path.substr(1); |
525 | 527 |
526 size_t separator_pos = command->find("/"); | 528 size_t separator_pos = command->find("/"); |
527 if (separator_pos != std::string::npos) { | 529 if (separator_pos != std::string::npos) { |
528 *target_id = command->substr(separator_pos + 1); | 530 *target_id = command->substr(separator_pos + 1); |
529 *command = command->substr(0, separator_pos); | 531 *command = command->substr(0, separator_pos); |
530 } | 532 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 GetMimeType(path)); | 691 GetMimeType(path)); |
690 } | 692 } |
691 | 693 |
692 void DevToolsHttpHandler::OnWebSocketRequest( | 694 void DevToolsHttpHandler::OnWebSocketRequest( |
693 int connection_id, | 695 int connection_id, |
694 const net::HttpServerRequestInfo& request) { | 696 const net::HttpServerRequestInfo& request) { |
695 if (!thread_) | 697 if (!thread_) |
696 return; | 698 return; |
697 | 699 |
698 std::string browser_prefix = "/devtools/browser"; | 700 std::string browser_prefix = "/devtools/browser"; |
699 size_t browser_pos = request.path.find(browser_prefix); | 701 if (base::StartsWith(request.path, browser_prefix, |
700 if (browser_pos == 0) { | 702 base::CompareCase::SENSITIVE)) { |
701 scoped_refptr<DevToolsAgentHost> browser_agent = | 703 scoped_refptr<DevToolsAgentHost> browser_agent = |
702 DevToolsAgentHost::CreateForBrowser( | 704 DevToolsAgentHost::CreateForBrowser( |
703 thread_->task_runner(), | 705 thread_->task_runner(), |
704 base::Bind(&ServerSocketFactory::CreateForTethering, | 706 base::Bind(&ServerSocketFactory::CreateForTethering, |
705 base::Unretained(socket_factory_))); | 707 base::Unretained(socket_factory_))); |
706 connection_to_client_[connection_id] = new DevToolsAgentHostClientImpl( | 708 connection_to_client_[connection_id] = new DevToolsAgentHostClientImpl( |
707 thread_->message_loop(), server_wrapper_, connection_id, browser_agent); | 709 thread_->message_loop(), server_wrapper_, connection_id, browser_agent); |
708 AcceptWebSocket(connection_id, request); | 710 AcceptWebSocket(connection_id, request); |
709 return; | 711 return; |
710 } | 712 } |
711 | 713 |
712 // Handle external connections (such as frontend api) on the embedder level. | 714 // Handle external connections (such as frontend api) on the embedder level. |
713 content::DevToolsExternalAgentProxyDelegate* external_delegate = | 715 content::DevToolsExternalAgentProxyDelegate* external_delegate = |
714 delegate_->HandleWebSocketConnection(request.path); | 716 delegate_->HandleWebSocketConnection(request.path); |
715 if (external_delegate) { | 717 if (external_delegate) { |
716 scoped_refptr<DevToolsAgentHost> agent_host = | 718 scoped_refptr<DevToolsAgentHost> agent_host = |
717 DevToolsAgentHost::Create(external_delegate); | 719 DevToolsAgentHost::Create(external_delegate); |
718 connection_to_client_[connection_id] = new DevToolsAgentHostClientImpl( | 720 connection_to_client_[connection_id] = new DevToolsAgentHostClientImpl( |
719 thread_->message_loop(), server_wrapper_, connection_id, agent_host); | 721 thread_->message_loop(), server_wrapper_, connection_id, agent_host); |
720 AcceptWebSocket(connection_id, request); | 722 AcceptWebSocket(connection_id, request); |
721 return; | 723 return; |
722 } | 724 } |
723 | 725 |
724 size_t pos = request.path.find(kPageUrlPrefix); | 726 if (!base::StartsWith(request.path, kPageUrlPrefix, |
725 if (pos != 0) { | 727 base::CompareCase::SENSITIVE)) { |
726 Send404(connection_id); | 728 Send404(connection_id); |
727 return; | 729 return; |
728 } | 730 } |
729 | 731 |
730 std::string target_id = request.path.substr(strlen(kPageUrlPrefix)); | 732 std::string target_id = request.path.substr(strlen(kPageUrlPrefix)); |
731 DevToolsTargetDescriptor* descriptor = GetDescriptor(target_id); | 733 DevToolsTargetDescriptor* descriptor = GetDescriptor(target_id); |
732 scoped_refptr<DevToolsAgentHost> agent = | 734 scoped_refptr<DevToolsAgentHost> agent = |
733 descriptor ? descriptor->GetAgentHost() : nullptr; | 735 descriptor ? descriptor->GetAgentHost() : nullptr; |
734 if (!agent.get()) { | 736 if (!agent.get()) { |
735 Send500(connection_id, "No such target id: " + target_id); | 737 Send500(connection_id, "No such target id: " + target_id); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 id.c_str(), | 932 id.c_str(), |
931 host); | 933 host); |
932 dictionary->SetString( | 934 dictionary->SetString( |
933 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 935 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
934 } | 936 } |
935 | 937 |
936 return dictionary; | 938 return dictionary; |
937 } | 939 } |
938 | 940 |
939 } // namespace devtools_http_handler | 941 } // namespace devtools_http_handler |
OLD | NEW |