OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_MESSAGE_PORT_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_MESSAGE_PORT_H_ | |
7 | |
8 #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.
| |
9 | |
10 namespace content { | |
11 class RenderProcessHost; | |
12 } // namespace content | |
13 | |
14 namespace extensions { | |
15 class NativeMessageProcess; | |
16 class ExtensionMessagePort; | |
17 class NativeMessagePort; | |
18 | |
19 // One side of the communication handled by extensions::MessageService. | |
20 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.
| |
21 public: | |
22 virtual ~MessagePort() {} | |
23 virtual void DispatchOnConnect(int dest_port_id, | |
24 const std::string& channel_name, | |
25 const std::string& tab_json, | |
26 const std::string& source_extension_id, | |
27 const std::string& target_extension_id) {} | |
28 virtual void DispatchOnDisconnect(int source_port_id, | |
29 bool connection_error) {} | |
30 virtual void DispatchOnMessage(const std::string& message, | |
31 int target_port_id) = 0; | |
32 virtual void IncrementLazyKeepaliveCount() {} | |
33 virtual void DecrementLazyKeepaliveCount() {} | |
34 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.
| |
35 ExtensionMessagePort* AsExtensionMessagePort(); | |
36 NativeMessagePort* AsNativeMessagePort(); | |
37 | |
38 protected: | |
39 MessagePort() {} | |
40 | |
41 private: | |
42 DISALLOW_COPY_AND_ASSIGN(MessagePort); | |
43 }; | |
44 | |
45 // A port that manages communication with an extension. | |
46 class ExtensionMessagePort : public MessagePort { | |
47 public: | |
48 ExtensionMessagePort(content::RenderProcessHost* process, | |
49 int routing_id, | |
50 const std::string& extension_id); | |
51 virtual void DispatchOnConnect( | |
52 int dest_port_id, | |
53 const std::string& channel_name, | |
54 const std::string& tab_json, | |
55 const std::string& source_extension_id, | |
56 const std::string& target_extension_id) OVERRIDE; | |
57 virtual void DispatchOnDisconnect(int source_port_id, | |
58 bool connection_error) OVERRIDE; | |
59 virtual void DispatchOnMessage(const std::string& message, | |
60 int target_port_id) OVERRIDE; | |
61 virtual void IncrementLazyKeepaliveCount() OVERRIDE; | |
62 virtual void DecrementLazyKeepaliveCount() OVERRIDE; | |
63 content::RenderProcessHost* process() { return process_; } | |
64 | |
65 private: | |
66 content::RenderProcessHost* process_; | |
67 int routing_id_; | |
68 std::string extension_id_; | |
69 void* background_host_ptr_; // used in IncrementLazyKeepaliveCount | |
70 }; | |
71 | |
72 // A port that manages communication with a native application. | |
73 class NativeMessagePort : public MessagePort { | |
74 public: | |
75 // Takes ownership of |native_process|. | |
76 explicit NativeMessagePort(NativeMessageProcess* native_process); | |
77 virtual ~NativeMessagePort(); | |
78 virtual void DispatchOnMessage(const std::string& message, | |
79 int target_port_id) OVERRIDE; | |
80 virtual bool IsNative() { return true; } OVERRIDE | |
81 | |
82 private: | |
83 NativeMessageProcess* native_process_; | |
84 }; | |
85 | |
86 } // namespace extensions | |
87 | |
88 #endif // CHROME_BROWSER_EXTENSIONS_MESSAGE_PORT_H_ | |
OLD | NEW |