| 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/command_line.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
| 29 #include "third_party/WebKit/public/public_features.h" | 29 #include "third_party/WebKit/public/public_features.h" |
| 30 | 30 |
| 31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 using content::WebContents; | 32 using content::WebContents; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 std::string PathWithoutParams(const std::string& path) { | 36 std::string PathWithoutParams(const std::string& path) { |
| 37 return GURL(std::string("chrome-devtools://devtools/") + path) | 37 return GURL(std::string("chrome-devtools://devtools/") + path) |
| 38 .path().substr(1); | 38 .path() |
| 39 .substr(1) |
| 40 .as_string(); |
| 39 } | 41 } |
| 40 | 42 |
| 41 const char kRemoteFrontendDomain[] = "chrome-devtools-frontend.appspot.com"; | 43 const char kRemoteFrontendDomain[] = "chrome-devtools-frontend.appspot.com"; |
| 42 const char kRemoteFrontendBase[] = | 44 const char kRemoteFrontendBase[] = |
| 43 "https://chrome-devtools-frontend.appspot.com/"; | 45 "https://chrome-devtools-frontend.appspot.com/"; |
| 44 const char kRemoteFrontendPath[] = "serve_file"; | 46 const char kRemoteFrontendPath[] = "serve_file"; |
| 45 const char kHttpNotFound[] = "HTTP/1.1 404 Not Found\n\n"; | 47 const char kHttpNotFound[] = "HTTP/1.1 404 Not Found\n\n"; |
| 46 | 48 |
| 47 #if BUILDFLAG(DEBUG_DEVTOOLS) | 49 #if BUILDFLAG(DEBUG_DEVTOOLS) |
| 48 // Local frontend url provided by InspectUI. | 50 // Local frontend url provided by InspectUI. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 90 |
| 89 std::string SanitizeEndpoint(const std::string& value) { | 91 std::string SanitizeEndpoint(const std::string& value) { |
| 90 if (value.find('&') != std::string::npos | 92 if (value.find('&') != std::string::npos |
| 91 || value.find('?') != std::string::npos) | 93 || value.find('?') != std::string::npos) |
| 92 return std::string(); | 94 return std::string(); |
| 93 return value; | 95 return value; |
| 94 } | 96 } |
| 95 | 97 |
| 96 std::string SanitizeRemoteBase(const std::string& value) { | 98 std::string SanitizeRemoteBase(const std::string& value) { |
| 97 GURL url(value); | 99 GURL url(value); |
| 98 std::string path = url.path(); | 100 std::string path = url.path().as_string(); |
| 99 std::vector<std::string> parts = base::SplitString( | 101 std::vector<std::string> parts = base::SplitString( |
| 100 path, "/", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | 102 path, "/", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 101 std::string revision = parts.size() > 2 ? parts[2] : ""; | 103 std::string revision = parts.size() > 2 ? parts[2] : ""; |
| 102 revision = SanitizeRevision(revision); | 104 revision = SanitizeRevision(revision); |
| 103 path = base::StringPrintf("/%s/%s/", kRemoteFrontendPath, revision.c_str()); | 105 path = base::StringPrintf("/%s/%s/", kRemoteFrontendPath, revision.c_str()); |
| 104 return SanitizeFrontendURL(url, url::kHttpsScheme, | 106 return SanitizeFrontendURL(url, url::kHttpsScheme, |
| 105 kRemoteFrontendDomain, path, false).spec(); | 107 kRemoteFrontendDomain, path, false).spec(); |
| 106 } | 108 } |
| 107 | 109 |
| 108 std::string SanitizeRemoteFrontendURL(const std::string& value) { | 110 std::string SanitizeRemoteFrontendURL(const std::string& value) { |
| 109 GURL url(net::UnescapeURLComponent(value, | 111 GURL url(net::UnescapeURLComponent(value, |
| 110 net::UnescapeRule::SPACES | net::UnescapeRule::PATH_SEPARATORS | | 112 net::UnescapeRule::SPACES | net::UnescapeRule::PATH_SEPARATORS | |
| 111 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS | | 113 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS | |
| 112 net::UnescapeRule::REPLACE_PLUS_WITH_SPACE)); | 114 net::UnescapeRule::REPLACE_PLUS_WITH_SPACE)); |
| 113 std::string path = url.path(); | 115 std::string path = url.path().as_string(); |
| 114 std::vector<std::string> parts = base::SplitString( | 116 std::vector<std::string> parts = base::SplitString( |
| 115 path, "/", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | 117 path, "/", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 116 std::string revision = parts.size() > 2 ? parts[2] : ""; | 118 std::string revision = parts.size() > 2 ? parts[2] : ""; |
| 117 revision = SanitizeRevision(revision); | 119 revision = SanitizeRevision(revision); |
| 118 std::string filename = parts.size() ? parts[parts.size() - 1] : ""; | 120 std::string filename = parts.size() ? parts[parts.size() - 1] : ""; |
| 119 if (filename != "devtools.html") | 121 if (filename != "devtools.html") |
| 120 filename = "inspector.html"; | 122 filename = "inspector.html"; |
| 121 path = base::StringPrintf("/serve_rev/%s/%s", | 123 path = base::StringPrintf("/serve_rev/%s/%s", |
| 122 revision.c_str(), filename.c_str()); | 124 revision.c_str(), filename.c_str()); |
| 123 std::string sanitized = SanitizeFrontendURL(url, url::kHttpsScheme, | 125 std::string sanitized = SanitizeFrontendURL(url, url::kHttpsScheme, |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 402 |
| 401 } // namespace | 403 } // namespace |
| 402 | 404 |
| 403 // DevToolsUI ----------------------------------------------------------------- | 405 // DevToolsUI ----------------------------------------------------------------- |
| 404 | 406 |
| 405 // static | 407 // static |
| 406 GURL DevToolsUI::GetProxyURL(const std::string& frontend_url) { | 408 GURL DevToolsUI::GetProxyURL(const std::string& frontend_url) { |
| 407 GURL url(frontend_url); | 409 GURL url(frontend_url); |
| 408 if (!url.is_valid() || url.host() != kRemoteFrontendDomain) | 410 if (!url.is_valid() || url.host() != kRemoteFrontendDomain) |
| 409 return GURL(kFallbackFrontendURL); | 411 return GURL(kFallbackFrontendURL); |
| 410 return GURL(base::StringPrintf("%s://%s/%s/%s", | 412 return GURL(base::StringPrintf( |
| 411 content::kChromeDevToolsScheme, | 413 "%s://%s/%s/%s", content::kChromeDevToolsScheme, |
| 412 chrome::kChromeUIDevToolsHost, | 414 chrome::kChromeUIDevToolsHost, chrome::kChromeUIDevToolsRemotePath, |
| 413 chrome::kChromeUIDevToolsRemotePath, | 415 url.path().substr(1).as_string().c_str())); |
| 414 url.path().substr(1).c_str())); | |
| 415 } | 416 } |
| 416 | 417 |
| 417 // static | 418 // static |
| 418 GURL DevToolsUI::GetRemoteBaseURL() { | 419 GURL DevToolsUI::GetRemoteBaseURL() { |
| 419 return GURL(base::StringPrintf( | 420 return GURL(base::StringPrintf( |
| 420 "%s%s/%s/", | 421 "%s%s/%s/", |
| 421 kRemoteFrontendBase, | 422 kRemoteFrontendBase, |
| 422 kRemoteFrontendPath, | 423 kRemoteFrontendPath, |
| 423 content::GetWebKitRevision().c_str())); | 424 content::GetWebKitRevision().c_str())); |
| 424 } | 425 } |
| 425 | 426 |
| 426 // static | 427 // static |
| 427 GURL DevToolsUI::SanitizeFrontendURL(const GURL& url) { | 428 GURL DevToolsUI::SanitizeFrontendURL(const GURL& url) { |
| 428 return ::SanitizeFrontendURL(url, content::kChromeDevToolsScheme, | 429 return ::SanitizeFrontendURL( |
| 429 chrome::kChromeUIDevToolsHost, SanitizeFrontendPath(url.path()), true); | 430 url, content::kChromeDevToolsScheme, chrome::kChromeUIDevToolsHost, |
| 431 SanitizeFrontendPath(url.path().as_string()), true); |
| 430 } | 432 } |
| 431 | 433 |
| 432 DevToolsUI::DevToolsUI(content::WebUI* web_ui) | 434 DevToolsUI::DevToolsUI(content::WebUI* web_ui) |
| 433 : WebUIController(web_ui) { | 435 : WebUIController(web_ui) { |
| 434 web_ui->SetBindings(0); | 436 web_ui->SetBindings(0); |
| 435 Profile* profile = Profile::FromWebUI(web_ui); | 437 Profile* profile = Profile::FromWebUI(web_ui); |
| 436 content::URLDataSource::Add( | 438 content::URLDataSource::Add( |
| 437 profile, | 439 profile, |
| 438 new DevToolsDataSource(profile->GetRequestContext())); | 440 new DevToolsDataSource(profile->GetRequestContext())); |
| 439 | 441 |
| 440 GURL url = web_ui->GetWebContents()->GetVisibleURL(); | 442 GURL url = web_ui->GetWebContents()->GetVisibleURL(); |
| 441 if (url.spec() == SanitizeFrontendURL(url).spec()) | 443 if (url.spec() == SanitizeFrontendURL(url).spec()) |
| 442 bindings_.reset(new DevToolsUIBindings(web_ui->GetWebContents())); | 444 bindings_.reset(new DevToolsUIBindings(web_ui->GetWebContents())); |
| 443 } | 445 } |
| 444 | 446 |
| 445 DevToolsUI::~DevToolsUI() { | 447 DevToolsUI::~DevToolsUI() { |
| 446 } | 448 } |
| OLD | NEW |