Chromium Code Reviews| 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 "ui/gfx/native_widget_types.h" | |
| 13 | |
| 14 class PrefService; | |
| 15 | |
| 16 namespace extensions { | |
| 17 | |
| 18 // An interface for receiving messages from MessageService (Chrome) using the | |
| 19 // Native Messaging API. A NativeMessageHost object hosts a native component, | |
| 20 // which can run in the browser-process or in a separate process (See | |
| 21 // NativeMessageProcessHost). | |
| 22 class NativeMessageHost { | |
| 23 public: | |
| 24 // Callback interface for receiving messages from the native component. | |
| 25 class Client { | |
| 26 public: | |
| 27 virtual ~Client() {} | |
| 28 | |
| 29 // Called on the UI thread. | |
| 30 virtual void PostMessageFromNativeHost(const std::string& message) = 0; | |
| 31 virtual void CloseChannel(const std::string& error_message) = 0; | |
| 32 }; | |
| 33 | |
| 34 // Creates the NativeMessageHost based on the |native_host_name|. | |
| 35 static scoped_ptr<NativeMessageHost> Create( | |
| 36 gfx::NativeView native_view, | |
| 37 const std::string& source_extension_id, | |
| 38 const std::string& native_host_name, | |
| 39 bool allow_user_level); | |
| 40 | |
| 41 virtual ~NativeMessageHost() {} | |
| 42 | |
| 43 // Sends a message to the native component with the specified payload. | |
| 44 virtual void Send(const std::string& json) = 0; | |
|
Sergey Ulanov
2014/09/27 00:24:10
Rename this to ProcessMessage()? Send() doesn't ma
kelvinp
2014/09/29 22:59:40
Done.
| |
| 45 | |
| 46 // Sets the client to receive messages from the native component. | |
| 47 virtual void set_client(base::WeakPtr<Client> client) = 0; | |
| 48 }; | |
| 49 | |
| 50 } // namespace extensions | |
| 51 | |
| 52 #endif // EXTENSIONS_BROWSER_API_MESSAGING_NATIVE_MESSAGE_HOST_H_ | |
| OLD | NEW |