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

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: Packing parameters to a stucture 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
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 const char kTargetTypeOther[] = "other"; 70 const char kTargetTypeOther[] = "other";
71 71
72 static GURL GetFaviconURLForContents(WebContents* web_contents) { 72 static GURL GetFaviconURLForContents(WebContents* web_contents) {
73 content::NavigationController& controller = web_contents->GetController(); 73 content::NavigationController& controller = web_contents->GetController();
74 content::NavigationEntry* entry = controller.GetActiveEntry(); 74 content::NavigationEntry* entry = controller.GetActiveEntry();
75 if (entry != NULL && entry->GetURL().is_valid()) 75 if (entry != NULL && entry->GetURL().is_valid())
76 return entry->GetFavicon().url; 76 return entry->GetFavicon().url;
77 return GURL(); 77 return GURL();
78 } 78 }
79 79
80 bool AuthenticateSocketAccess(
81 const net::UnixDomainServerSocket::Credentials& credentials) {
82 JNIEnv* env = base::android::AttachCurrentThread();
83 return Java_DevToolsServer_checkPermission(env,
84 credentials.process_id, credentials.user_id) ||
byungchul 2014/08/04 22:18:02 wrong indentation. Should be aligned to '(', or li
SeRya 2014/08/05 10:32:27 Done.
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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( 372 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
365 net::StreamListenSocket::Delegate* delegate, 373 net::StreamListenSocket::Delegate* delegate,
366 std::string* name) OVERRIDE { 374 std::string* name) OVERRIDE {
367 *name = base::StringPrintf( 375 *name = base::StringPrintf(
368 kTetheringSocketName, getpid(), ++last_tethering_socket_); 376 kTetheringSocketName, getpid(), ++last_tethering_socket_);
369 return net::deprecated::UnixDomainListenSocket:: 377 return net::deprecated::UnixDomainListenSocket::
370 CreateAndListenWithAbstractNamespace( 378 CreateAndListenWithAbstractNamespace(
371 *name, 379 *name,
372 "", 380 "",
373 delegate, 381 delegate,
374 base::Bind(&content::CanUserConnectToDevTools)) 382 base::Bind(&AuthenticateSocketAccess))
375 .PassAs<net::StreamListenSocket>(); 383 .PassAs<net::StreamListenSocket>();
376 } 384 }
377 385
378 private: 386 private:
379 static void PopulatePageThumbnails() { 387 static void PopulatePageThumbnails() {
380 Profile* profile = 388 Profile* profile =
381 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); 389 ProfileManager::GetLastUsedProfile()->GetOriginalProfile();
382 history::TopSites* top_sites = profile->GetTopSites(); 390 history::TopSites* top_sites = profile->GetTopSites();
383 if (top_sites) 391 if (top_sites)
384 top_sites->SyncWithHistory(); 392 top_sites->SyncWithHistory();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 428 }
421 429
422 void DevToolsServer::Start() { 430 void DevToolsServer::Start() {
423 if (protocol_handler_) 431 if (protocol_handler_)
424 return; 432 return;
425 433
426 protocol_handler_ = content::DevToolsHttpHandler::Start( 434 protocol_handler_ = content::DevToolsHttpHandler::Start(
427 new net::deprecated::UnixDomainListenSocketWithAbstractNamespaceFactory( 435 new net::deprecated::UnixDomainListenSocketWithAbstractNamespaceFactory(
428 socket_name_, 436 socket_name_,
429 base::StringPrintf("%s_%d", socket_name_.c_str(), getpid()), 437 base::StringPrintf("%s_%d", socket_name_.c_str(), getpid()),
430 base::Bind(&content::CanUserConnectToDevTools)), 438 base::Bind(&AuthenticateSocketAccess)),
431 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), 439 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()),
432 new DevToolsServerDelegate(), 440 new DevToolsServerDelegate(),
433 base::FilePath()); 441 base::FilePath());
434 } 442 }
435 443
436 void DevToolsServer::Stop() { 444 void DevToolsServer::Stop() {
437 if (!protocol_handler_) 445 if (!protocol_handler_)
438 return; 446 return;
439 // Note that the call to Stop() below takes care of |protocol_handler_| 447 // Note that the call to Stop() below takes care of |protocol_handler_|
440 // deletion. 448 // deletion.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 jobject obj, 480 jobject obj,
473 jlong server, 481 jlong server,
474 jboolean enabled) { 482 jboolean enabled) {
475 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); 483 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server);
476 if (enabled) { 484 if (enabled) {
477 devtools_server->Start(); 485 devtools_server->Start();
478 } else { 486 } else {
479 devtools_server->Stop(); 487 devtools_server->Stop();
480 } 488 }
481 } 489 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698