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

Side by Side Diff: chrome/browser/debugger/devtools_http_protocol_handler.cc

Issue 6356015: DevTools: enable remote debugging with front-end served from the cloud. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Extra qualification removed. Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/debugger/devtools_http_protocol_handler.h" 5 #include "chrome/browser/debugger/devtools_http_protocol_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // Message handling routines 64 // Message handling routines
65 void OnDispatchOnInspectorFrontend(const std::string& data) { 65 void OnDispatchOnInspectorFrontend(const std::string& data) {
66 socket_->SendOverWebSocket(data); 66 socket_->SendOverWebSocket(data);
67 } 67 }
68 virtual void FrameNavigating(const std::string& url) {} 68 virtual void FrameNavigating(const std::string& url) {}
69 HttpListenSocket* socket_; 69 HttpListenSocket* socket_;
70 }; 70 };
71 71
72 } // namespace 72 } // namespace
73 73
74
75 // static
76 DevToolsHttpProtocolHandler* DevToolsHttpProtocolHandler::Start(
77 int port,
78 const std::string& frontend_url) {
79 scoped_refptr<DevToolsHttpProtocolHandler> http_handler =
80 new DevToolsHttpProtocolHandler(port, frontend_url);
81 http_handler->Start();
82 return http_handler.get();
yurys 2011/01/31 14:58:24 You should return scoped_refptr to makes sure the
pfeldman 2011/01/31 15:15:54 Done.
83 }
84
74 DevToolsHttpProtocolHandler::~DevToolsHttpProtocolHandler() { 85 DevToolsHttpProtocolHandler::~DevToolsHttpProtocolHandler() {
75 // Stop() must be called prior to this being called 86 // Stop() must be called prior to this being called
76 DCHECK(server_.get() == NULL); 87 DCHECK(server_.get() == NULL);
77 } 88 }
78 89
79 void DevToolsHttpProtocolHandler::Start() { 90 void DevToolsHttpProtocolHandler::Start() {
80 BrowserThread::PostTask( 91 BrowserThread::PostTask(
81 BrowserThread::IO, FROM_HERE, 92 BrowserThread::IO, FROM_HERE,
82 NewRunnableMethod(this, &DevToolsHttpProtocolHandler::Init)); 93 NewRunnableMethod(this, &DevToolsHttpProtocolHandler::Init));
83 } 94 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 FROM_HERE, 174 FROM_HERE,
164 NewRunnableMethod( 175 NewRunnableMethod(
165 this, 176 this,
166 &DevToolsHttpProtocolHandler::OnCloseUI, 177 &DevToolsHttpProtocolHandler::OnCloseUI,
167 make_scoped_refptr(socket))); 178 make_scoped_refptr(socket)));
168 } 179 }
169 180
170 void DevToolsHttpProtocolHandler::OnHttpRequestUI( 181 void DevToolsHttpProtocolHandler::OnHttpRequestUI(
171 HttpListenSocket* socket, 182 HttpListenSocket* socket,
172 const HttpServerRequestInfo& info) { 183 const HttpServerRequestInfo& info) {
173 std::string response = "<html><body>"; 184 std::string response = "<html><body><script>"
185 "function addTab(id, url, attached, frontendUrl) {"
186 " if (!attached) {"
187 " var a = document.createElement('a');"
188 " a.textContent = url;"
189 " a.href = frontendUrl + '?remotehost=' + window.location.host +"
190 "'&pageId=' + id;"
yurys 2011/01/31 14:58:24 nit: wrong alignment
pfeldman 2011/01/31 15:15:54 Done.
191 " document.body.appendChild(a);"
192 " } else {"
193 " var span = document.createElement('span');"
194 " span.textContent = url + ' (attached)';"
195 " document.body.appendChild(span);"
196 " }"
197 " document.body.appendChild(document.createElement('br'));"
198 "}";
199
174 for (BrowserList::const_iterator it = BrowserList::begin(), 200 for (BrowserList::const_iterator it = BrowserList::begin(),
175 end = BrowserList::end(); it != end; ++it) { 201 end = BrowserList::end(); it != end; ++it) {
176 TabStripModel* model = (*it)->tabstrip_model(); 202 TabStripModel* model = (*it)->tabstrip_model();
177 for (int i = 0, size = model->count(); i < size; ++i) { 203 for (int i = 0, size = model->count(); i < size; ++i) {
178 TabContentsWrapper* tab_contents = model->GetTabContentsAt(i); 204 TabContentsWrapper* tab_contents = model->GetTabContentsAt(i);
179 NavigationController& controller = tab_contents->controller(); 205 NavigationController& controller = tab_contents->controller();
180 NavigationEntry* entry = controller.GetActiveEntry(); 206 NavigationEntry* entry = controller.GetActiveEntry();
181 if (entry == NULL) 207 if (entry == NULL)
182 continue; 208 continue;
183 209
184 if (!entry->url().is_valid()) 210 if (!entry->url().is_valid())
185 continue; 211 continue;
186 212
187 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> 213 DevToolsClientHost* client_host = DevToolsManager::GetInstance()->
188 GetDevToolsClientHostFor(tab_contents->tab_contents()-> 214 GetDevToolsClientHostFor(tab_contents->tab_contents()->
189 render_view_host()); 215 render_view_host());
190 if (!client_host) { 216 response += StringPrintf(
191 response += StringPrintf( 217 "addTab(%d, '%s', %s, '%s');\n",
192 "<a href='/devtools/devtools.html?page=%d'>%s (%s)</a><br>", 218 controller.session_id().id(),
193 controller.session_id().id(), 219 entry->url().spec().c_str(),
194 UTF16ToUTF8(entry->title()).c_str(), 220 client_host ? "true" : "false",
195 entry->url().spec().c_str()); 221 overriden_frontend_url_.c_str());
196 } else {
197 response += StringPrintf(
198 "%s (%s)<br>",
199 UTF16ToUTF8(entry->title()).c_str(),
200 entry->url().spec().c_str());
201 }
202 } 222 }
203 } 223 }
204 response += "</body></html>"; 224 response += "</script></body></html>";
205 Send200(socket, response, "text/html; charset=UTF-8"); 225 Send200(socket, response, "text/html; charset=UTF-8");
206 } 226 }
207 227
208 void DevToolsHttpProtocolHandler::OnWebSocketRequestUI( 228 void DevToolsHttpProtocolHandler::OnWebSocketRequestUI(
209 HttpListenSocket* socket, 229 HttpListenSocket* socket,
210 const HttpServerRequestInfo& request) { 230 const HttpServerRequestInfo& request) {
211 std::string prefix = "/devtools/page/"; 231 std::string prefix = "/devtools/page/";
212 size_t pos = request.path.find(prefix); 232 size_t pos = request.path.find(prefix);
213 if (pos != 0) { 233 if (pos != 0) {
214 Send404(socket); 234 Send404(socket);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 if (!request->status().is_success() || bytes_read <= 0) 353 if (!request->status().is_success() || bytes_read <= 0)
334 break; 354 break;
335 socket->Send(buffer->data(), bytes_read); 355 socket->Send(buffer->data(), bytes_read);
336 } while (request->Read(buffer, kBufferSize, &bytes_read)); 356 } while (request->Read(buffer, kBufferSize, &bytes_read));
337 357
338 // See comments re: HEAD requests in OnResponseStarted(). 358 // See comments re: HEAD requests in OnResponseStarted().
339 if (!request->status().is_io_pending()) 359 if (!request->status().is_io_pending())
340 RequestCompleted(request); 360 RequestCompleted(request);
341 } 361 }
342 362
343 DevToolsHttpProtocolHandler::DevToolsHttpProtocolHandler(int port) 363 DevToolsHttpProtocolHandler::DevToolsHttpProtocolHandler(
364 int port,
365 const std::string& frontend_host)
344 : port_(port), 366 : port_(port),
367 overriden_frontend_url_(frontend_host),
345 server_(NULL) { 368 server_(NULL) {
369 if (overriden_frontend_url_.empty())
370 overriden_frontend_url_ = "/devtools/devtools.html";
yurys 2011/01/31 14:58:24 is there a constant for devtools.html ?
pfeldman 2011/01/31 15:15:54 Not really.
346 } 371 }
347 372
348 void DevToolsHttpProtocolHandler::Init() { 373 void DevToolsHttpProtocolHandler::Init() {
349 server_ = HttpListenSocket::Listen("127.0.0.1", port_, this); 374 server_ = HttpListenSocket::Listen("127.0.0.1", port_, this);
350 } 375 }
351 376
352 // Run on I/O thread 377 // Run on I/O thread
353 void DevToolsHttpProtocolHandler::Teardown() { 378 void DevToolsHttpProtocolHandler::Teardown() {
354 server_ = NULL; 379 server_ = NULL;
355 } 380 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 void DevToolsHttpProtocolHandler::ReleaseSocket( 446 void DevToolsHttpProtocolHandler::ReleaseSocket(
422 HttpListenSocket* socket) { 447 HttpListenSocket* socket) {
423 // This in fact is scoped ref ptr. It'll get nuked on exit. 448 // This in fact is scoped ref ptr. It'll get nuked on exit.
424 } 449 }
425 450
426 TabContents* DevToolsHttpProtocolHandler::GetTabContents(int session_id) { 451 TabContents* DevToolsHttpProtocolHandler::GetTabContents(int session_id) {
427 for (BrowserList::const_iterator it = BrowserList::begin(), 452 for (BrowserList::const_iterator it = BrowserList::begin(),
428 end = BrowserList::end(); it != end; ++it) { 453 end = BrowserList::end(); it != end; ++it) {
429 TabStripModel* model = (*it)->tabstrip_model(); 454 TabStripModel* model = (*it)->tabstrip_model();
430 for (int i = 0, size = model->count(); i < size; ++i) { 455 for (int i = 0, size = model->count(); i < size; ++i) {
456 TabContentsWrapper* tab_contents = model->GetTabContentsAt(i);
431 NavigationController& controller = 457 NavigationController& controller =
432 model->GetTabContentsAt(i)->controller(); 458 tab_contents->controller();
433 if (controller.session_id().id() == session_id) 459 if (controller.session_id().id() == session_id)
434 return controller.tab_contents(); 460 return controller.tab_contents();
435 } 461 }
436 } 462 }
437 return NULL; 463 return NULL;
438 } 464 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698