Chromium Code Reviews| Index: chrome/browser/extensions/message_port.h |
| diff --git a/chrome/browser/extensions/message_port.h b/chrome/browser/extensions/message_port.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..689d54db2ebca95854b5cdb3f1d350a33ae0b9e3 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/message_port.h |
| @@ -0,0 +1,88 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_MESSAGE_PORT_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_MESSAGE_PORT_H_ |
| + |
| +#include "chrome/browser/extensions/message_service.h" |
|
Aaron Boodman
2012/08/15 03:39:21
Pull all of the messaging-related classes into c/b
eaugusti
2012/08/21 23:08:34
Done.
|
| + |
| +namespace content { |
| +class RenderProcessHost; |
| +} // namespace content |
| + |
| +namespace extensions { |
| +class NativeMessageProcess; |
| +class ExtensionMessagePort; |
| +class NativeMessagePort; |
| + |
| +// One side of the communication handled by extensions::MessageService. |
| +class MessagePort { |
|
Aaron Boodman
2012/08/15 03:39:21
Also, I think it would be nicer to define this as
eaugusti
2012/08/21 23:08:34
Done.
|
| + public: |
| + virtual ~MessagePort() {} |
| + virtual void DispatchOnConnect(int dest_port_id, |
| + const std::string& channel_name, |
| + const std::string& tab_json, |
| + const std::string& source_extension_id, |
| + const std::string& target_extension_id) {} |
| + virtual void DispatchOnDisconnect(int source_port_id, |
| + bool connection_error) {} |
| + virtual void DispatchOnMessage(const std::string& message, |
| + int target_port_id) = 0; |
| + virtual void IncrementLazyKeepaliveCount() {} |
| + virtual void DecrementLazyKeepaliveCount() {} |
| + virtual bool IsNative() { return false; } |
|
Aaron Boodman
2012/08/15 03:39:21
Ghetto-RTTI :(. It's better to tell the object wha
eaugusti
2012/08/21 23:08:34
Done.
|
| + ExtensionMessagePort* AsExtensionMessagePort(); |
| + NativeMessagePort* AsNativeMessagePort(); |
| + |
| + protected: |
| + MessagePort() {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(MessagePort); |
| +}; |
| + |
| +// A port that manages communication with an extension. |
| +class ExtensionMessagePort : public MessagePort { |
| + public: |
| + ExtensionMessagePort(content::RenderProcessHost* process, |
| + int routing_id, |
| + const std::string& extension_id); |
| + virtual void DispatchOnConnect( |
| + int dest_port_id, |
| + const std::string& channel_name, |
| + const std::string& tab_json, |
| + const std::string& source_extension_id, |
| + const std::string& target_extension_id) OVERRIDE; |
| + virtual void DispatchOnDisconnect(int source_port_id, |
| + bool connection_error) OVERRIDE; |
| + virtual void DispatchOnMessage(const std::string& message, |
| + int target_port_id) OVERRIDE; |
| + virtual void IncrementLazyKeepaliveCount() OVERRIDE; |
| + virtual void DecrementLazyKeepaliveCount() OVERRIDE; |
| + content::RenderProcessHost* process() { return process_; } |
| + |
| + private: |
| + content::RenderProcessHost* process_; |
| + int routing_id_; |
| + std::string extension_id_; |
| + void* background_host_ptr_; // used in IncrementLazyKeepaliveCount |
| +}; |
| + |
| +// A port that manages communication with a native application. |
| +class NativeMessagePort : public MessagePort { |
| + public: |
| + // Takes ownership of |native_process|. |
| + explicit NativeMessagePort(NativeMessageProcess* native_process); |
| + virtual ~NativeMessagePort(); |
| + virtual void DispatchOnMessage(const std::string& message, |
| + int target_port_id) OVERRIDE; |
| + virtual bool IsNative() { return true; } OVERRIDE |
| + |
| + private: |
| + NativeMessageProcess* native_process_; |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_MESSAGE_PORT_H_ |