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

Side by Side Diff: chrome/browser/extensions/api/socket/tcp_socket.h

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 unified diff | Download patch | Annotate | Revision Log
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 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "chrome/browser/extensions/api/socket/socket.h" 10 #include "chrome/browser/extensions/api/socket/socket.h"
11 11
12 // This looks like it should be forward-declarable, but it does some tricky 12 // This looks like it should be forward-declarable, but it does some tricky
13 // moves that make it easier to just include it. 13 // moves that make it easier to just include it.
14 #include "net/socket/tcp_client_socket.h" 14 #include "net/socket/tcp_client_socket.h"
15 15
16 namespace net { 16 namespace net {
17 class Socket; 17 class Socket;
18 } 18 }
19 19
20 namespace extensions { 20 namespace extensions {
21 21
22 class ApiResourceEventNotifier; 22 class ApiResourceEventNotifier;
23 23
24 class TCPSocket : public Socket { 24 class TCPSocket : public Socket {
25 public: 25 public:
26 explicit TCPSocket(ApiResourceEventNotifier* event_notifier); 26 TCPSocket(const std::string& owner_extension_id,
27 ApiResourceEventNotifier* event_notifier);
27 virtual ~TCPSocket(); 28 virtual ~TCPSocket();
28 29
29 virtual void Connect(const std::string& address, 30 virtual void Connect(const std::string& address,
30 int port, 31 int port,
31 const CompletionCallback& callback) OVERRIDE; 32 const CompletionCallback& callback) OVERRIDE;
32 virtual void Disconnect() OVERRIDE; 33 virtual void Disconnect() OVERRIDE;
33 virtual int Bind(const std::string& address, int port) OVERRIDE; 34 virtual int Bind(const std::string& address, int port) OVERRIDE;
34 virtual void Read(int count, 35 virtual void Read(int count,
35 const ReadCompletionCallback& callback) OVERRIDE; 36 const ReadCompletionCallback& callback) OVERRIDE;
36 virtual void RecvFrom(int count, 37 virtual void RecvFrom(int count,
37 const RecvFromCompletionCallback& callback) OVERRIDE; 38 const RecvFromCompletionCallback& callback) OVERRIDE;
38 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, 39 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer,
39 int byte_count, 40 int byte_count,
40 const std::string& address, 41 const std::string& address,
41 int port, 42 int port,
42 const CompletionCallback& callback) OVERRIDE; 43 const CompletionCallback& callback) OVERRIDE;
43 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE; 44 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE;
44 virtual bool SetNoDelay(bool no_delay) OVERRIDE; 45 virtual bool SetNoDelay(bool no_delay) OVERRIDE;
45 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE; 46 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE;
46 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE; 47 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE;
47 virtual Socket::SocketType GetSocketType() const OVERRIDE; 48 virtual Socket::SocketType GetSocketType() const OVERRIDE;
48 49
49 static TCPSocket* CreateSocketForTesting( 50 static TCPSocket* CreateSocketForTesting(
50 net::TCPClientSocket* tcp_client_socket, 51 net::TCPClientSocket* tcp_client_socket,
52 const std::string& owner_extension_id,
51 ApiResourceEventNotifier* event_notifier); 53 ApiResourceEventNotifier* event_notifier);
52 54
53 protected: 55 protected:
54 virtual int WriteImpl(net::IOBuffer* io_buffer, 56 virtual int WriteImpl(net::IOBuffer* io_buffer,
55 int io_buffer_size, 57 int io_buffer_size,
56 const net::CompletionCallback& callback) OVERRIDE; 58 const net::CompletionCallback& callback) OVERRIDE;
57 59
58 private: 60 private:
59 void OnConnectComplete(int result); 61 void OnConnectComplete(int result);
60 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, 62 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer,
61 int result); 63 int result);
62 64
63 TCPSocket(net::TCPClientSocket* tcp_client_socket, 65 TCPSocket(net::TCPClientSocket* tcp_client_socket,
66 const std::string& owner_extension_id,
64 ApiResourceEventNotifier* event_notifier); 67 ApiResourceEventNotifier* event_notifier);
65 68
66 scoped_ptr<net::TCPClientSocket> socket_; 69 scoped_ptr<net::TCPClientSocket> socket_;
67 70
68 CompletionCallback connect_callback_; 71 CompletionCallback connect_callback_;
69 72
70 ReadCompletionCallback read_callback_; 73 ReadCompletionCallback read_callback_;
71 }; 74 };
72 75
73 } // namespace extensions 76 } // namespace extensions
74 77
75 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ 78 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/socket/socket_api.cc ('k') | chrome/browser/extensions/api/socket/tcp_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698