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

Side by Side Diff: components/devtools_http_handler/devtools_http_handler.cc

Issue 2137503002: Revert of Replace string::find(prefix) == 0 pattern with base::StartsWith(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « chromeos/settings/timezone_settings.cc ('k') | components/leveldb/env_mojo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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
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 (base::StartsWith(info.path, "/json", base::CompareCase::SENSITIVE)) { 398 if (info.path.find("/json") == 0) {
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 (base::StartsWith(info.path, kThumbUrlPrefix, 409 if (info.path.find(kThumbUrlPrefix) == 0) {
410 base::CompareCase::SENSITIVE)) {
411 // Thumbnail request. 410 // Thumbnail request.
412 const std::string target_id = info.path.substr(strlen(kThumbUrlPrefix)); 411 const std::string target_id = info.path.substr(strlen(kThumbUrlPrefix));
413 BrowserThread::PostTask( 412 BrowserThread::PostTask(
414 BrowserThread::UI, 413 BrowserThread::UI,
415 FROM_HERE, 414 FROM_HERE,
416 base::Bind(&DevToolsHttpHandler::OnThumbnailRequest, 415 base::Bind(&DevToolsHttpHandler::OnThumbnailRequest,
417 handler_, 416 handler_,
418 connection_id, 417 connection_id,
419 target_id)); 418 target_id));
420 return; 419 return;
421 } 420 }
422 421
423 if (info.path.empty() || info.path == "/") { 422 if (info.path.empty() || info.path == "/") {
424 // Discovery page request. 423 // Discovery page request.
425 BrowserThread::PostTask( 424 BrowserThread::PostTask(
426 BrowserThread::UI, 425 BrowserThread::UI,
427 FROM_HERE, 426 FROM_HERE,
428 base::Bind(&DevToolsHttpHandler::OnDiscoveryPageRequest, 427 base::Bind(&DevToolsHttpHandler::OnDiscoveryPageRequest,
429 handler_, 428 handler_,
430 connection_id)); 429 connection_id));
431 return; 430 return;
432 } 431 }
433 432
434 if (!base::StartsWith(info.path, "/devtools/", 433 if (info.path.find("/devtools/") != 0) {
435 base::CompareCase::SENSITIVE)) {
436 server_->Send404(connection_id); 434 server_->Send404(connection_id);
437 return; 435 return;
438 } 436 }
439 437
440 std::string filename = PathWithoutParams(info.path.substr(10)); 438 std::string filename = PathWithoutParams(info.path.substr(10));
441 std::string mime_type = GetMimeType(filename); 439 std::string mime_type = GetMimeType(filename);
442 440
443 if (!frontend_dir_.empty()) { 441 if (!frontend_dir_.empty()) {
444 base::FilePath path = frontend_dir_.AppendASCII(filename); 442 base::FilePath path = frontend_dir_.AppendASCII(filename);
445 std::string data; 443 std::string data;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 const std::string& path, 510 const std::string& path,
513 std::string* command, 511 std::string* command,
514 std::string* target_id) { 512 std::string* target_id) {
515 513
516 // Fall back to list in case of empty query. 514 // Fall back to list in case of empty query.
517 if (path.empty()) { 515 if (path.empty()) {
518 *command = "list"; 516 *command = "list";
519 return true; 517 return true;
520 } 518 }
521 519
522 if (!base::StartsWith(path, "/", base::CompareCase::SENSITIVE)) { 520 if (path.find("/") != 0) {
523 // Malformed command. 521 // Malformed command.
524 return false; 522 return false;
525 } 523 }
526 *command = path.substr(1); 524 *command = path.substr(1);
527 525
528 size_t separator_pos = command->find("/"); 526 size_t separator_pos = command->find("/");
529 if (separator_pos != std::string::npos) { 527 if (separator_pos != std::string::npos) {
530 *target_id = command->substr(separator_pos + 1); 528 *target_id = command->substr(separator_pos + 1);
531 *command = command->substr(0, separator_pos); 529 *command = command->substr(0, separator_pos);
532 } 530 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 GetMimeType(path)); 689 GetMimeType(path));
692 } 690 }
693 691
694 void DevToolsHttpHandler::OnWebSocketRequest( 692 void DevToolsHttpHandler::OnWebSocketRequest(
695 int connection_id, 693 int connection_id,
696 const net::HttpServerRequestInfo& request) { 694 const net::HttpServerRequestInfo& request) {
697 if (!thread_) 695 if (!thread_)
698 return; 696 return;
699 697
700 std::string browser_prefix = "/devtools/browser"; 698 std::string browser_prefix = "/devtools/browser";
701 if (base::StartsWith(request.path, browser_prefix, 699 size_t browser_pos = request.path.find(browser_prefix);
702 base::CompareCase::SENSITIVE)) { 700 if (browser_pos == 0) {
703 scoped_refptr<DevToolsAgentHost> browser_agent = 701 scoped_refptr<DevToolsAgentHost> browser_agent =
704 DevToolsAgentHost::CreateForBrowser( 702 DevToolsAgentHost::CreateForBrowser(
705 thread_->task_runner(), 703 thread_->task_runner(),
706 base::Bind(&ServerSocketFactory::CreateForTethering, 704 base::Bind(&ServerSocketFactory::CreateForTethering,
707 base::Unretained(socket_factory_))); 705 base::Unretained(socket_factory_)));
708 connection_to_client_[connection_id] = new DevToolsAgentHostClientImpl( 706 connection_to_client_[connection_id] = new DevToolsAgentHostClientImpl(
709 thread_->message_loop(), server_wrapper_, connection_id, browser_agent); 707 thread_->message_loop(), server_wrapper_, connection_id, browser_agent);
710 AcceptWebSocket(connection_id, request); 708 AcceptWebSocket(connection_id, request);
711 return; 709 return;
712 } 710 }
713 711
714 // Handle external connections (such as frontend api) on the embedder level. 712 // Handle external connections (such as frontend api) on the embedder level.
715 content::DevToolsExternalAgentProxyDelegate* external_delegate = 713 content::DevToolsExternalAgentProxyDelegate* external_delegate =
716 delegate_->HandleWebSocketConnection(request.path); 714 delegate_->HandleWebSocketConnection(request.path);
717 if (external_delegate) { 715 if (external_delegate) {
718 scoped_refptr<DevToolsAgentHost> agent_host = 716 scoped_refptr<DevToolsAgentHost> agent_host =
719 DevToolsAgentHost::Create(external_delegate); 717 DevToolsAgentHost::Create(external_delegate);
720 connection_to_client_[connection_id] = new DevToolsAgentHostClientImpl( 718 connection_to_client_[connection_id] = new DevToolsAgentHostClientImpl(
721 thread_->message_loop(), server_wrapper_, connection_id, agent_host); 719 thread_->message_loop(), server_wrapper_, connection_id, agent_host);
722 AcceptWebSocket(connection_id, request); 720 AcceptWebSocket(connection_id, request);
723 return; 721 return;
724 } 722 }
725 723
726 if (!base::StartsWith(request.path, kPageUrlPrefix, 724 size_t pos = request.path.find(kPageUrlPrefix);
727 base::CompareCase::SENSITIVE)) { 725 if (pos != 0) {
728 Send404(connection_id); 726 Send404(connection_id);
729 return; 727 return;
730 } 728 }
731 729
732 std::string target_id = request.path.substr(strlen(kPageUrlPrefix)); 730 std::string target_id = request.path.substr(strlen(kPageUrlPrefix));
733 DevToolsTargetDescriptor* descriptor = GetDescriptor(target_id); 731 DevToolsTargetDescriptor* descriptor = GetDescriptor(target_id);
734 scoped_refptr<DevToolsAgentHost> agent = 732 scoped_refptr<DevToolsAgentHost> agent =
735 descriptor ? descriptor->GetAgentHost() : nullptr; 733 descriptor ? descriptor->GetAgentHost() : nullptr;
736 if (!agent.get()) { 734 if (!agent.get()) {
737 Send500(connection_id, "No such target id: " + target_id); 735 Send500(connection_id, "No such target id: " + target_id);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 id.c_str(), 930 id.c_str(),
933 host); 931 host);
934 dictionary->SetString( 932 dictionary->SetString(
935 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); 933 kTargetDevtoolsFrontendUrlField, devtools_frontend_url);
936 } 934 }
937 935
938 return dictionary; 936 return dictionary;
939 } 937 }
940 938
941 } // namespace devtools_http_handler 939 } // namespace devtools_http_handler
OLDNEW
« no previous file with comments | « chromeos/settings/timezone_settings.cc ('k') | components/leveldb/env_mojo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698