Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: chrome/browser/ui/webui/devtools_ui.cc

Issue 2109243003: Introduce --remote-debugging-frontend switch for custom remote debugging front-end (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: support absolute path instead of HTTP endpoint Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/devtools/remote_debugging_server.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_util.h" 10 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
13 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/devtools_frontend_host.h" 16 #include "content/public/browser/devtools_frontend_host.h"
15 #include "content/public/browser/url_data_source.h" 17 #include "content/public/browser/url_data_source.h"
16 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_ui.h" 19 #include "content/public/browser/web_ui.h"
18 #include "content/public/common/user_agent.h" 20 #include "content/public/common/user_agent.h"
21 #include "net/base/filename_util.h"
22 #include "net/base/load_flags.h"
19 #include "net/url_request/url_fetcher.h" 23 #include "net/url_request/url_fetcher.h"
20 #include "net/url_request/url_fetcher_delegate.h" 24 #include "net/url_request/url_fetcher_delegate.h"
21 #include "net/url_request/url_request_context_getter.h" 25 #include "net/url_request/url_request_context_getter.h"
22 26
23 using content::BrowserThread; 27 using content::BrowserThread;
24 using content::WebContents; 28 using content::WebContents;
25 29
26 namespace { 30 namespace {
27 31
28 std::string PathWithoutParams(const std::string& path) { 32 std::string PathWithoutParams(const std::string& path) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 int render_process_id, 112 int render_process_id,
109 int render_frame_id, 113 int render_frame_id,
110 const GotDataCallback& callback); 114 const GotDataCallback& callback);
111 115
112 // Serves remote DevTools frontend from hard-coded App Engine domain. 116 // Serves remote DevTools frontend from hard-coded App Engine domain.
113 void StartRemoteDataRequest(const std::string& path, 117 void StartRemoteDataRequest(const std::string& path,
114 int render_process_id, 118 int render_process_id,
115 int render_frame_id, 119 int render_frame_id,
116 const GotDataCallback& callback); 120 const GotDataCallback& callback);
117 121
122 // Serves remote DevTools frontend from any endpoint, passed through
123 // command-line flag.
124 void StartCustomDataRequest(const GURL& url,
125 int render_process_id,
126 int render_frame_id,
127 const GotDataCallback& callback);
128
118 ~DevToolsDataSource() override; 129 ~DevToolsDataSource() override;
119 130
120 scoped_refptr<net::URLRequestContextGetter> request_context_; 131 scoped_refptr<net::URLRequestContextGetter> request_context_;
121 132
122 using PendingRequestsMap = std::map<const net::URLFetcher*, GotDataCallback>; 133 using PendingRequestsMap = std::map<const net::URLFetcher*, GotDataCallback>;
123 PendingRequestsMap pending_; 134 PendingRequestsMap pending_;
124 135
125 DISALLOW_COPY_AND_ASSIGN(DevToolsDataSource); 136 DISALLOW_COPY_AND_ASSIGN(DevToolsDataSource);
126 }; 137 };
127 138
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // Serve request from remote location. 171 // Serve request from remote location.
161 std::string remote_path_prefix(chrome::kChromeUIDevToolsRemotePath); 172 std::string remote_path_prefix(chrome::kChromeUIDevToolsRemotePath);
162 remote_path_prefix += "/"; 173 remote_path_prefix += "/";
163 if (base::StartsWith(path, remote_path_prefix, 174 if (base::StartsWith(path, remote_path_prefix,
164 base::CompareCase::INSENSITIVE_ASCII)) { 175 base::CompareCase::INSENSITIVE_ASCII)) {
165 StartRemoteDataRequest(path.substr(remote_path_prefix.length()), 176 StartRemoteDataRequest(path.substr(remote_path_prefix.length()),
166 render_process_id, render_frame_id, callback); 177 render_process_id, render_frame_id, callback);
167 return; 178 return;
168 } 179 }
169 180
181 base::FilePath remote_frontend_path =
182 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
183 switches::kRemoteDebuggingFrontend);
184
185 if (remote_frontend_path.empty()) {
186 callback.Run(NULL);
187 return;
188 }
189
190 // Serve request from custom location.
191 std::string custom_path_prefix(chrome::kChromeUIDevToolsCustomPath);
192 custom_path_prefix += "/";
193
194 // Generated files should be fetched from bundle.
195 if (base::StartsWith(path, custom_path_prefix + "gen/",
196 base::CompareCase::INSENSITIVE_ASCII)) {
197 StartBundledDataRequest(path.substr(custom_path_prefix.length()),
198 render_process_id, render_frame_id, callback);
199 return;
200 }
201 if (base::StartsWith(path, custom_path_prefix,
202 base::CompareCase::INSENSITIVE_ASCII)) {
203 // Create a dummy url to extract path.
204 GURL dummy_url =
205 GURL("http://example.com/" + path.substr(custom_path_prefix.length()));
206 std::string dummy_url_path = dummy_url.path();
207 base::FilePath file_path(base::FilePath::StringType(dummy_url_path.begin(),
208 dummy_url_path.end()));
209 file_path = remote_frontend_path.Append(file_path);
210 GURL url = net::FilePathToFileURL(file_path);
211 StartCustomDataRequest(url, render_process_id, render_frame_id, callback);
212 return;
213 }
214
170 callback.Run(NULL); 215 callback.Run(NULL);
171 } 216 }
172 217
173 std::string DevToolsDataSource::GetMimeType(const std::string& path) const { 218 std::string DevToolsDataSource::GetMimeType(const std::string& path) const {
174 return GetMimeTypeForPath(path); 219 return GetMimeTypeForPath(path);
175 } 220 }
176 221
177 bool DevToolsDataSource::ShouldAddContentSecurityPolicy() const { 222 bool DevToolsDataSource::ShouldAddContentSecurityPolicy() const {
178 return false; 223 return false;
179 } 224 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 new base::RefCountedStaticMemory(kHttpNotFound, strlen(kHttpNotFound))); 261 new base::RefCountedStaticMemory(kHttpNotFound, strlen(kHttpNotFound)));
217 return; 262 return;
218 } 263 }
219 net::URLFetcher* fetcher = 264 net::URLFetcher* fetcher =
220 net::URLFetcher::Create(url, net::URLFetcher::GET, this).release(); 265 net::URLFetcher::Create(url, net::URLFetcher::GET, this).release();
221 pending_[fetcher] = callback; 266 pending_[fetcher] = callback;
222 fetcher->SetRequestContext(request_context_.get()); 267 fetcher->SetRequestContext(request_context_.get());
223 fetcher->Start(); 268 fetcher->Start();
224 } 269 }
225 270
271 void DevToolsDataSource::StartCustomDataRequest(
272 const GURL& url,
273 int render_process_id,
274 int render_frame_id,
275 const content::URLDataSource::GotDataCallback& callback) {
276 if (!url.is_valid()) {
277 callback.Run(
278 new base::RefCountedStaticMemory(kHttpNotFound, strlen(kHttpNotFound)));
279 return;
280 }
281 net::URLFetcher* fetcher =
282 net::URLFetcher::Create(url, net::URLFetcher::GET, this).release();
283 pending_[fetcher] = callback;
284 fetcher->SetRequestContext(request_context_.get());
285 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
286 fetcher->Start();
287 }
288
226 void DevToolsDataSource::OnURLFetchComplete(const net::URLFetcher* source) { 289 void DevToolsDataSource::OnURLFetchComplete(const net::URLFetcher* source) {
227 DCHECK(source); 290 DCHECK(source);
228 PendingRequestsMap::iterator it = pending_.find(source); 291 PendingRequestsMap::iterator it = pending_.find(source);
229 DCHECK(it != pending_.end()); 292 DCHECK(it != pending_.end());
230 std::string response; 293 std::string response;
231 source->GetResponseAsString(&response); 294 source->GetResponseAsString(&response);
232 delete source; 295 delete source;
233 it->second.Run(base::RefCountedString::TakeString(&response)); 296 it->second.Run(base::RefCountedString::TakeString(&response));
234 pending_.erase(it); 297 pending_.erase(it);
235 } 298 }
(...skipping 28 matching lines...) Expand all
264 bindings_(web_ui->GetWebContents()) { 327 bindings_(web_ui->GetWebContents()) {
265 web_ui->SetBindings(0); 328 web_ui->SetBindings(0);
266 Profile* profile = Profile::FromWebUI(web_ui); 329 Profile* profile = Profile::FromWebUI(web_ui);
267 content::URLDataSource::Add( 330 content::URLDataSource::Add(
268 profile, 331 profile,
269 new DevToolsDataSource(profile->GetRequestContext())); 332 new DevToolsDataSource(profile->GetRequestContext()));
270 } 333 }
271 334
272 DevToolsUI::~DevToolsUI() { 335 DevToolsUI::~DevToolsUI() {
273 } 336 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/remote_debugging_server.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698