| 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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 if (!ParseJsonPath(path, &command, &target_id)) { | 505 if (!ParseJsonPath(path, &command, &target_id)) { |
| 506 SendJson(connection_id, | 506 SendJson(connection_id, |
| 507 net::HTTP_NOT_FOUND, | 507 net::HTTP_NOT_FOUND, |
| 508 NULL, | 508 NULL, |
| 509 "Malformed query: " + info.path, | 509 "Malformed query: " + info.path, |
| 510 jsonp); | 510 jsonp); |
| 511 return; | 511 return; |
| 512 } | 512 } |
| 513 | 513 |
| 514 if (command == "version") { | 514 if (command == "version") { |
| 515 DictionaryValue version; | 515 base::DictionaryValue version; |
| 516 version.SetString("Protocol-Version", | 516 version.SetString("Protocol-Version", |
| 517 WebKit::WebDevToolsAgent::inspectorProtocolVersion()); | 517 WebKit::WebDevToolsAgent::inspectorProtocolVersion()); |
| 518 version.SetString("WebKit-Version", | 518 version.SetString("WebKit-Version", |
| 519 webkit_glue::GetWebKitVersion()); | 519 webkit_glue::GetWebKitVersion()); |
| 520 version.SetString("Browser", | 520 version.SetString("Browser", |
| 521 content::GetContentClient()->GetProduct()); | 521 content::GetContentClient()->GetProduct()); |
| 522 version.SetString("User-Agent", | 522 version.SetString("User-Agent", |
| 523 webkit_glue::GetUserAgent(GURL(chrome::kAboutBlankURL))); | 523 webkit_glue::GetUserAgent(GURL(chrome::kAboutBlankURL))); |
| 524 SendJson(connection_id, net::HTTP_OK, &version, "", jsonp); | 524 SendJson(connection_id, net::HTTP_OK, &version, "", jsonp); |
| 525 return; | 525 return; |
| 526 } | 526 } |
| 527 | 527 |
| 528 if (command == "list") { | 528 if (command == "list") { |
| 529 PageList page_list = GeneratePageList(); | 529 PageList page_list = GeneratePageList(); |
| 530 ListValue json_pages_list; | 530 base::ListValue json_pages_list; |
| 531 std::string host = info.headers["Host"]; | 531 std::string host = info.headers["Host"]; |
| 532 for (PageList::iterator i = page_list.begin(); i != page_list.end(); ++i) | 532 for (PageList::iterator i = page_list.begin(); i != page_list.end(); ++i) |
| 533 json_pages_list.Append(SerializePageInfo(*i, host)); | 533 json_pages_list.Append(SerializePageInfo(*i, host)); |
| 534 SendJson(connection_id, net::HTTP_OK, &json_pages_list, "", jsonp); | 534 SendJson(connection_id, net::HTTP_OK, &json_pages_list, "", jsonp); |
| 535 return; | 535 return; |
| 536 } | 536 } |
| 537 | 537 |
| 538 if (command == "new") { | 538 if (command == "new") { |
| 539 RenderViewHost* rvh = delegate_->CreateNewTarget(); | 539 RenderViewHost* rvh = delegate_->CreateNewTarget(); |
| 540 if (!rvh) { | 540 if (!rvh) { |
| 541 SendJson(connection_id, | 541 SendJson(connection_id, |
| 542 net::HTTP_INTERNAL_SERVER_ERROR, | 542 net::HTTP_INTERNAL_SERVER_ERROR, |
| 543 NULL, | 543 NULL, |
| 544 "Could not create new page", | 544 "Could not create new page", |
| 545 jsonp); | 545 jsonp); |
| 546 return; | 546 return; |
| 547 } | 547 } |
| 548 PageInfo page_info = CreatePageInfo( | 548 PageInfo page_info = |
| 549 rvh, | 549 CreatePageInfo(rvh, DevToolsHttpHandlerDelegate::kTargetTypeTab); |
| 550 DevToolsHttpHandlerDelegate::kTargetTypeTab); | |
| 551 std::string host = info.headers["Host"]; | 550 std::string host = info.headers["Host"]; |
| 552 scoped_ptr<DictionaryValue> dictionary(SerializePageInfo(page_info, host)); | 551 scoped_ptr<base::DictionaryValue> dictionary( |
| 552 SerializePageInfo(page_info, host)); |
| 553 SendJson(connection_id, net::HTTP_OK, dictionary.get(), "", jsonp); | 553 SendJson(connection_id, net::HTTP_OK, dictionary.get(), "", jsonp); |
| 554 return; | 554 return; |
| 555 } | 555 } |
| 556 | 556 |
| 557 if (command == "activate" || command == "close") { | 557 if (command == "activate" || command == "close") { |
| 558 DevToolsAgentHost* agent_host = binding_->ForIdentifier(target_id); | 558 DevToolsAgentHost* agent_host = binding_->ForIdentifier(target_id); |
| 559 RenderViewHost* rvh = agent_host ? agent_host->GetRenderViewHost() : NULL; | 559 RenderViewHost* rvh = agent_host ? agent_host->GetRenderViewHost() : NULL; |
| 560 if (!rvh) { | 560 if (!rvh) { |
| 561 SendJson(connection_id, | 561 SendJson(connection_id, |
| 562 net::HTTP_NOT_FOUND, | 562 net::HTTP_NOT_FOUND, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 return; | 741 return; |
| 742 thread_->message_loop()->PostTask( | 742 thread_->message_loop()->PostTask( |
| 743 FROM_HERE, | 743 FROM_HERE, |
| 744 base::Bind(&DevToolsHttpHandlerImpl::Teardown, this)); | 744 base::Bind(&DevToolsHttpHandlerImpl::Teardown, this)); |
| 745 // Thread::Stop joins the thread. | 745 // Thread::Stop joins the thread. |
| 746 thread_->Stop(); | 746 thread_->Stop(); |
| 747 } | 747 } |
| 748 | 748 |
| 749 void DevToolsHttpHandlerImpl::SendJson(int connection_id, | 749 void DevToolsHttpHandlerImpl::SendJson(int connection_id, |
| 750 net::HttpStatusCode status_code, | 750 net::HttpStatusCode status_code, |
| 751 Value* value, | 751 base::Value* value, |
| 752 const std::string& message, | 752 const std::string& message, |
| 753 const std::string& jsonp) { | 753 const std::string& jsonp) { |
| 754 if (!thread_.get()) | 754 if (!thread_.get()) |
| 755 return; | 755 return; |
| 756 | 756 |
| 757 // Serialize value and message. | 757 // Serialize value and message. |
| 758 std::string json_value; | 758 std::string json_value; |
| 759 if (value) { | 759 if (value) { |
| 760 base::JSONWriter::WriteWithOptions(value, | 760 base::JSONWriter::WriteWithOptions(value, |
| 761 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 761 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 762 &json_value); | 762 &json_value); |
| 763 } | 763 } |
| 764 std::string json_message; | 764 std::string json_message; |
| 765 scoped_ptr<Value> message_object(Value::CreateStringValue(message)); | 765 scoped_ptr<base::Value> message_object(new base::StringValue(message)); |
| 766 base::JSONWriter::Write(message_object.get(), &json_message); | 766 base::JSONWriter::Write(message_object.get(), &json_message); |
| 767 | 767 |
| 768 std::string response; | 768 std::string response; |
| 769 std::string mime_type = "application/json; charset=UTF-8"; | 769 std::string mime_type = "application/json; charset=UTF-8"; |
| 770 | 770 |
| 771 // Wrap jsonp if necessary. | 771 // Wrap jsonp if necessary. |
| 772 if (!jsonp.empty()) { | 772 if (!jsonp.empty()) { |
| 773 mime_type = "text/javascript; charset=UTF-8"; | 773 mime_type = "text/javascript; charset=UTF-8"; |
| 774 response = StringPrintf("%s(%s, %d, %s);", | 774 response = StringPrintf("%s(%s, %d, %s);", |
| 775 jsonp.c_str(), | 775 jsonp.c_str(), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 NavigationController& controller = web_contents->GetController(); | 865 NavigationController& controller = web_contents->GetController(); |
| 866 NavigationEntry* entry = controller.GetActiveEntry(); | 866 NavigationEntry* entry = controller.GetActiveEntry(); |
| 867 if (entry != NULL && entry->GetURL().is_valid()) { | 867 if (entry != NULL && entry->GetURL().is_valid()) { |
| 868 page_info.thumbnail_url = "/thumb/" + entry->GetURL().spec(); | 868 page_info.thumbnail_url = "/thumb/" + entry->GetURL().spec(); |
| 869 page_info.favicon_url = entry->GetFavicon().url.spec(); | 869 page_info.favicon_url = entry->GetFavicon().url.spec(); |
| 870 } | 870 } |
| 871 } | 871 } |
| 872 return page_info; | 872 return page_info; |
| 873 } | 873 } |
| 874 | 874 |
| 875 DictionaryValue* DevToolsHttpHandlerImpl::SerializePageInfo( | 875 base::DictionaryValue* DevToolsHttpHandlerImpl::SerializePageInfo( |
| 876 const PageInfo& page_info, | 876 const PageInfo& page_info, |
| 877 const std::string& host) { | 877 const std::string& host) { |
| 878 DictionaryValue* dictionary = new DictionaryValue; | 878 base::DictionaryValue* dictionary = new base::DictionaryValue; |
| 879 dictionary->SetString("title", page_info.title); | 879 dictionary->SetString("title", page_info.title); |
| 880 dictionary->SetString("url", page_info.url); | 880 dictionary->SetString("url", page_info.url); |
| 881 dictionary->SetString("type", page_info.type); | 881 dictionary->SetString("type", page_info.type); |
| 882 dictionary->SetString("id", page_info.id); | 882 dictionary->SetString("id", page_info.id); |
| 883 dictionary->SetString("thumbnailUrl", page_info.thumbnail_url); | 883 dictionary->SetString("thumbnailUrl", page_info.thumbnail_url); |
| 884 dictionary->SetString("faviconUrl", page_info.favicon_url); | 884 dictionary->SetString("faviconUrl", page_info.favicon_url); |
| 885 if (!page_info.attached) { | 885 if (!page_info.attached) { |
| 886 dictionary->SetString("webSocketDebuggerUrl", | 886 dictionary->SetString("webSocketDebuggerUrl", |
| 887 base::StringPrintf("ws://%s/devtools/page/%s", | 887 base::StringPrintf("ws://%s/devtools/page/%s", |
| 888 host.c_str(), | 888 host.c_str(), |
| 889 page_info.id.c_str())); | 889 page_info.id.c_str())); |
| 890 std::string devtools_frontend_url = GetFrontendURLInternal( | 890 std::string devtools_frontend_url = GetFrontendURLInternal( |
| 891 page_info.id.c_str(), | 891 page_info.id.c_str(), |
| 892 host); | 892 host); |
| 893 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); | 893 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); |
| 894 } | 894 } |
| 895 return dictionary; | 895 return dictionary; |
| 896 } | 896 } |
| 897 | 897 |
| 898 } // namespace content | 898 } // namespace content |
| OLD | NEW |