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/debugger/devtools_http_handler_impl.h" | 5 #include "content/browser/debugger/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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 160 } |
161 | 161 |
162 void DevToolsHttpHandlerImpl::SetRenderViewHostBinding( | 162 void DevToolsHttpHandlerImpl::SetRenderViewHostBinding( |
163 RenderViewHostBinding* binding) { | 163 RenderViewHostBinding* binding) { |
164 if (binding) | 164 if (binding) |
165 binding_ = binding; | 165 binding_ = binding; |
166 else | 166 else |
167 binding_ = default_binding_.get(); | 167 binding_ = default_binding_.get(); |
168 } | 168 } |
169 | 169 |
| 170 GURL DevToolsHttpHandlerImpl::GetFrontendURL(RenderViewHost* render_view_host) { |
| 171 net::IPEndPoint ip_address; |
| 172 if (server_->GetLocalAddress(&ip_address)) |
| 173 return GURL(); |
| 174 std::string host = ip_address.ToString(); |
| 175 std::string id = binding_->GetIdentifier(render_view_host); |
| 176 return GURL(std::string("http://") + |
| 177 ip_address.ToString() + |
| 178 GetFrontendURLInternal(id, host)); |
| 179 } |
| 180 |
170 static std::string PathWithoutParams(const std::string& path) { | 181 static std::string PathWithoutParams(const std::string& path) { |
171 size_t query_position = path.find("?"); | 182 size_t query_position = path.find("?"); |
172 if (query_position != std::string::npos) | 183 if (query_position != std::string::npos) |
173 return path.substr(0, query_position); | 184 return path.substr(0, query_position); |
174 return path; | 185 return path; |
175 } | 186 } |
176 | 187 |
177 static std::string GetMimeType(const std::string& filename) { | 188 static std::string GetMimeType(const std::string& filename) { |
178 if (EndsWith(filename, ".html", false)) { | 189 if (EndsWith(filename, ".html", false)) { |
179 return "text/html"; | 190 return "text/html"; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 page_info.favicon_url = entry->GetFavicon().url.spec(); | 381 page_info.favicon_url = entry->GetFavicon().url.spec(); |
371 } | 382 } |
372 } | 383 } |
373 page_list.push_back(page_info); | 384 page_list.push_back(page_info); |
374 } | 385 } |
375 } | 386 } |
376 std::sort(page_list.begin(), page_list.end(), SortPageListByTime); | 387 std::sort(page_list.begin(), page_list.end(), SortPageListByTime); |
377 return page_list; | 388 return page_list; |
378 } | 389 } |
379 | 390 |
| 391 std::string DevToolsHttpHandlerImpl::GetFrontendURLInternal( |
| 392 const std::string rvh_id, |
| 393 const std::string& host) { |
| 394 return base::StringPrintf( |
| 395 "%s%sws=%s/devtools/page/%s", |
| 396 overridden_frontend_url_.c_str(), |
| 397 overridden_frontend_url_.find("?") == std::string::npos ? "?" : "&", |
| 398 host.c_str(), |
| 399 rvh_id.c_str()); |
| 400 } |
| 401 |
380 void DevToolsHttpHandlerImpl::OnJsonRequestUI( | 402 void DevToolsHttpHandlerImpl::OnJsonRequestUI( |
381 int connection_id, | 403 int connection_id, |
382 const net::HttpServerRequestInfo& info) { | 404 const net::HttpServerRequestInfo& info) { |
383 PageList page_list = GeneratePageList(); | 405 PageList page_list = GeneratePageList(); |
384 ListValue json_pages_list; | 406 ListValue json_pages_list; |
385 std::string host = info.headers["Host"]; | 407 std::string host = info.headers["Host"]; |
386 for (PageList::iterator i = page_list.begin(); | 408 for (PageList::iterator i = page_list.begin(); |
387 i != page_list.end(); ++i) { | 409 i != page_list.end(); ++i) { |
388 DictionaryValue* page_info = new DictionaryValue; | 410 DictionaryValue* page_info = new DictionaryValue; |
389 json_pages_list.Append(page_info); | 411 json_pages_list.Append(page_info); |
390 page_info->SetString("title", i->title); | 412 page_info->SetString("title", i->title); |
391 page_info->SetString("url", i->url); | 413 page_info->SetString("url", i->url); |
392 page_info->SetString("thumbnailUrl", i->thumbnail_url); | 414 page_info->SetString("thumbnailUrl", i->thumbnail_url); |
393 page_info->SetString("faviconUrl", i->favicon_url); | 415 page_info->SetString("faviconUrl", i->favicon_url); |
394 if (!i->attached) { | 416 if (!i->attached) { |
395 page_info->SetString("webSocketDebuggerUrl", | 417 page_info->SetString("webSocketDebuggerUrl", |
396 base::StringPrintf("ws://%s/devtools/page/%s", | 418 base::StringPrintf("ws://%s/devtools/page/%s", |
397 host.c_str(), | 419 host.c_str(), |
398 i->id.c_str())); | 420 i->id.c_str())); |
399 std::string devtools_frontend_url = base::StringPrintf( | 421 std::string devtools_frontend_url = GetFrontendURLInternal(i->id.c_str(), |
400 "%s%sws=%s/devtools/page/%s", | 422 host); |
401 overridden_frontend_url_.c_str(), | |
402 overridden_frontend_url_.find("?") == std::string::npos ? "?" : "&", | |
403 host.c_str(), | |
404 i->id.c_str()); | |
405 page_info->SetString("devtoolsFrontendUrl", devtools_frontend_url); | 423 page_info->SetString("devtoolsFrontendUrl", devtools_frontend_url); |
406 } | 424 } |
407 } | 425 } |
408 | 426 |
409 std::string response; | 427 std::string response; |
410 base::JSONWriter::WriteWithOptions(&json_pages_list, | 428 base::JSONWriter::WriteWithOptions(&json_pages_list, |
411 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 429 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
412 &response); | 430 &response); |
413 Send200(connection_id, response, "application/json; charset=UTF-8"); | 431 Send200(connection_id, response, "application/json; charset=UTF-8"); |
414 } | 432 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 void DevToolsHttpHandlerImpl::AcceptWebSocket( | 636 void DevToolsHttpHandlerImpl::AcceptWebSocket( |
619 int connection_id, | 637 int connection_id, |
620 const net::HttpServerRequestInfo& request) { | 638 const net::HttpServerRequestInfo& request) { |
621 BrowserThread::PostTask( | 639 BrowserThread::PostTask( |
622 BrowserThread::IO, FROM_HERE, | 640 BrowserThread::IO, FROM_HERE, |
623 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), | 641 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), |
624 connection_id, request)); | 642 connection_id, request)); |
625 } | 643 } |
626 | 644 |
627 } // namespace content | 645 } // namespace content |
OLD | NEW |