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

Unified Diff: chrome/browser/extensions/api/socket/socket_api.cc

Issue 10919201: Make sure that a given app/extension requests only its own resources. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improve tests; fix merge conflicts. Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/socket/socket_api.cc
diff --git a/chrome/browser/extensions/api/socket/socket_api.cc b/chrome/browser/extensions/api/socket/socket_api.cc
index fb23691bcaec335b44b272c2e820f6ddae584a17..ce400e52555c92c8b066844f108681bec9f28690 100644
--- a/chrome/browser/extensions/api/socket/socket_api.cc
+++ b/chrome/browser/extensions/api/socket/socket_api.cc
@@ -58,6 +58,14 @@ bool SocketAsyncApiFunction::Respond() {
return error_.empty();
}
+Socket* SocketAsyncApiFunction::GetSocket(int api_resource_id) {
+ return manager_->Get(extension_->id(), api_resource_id);
+}
+
+void SocketAsyncApiFunction::RemoveSocket(int api_resource_id) {
+ manager_->Remove(extension_->id(), api_resource_id);
+}
+
SocketExtensionWithDnsLookupFunction::SocketExtensionWithDnsLookupFunction()
: io_thread_(g_browser_process->io_thread()),
request_handle_(new net::HostResolver::RequestHandle),
@@ -132,9 +140,9 @@ bool SocketCreateFunction::Prepare() {
void SocketCreateFunction::Work() {
Socket* socket = NULL;
if (socket_type_ == kSocketTypeTCP) {
- socket = new TCPSocket(event_notifier_);
+ socket = new TCPSocket(extension_->id(), event_notifier_);
} else if (socket_type_== kSocketTypeUDP) {
- socket = new UDPSocket(event_notifier_);
+ socket = new UDPSocket(extension_->id(), event_notifier_);
}
DCHECK(socket);
@@ -149,7 +157,7 @@ bool SocketDestroyFunction::Prepare() {
}
void SocketDestroyFunction::Work() {
- manager_->Remove(socket_id_);
+ RemoveSocket(socket_id_);
}
SocketConnectFunction::SocketConnectFunction()
@@ -168,7 +176,7 @@ bool SocketConnectFunction::Prepare() {
}
void SocketConnectFunction::AsyncWorkStart() {
- socket_ = manager_->Get(socket_id_);
+ socket_ = GetSocket(socket_id_);
if (!socket_) {
error_ = kSocketNotFoundError;
SetResult(Value::CreateIntegerValue(-1));
@@ -227,7 +235,7 @@ bool SocketDisconnectFunction::Prepare() {
}
void SocketDisconnectFunction::Work() {
- Socket* socket = manager_->Get(socket_id_);
+ Socket* socket = GetSocket(socket_id_);
if (socket)
socket->Disconnect();
else
@@ -244,7 +252,7 @@ bool SocketBindFunction::Prepare() {
void SocketBindFunction::Work() {
int result = -1;
- Socket* socket = manager_->Get(socket_id_);
+ Socket* socket = GetSocket(socket_id_);
if (!socket) {
error_ = kSocketNotFoundError;
@@ -280,7 +288,7 @@ bool SocketReadFunction::Prepare() {
}
void SocketReadFunction::AsyncWorkStart() {
- Socket* socket = manager_->Get(params_->socket_id);
+ Socket* socket = GetSocket(params_->socket_id);
if (!socket) {
error_ = kSocketNotFoundError;
OnCompleted(-1, NULL);
@@ -328,7 +336,7 @@ bool SocketWriteFunction::Prepare() {
}
void SocketWriteFunction::AsyncWorkStart() {
- Socket* socket = manager_->Get(socket_id_);
+ Socket* socket = GetSocket(socket_id_);
if (!socket) {
error_ = kSocketNotFoundError;
@@ -361,7 +369,7 @@ bool SocketRecvFromFunction::Prepare() {
}
void SocketRecvFromFunction::AsyncWorkStart() {
- Socket* socket = manager_->Get(params_->socket_id);
+ Socket* socket = GetSocket(params_->socket_id);
if (!socket) {
error_ = kSocketNotFoundError;
OnCompleted(-1, NULL, std::string(), 0);
@@ -416,7 +424,7 @@ bool SocketSendToFunction::Prepare() {
}
void SocketSendToFunction::AsyncWorkStart() {
- socket_ = manager_->Get(socket_id_);
+ socket_ = GetSocket(socket_id_);
if (!socket_) {
error_ = kSocketNotFoundError;
SetResult(Value::CreateIntegerValue(-1));
@@ -475,7 +483,7 @@ bool SocketSetKeepAliveFunction::Prepare() {
void SocketSetKeepAliveFunction::Work() {
bool result = false;
- Socket* socket = manager_->Get(params_->socket_id);
+ Socket* socket = GetSocket(params_->socket_id);
if (socket) {
int delay = 0;
if (params_->delay.get())
@@ -501,7 +509,7 @@ bool SocketSetNoDelayFunction::Prepare() {
void SocketSetNoDelayFunction::Work() {
bool result = false;
- Socket* socket = manager_->Get(params_->socket_id);
+ Socket* socket = GetSocket(params_->socket_id);
if (socket)
result = socket->SetNoDelay(params_->no_delay);
else
@@ -522,7 +530,7 @@ bool SocketGetInfoFunction::Prepare() {
void SocketGetInfoFunction::Work() {
api::socket::SocketInfo info;
- Socket* socket = manager_->Get(params_->socket_id);
+ Socket* socket = GetSocket(params_->socket_id);
if (socket) {
// This represents what we know about the socket, and does not call through
// to the system.
« no previous file with comments | « chrome/browser/extensions/api/socket/socket_api.h ('k') | chrome/browser/extensions/api/socket/tcp_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698