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