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 "base/macros.h" |
9 #include "chrome/browser/extensions/api/messaging/message_service.h" | 9 #include "chrome/browser/extensions/api/messaging/message_service.h" |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 int port_id, | 39 int port_id, |
40 const std::string& extension_id, | 40 const std::string& extension_id, |
41 content::RenderProcessHost* extension_process); | 41 content::RenderProcessHost* extension_process); |
42 ~ExtensionMessagePort() override; | 42 ~ExtensionMessagePort() override; |
43 | 43 |
44 // MessageService::MessagePort: | 44 // MessageService::MessagePort: |
45 void RemoveCommonFrames(const MessagePort& port) override; | 45 void RemoveCommonFrames(const MessagePort& port) override; |
46 bool HasFrame(content::RenderFrameHost* rfh) const override; | 46 bool HasFrame(content::RenderFrameHost* rfh) const override; |
47 bool IsValidPort() override; | 47 bool IsValidPort() override; |
48 void DispatchOnConnect(const std::string& channel_name, | 48 void DispatchOnConnect(const std::string& channel_name, |
49 scoped_ptr<base::DictionaryValue> source_tab, | 49 std::unique_ptr<base::DictionaryValue> source_tab, |
50 int source_frame_id, | 50 int source_frame_id, |
51 int guest_process_id, | 51 int guest_process_id, |
52 int guest_render_frame_routing_id, | 52 int guest_render_frame_routing_id, |
53 const std::string& source_extension_id, | 53 const std::string& source_extension_id, |
54 const std::string& target_extension_id, | 54 const std::string& target_extension_id, |
55 const GURL& source_url, | 55 const GURL& source_url, |
56 const std::string& tls_channel_id) override; | 56 const std::string& tls_channel_id) override; |
57 void DispatchOnDisconnect(const std::string& error_message) override; | 57 void DispatchOnDisconnect(const std::string& error_message) override; |
58 void DispatchOnMessage(const Message& message) override; | 58 void DispatchOnMessage(const Message& message) override; |
59 void IncrementLazyKeepaliveCount() override; | 59 void IncrementLazyKeepaliveCount() override; |
60 void DecrementLazyKeepaliveCount() override; | 60 void DecrementLazyKeepaliveCount() override; |
61 void OpenPort(int process_id, int routing_id) override; | 61 void OpenPort(int process_id, int routing_id) override; |
62 void ClosePort(int process_id, int routing_id) override; | 62 void ClosePort(int process_id, int routing_id) override; |
63 | 63 |
64 private: | 64 private: |
65 class FrameTracker; | 65 class FrameTracker; |
66 | 66 |
67 // Registers a frame as a receiver / sender. | 67 // Registers a frame as a receiver / sender. |
68 void RegisterFrame(content::RenderFrameHost* rfh); | 68 void RegisterFrame(content::RenderFrameHost* rfh); |
69 | 69 |
70 // Unregisters a frame as a receiver / sender. When there are no registered | 70 // Unregisters a frame as a receiver / sender. When there are no registered |
71 // frames any more, the port closes via CloseChannel(). | 71 // frames any more, the port closes via CloseChannel(). |
72 void UnregisterFrame(content::RenderFrameHost* rfh); | 72 void UnregisterFrame(content::RenderFrameHost* rfh); |
73 | 73 |
74 // Immediately close the port and its associated channel. | 74 // Immediately close the port and its associated channel. |
75 void CloseChannel(); | 75 void CloseChannel(); |
76 | 76 |
77 // Send a IPC message to the renderer for all registered frames. | 77 // Send a IPC message to the renderer for all registered frames. |
78 void SendToPort(scoped_ptr<IPC::Message> msg); | 78 void SendToPort(std::unique_ptr<IPC::Message> msg); |
79 | 79 |
80 base::WeakPtr<MessageService> weak_message_service_; | 80 base::WeakPtr<MessageService> weak_message_service_; |
81 | 81 |
82 int port_id_; | 82 int port_id_; |
83 std::string extension_id_; | 83 std::string extension_id_; |
84 content::BrowserContext* browser_context_; | 84 content::BrowserContext* browser_context_; |
85 // Only for receivers in an extension process. | 85 // Only for receivers in an extension process. |
86 content::RenderProcessHost* extension_process_; | 86 content::RenderProcessHost* extension_process_; |
87 | 87 |
88 // When the port is used as a sender, this set contains only one element. | 88 // When the port is used as a sender, this set contains only one element. |
89 // If used as a receiver, it may contain any number of frames. | 89 // If used as a receiver, it may contain any number of frames. |
90 // This set is populated before the first message is sent to the destination, | 90 // This set is populated before the first message is sent to the destination, |
91 // and shrinks over time when the port is rejected by the recipient frame, or | 91 // and shrinks over time when the port is rejected by the recipient frame, or |
92 // when the frame is removed or unloaded. | 92 // when the frame is removed or unloaded. |
93 std::set<content::RenderFrameHost*> frames_; | 93 std::set<content::RenderFrameHost*> frames_; |
94 | 94 |
95 // Whether the renderer acknowledged creation of the port. This is used to | 95 // Whether the renderer acknowledged creation of the port. This is used to |
96 // distinguish abnormal port closure (e.g. no receivers) from explicit port | 96 // distinguish abnormal port closure (e.g. no receivers) from explicit port |
97 // closure (e.g. by the port.disconnect() JavaScript method in the renderer). | 97 // closure (e.g. by the port.disconnect() JavaScript method in the renderer). |
98 bool did_create_port_; | 98 bool did_create_port_; |
99 | 99 |
100 ExtensionHost* background_host_ptr_; // used in IncrementLazyKeepaliveCount | 100 ExtensionHost* background_host_ptr_; // used in IncrementLazyKeepaliveCount |
101 scoped_ptr<FrameTracker> frame_tracker_; | 101 std::unique_ptr<FrameTracker> frame_tracker_; |
102 | 102 |
103 DISALLOW_COPY_AND_ASSIGN(ExtensionMessagePort); | 103 DISALLOW_COPY_AND_ASSIGN(ExtensionMessagePort); |
104 }; | 104 }; |
105 | 105 |
106 } // namespace extensions | 106 } // namespace extensions |
107 | 107 |
108 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_ | 108 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_ |
OLD | NEW |