OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef EXTENSIONS_BROWSER_API_MESSAGING_NATIVE_MESSAGE_HOST_H_ | |
6 #define EXTENSIONS_BROWSER_API_MESSAGING_NATIVE_MESSAGE_HOST_H_ | |
7 | |
8 #include <string> | |
9 #include "base/memory/scoped_ptr.h" | |
Sergey Ulanov
2014/09/22 23:42:59
Empty line above this one.
kelvinp
2014/09/23 20:16:42
Done.
| |
10 #include "base/memory/weak_ptr.h" | |
11 #include "ui/gfx/native_widget_types.h" | |
12 | |
13 class PrefService; | |
14 | |
15 namespace extensions { | |
16 | |
17 // An interface for receiving messages from MessageService (Chrome) using the | |
18 // Native Messaging API. A NativeMessageHost object hosts a native component, | |
19 // which can run in the browser-process or in a separate process (SEe | |
20 // NativeMessageProcessHost). | |
21 class NativeMessageHost { | |
22 public: | |
23 // Result returned from IsHostAllowed(). | |
24 enum PolicyPermission { | |
25 DISALLOW, // The host is not allowed. | |
26 ALLOW_SYSTEM_ONLY, // Allowed only when installed on system level. | |
27 ALLOW_ALL, // Allowed when installed on system or user level. | |
28 }; | |
29 | |
30 // Callback interface for receiving messages from the native component. It is | |
31 // implemented by MessageService. | |
32 class Client { | |
33 public: | |
34 virtual ~Client() {} | |
35 | |
36 // Called on the UI thread. | |
37 virtual void PostMessageFromNative(int port_id, | |
Sergey Ulanov
2014/09/22 23:42:59
Maybe PostMessageFromNativeHost()?
kelvinp
2014/09/23 20:16:42
Done.
| |
38 const std::string& message) = 0; | |
39 virtual void CloseChannel(int port_id, | |
40 const std::string& error_message) = 0; | |
41 }; | |
42 | |
43 // Creates the NativeMessageHost based on the |native_host_name|. | |
44 static scoped_ptr<NativeMessageHost> Create( | |
45 gfx::NativeView native_view, | |
46 base::WeakPtr<Client> weak_client_ui, | |
Sergey Ulanov
2014/09/22 23:42:59
I think this should be called |client|. It has not
kelvinp
2014/09/23 20:16:42
Done. Copy and paste from existing code does not
| |
47 const std::string& source_extension_id, | |
48 const std::string& native_host_name, | |
49 int destination_port, | |
50 bool allow_user_level); | |
51 | |
52 // Returns policy permissions for the host with the specified name. | |
53 static PolicyPermission IsHostAllowed(const PrefService* pref_service, | |
54 const std::string& native_host_name); | |
55 | |
56 // Sends a message to the native component with the specified payload. | |
57 virtual void Send(const std::string& json) = 0; | |
58 | |
59 virtual ~NativeMessageHost() {} | |
60 }; | |
61 | |
62 } // namespace extensions | |
63 | |
64 #endif // EXTENSIONS_BROWSER_API_MESSAGING_NATIVE_MESSAGE_HOST_H_ | |
OLD | NEW |