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