OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_ |
7 | 7 |
8 #include "chrome/browser/extensions/api/messaging/message_service.h" | 8 #include "chrome/browser/extensions/api/messaging/message_service.h" |
9 | 9 |
10 class GURL; | 10 class GURL; |
11 | 11 |
12 namespace content { | 12 namespace content { |
| 13 class BrowserContext; |
| 14 class RenderFrameHost; |
13 class RenderProcessHost; | 15 class RenderProcessHost; |
14 } // namespace content | 16 } // namespace content |
15 | 17 |
| 18 namespace IPC { |
| 19 class Message; |
| 20 } // namespace IPC |
| 21 |
16 namespace extensions { | 22 namespace extensions { |
17 | 23 |
18 // A port that manages communication with an extension. | 24 // A port that manages communication with an extension. |
| 25 // The port's lifetime will end when either all receivers close the port, or |
| 26 // when the opener / receiver explicitly closes the channel. |
19 class ExtensionMessagePort : public MessageService::MessagePort { | 27 class ExtensionMessagePort : public MessageService::MessagePort { |
20 public: | 28 public: |
21 ExtensionMessagePort(content::RenderProcessHost* process, | 29 // Create a port that is tied to frame(s) in a single tab. |
22 int routing_id, | 30 ExtensionMessagePort(base::WeakPtr<MessageService> message_service, |
23 const std::string& extension_id); | 31 int port_id, |
24 void DispatchOnConnect(int dest_port_id, | 32 const std::string& extension_id, |
25 const std::string& channel_name, | 33 content::RenderFrameHost* rfh, |
| 34 bool include_child_frames); |
| 35 // Create a port that is tied to all frames of an extension, possibly spanning |
| 36 // multiple tabs, including the invisible background page, popups, etc. |
| 37 ExtensionMessagePort(base::WeakPtr<MessageService> message_service, |
| 38 int port_id, |
| 39 const std::string& extension_id, |
| 40 content::RenderProcessHost* extension_process); |
| 41 ~ExtensionMessagePort() override; |
| 42 |
| 43 bool IsValidPort() override; |
| 44 void DispatchOnConnect(const std::string& channel_name, |
26 scoped_ptr<base::DictionaryValue> source_tab, | 45 scoped_ptr<base::DictionaryValue> source_tab, |
27 int source_frame_id, | 46 int source_frame_id, |
28 int target_tab_id, | |
29 int target_frame_id, | |
30 int guest_process_id, | 47 int guest_process_id, |
31 int guest_render_frame_routing_id, | 48 int guest_render_frame_routing_id, |
32 const std::string& source_extension_id, | 49 const std::string& source_extension_id, |
33 const std::string& target_extension_id, | 50 const std::string& target_extension_id, |
34 const GURL& source_url, | 51 const GURL& source_url, |
35 const std::string& tls_channel_id) override; | 52 const std::string& tls_channel_id) override; |
36 void DispatchOnDisconnect(int source_port_id, | 53 void DispatchOnDisconnect(const std::string& error_message) override; |
37 const std::string& error_message) override; | 54 void DispatchOnMessage(const Message& message) override; |
38 void DispatchOnMessage(const Message& message, int target_port_id) override; | |
39 void IncrementLazyKeepaliveCount() override; | 55 void IncrementLazyKeepaliveCount() override; |
40 void DecrementLazyKeepaliveCount() override; | 56 void DecrementLazyKeepaliveCount() override; |
41 content::RenderProcessHost* GetRenderProcessHost() override; | 57 void OpenPort(int process_id, int routing_id) override; |
| 58 void ClosePort(int process_id, int routing_id) override; |
42 | 59 |
43 private: | 60 private: |
44 content::RenderProcessHost* process_; | 61 class FrameTracker; |
45 int routing_id_; | 62 |
| 63 void RegisterFrame(content::RenderFrameHost* rfh); |
| 64 void UnregisterFrame(content::RenderFrameHost* rfh); |
| 65 void CloseChannel(); |
| 66 void SendToPort(IPC::Message* msg); |
| 67 |
| 68 base::WeakPtr<MessageService> weak_message_service_; |
| 69 int port_id_; |
46 std::string extension_id_; | 70 std::string extension_id_; |
| 71 bool did_create_port_; |
| 72 content::BrowserContext* browser_context_; |
| 73 std::set<content::RenderFrameHost*> frames_; |
| 74 // Only for receivers in an extension process. |
| 75 content::RenderProcessHost* extension_process_; |
47 void* background_host_ptr_; // used in IncrementLazyKeepaliveCount | 76 void* background_host_ptr_; // used in IncrementLazyKeepaliveCount |
| 77 scoped_ptr<FrameTracker> frame_tracker_; |
48 }; | 78 }; |
49 | 79 |
50 } // namespace extensions | 80 } // namespace extensions |
51 | 81 |
52 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_ | 82 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_ |
OLD | NEW |