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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_message_process_host.h

Issue 12285015: Require manifests for native messaging hosts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | 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_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 10
(...skipping 22 matching lines...) Expand all
33 // 33 //
34 // This class must only be created, called, and deleted on the IO thread. 34 // This class must only be created, called, and deleted on the IO thread.
35 // Public methods typically accept callbacks which will be invoked on the UI 35 // Public methods typically accept callbacks which will be invoked on the UI
36 // thread. 36 // thread.
37 class NativeMessageProcessHost 37 class NativeMessageProcessHost
38 #if defined(OS_POSIX) 38 #if defined(OS_POSIX)
39 : public MessageLoopForIO::Watcher 39 : public MessageLoopForIO::Watcher
40 #endif // !defined(OS_POSIX) 40 #endif // !defined(OS_POSIX)
41 { 41 {
42 public: 42 public:
43 // Interface for classes that which to recieve messages from the native 43 // Interface for the object that receives messages from the native process.
44 // process.
45 class Client { 44 class Client {
46 public: 45 public:
47 virtual ~Client() {} 46 virtual ~Client() {}
48 // Called on the UI thread. 47 // Called on the UI thread.
49 virtual void PostMessageFromNativeProcess(int port_id, 48 virtual void PostMessageFromNativeProcess(int port_id,
50 const std::string& message) = 0; 49 const std::string& message) = 0;
51 virtual void CloseChannel(int port_id, bool error) = 0; 50 virtual void CloseChannel(int port_id, bool error) = 0;
52 }; 51 };
53 52
54 virtual ~NativeMessageProcessHost(); 53 virtual ~NativeMessageProcessHost();
55 54
56 static scoped_ptr<NativeMessageProcessHost> Create( 55 static scoped_ptr<NativeMessageProcessHost> Create(
57 base::WeakPtr<Client> weak_client_ui, 56 base::WeakPtr<Client> weak_client_ui,
57 const std::string& source_extension_id,
58 const std::string& native_host_name, 58 const std::string& native_host_name,
59 int destination_port); 59 int destination_port);
60 60
61 // Create using specified |launcher|. Used in tests. 61 // Create using specified |launcher|. Used in tests.
62 static scoped_ptr<NativeMessageProcessHost> CreateWithLauncher( 62 static scoped_ptr<NativeMessageProcessHost> CreateWithLauncher(
63 base::WeakPtr<Client> weak_client_ui, 63 base::WeakPtr<Client> weak_client_ui,
64 const std::string& source_extension_id,
64 const std::string& native_host_name, 65 const std::string& native_host_name,
65 int destination_port, 66 int destination_port,
66 scoped_ptr<NativeProcessLauncher> launcher); 67 scoped_ptr<NativeProcessLauncher> launcher);
67 68
68 // Send a message with the specified payload. 69 // Send a message with the specified payload.
69 void Send(const std::string& json); 70 void Send(const std::string& json);
70 71
71 #if defined(OS_POSIX) 72 #if defined(OS_POSIX)
72 // MessageLoopForIO::Watcher interface 73 // MessageLoopForIO::Watcher interface
73 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; 74 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
74 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; 75 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
75 #endif // !defined(OS_POSIX) 76 #endif // !defined(OS_POSIX)
76 77
77 // Try and read a single message from |read_file_|. This should only be called 78 // Try and read a single message from |read_file_|. This should only be called
78 // in unittests when you know there is data in the file. 79 // in unittests when you know there is data in the file.
79 void ReadNowForTesting(); 80 void ReadNowForTesting();
80 81
81 private: 82 private:
82 NativeMessageProcessHost(base::WeakPtr<Client> weak_client_ui, 83 NativeMessageProcessHost(base::WeakPtr<Client> weak_client_ui,
84 const std::string& source_extension_id,
83 const std::string& native_host_name, 85 const std::string& native_host_name,
84 int destination_port, 86 int destination_port,
85 scoped_ptr<NativeProcessLauncher> launcher); 87 scoped_ptr<NativeProcessLauncher> launcher);
86 88
87 // Starts the host process. 89 // Starts the host process.
88 void LaunchHostProcess(); 90 void LaunchHostProcess();
89 91
90 // Callback for NativeProcessLauncher::Launch(). 92 // Callback for NativeProcessLauncher::Launch().
91 void OnHostProcessLaunched( 93 void OnHostProcessLaunched(
92 base::ProcessHandle native_process_handle, 94 base::ProcessHandle native_process_handle,
(...skipping 16 matching lines...) Expand all
109 // write to/from it. Closes IO pipes and schedules CloseChannel() call. 111 // write to/from it. Closes IO pipes and schedules CloseChannel() call.
110 void OnError(); 112 void OnError();
111 113
112 // Closes the connection. Called from OnError() and destructor. 114 // Closes the connection. Called from OnError() and destructor.
113 void Close(); 115 void Close();
114 116
115 // The Client messages will be posted to. Should only be accessed from the 117 // The Client messages will be posted to. Should only be accessed from the
116 // UI thread. 118 // UI thread.
117 base::WeakPtr<Client> weak_client_ui_; 119 base::WeakPtr<Client> weak_client_ui_;
118 120
121 // ID of the calling extension.
122 std::string source_extension_id_;
123
119 // Name of the native messaging host. 124 // Name of the native messaging host.
120 std::string native_host_name_; 125 std::string native_host_name_;
121 126
122 // The id of the port on the other side of this connection. This is passed to 127 // The id of the port on the other side of this connection. This is passed to
123 // |weak_client_ui_| when posting messages. 128 // |weak_client_ui_| when posting messages.
124 int destination_port_; 129 int destination_port_;
125 130
126 // Launcher used to launch the native process. 131 // Launcher used to launch the native process.
127 scoped_ptr<NativeProcessLauncher> launcher_; 132 scoped_ptr<NativeProcessLauncher> launcher_;
128 133
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 169
165 // Set to true when a write is pending. 170 // Set to true when a write is pending.
166 bool write_pending_; 171 bool write_pending_;
167 172
168 DISALLOW_COPY_AND_ASSIGN(NativeMessageProcessHost); 173 DISALLOW_COPY_AND_ASSIGN(NativeMessageProcessHost);
169 }; 174 };
170 175
171 } // namespace extensions 176 } // namespace extensions
172 177
173 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H _ 178 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698