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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 if (info.path.find("/json") == 0) { | 207 if (info.path.find("/json") == 0) { |
208 // Pages discovery json request. | 208 // Pages discovery json request. |
209 BrowserThread::PostTask( | 209 BrowserThread::PostTask( |
210 BrowserThread::UI, | 210 BrowserThread::UI, |
211 FROM_HERE, | 211 FROM_HERE, |
212 base::Bind(&DevToolsHttpHandlerImpl::OnJsonRequestUI, | 212 base::Bind(&DevToolsHttpHandlerImpl::OnJsonRequestUI, |
213 this, | 213 this, |
214 connection_id, | 214 connection_id, |
215 info)); | 215 info)); |
216 return; | 216 return; |
| 217 } else if (info.path.find("/thumb/") == 0) { |
| 218 // Thumbnail request. |
| 219 BrowserThread::PostTask( |
| 220 BrowserThread::UI, |
| 221 FROM_HERE, |
| 222 base::Bind(&DevToolsHttpHandlerImpl::OnThumbnailRequestUI, |
| 223 this, |
| 224 connection_id, |
| 225 info)); |
| 226 return; |
217 } | 227 } |
218 | 228 |
219 if (info.path == "" || info.path == "/") { | 229 if (info.path == "" || info.path == "/") { |
220 std::string response = delegate_->GetDiscoveryPageHTML(); | 230 std::string response = delegate_->GetDiscoveryPageHTML(); |
221 server_->Send200(connection_id, response, "text/html; charset=UTF-8"); | 231 server_->Send200(connection_id, response, "text/html; charset=UTF-8"); |
222 return; | 232 return; |
223 } | 233 } |
224 | 234 |
225 // Proxy static files from chrome-devtools://devtools/*. | 235 // Proxy static files from chrome-devtools://devtools/*. |
226 net::URLRequestContext* request_context = | 236 net::URLRequestContext* request_context = |
(...skipping 16 matching lines...) Expand all Loading... |
243 content::GetContentClient()->GetDataResource( | 253 content::GetContentClient()->GetDataResource( |
244 resource_id, ui::SCALE_FACTOR_NONE); | 254 resource_id, ui::SCALE_FACTOR_NONE); |
245 server_->Send200(connection_id, | 255 server_->Send200(connection_id, |
246 data.as_string(), | 256 data.as_string(), |
247 GetMimeType(filename)); | 257 GetMimeType(filename)); |
248 } | 258 } |
249 return; | 259 return; |
250 } | 260 } |
251 std::string base_url = delegate_->GetFrontendResourcesBaseURL(); | 261 std::string base_url = delegate_->GetFrontendResourcesBaseURL(); |
252 request = request_context->CreateRequest(GURL(base_url + filename), this); | 262 request = request_context->CreateRequest(GURL(base_url + filename), this); |
253 } else if (info.path.find("/thumb/") == 0) { | |
254 request = request_context->CreateRequest( | |
255 GURL("chrome:/" + info.path), this); | |
256 } else { | 263 } else { |
257 server_->Send404(connection_id); | 264 server_->Send404(connection_id); |
258 return; | 265 return; |
259 } | 266 } |
260 | 267 |
261 Bind(request, connection_id); | 268 Bind(request, connection_id); |
262 request->Start(); | 269 request->Start(); |
263 } | 270 } |
264 | 271 |
265 void DevToolsHttpHandlerImpl::OnWebSocketRequest( | 272 void DevToolsHttpHandlerImpl::OnWebSocketRequest( |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 if (jsonp_pos == std::string::npos) { | 437 if (jsonp_pos == std::string::npos) { |
431 Send200(connection_id, response, "application/json; charset=UTF-8"); | 438 Send200(connection_id, response, "application/json; charset=UTF-8"); |
432 return; | 439 return; |
433 } | 440 } |
434 | 441 |
435 std::string jsonp = info.path.substr(jsonp_pos + 7); | 442 std::string jsonp = info.path.substr(jsonp_pos + 7); |
436 response = StringPrintf("%s(%s);", jsonp.c_str(), response.c_str()); | 443 response = StringPrintf("%s(%s);", jsonp.c_str(), response.c_str()); |
437 Send200(connection_id, response, "text/javascript; charset=UTF-8"); | 444 Send200(connection_id, response, "text/javascript; charset=UTF-8"); |
438 } | 445 } |
439 | 446 |
| 447 void DevToolsHttpHandlerImpl::OnThumbnailRequestUI( |
| 448 int connection_id, |
| 449 const net::HttpServerRequestInfo& info) { |
| 450 std::string prefix = "/thumb/"; |
| 451 size_t pos = info.path.find(prefix); |
| 452 if (pos != 0) { |
| 453 Send404(connection_id); |
| 454 return; |
| 455 } |
| 456 |
| 457 std::string page_url = info.path.substr(prefix.length()); |
| 458 std::string data = delegate_->GetPageThumbnailData(GURL(page_url)); |
| 459 if (!data.empty()) |
| 460 Send200(connection_id, data, "image/png"); |
| 461 else |
| 462 Send404(connection_id); |
| 463 } |
| 464 |
440 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( | 465 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( |
441 int connection_id, | 466 int connection_id, |
442 const net::HttpServerRequestInfo& request) { | 467 const net::HttpServerRequestInfo& request) { |
443 std::string prefix = "/devtools/page/"; | 468 std::string prefix = "/devtools/page/"; |
444 size_t pos = request.path.find(prefix); | 469 size_t pos = request.path.find(prefix); |
445 if (pos != 0) { | 470 if (pos != 0) { |
446 Send404(connection_id); | 471 Send404(connection_id); |
447 return; | 472 return; |
448 } | 473 } |
449 | 474 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 void DevToolsHttpHandlerImpl::AcceptWebSocket( | 667 void DevToolsHttpHandlerImpl::AcceptWebSocket( |
643 int connection_id, | 668 int connection_id, |
644 const net::HttpServerRequestInfo& request) { | 669 const net::HttpServerRequestInfo& request) { |
645 BrowserThread::PostTask( | 670 BrowserThread::PostTask( |
646 BrowserThread::IO, FROM_HERE, | 671 BrowserThread::IO, FROM_HERE, |
647 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), | 672 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), |
648 connection_id, request)); | 673 connection_id, request)); |
649 } | 674 } |
650 | 675 |
651 } // namespace content | 676 } // namespace content |
OLD | NEW |