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

Side by Side Diff: chrome/browser/extensions/extension_web_socket_proxy_private_api.cc

Issue 9317013: Add a centralized mechanism for whitelisting access to extension permissions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 8 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extensions/extension_web_socket_proxy_private_api.h" 5 #include "chrome/browser/extensions/extension_web_socket_proxy_private_api.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/internal_auth.h" 12 #include "chrome/browser/internal_auth.h"
13 #include "chrome/browser/io_thread.h" 13 #include "chrome/browser/io_thread.h"
14 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
19 #include "net/base/escape.h" 19 #include "net/base/escape.h"
20 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
21 #include "net/base/net_log.h" 21 #include "net/base/net_log.h"
22 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
23 #include "net/base/single_request_host_resolver.h" 23 #include "net/base/single_request_host_resolver.h"
24 24
25 #if defined(OS_CHROMEOS) 25 #if defined(OS_CHROMEOS)
26 #include "chrome/browser/chromeos/web_socket_proxy_controller.h" 26 #include "chrome/browser/chromeos/web_socket_proxy_controller.h"
27 #endif 27 #endif
28 28
29 namespace {
30 const char kPermissionDeniedError[] =
31 "Extension does not have permission to use this method.";
32 }
33
34 WebSocketProxyPrivate::WebSocketProxyPrivate() 29 WebSocketProxyPrivate::WebSocketProxyPrivate()
35 : port_(-1), 30 : port_(-1),
36 listening_port_(-1), 31 listening_port_(-1),
37 do_tls_(false), 32 do_tls_(false),
38 is_finalized_(false) { 33 is_finalized_(false) {
39 } 34 }
40 35
41 WebSocketProxyPrivate::~WebSocketProxyPrivate() { 36 WebSocketProxyPrivate::~WebSocketProxyPrivate() {
42 } 37 }
43 38
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 bool WebSocketProxyPrivate::RunImpl() { 94 bool WebSocketProxyPrivate::RunImpl() {
100 AddRef(); 95 AddRef();
101 result_.reset(Value::CreateStringValue("")); 96 result_.reset(Value::CreateStringValue(""));
102 97
103 #if defined(OS_CHROMEOS) 98 #if defined(OS_CHROMEOS)
104 bool delay_response = false; 99 bool delay_response = false;
105 100
106 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &hostname_)); 101 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &hostname_));
107 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &port_)); 102 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &port_));
108 103
109 if (chromeos::WebSocketProxyController::CheckCredentials( 104 listening_port_ = chromeos::WebSocketProxyController::GetPort();
110 extension_id(), hostname_, port_, 105 if (listening_port_ < 1) {
111 do_tls_ ? chromeos::WebSocketProxyController::TLS_OVER_TCP : 106 delay_response = true;
112 chromeos::WebSocketProxyController::PLAIN_TCP)) { 107 registrar_.Add(
113 listening_port_ = chromeos::WebSocketProxyController::GetPort(); 108 this, chrome::NOTIFICATION_WEB_SOCKET_PROXY_STARTED,
114 if (listening_port_ < 1) { 109 content::NotificationService::AllSources());
115 delay_response = true;
116 registrar_.Add(
117 this, chrome::NOTIFICATION_WEB_SOCKET_PROXY_STARTED,
118 content::NotificationService::AllSources());
119 }
120 map_["hostname"] = hostname_;
121 map_["port"] = base::IntToString(port_);
122 map_["extension_id"] = extension_id();
123 } else {
124 error_ = kPermissionDeniedError;
125 return false;
126 } 110 }
111 map_["hostname"] = hostname_;
112 map_["port"] = base::IntToString(port_);
113 map_["extension_id"] = extension_id();
127 114
128 if (delay_response) { 115 if (delay_response) {
129 const int kTimeout = 12; 116 const int kTimeout = 12;
130 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kTimeout), 117 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kTimeout),
131 this, &WebSocketProxyPrivate::ResolveHost); 118 this, &WebSocketProxyPrivate::ResolveHost);
132 } else { 119 } else {
133 ResolveHost(); 120 ResolveHost();
134 } 121 }
135 #else 122 #else
136 Finalize(); 123 Finalize();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 void WebSocketProxyPrivateGetPassportForTCPFunction::CustomFinalize() { 196 void WebSocketProxyPrivateGetPassportForTCPFunction::CustomFinalize() {
210 #if defined(OS_CHROMEOS) 197 #if defined(OS_CHROMEOS)
211 std::string passport = 198 std::string passport =
212 browser::InternalAuthGeneration::GeneratePassport( 199 browser::InternalAuthGeneration::GeneratePassport(
213 "web_socket_proxy", map_) + std::string(":"); 200 "web_socket_proxy", map_) + std::string(":");
214 if (ContainsKey(map_, "addr")) 201 if (ContainsKey(map_, "addr"))
215 passport += map_["addr"]; 202 passport += map_["addr"];
216 result_.reset(Value::CreateStringValue(passport)); 203 result_.reset(Value::CreateStringValue(passport));
217 #endif 204 #endif
218 } 205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698