| 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/android/dev_tools_server.h" | 5 #include "chrome/browser/android/dev_tools_server.h" |
| 6 | 6 |
| 7 #include <pwd.h> | 7 #include <pwd.h> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "content/public/browser/favicon_status.h" | 33 #include "content/public/browser/favicon_status.h" |
| 34 #include "content/public/browser/navigation_entry.h" | 34 #include "content/public/browser/navigation_entry.h" |
| 35 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
| 36 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 37 #include "content/public/browser/web_contents_delegate.h" | 37 #include "content/public/browser/web_contents_delegate.h" |
| 38 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
| 39 #include "content/public/common/url_constants.h" | 39 #include "content/public/common/url_constants.h" |
| 40 #include "content/public/common/user_agent.h" | 40 #include "content/public/common/user_agent.h" |
| 41 #include "grit/browser_resources.h" | 41 #include "grit/browser_resources.h" |
| 42 #include "jni/DevToolsServer_jni.h" | 42 #include "jni/DevToolsServer_jni.h" |
| 43 #include "net/socket/unix_domain_socket_posix.h" | 43 #include "net/base/net_errors.h" |
| 44 #include "net/socket/unix_domain_listen_socket_posix.h" |
| 45 #include "net/socket/unix_domain_server_socket_posix.h" |
| 44 #include "net/url_request/url_request_context_getter.h" | 46 #include "net/url_request/url_request_context_getter.h" |
| 45 #include "ui/base/resource/resource_bundle.h" | 47 #include "ui/base/resource/resource_bundle.h" |
| 46 | 48 |
| 47 using content::DevToolsAgentHost; | 49 using content::DevToolsAgentHost; |
| 48 using content::RenderViewHost; | 50 using content::RenderViewHost; |
| 49 using content::WebContents; | 51 using content::WebContents; |
| 50 | 52 |
| 51 namespace { | 53 namespace { |
| 52 | 54 |
| 53 // TL;DR: Do not change this string. | 55 // TL;DR: Do not change this string. |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 361 } |
| 360 | 362 |
| 361 callback.Run(targets); | 363 callback.Run(targets); |
| 362 } | 364 } |
| 363 | 365 |
| 364 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( | 366 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( |
| 365 net::StreamListenSocket::Delegate* delegate, | 367 net::StreamListenSocket::Delegate* delegate, |
| 366 std::string* name) OVERRIDE { | 368 std::string* name) OVERRIDE { |
| 367 *name = base::StringPrintf( | 369 *name = base::StringPrintf( |
| 368 kTetheringSocketName, getpid(), ++last_tethering_socket_); | 370 kTetheringSocketName, getpid(), ++last_tethering_socket_); |
| 369 return net::UnixDomainSocket::CreateAndListenWithAbstractNamespace( | 371 return net::UnixDomainListenSocket::CreateAndListenWithAbstractNamespace( |
| 370 *name, | 372 *name, |
| 371 "", | 373 "", |
| 372 delegate, | 374 delegate, |
| 373 base::Bind(&content::CanUserConnectToDevTools)) | 375 base::Bind(&content::CanUserConnectToDevTools)) |
| 374 .PassAs<net::StreamListenSocket>(); | 376 .PassAs<net::StreamListenSocket>(); |
| 375 } | 377 } |
| 376 | 378 |
| 377 private: | 379 private: |
| 378 static void PopulatePageThumbnails() { | 380 static void PopulatePageThumbnails() { |
| 379 Profile* profile = | 381 Profile* profile = |
| 380 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); | 382 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
| 381 history::TopSites* top_sites = profile->GetTopSites(); | 383 history::TopSites* top_sites = profile->GetTopSites(); |
| 382 if (top_sites) | 384 if (top_sites) |
| 383 top_sites->SyncWithHistory(); | 385 top_sites->SyncWithHistory(); |
| 384 } | 386 } |
| 385 | 387 |
| 386 int last_tethering_socket_; | 388 int last_tethering_socket_; |
| 387 | 389 |
| 388 DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate); | 390 DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate); |
| 389 }; | 391 }; |
| 390 | 392 |
| 393 // Factory for UnixDomainServerSocket. It tries a fallback socket when |
| 394 // original socket doesn't work. |
| 395 class UnixDomainServerSocketFactory |
| 396 : public content::DevToolsHttpHandler::ServerSocketFactory { |
| 397 public: |
| 398 explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
| 399 : content::DevToolsHttpHandler::ServerSocketFactory(socket_name, 0, 1) {} |
| 400 |
| 401 private: |
| 402 // content::DevToolsHttpHandler::ServerSocketFactory. |
| 403 virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE { |
| 404 return scoped_ptr<net::ServerSocket>( |
| 405 new net::UnixDomainServerSocket( |
| 406 base::Bind(&content::CanUserConnectToDevTools), |
| 407 true)); |
| 408 } |
| 409 |
| 410 virtual scoped_ptr<net::ServerSocket> CreateAndListen() const OVERRIDE { |
| 411 scoped_ptr<net::ServerSocket> socket = Create(); |
| 412 if (!socket) |
| 413 return scoped_ptr<net::ServerSocket>(); |
| 414 |
| 415 if (socket->ListenWithAddressAndPort(address_, port_, backlog_) == net::OK) |
| 416 return socket.Pass(); |
| 417 |
| 418 // Tries a fallback socket name. |
| 419 const std::string fallback_address( |
| 420 base::StringPrintf("%s_%d", address_.c_str(), getpid())); |
| 421 if (socket->ListenWithAddressAndPort(fallback_address, port_, backlog_) |
| 422 == net::OK) |
| 423 return socket.Pass(); |
| 424 |
| 425 return scoped_ptr<net::ServerSocket>(); |
| 426 } |
| 427 |
| 428 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); |
| 429 }; |
| 430 |
| 391 } // namespace | 431 } // namespace |
| 392 | 432 |
| 393 DevToolsServer::DevToolsServer() | 433 DevToolsServer::DevToolsServer() |
| 394 : socket_name_(base::StringPrintf(kDevToolsChannelNameFormat, | 434 : socket_name_(base::StringPrintf(kDevToolsChannelNameFormat, |
| 395 kDefaultSocketNamePrefix)), | 435 kDefaultSocketNamePrefix)), |
| 396 protocol_handler_(NULL) { | 436 protocol_handler_(NULL) { |
| 397 // Override the default socket name if one is specified on the command line. | 437 // Override the default socket name if one is specified on the command line. |
| 398 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 438 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 399 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { | 439 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { |
| 400 socket_name_ = command_line.GetSwitchValueASCII( | 440 socket_name_ = command_line.GetSwitchValueASCII( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 415 } | 455 } |
| 416 | 456 |
| 417 DevToolsServer::~DevToolsServer() { | 457 DevToolsServer::~DevToolsServer() { |
| 418 Stop(); | 458 Stop(); |
| 419 } | 459 } |
| 420 | 460 |
| 421 void DevToolsServer::Start() { | 461 void DevToolsServer::Start() { |
| 422 if (protocol_handler_) | 462 if (protocol_handler_) |
| 423 return; | 463 return; |
| 424 | 464 |
| 465 scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> factory( |
| 466 new UnixDomainServerSocketFactory(socket_name_)); |
| 425 protocol_handler_ = content::DevToolsHttpHandler::Start( | 467 protocol_handler_ = content::DevToolsHttpHandler::Start( |
| 426 new net::UnixDomainSocketWithAbstractNamespaceFactory( | 468 factory.Pass(), |
| 427 socket_name_, | |
| 428 base::StringPrintf("%s_%d", socket_name_.c_str(), getpid()), | |
| 429 base::Bind(&content::CanUserConnectToDevTools)), | |
| 430 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), | 469 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), |
| 431 new DevToolsServerDelegate(), | 470 new DevToolsServerDelegate(), |
| 432 base::FilePath()); | 471 base::FilePath()); |
| 433 } | 472 } |
| 434 | 473 |
| 435 void DevToolsServer::Stop() { | 474 void DevToolsServer::Stop() { |
| 436 if (!protocol_handler_) | 475 if (!protocol_handler_) |
| 437 return; | 476 return; |
| 438 // Note that the call to Stop() below takes care of |protocol_handler_| | 477 // Note that the call to Stop() below takes care of |protocol_handler_| |
| 439 // deletion. | 478 // deletion. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 jobject obj, | 510 jobject obj, |
| 472 jlong server, | 511 jlong server, |
| 473 jboolean enabled) { | 512 jboolean enabled) { |
| 474 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); | 513 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); |
| 475 if (enabled) { | 514 if (enabled) { |
| 476 devtools_server->Start(); | 515 devtools_server->Start(); |
| 477 } else { | 516 } else { |
| 478 devtools_server->Stop(); | 517 devtools_server->Stop(); |
| 479 } | 518 } |
| 480 } | 519 } |
| OLD | NEW |