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

Side by Side Diff: chrome/browser/android/dev_tools_server.cc

Issue 382143005: Supports DevTools socket access authentication based on Android permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Commented process_id Created 6 years, 4 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/android/dev_tools_server.h ('k') | content/browser/android/devtools_auth.cc » ('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/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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // (see the code under chrome/browser/devtools/device). 56 // (see the code under chrome/browser/devtools/device).
57 // If this string ever changes it would not be sufficient to change the 57 // If this string ever changes it would not be sufficient to change the
58 // corresponding string on the client side. Since debugging an older version of 58 // corresponding string on the client side. Since debugging an older version of
59 // Chrome for Android from a newer version of desktop Chrome is a very common 59 // Chrome for Android from a newer version of desktop Chrome is a very common
60 // scenario, the client code will have to be modified to recognize both the old 60 // scenario, the client code will have to be modified to recognize both the old
61 // and the new format. 61 // and the new format.
62 const char kDevToolsChannelNameFormat[] = "%s_devtools_remote"; 62 const char kDevToolsChannelNameFormat[] = "%s_devtools_remote";
63 63
64 const char kFrontEndURL[] = 64 const char kFrontEndURL[] =
65 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; 65 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html";
66 const char kDefaultSocketNamePrefix[] = "chrome";
67 const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d"; 66 const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d";
68 67
69 const char kTargetTypePage[] = "page"; 68 const char kTargetTypePage[] = "page";
70 const char kTargetTypeOther[] = "other"; 69 const char kTargetTypeOther[] = "other";
71 70
72 static GURL GetFaviconURLForContents(WebContents* web_contents) { 71 static GURL GetFaviconURLForContents(WebContents* web_contents) {
73 content::NavigationController& controller = web_contents->GetController(); 72 content::NavigationController& controller = web_contents->GetController();
74 content::NavigationEntry* entry = controller.GetActiveEntry(); 73 content::NavigationEntry* entry = controller.GetActiveEntry();
75 if (entry != NULL && entry->GetURL().is_valid()) 74 if (entry != NULL && entry->GetURL().is_valid())
76 return entry->GetFavicon().url; 75 return entry->GetFavicon().url;
77 return GURL(); 76 return GURL();
78 } 77 }
79 78
79 bool AuthorizeSocketAccessWithDebugPermission(
80 const net::UnixDomainServerSocket::Credentials& credentials) {
81 JNIEnv* env = base::android::AttachCurrentThread();
82 return Java_DevToolsServer_checkDebugPermission(
83 env, base::android::GetApplicationContext(),
84 credentials.process_id, credentials.user_id) ||
85 content::CanUserConnectToDevTools(credentials);
86 }
87
80 class TargetBase : public content::DevToolsTarget { 88 class TargetBase : public content::DevToolsTarget {
81 public: 89 public:
82 // content::DevToolsTarget implementation: 90 // content::DevToolsTarget implementation:
83 virtual std::string GetParentId() const OVERRIDE { return std::string(); } 91 virtual std::string GetParentId() const OVERRIDE { return std::string(); }
84 92
85 virtual std::string GetTitle() const OVERRIDE { return title_; } 93 virtual std::string GetTitle() const OVERRIDE { return title_; }
86 94
87 virtual std::string GetDescription() const OVERRIDE { return std::string(); } 95 virtual std::string GetDescription() const OVERRIDE { return std::string(); }
88 96
89 virtual GURL GetURL() const OVERRIDE { return url_; } 97 virtual GURL GetURL() const OVERRIDE { return url_; }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 269 }
262 270
263 private: 271 private:
264 scoped_refptr<DevToolsAgentHost> agent_host_; 272 scoped_refptr<DevToolsAgentHost> agent_host_;
265 }; 273 };
266 274
267 // Delegate implementation for the devtools http handler on android. A new 275 // Delegate implementation for the devtools http handler on android. A new
268 // instance of this gets created each time devtools is enabled. 276 // instance of this gets created each time devtools is enabled.
269 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { 277 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
270 public: 278 public:
271 DevToolsServerDelegate() 279 explicit DevToolsServerDelegate(
272 : last_tethering_socket_(0) { 280 const net::UnixDomainServerSocket::AuthCallback& auth_callback)
281 : last_tethering_socket_(0),
282 auth_callback_(auth_callback) {
273 } 283 }
274 284
275 virtual std::string GetDiscoveryPageHTML() OVERRIDE { 285 virtual std::string GetDiscoveryPageHTML() OVERRIDE {
276 // TopSites updates itself after a delay. Ask TopSites to update itself 286 // TopSites updates itself after a delay. Ask TopSites to update itself
277 // when we're about to show the remote debugging landing page. 287 // when we're about to show the remote debugging landing page.
278 content::BrowserThread::PostTask( 288 content::BrowserThread::PostTask(
279 content::BrowserThread::UI, 289 content::BrowserThread::UI,
280 FROM_HERE, 290 FROM_HERE,
281 base::Bind(&DevToolsServerDelegate::PopulatePageThumbnails)); 291 base::Bind(&DevToolsServerDelegate::PopulatePageThumbnails));
282 return ResourceBundle::GetSharedInstance().GetRawDataResource( 292 return ResourceBundle::GetSharedInstance().GetRawDataResource(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( 374 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
365 net::StreamListenSocket::Delegate* delegate, 375 net::StreamListenSocket::Delegate* delegate,
366 std::string* name) OVERRIDE { 376 std::string* name) OVERRIDE {
367 *name = base::StringPrintf( 377 *name = base::StringPrintf(
368 kTetheringSocketName, getpid(), ++last_tethering_socket_); 378 kTetheringSocketName, getpid(), ++last_tethering_socket_);
369 return net::deprecated::UnixDomainListenSocket:: 379 return net::deprecated::UnixDomainListenSocket::
370 CreateAndListenWithAbstractNamespace( 380 CreateAndListenWithAbstractNamespace(
371 *name, 381 *name,
372 "", 382 "",
373 delegate, 383 delegate,
374 base::Bind(&content::CanUserConnectToDevTools)) 384 auth_callback_)
375 .PassAs<net::StreamListenSocket>(); 385 .PassAs<net::StreamListenSocket>();
376 } 386 }
377 387
378 private: 388 private:
379 static void PopulatePageThumbnails() { 389 static void PopulatePageThumbnails() {
380 Profile* profile = 390 Profile* profile =
381 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); 391 ProfileManager::GetLastUsedProfile()->GetOriginalProfile();
382 history::TopSites* top_sites = profile->GetTopSites(); 392 history::TopSites* top_sites = profile->GetTopSites();
383 if (top_sites) 393 if (top_sites)
384 top_sites->SyncWithHistory(); 394 top_sites->SyncWithHistory();
385 } 395 }
386 396
387 int last_tethering_socket_; 397 int last_tethering_socket_;
398 const net::UnixDomainServerSocket::AuthCallback auth_callback_;
388 399
389 DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate); 400 DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate);
390 }; 401 };
391 402
392 } // namespace 403 } // namespace
393 404
394 DevToolsServer::DevToolsServer()
395 : socket_name_(base::StringPrintf(kDevToolsChannelNameFormat,
396 kDefaultSocketNamePrefix)),
397 protocol_handler_(NULL) {
398 // Override the default socket name if one is specified on the command line.
399 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
400 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) {
401 socket_name_ = command_line.GetSwitchValueASCII(
402 switches::kRemoteDebuggingSocketName);
403 }
404 }
405
406 DevToolsServer::DevToolsServer(const std::string& socket_name_prefix) 405 DevToolsServer::DevToolsServer(const std::string& socket_name_prefix)
407 : socket_name_(base::StringPrintf(kDevToolsChannelNameFormat, 406 : socket_name_(base::StringPrintf(kDevToolsChannelNameFormat,
408 socket_name_prefix.c_str())), 407 socket_name_prefix.c_str())),
409 protocol_handler_(NULL) { 408 protocol_handler_(NULL) {
410 // Override the socket name if one is specified on the command line. 409 // Override the socket name if one is specified on the command line.
411 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 410 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
412 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { 411 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) {
413 socket_name_ = command_line.GetSwitchValueASCII( 412 socket_name_ = command_line.GetSwitchValueASCII(
414 switches::kRemoteDebuggingSocketName); 413 switches::kRemoteDebuggingSocketName);
415 } 414 }
416 } 415 }
417 416
418 DevToolsServer::~DevToolsServer() { 417 DevToolsServer::~DevToolsServer() {
419 Stop(); 418 Stop();
420 } 419 }
421 420
422 void DevToolsServer::Start() { 421 void DevToolsServer::Start(bool allow_debug_permission) {
423 if (protocol_handler_) 422 if (protocol_handler_)
424 return; 423 return;
425 424
425 net::UnixDomainServerSocket::AuthCallback auth_callback =
426 allow_debug_permission ?
427 base::Bind(&AuthorizeSocketAccessWithDebugPermission) :
428 base::Bind(&content::CanUserConnectToDevTools);
429
426 protocol_handler_ = content::DevToolsHttpHandler::Start( 430 protocol_handler_ = content::DevToolsHttpHandler::Start(
427 new net::deprecated::UnixDomainListenSocketWithAbstractNamespaceFactory( 431 new net::deprecated::UnixDomainListenSocketWithAbstractNamespaceFactory(
428 socket_name_, 432 socket_name_,
429 base::StringPrintf("%s_%d", socket_name_.c_str(), getpid()), 433 base::StringPrintf("%s_%d", socket_name_.c_str(), getpid()),
430 base::Bind(&content::CanUserConnectToDevTools)), 434 auth_callback),
431 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), 435 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()),
432 new DevToolsServerDelegate(), 436 new DevToolsServerDelegate(auth_callback),
433 base::FilePath()); 437 base::FilePath());
434 } 438 }
435 439
436 void DevToolsServer::Stop() { 440 void DevToolsServer::Stop() {
437 if (!protocol_handler_) 441 if (!protocol_handler_)
438 return; 442 return;
439 // Note that the call to Stop() below takes care of |protocol_handler_| 443 // Note that the call to Stop() below takes care of |protocol_handler_|
440 // deletion. 444 // deletion.
441 protocol_handler_->Stop(); 445 protocol_handler_->Stop();
442 protocol_handler_ = NULL; 446 protocol_handler_ = NULL;
(...skipping 21 matching lines...) Expand all
464 468
465 static jboolean IsRemoteDebuggingEnabled(JNIEnv* env, 469 static jboolean IsRemoteDebuggingEnabled(JNIEnv* env,
466 jobject obj, 470 jobject obj,
467 jlong server) { 471 jlong server) {
468 return reinterpret_cast<DevToolsServer*>(server)->IsStarted(); 472 return reinterpret_cast<DevToolsServer*>(server)->IsStarted();
469 } 473 }
470 474
471 static void SetRemoteDebuggingEnabled(JNIEnv* env, 475 static void SetRemoteDebuggingEnabled(JNIEnv* env,
472 jobject obj, 476 jobject obj,
473 jlong server, 477 jlong server,
474 jboolean enabled) { 478 jboolean enabled,
479 jboolean allow_debug_permission) {
475 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); 480 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server);
476 if (enabled) { 481 if (enabled) {
477 devtools_server->Start(); 482 devtools_server->Start(allow_debug_permission);
478 } else { 483 } else {
479 devtools_server->Stop(); 484 devtools_server->Stop();
480 } 485 }
481 } 486 }
OLDNEW
« no previous file with comments | « chrome/browser/android/dev_tools_server.h ('k') | content/browser/android/devtools_auth.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698