 Chromium Code Reviews
 Chromium Code Reviews Issue 189233008:
  DevTools: remove the --remote-debugging-frontend flag.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 189233008:
  DevTools: remove the --remote-debugging-frontend flag.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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 "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" | 
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 BrowserThread::FILE, FROM_HERE, | 209 BrowserThread::FILE, FROM_HERE, | 
| 210 base::Bind(&DevToolsHttpHandlerImpl::StopHandlerThread, this), | 210 base::Bind(&DevToolsHttpHandlerImpl::StopHandlerThread, this), | 
| 211 base::Bind(&DevToolsHttpHandlerImpl::ResetHandlerThreadAndRelease, this)); | 211 base::Bind(&DevToolsHttpHandlerImpl::ResetHandlerThreadAndRelease, this)); | 
| 212 } | 212 } | 
| 213 | 213 | 
| 214 GURL DevToolsHttpHandlerImpl::GetFrontendURL() { | 214 GURL DevToolsHttpHandlerImpl::GetFrontendURL() { | 
| 215 net::IPEndPoint ip_address; | 215 net::IPEndPoint ip_address; | 
| 216 if (server_->GetLocalAddress(&ip_address)) | 216 if (server_->GetLocalAddress(&ip_address)) | 
| 217 return GURL(); | 217 return GURL(); | 
| 218 return GURL(std::string("http://") + ip_address.ToString() + | 218 return GURL(std::string("http://") + ip_address.ToString() + | 
| 219 overridden_frontend_url_); | 219 frontend_url_); | 
| 220 } | 220 } | 
| 221 | 221 | 
| 222 static std::string PathWithoutParams(const std::string& path) { | 222 static std::string PathWithoutParams(const std::string& path) { | 
| 223 size_t query_position = path.find("?"); | 223 size_t query_position = path.find("?"); | 
| 224 if (query_position != std::string::npos) | 224 if (query_position != std::string::npos) | 
| 225 return path.substr(0, query_position); | 225 return path.substr(0, query_position); | 
| 226 return path; | 226 return path; | 
| 227 } | 227 } | 
| 228 | 228 | 
| 229 static std::string GetMimeType(const std::string& filename) { | 229 static std::string GetMimeType(const std::string& filename) { | 
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 BrowserThread::UI, | 380 BrowserThread::UI, | 
| 381 FROM_HERE, | 381 FROM_HERE, | 
| 382 base::Bind( | 382 base::Bind( | 
| 383 &DevToolsHttpHandlerImpl::OnCloseUI, | 383 &DevToolsHttpHandlerImpl::OnCloseUI, | 
| 384 this, | 384 this, | 
| 385 connection_id)); | 385 connection_id)); | 
| 386 } | 386 } | 
| 387 | 387 | 
| 388 std::string DevToolsHttpHandlerImpl::GetFrontendURLInternal( | 388 std::string DevToolsHttpHandlerImpl::GetFrontendURLInternal( | 
| 389 const std::string id, | 389 const std::string id, | 
| 390 const std::string& host) { | 390 const std::string& host, | 
| 391 const std::string& frontend_url) { | |
| 391 return base::StringPrintf( | 392 return base::StringPrintf( | 
| 392 "%s%sws=%s%s%s", | 393 "%s%sws=%s%s%s", | 
| 393 overridden_frontend_url_.c_str(), | 394 frontend_url.c_str(), | 
| 394 overridden_frontend_url_.find("?") == std::string::npos ? "?" : "&", | 395 frontend_url.find("?") == std::string::npos ? "?" : "&", | 
| 395 host.c_str(), | 396 host.c_str(), | 
| 396 kPageUrlPrefix, | 397 kPageUrlPrefix, | 
| 397 id.c_str()); | 398 id.c_str()); | 
| 398 } | 399 } | 
| 399 | 400 | 
| 400 static bool ParseJsonPath( | 401 static bool ParseJsonPath( | 
| 401 const std::string& path, | 402 const std::string& path, | 
| 402 std::string* command, | 403 std::string* command, | 
| 403 std::string* target_id) { | 404 std::string* target_id) { | 
| 404 | 405 | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 422 return true; | 423 return true; | 
| 423 } | 424 } | 
| 424 | 425 | 
| 425 void DevToolsHttpHandlerImpl::OnJsonRequestUI( | 426 void DevToolsHttpHandlerImpl::OnJsonRequestUI( | 
| 426 int connection_id, | 427 int connection_id, | 
| 427 const net::HttpServerRequestInfo& info) { | 428 const net::HttpServerRequestInfo& info) { | 
| 428 // Trim /json | 429 // Trim /json | 
| 429 std::string path = info.path.substr(5); | 430 std::string path = info.path.substr(5); | 
| 430 | 431 | 
| 431 // Trim fragment and query | 432 // Trim fragment and query | 
| 432 std::string query; | 433 GURL aux_url; | 
| 433 size_t query_pos = path.find("?"); | 434 size_t query_pos = path.find("?"); | 
| 434 if (query_pos != std::string::npos) { | 435 if (query_pos != std::string::npos) { | 
| 435 query = path.substr(query_pos + 1); | 436 std::string query = path.substr(query_pos + 1); | 
| 436 path = path.substr(0, query_pos); | 437 path = path.substr(0, query_pos); | 
| 438 | |
| 439 aux_url = GURL(net::UnescapeURLComponent( | |
| 440 query, net::UnescapeRule::URL_SPECIAL_CHARS)); | |
| 437 } | 441 } | 
| 438 | 442 | 
| 439 size_t fragment_pos = path.find("#"); | 443 size_t fragment_pos = path.find("#"); | 
| 440 if (fragment_pos != std::string::npos) | 444 if (fragment_pos != std::string::npos) | 
| 441 path = path.substr(0, fragment_pos); | 445 path = path.substr(0, fragment_pos); | 
| 442 | 446 | 
| 443 std::string command; | 447 std::string command; | 
| 444 std::string target_id; | 448 std::string target_id; | 
| 445 if (!ParseJsonPath(path, &command, &target_id)) { | 449 if (!ParseJsonPath(path, &command, &target_id)) { | 
| 446 SendJson(connection_id, | 450 SendJson(connection_id, | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 463 #endif | 467 #endif | 
| 464 SendJson(connection_id, net::HTTP_OK, &version, std::string()); | 468 SendJson(connection_id, net::HTTP_OK, &version, std::string()); | 
| 465 return; | 469 return; | 
| 466 } | 470 } | 
| 467 | 471 | 
| 468 if (command == "list") { | 472 if (command == "list") { | 
| 469 std::string host = info.headers["host"]; | 473 std::string host = info.headers["host"]; | 
| 470 AddRef(); // Balanced in OnTargetListReceived. | 474 AddRef(); // Balanced in OnTargetListReceived. | 
| 471 delegate_->EnumerateTargets( | 475 delegate_->EnumerateTargets( | 
| 472 base::Bind(&DevToolsHttpHandlerImpl::OnTargetListReceived, | 476 base::Bind(&DevToolsHttpHandlerImpl::OnTargetListReceived, | 
| 473 this, connection_id, host)); | 477 this, connection_id, host, aux_url)); | 
| 474 return; | 478 return; | 
| 475 } | 479 } | 
| 476 | 480 | 
| 477 if (command == "new") { | 481 if (command == "new") { | 
| 478 GURL url(net::UnescapeURLComponent( | 482 if (!aux_url.is_valid()) | 
| 479 query, net::UnescapeRule::URL_SPECIAL_CHARS)); | 483 aux_url = GURL(kAboutBlankURL); | 
| 480 if (!url.is_valid()) | 484 scoped_ptr<DevToolsTarget> target(delegate_->CreateNewTarget(aux_url)); | 
| 481 url = GURL(kAboutBlankURL); | |
| 482 scoped_ptr<DevToolsTarget> target(delegate_->CreateNewTarget(url)); | |
| 483 if (!target) { | 485 if (!target) { | 
| 484 SendJson(connection_id, | 486 SendJson(connection_id, | 
| 485 net::HTTP_INTERNAL_SERVER_ERROR, | 487 net::HTTP_INTERNAL_SERVER_ERROR, | 
| 486 NULL, | 488 NULL, | 
| 487 "Could not create new page"); | 489 "Could not create new page"); | 
| 488 return; | 490 return; | 
| 489 } | 491 } | 
| 490 std::string host = info.headers["host"]; | 492 std::string host = info.headers["host"]; | 
| 491 scoped_ptr<base::DictionaryValue> dictionary( | 493 scoped_ptr<base::DictionaryValue> dictionary( | 
| 492 SerializeTarget(*target.get(), host)); | 494 SerializeTarget(*target.get(), host, aux_url)); | 
| 493 SendJson(connection_id, net::HTTP_OK, dictionary.get(), std::string()); | 495 SendJson(connection_id, net::HTTP_OK, dictionary.get(), std::string()); | 
| 494 const std::string target_id = target->GetId(); | 496 const std::string target_id = target->GetId(); | 
| 495 target_map_[target_id] = target.release(); | 497 target_map_[target_id] = target.release(); | 
| 496 return; | 498 return; | 
| 497 } | 499 } | 
| 498 | 500 | 
| 499 if (command == "activate" || command == "close") { | 501 if (command == "activate" || command == "close") { | 
| 500 DevToolsTarget* target = GetTarget(target_id); | 502 DevToolsTarget* target = GetTarget(target_id); | 
| 501 if (!target) { | 503 if (!target) { | 
| 502 SendJson(connection_id, | 504 SendJson(connection_id, | 
| (...skipping 30 matching lines...) Expand all Loading... | |
| 533 SendJson(connection_id, | 535 SendJson(connection_id, | 
| 534 net::HTTP_NOT_FOUND, | 536 net::HTTP_NOT_FOUND, | 
| 535 NULL, | 537 NULL, | 
| 536 "Unknown command: " + command); | 538 "Unknown command: " + command); | 
| 537 return; | 539 return; | 
| 538 } | 540 } | 
| 539 | 541 | 
| 540 void DevToolsHttpHandlerImpl::OnTargetListReceived( | 542 void DevToolsHttpHandlerImpl::OnTargetListReceived( | 
| 541 int connection_id, | 543 int connection_id, | 
| 542 const std::string& host, | 544 const std::string& host, | 
| 545 const GURL& aux_url, | |
| 543 const DevToolsHttpHandlerDelegate::TargetList& targets) { | 546 const DevToolsHttpHandlerDelegate::TargetList& targets) { | 
| 544 DevToolsHttpHandlerDelegate::TargetList sorted_targets = targets; | 547 DevToolsHttpHandlerDelegate::TargetList sorted_targets = targets; | 
| 545 std::sort(sorted_targets.begin(), sorted_targets.end(), TimeComparator); | 548 std::sort(sorted_targets.begin(), sorted_targets.end(), TimeComparator); | 
| 546 | 549 | 
| 547 STLDeleteValues(&target_map_); | 550 STLDeleteValues(&target_map_); | 
| 548 base::ListValue list_value; | 551 base::ListValue list_value; | 
| 549 for (DevToolsHttpHandlerDelegate::TargetList::const_iterator it = | 552 for (DevToolsHttpHandlerDelegate::TargetList::const_iterator it = | 
| 550 sorted_targets.begin(); it != sorted_targets.end(); ++it) { | 553 sorted_targets.begin(); it != sorted_targets.end(); ++it) { | 
| 551 DevToolsTarget* target = *it; | 554 DevToolsTarget* target = *it; | 
| 552 target_map_[target->GetId()] = target; | 555 target_map_[target->GetId()] = target; | 
| 553 list_value.Append(SerializeTarget(*target, host)); | 556 list_value.Append(SerializeTarget(*target, host, aux_url)); | 
| 554 } | 557 } | 
| 555 SendJson(connection_id, net::HTTP_OK, &list_value, std::string()); | 558 SendJson(connection_id, net::HTTP_OK, &list_value, std::string()); | 
| 556 Release(); // Balanced in OnJsonRequestUI. | 559 Release(); // Balanced in OnJsonRequestUI. | 
| 557 } | 560 } | 
| 558 | 561 | 
| 559 DevToolsTarget* DevToolsHttpHandlerImpl::GetTarget(const std::string& id) { | 562 DevToolsTarget* DevToolsHttpHandlerImpl::GetTarget(const std::string& id) { | 
| 560 TargetMap::const_iterator it = target_map_.find(id); | 563 TargetMap::const_iterator it = target_map_.find(id); | 
| 561 if (it == target_map_.end()) | 564 if (it == target_map_.end()) | 
| 562 return NULL; | 565 return NULL; | 
| 563 return it->second; | 566 return it->second; | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 DevToolsManager::GetInstance()->ClientHostClosing(client_host); | 638 DevToolsManager::GetInstance()->ClientHostClosing(client_host); | 
| 636 delete client_host; | 639 delete client_host; | 
| 637 connection_to_client_host_ui_.erase(connection_id); | 640 connection_to_client_host_ui_.erase(connection_id); | 
| 638 } | 641 } | 
| 639 } | 642 } | 
| 640 | 643 | 
| 641 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( | 644 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( | 
| 642 const net::StreamListenSocketFactory* socket_factory, | 645 const net::StreamListenSocketFactory* socket_factory, | 
| 643 const std::string& frontend_url, | 646 const std::string& frontend_url, | 
| 644 DevToolsHttpHandlerDelegate* delegate) | 647 DevToolsHttpHandlerDelegate* delegate) | 
| 645 : overridden_frontend_url_(frontend_url), | 648 : frontend_url_(frontend_url), | 
| 646 socket_factory_(socket_factory), | 649 socket_factory_(socket_factory), | 
| 647 delegate_(delegate) { | 650 delegate_(delegate) { | 
| 648 if (overridden_frontend_url_.empty()) | 651 if (frontend_url_.empty()) | 
| 649 overridden_frontend_url_ = "/devtools/devtools.html"; | 652 frontend_url_ = "/devtools/devtools.html"; | 
| 650 | 653 | 
| 651 // Balanced in ResetHandlerThreadAndRelease(). | 654 // Balanced in ResetHandlerThreadAndRelease(). | 
| 652 AddRef(); | 655 AddRef(); | 
| 653 } | 656 } | 
| 654 | 657 | 
| 655 // Runs on the handler thread | 658 // Runs on the handler thread | 
| 656 void DevToolsHttpHandlerImpl::Init() { | 659 void DevToolsHttpHandlerImpl::Init() { | 
| 657 server_ = new net::HttpServer(*socket_factory_.get(), this); | 660 server_ = new net::HttpServer(*socket_factory_.get(), this); | 
| 658 } | 661 } | 
| 659 | 662 | 
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 741 if (!thread_) | 744 if (!thread_) | 
| 742 return; | 745 return; | 
| 743 thread_->message_loop()->PostTask( | 746 thread_->message_loop()->PostTask( | 
| 744 FROM_HERE, | 747 FROM_HERE, | 
| 745 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), | 748 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), | 
| 746 connection_id, request)); | 749 connection_id, request)); | 
| 747 } | 750 } | 
| 748 | 751 | 
| 749 base::DictionaryValue* DevToolsHttpHandlerImpl::SerializeTarget( | 752 base::DictionaryValue* DevToolsHttpHandlerImpl::SerializeTarget( | 
| 750 const DevToolsTarget& target, | 753 const DevToolsTarget& target, | 
| 751 const std::string& host) { | 754 const std::string& host, | 
| 755 const GURL& aux_url) { | |
| 752 base::DictionaryValue* dictionary = new base::DictionaryValue; | 756 base::DictionaryValue* dictionary = new base::DictionaryValue; | 
| 753 | 757 | 
| 754 std::string id = target.GetId(); | 758 std::string id = target.GetId(); | 
| 755 dictionary->SetString(kTargetIdField, id); | 759 dictionary->SetString(kTargetIdField, id); | 
| 756 dictionary->SetString(kTargetTypeField, target.GetType()); | 760 dictionary->SetString(kTargetTypeField, target.GetType()); | 
| 757 dictionary->SetString(kTargetTitleField, | 761 dictionary->SetString(kTargetTitleField, | 
| 758 net::EscapeForHTML(target.GetTitle())); | 762 net::EscapeForHTML(target.GetTitle())); | 
| 759 dictionary->SetString(kTargetDescriptionField, target.GetDescription()); | 763 dictionary->SetString(kTargetDescriptionField, target.GetDescription()); | 
| 760 | 764 | 
| 761 GURL url = target.GetUrl(); | 765 GURL url = target.GetUrl(); | 
| 762 dictionary->SetString(kTargetUrlField, url.spec()); | 766 dictionary->SetString(kTargetUrlField, url.spec()); | 
| 763 | 767 | 
| 764 GURL favicon_url = target.GetFaviconUrl(); | 768 GURL favicon_url = target.GetFaviconUrl(); | 
| 765 if (favicon_url.is_valid()) | 769 if (favicon_url.is_valid()) | 
| 766 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec()); | 770 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec()); | 
| 767 | 771 | 
| 768 if (!delegate_->GetPageThumbnailData(url).empty()) { | 772 if (!delegate_->GetPageThumbnailData(url).empty()) { | 
| 769 dictionary->SetString(kTargetThumbnailUrlField, | 773 dictionary->SetString(kTargetThumbnailUrlField, | 
| 770 std::string(kThumbUrlPrefix) + id); | 774 std::string(kThumbUrlPrefix) + id); | 
| 771 } | 775 } | 
| 772 | 776 | 
| 773 if (!target.IsAttached()) { | 777 if (!target.IsAttached()) { | 
| 774 dictionary->SetString(kTargetWebSocketDebuggerUrlField, | 778 dictionary->SetString(kTargetWebSocketDebuggerUrlField, | 
| 775 base::StringPrintf("ws://%s%s%s", | 779 base::StringPrintf("ws://%s%s%s", | 
| 776 host.c_str(), | 780 host.c_str(), | 
| 777 kPageUrlPrefix, | 781 kPageUrlPrefix, | 
| 778 id.c_str())); | 782 id.c_str())); | 
| 783 std::string overridden_frontend_url = | |
| 784 aux_url.is_valid() ? aux_url.spec() : frontend_url_; | |
| 
vsevik
2014/03/11 10:50:44
Is this is the only place where this field is used
 | |
| 785 | |
| 779 std::string devtools_frontend_url = GetFrontendURLInternal( | 786 std::string devtools_frontend_url = GetFrontendURLInternal( | 
| 780 id.c_str(), | 787 id.c_str(), | 
| 781 host); | 788 host, | 
| 789 overridden_frontend_url); | |
| 782 dictionary->SetString( | 790 dictionary->SetString( | 
| 783 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 791 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 
| 784 } | 792 } | 
| 785 | 793 | 
| 786 return dictionary; | 794 return dictionary; | 
| 787 } | 795 } | 
| 788 | 796 | 
| 789 } // namespace content | 797 } // namespace content | 
| OLD | NEW |