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 "chrome/browser/ui/webui/devtools_ui.h" | 5 #include "chrome/browser/ui/webui/devtools_ui.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
7 #include "base/macros.h" | 8 #include "base/macros.h" |
8 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
9 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
14 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/devtools_frontend_host.h" | 17 #include "content/public/browser/devtools_frontend_host.h" |
16 #include "content/public/browser/url_data_source.h" | 18 #include "content/public/browser/url_data_source.h" |
17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
19 #include "content/public/common/user_agent.h" | 21 #include "content/public/common/user_agent.h" |
20 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
| 23 #include "net/base/filename_util.h" |
| 24 #include "net/base/load_flags.h" |
21 #include "net/base/url_util.h" | 25 #include "net/base/url_util.h" |
22 #include "net/url_request/url_fetcher.h" | 26 #include "net/url_request/url_fetcher.h" |
23 #include "net/url_request/url_fetcher_delegate.h" | 27 #include "net/url_request/url_fetcher_delegate.h" |
24 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
25 | 29 |
26 using content::BrowserThread; | 30 using content::BrowserThread; |
27 using content::WebContents; | 31 using content::WebContents; |
28 | 32 |
29 namespace { | 33 namespace { |
30 | 34 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 void OnURLFetchComplete(const net::URLFetcher* source) override; | 234 void OnURLFetchComplete(const net::URLFetcher* source) override; |
231 | 235 |
232 // Serves bundled DevTools frontend from ResourceBundle. | 236 // Serves bundled DevTools frontend from ResourceBundle. |
233 void StartBundledDataRequest(const std::string& path, | 237 void StartBundledDataRequest(const std::string& path, |
234 const GotDataCallback& callback); | 238 const GotDataCallback& callback); |
235 | 239 |
236 // Serves remote DevTools frontend from hard-coded App Engine domain. | 240 // Serves remote DevTools frontend from hard-coded App Engine domain. |
237 void StartRemoteDataRequest(const std::string& path, | 241 void StartRemoteDataRequest(const std::string& path, |
238 const GotDataCallback& callback); | 242 const GotDataCallback& callback); |
239 | 243 |
| 244 // Serves remote DevTools frontend from any endpoint, passed through |
| 245 // command-line flag. |
| 246 void StartCustomDataRequest(const GURL& url, |
| 247 const GotDataCallback& callback); |
| 248 |
240 ~DevToolsDataSource() override; | 249 ~DevToolsDataSource() override; |
241 | 250 |
242 scoped_refptr<net::URLRequestContextGetter> request_context_; | 251 scoped_refptr<net::URLRequestContextGetter> request_context_; |
243 | 252 |
244 using PendingRequestsMap = std::map<const net::URLFetcher*, GotDataCallback>; | 253 using PendingRequestsMap = std::map<const net::URLFetcher*, GotDataCallback>; |
245 PendingRequestsMap pending_; | 254 PendingRequestsMap pending_; |
246 | 255 |
247 DISALLOW_COPY_AND_ASSIGN(DevToolsDataSource); | 256 DISALLOW_COPY_AND_ASSIGN(DevToolsDataSource); |
248 }; | 257 }; |
249 | 258 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 // Serve request from remote location. | 290 // Serve request from remote location. |
282 std::string remote_path_prefix(chrome::kChromeUIDevToolsRemotePath); | 291 std::string remote_path_prefix(chrome::kChromeUIDevToolsRemotePath); |
283 remote_path_prefix += "/"; | 292 remote_path_prefix += "/"; |
284 if (base::StartsWith(path, remote_path_prefix, | 293 if (base::StartsWith(path, remote_path_prefix, |
285 base::CompareCase::INSENSITIVE_ASCII)) { | 294 base::CompareCase::INSENSITIVE_ASCII)) { |
286 StartRemoteDataRequest(path.substr(remote_path_prefix.length()), | 295 StartRemoteDataRequest(path.substr(remote_path_prefix.length()), |
287 callback); | 296 callback); |
288 return; | 297 return; |
289 } | 298 } |
290 | 299 |
| 300 std::string custom_frontend_url = |
| 301 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 302 switches::kCustomDevtoolsFrontend); |
| 303 |
| 304 if (custom_frontend_url.empty()) { |
| 305 callback.Run(NULL); |
| 306 return; |
| 307 } |
| 308 |
| 309 // Serve request from custom location. |
| 310 std::string custom_path_prefix(chrome::kChromeUIDevToolsCustomPath); |
| 311 custom_path_prefix += "/"; |
| 312 |
| 313 if (base::StartsWith(path, custom_path_prefix, |
| 314 base::CompareCase::INSENSITIVE_ASCII)) { |
| 315 GURL url = GURL(custom_frontend_url + |
| 316 path.substr(custom_path_prefix.length())); |
| 317 StartCustomDataRequest(url, callback); |
| 318 return; |
| 319 } |
| 320 |
291 callback.Run(NULL); | 321 callback.Run(NULL); |
292 } | 322 } |
293 | 323 |
294 std::string DevToolsDataSource::GetMimeType(const std::string& path) const { | 324 std::string DevToolsDataSource::GetMimeType(const std::string& path) const { |
295 return GetMimeTypeForPath(path); | 325 return GetMimeTypeForPath(path); |
296 } | 326 } |
297 | 327 |
298 bool DevToolsDataSource::ShouldAddContentSecurityPolicy() const { | 328 bool DevToolsDataSource::ShouldAddContentSecurityPolicy() const { |
299 return false; | 329 return false; |
300 } | 330 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 new base::RefCountedStaticMemory(kHttpNotFound, strlen(kHttpNotFound))); | 363 new base::RefCountedStaticMemory(kHttpNotFound, strlen(kHttpNotFound))); |
334 return; | 364 return; |
335 } | 365 } |
336 net::URLFetcher* fetcher = | 366 net::URLFetcher* fetcher = |
337 net::URLFetcher::Create(url, net::URLFetcher::GET, this).release(); | 367 net::URLFetcher::Create(url, net::URLFetcher::GET, this).release(); |
338 pending_[fetcher] = callback; | 368 pending_[fetcher] = callback; |
339 fetcher->SetRequestContext(request_context_.get()); | 369 fetcher->SetRequestContext(request_context_.get()); |
340 fetcher->Start(); | 370 fetcher->Start(); |
341 } | 371 } |
342 | 372 |
| 373 void DevToolsDataSource::StartCustomDataRequest( |
| 374 const GURL& url, |
| 375 const content::URLDataSource::GotDataCallback& callback) { |
| 376 if (!url.is_valid()) { |
| 377 callback.Run( |
| 378 new base::RefCountedStaticMemory(kHttpNotFound, strlen(kHttpNotFound))); |
| 379 return; |
| 380 } |
| 381 net::URLFetcher* fetcher = |
| 382 net::URLFetcher::Create(url, net::URLFetcher::GET, this).release(); |
| 383 pending_[fetcher] = callback; |
| 384 fetcher->SetRequestContext(request_context_.get()); |
| 385 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 386 fetcher->Start(); |
| 387 } |
| 388 |
343 void DevToolsDataSource::OnURLFetchComplete(const net::URLFetcher* source) { | 389 void DevToolsDataSource::OnURLFetchComplete(const net::URLFetcher* source) { |
344 DCHECK(source); | 390 DCHECK(source); |
345 PendingRequestsMap::iterator it = pending_.find(source); | 391 PendingRequestsMap::iterator it = pending_.find(source); |
346 DCHECK(it != pending_.end()); | 392 DCHECK(it != pending_.end()); |
347 std::string response; | 393 std::string response; |
348 source->GetResponseAsString(&response); | 394 source->GetResponseAsString(&response); |
349 delete source; | 395 delete source; |
350 it->second.Run(base::RefCountedString::TakeString(&response)); | 396 it->second.Run(base::RefCountedString::TakeString(&response)); |
351 pending_.erase(it); | 397 pending_.erase(it); |
352 } | 398 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 profile, | 436 profile, |
391 new DevToolsDataSource(profile->GetRequestContext())); | 437 new DevToolsDataSource(profile->GetRequestContext())); |
392 | 438 |
393 GURL url = web_ui->GetWebContents()->GetVisibleURL(); | 439 GURL url = web_ui->GetWebContents()->GetVisibleURL(); |
394 if (url.spec() == SanitizeFrontendURL(url).spec()) | 440 if (url.spec() == SanitizeFrontendURL(url).spec()) |
395 bindings_.reset(new DevToolsUIBindings(web_ui->GetWebContents())); | 441 bindings_.reset(new DevToolsUIBindings(web_ui->GetWebContents())); |
396 } | 442 } |
397 | 443 |
398 DevToolsUI::~DevToolsUI() { | 444 DevToolsUI::~DevToolsUI() { |
399 } | 445 } |
OLD | NEW |