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

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

Issue 591463003: Remote Assistance on Chrome OS Part III - NativeMessageHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@native_messaging
Patch Set: Created 6 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
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
11 #include "base/files/file.h" 11 #include "base/files/file.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/process/process.h" 15 #include "base/process/process.h"
16 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" 16 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h"
17 #include "extensions/browser/api/messaging/native_message_host.h"
17 #include "ui/gfx/native_widget_types.h" 18 #include "ui/gfx/native_widget_types.h"
18 19
19 class PrefService; 20 class PrefService;
Sergey Ulanov 2014/09/22 23:42:59 this can be removed
kelvinp 2014/09/23 20:16:42 Done.
20 21
21 namespace net { 22 namespace net {
22 23
23 class DrainableIOBuffer; 24 class DrainableIOBuffer;
24 class FileStream; 25 class FileStream;
25 class IOBuffer; 26 class IOBuffer;
26 class IOBufferWithSize; 27 class IOBufferWithSize;
27 28
28 } // namespace net 29 } // namespace net
29 30
30 namespace extensions { 31 namespace extensions {
31 32
32 // Manages the native side of a connection between an extension and a native 33 // Manages the native side of a connection between an extension and a native
33 // process. 34 // process.
34 // 35 //
35 // This class must only be created, called, and deleted on the IO thread. 36 // This class must only be created, called, and deleted on the IO thread.
36 // Public methods typically accept callbacks which will be invoked on the UI 37 // Public methods typically accept callbacks which will be invoked on the UI
37 // thread. 38 // thread.
38 class NativeMessageProcessHost 39 class NativeMessageProcessHost :
39 #if defined(OS_POSIX) 40 #if defined(OS_POSIX)
40 : public base::MessageLoopForIO::Watcher 41 public base::MessageLoopForIO::Watcher,
41 #endif // !defined(OS_POSIX) 42 #endif // !defined(OS_POSIX)
42 { 43 public NativeMessageHost {
43 public: 44 public:
44 // Interface for the object that receives messages from the native process. 45 typedef NativeMessageHost::Client Client;
45 class Client {
46 public:
47 virtual ~Client() {}
48 // Called on the UI thread.
49 virtual void PostMessageFromNativeProcess(int port_id,
50 const std::string& message) = 0;
51 virtual void CloseChannel(int port_id,
52 const std::string& error_message) = 0;
53 };
54
55 // Result returned from IsHostAllowed().
56 enum PolicyPermission {
57 DISALLOW, // The host is not allowed.
58 ALLOW_SYSTEM_ONLY, // Allowed only when installed on system level.
59 ALLOW_ALL, // Allowed when installed on system or user level.
60 };
61 46
62 virtual ~NativeMessageProcessHost(); 47 virtual ~NativeMessageProcessHost();
63 48
64 // Returns policy permissions for the host with the specified name. 49 // Create using specified |launcher|. Used in tests.
65 static PolicyPermission IsHostAllowed(const PrefService* pref_service, 50 static scoped_ptr<NativeMessageHost> CreateWithLauncher(
66 const std::string& native_host_name);
67
68 static scoped_ptr<NativeMessageProcessHost> Create(
69 gfx::NativeView native_view,
70 base::WeakPtr<Client> weak_client_ui, 51 base::WeakPtr<Client> weak_client_ui,
71 const std::string& source_extension_id, 52 const std::string& source_extension_id,
72 const std::string& native_host_name, 53 const std::string& native_host_name,
73 int destination_port,
74 bool allow_user_level);
75
76 // Create using specified |launcher|. Used in tests.
77 static scoped_ptr<NativeMessageProcessHost> CreateWithLauncher(
78 base::WeakPtr<Client> weak_client_ui,
79 const std::string& source_extension_id,
80 const std::string& native_host_name,
81 int destination_port, 54 int destination_port,
82 scoped_ptr<NativeProcessLauncher> launcher); 55 scoped_ptr<NativeProcessLauncher> launcher);
83 56
84 // Send a message with the specified payload. 57 // Send a message with the specified payload.
Sergey Ulanov 2014/09/22 23:42:59 Replace this comment with // NativeMessageHost imp
kelvinp 2014/09/23 20:16:42 Done.
85 void Send(const std::string& json); 58 virtual void Send(const std::string& json) OVERRIDE;
86 59
87 #if defined(OS_POSIX) 60 #if defined(OS_POSIX)
88 // MessageLoopForIO::Watcher interface 61 // MessageLoopForIO::Watcher interface
89 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; 62 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
90 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; 63 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
91 #endif // !defined(OS_POSIX) 64 #endif // !defined(OS_POSIX)
92 65
93 // Try and read a single message from |read_file_|. This should only be called 66 // Try and read a single message from |read_file_|. This should only be called
94 // in unittests when you know there is data in the file. 67 // in unittests when you know there is data in the file.
95 void ReadNowForTesting(); 68 void ReadNowForTesting();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 149
177 // Set to true when a write is pending. 150 // Set to true when a write is pending.
178 bool write_pending_; 151 bool write_pending_;
179 152
180 DISALLOW_COPY_AND_ASSIGN(NativeMessageProcessHost); 153 DISALLOW_COPY_AND_ASSIGN(NativeMessageProcessHost);
181 }; 154 };
182 155
183 } // namespace extensions 156 } // namespace extensions
184 157
185 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H _ 158 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698