| 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 | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/single_thread_task_runner.h" | |
| 12 #include "ui/gfx/native_widget_types.h" | |
| 13 | |
| 14 namespace extensions { | |
| 15 | |
| 16 // An interface for receiving messages from MessageService (Chrome) using the | |
| 17 // Native Messaging API. A NativeMessageHost object hosts a native component, | |
| 18 // which can run in the browser-process or in a separate process (See | |
| 19 // NativeMessageProcessHost). | |
| 20 class NativeMessageHost { | |
| 21 public: | |
| 22 static const char kFailedToStartError[]; | |
| 23 static const char kInvalidNameError[]; | |
| 24 static const char kNativeHostExited[]; | |
| 25 static const char kNotFoundError[]; | |
| 26 static const char kForbiddenError[]; | |
| 27 static const char kHostInputOuputError[]; | |
| 28 | |
| 29 // Callback interface for receiving messages from the native host. | |
| 30 class Client { | |
| 31 public: | |
| 32 virtual ~Client() {} | |
| 33 | |
| 34 // Called on the UI thread. | |
| 35 virtual void PostMessageFromNativeHost(const std::string& message) = 0; | |
| 36 virtual void CloseChannel(const std::string& error_message) = 0; | |
| 37 }; | |
| 38 | |
| 39 // Creates the NativeMessageHost based on the |native_host_name|. | |
| 40 static scoped_ptr<NativeMessageHost> Create( | |
| 41 gfx::NativeView native_view, | |
| 42 const std::string& source_extension_id, | |
| 43 const std::string& native_host_name, | |
| 44 bool allow_user_level, | |
| 45 std::string* error); | |
| 46 | |
| 47 virtual ~NativeMessageHost() {} | |
| 48 | |
| 49 // Called when a message is received from MessageService (Chrome). | |
| 50 virtual void OnMessage(const std::string& message) = 0; | |
| 51 | |
| 52 // Sets the client to start receiving messages from the native host. | |
| 53 virtual void Start(Client* client) = 0; | |
| 54 | |
| 55 // Returns the task runner that the host runs on. The Client should only | |
| 56 // invoke OnMessage() on this task runner. | |
| 57 virtual scoped_refptr<base::SingleThreadTaskRunner> task_runner() const = 0; | |
| 58 }; | |
| 59 | |
| 60 } // namespace extensions | |
| 61 | |
| 62 #endif // EXTENSIONS_BROWSER_API_MESSAGING_NATIVE_MESSAGE_HOST_H_ | |
| OLD | NEW |