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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 .path().substr(1); | 33 .path().substr(1); |
34 } | 34 } |
35 | 35 |
36 const char kRemoteFrontendDomain[] = "chrome-devtools-frontend.appspot.com"; | 36 const char kRemoteFrontendDomain[] = "chrome-devtools-frontend.appspot.com"; |
37 const char kRemoteFrontendBase[] = | 37 const char kRemoteFrontendBase[] = |
38 "https://chrome-devtools-frontend.appspot.com/"; | 38 "https://chrome-devtools-frontend.appspot.com/"; |
39 const char kHttpNotFound[] = "HTTP/1.1 404 Not Found\n\n"; | 39 const char kHttpNotFound[] = "HTTP/1.1 404 Not Found\n\n"; |
40 | 40 |
41 #if defined(DEBUG_DEVTOOLS) | 41 #if defined(DEBUG_DEVTOOLS) |
42 // Local frontend url provided by InspectUI. | 42 // Local frontend url provided by InspectUI. |
43 const char kLocalFrontendURL[] = | 43 const char kFallbackFrontendURL[] = |
44 "chrome-devtools://devtools/bundled/devtools.html"; | 44 "chrome-devtools://devtools/bundled/devtools.html"; |
| 45 #else |
| 46 // URL causing the DevTools window to display a plain text warning. |
| 47 const char kFallbackFrontendURL[] = |
| 48 "data:text/plain,Cannot load DevTools frontend from an untrusted origin"; |
45 #endif // defined(DEBUG_DEVTOOLS) | 49 #endif // defined(DEBUG_DEVTOOLS) |
46 | 50 |
| 51 |
47 class FetchRequest : public net::URLFetcherDelegate { | 52 class FetchRequest : public net::URLFetcherDelegate { |
48 public: | 53 public: |
49 FetchRequest(net::URLRequestContextGetter* request_context, | 54 FetchRequest(net::URLRequestContextGetter* request_context, |
50 const GURL& url, | 55 const GURL& url, |
51 const content::URLDataSource::GotDataCallback& callback) | 56 const content::URLDataSource::GotDataCallback& callback) |
52 : callback_(callback) { | 57 : callback_(callback) { |
53 if (!url.is_valid()) { | 58 if (!url.is_valid()) { |
54 OnURLFetchComplete(NULL); | 59 OnURLFetchComplete(NULL); |
55 return; | 60 return; |
56 } | 61 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 scoped_refptr<net::URLRequestContextGetter> request_context_; | 188 scoped_refptr<net::URLRequestContextGetter> request_context_; |
184 | 189 |
185 DISALLOW_COPY_AND_ASSIGN(DevToolsDataSource); | 190 DISALLOW_COPY_AND_ASSIGN(DevToolsDataSource); |
186 }; | 191 }; |
187 | 192 |
188 } // namespace | 193 } // namespace |
189 | 194 |
190 // static | 195 // static |
191 GURL DevToolsUI::GetProxyURL(const std::string& frontend_url) { | 196 GURL DevToolsUI::GetProxyURL(const std::string& frontend_url) { |
192 GURL url(frontend_url); | 197 GURL url(frontend_url); |
193 #if defined(DEBUG_DEVTOOLS) | |
194 if (!url.is_valid() || url.host() != kRemoteFrontendDomain) { | 198 if (!url.is_valid() || url.host() != kRemoteFrontendDomain) { |
195 return GURL(kLocalFrontendURL); | 199 return GURL(kFallbackFrontendURL); |
196 } | 200 } |
197 #endif // defined(DEBUG_DEVTOOLS) | |
198 CHECK(url.is_valid()); | |
199 CHECK_EQ(url.host(), kRemoteFrontendDomain); | |
200 return GURL(base::StringPrintf("%s://%s/%s/%s", | 201 return GURL(base::StringPrintf("%s://%s/%s/%s", |
201 chrome::kChromeDevToolsScheme, | 202 chrome::kChromeDevToolsScheme, |
202 chrome::kChromeUIDevToolsHost, | 203 chrome::kChromeUIDevToolsHost, |
203 chrome::kChromeUIDevToolsRemotePath, | 204 chrome::kChromeUIDevToolsRemotePath, |
204 url.path().substr(1).c_str())); | 205 url.path().substr(1).c_str())); |
205 } | 206 } |
206 | 207 |
207 DevToolsUI::DevToolsUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 208 DevToolsUI::DevToolsUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
208 web_ui->SetBindings(0); | 209 web_ui->SetBindings(0); |
209 Profile* profile = Profile::FromWebUI(web_ui); | 210 Profile* profile = Profile::FromWebUI(web_ui); |
210 content::URLDataSource::Add( | 211 content::URLDataSource::Add( |
211 profile, | 212 profile, |
212 new DevToolsDataSource(profile->GetRequestContext())); | 213 new DevToolsDataSource(profile->GetRequestContext())); |
213 } | 214 } |
OLD | NEW |