OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_ | 5 #ifndef EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_ |
6 #define EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_ | 6 #define EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_ |
7 | 7 |
| 8 #include <set> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "extensions/renderer/object_backed_native_handler.h" | 13 #include "extensions/renderer/object_backed_native_handler.h" |
13 | 14 |
14 struct ExtensionMsg_ExternalConnectionInfo; | 15 struct ExtensionMsg_ExternalConnectionInfo; |
15 struct ExtensionMsg_TabConnectionInfo; | 16 struct ExtensionMsg_TabConnectionInfo; |
16 | 17 |
17 namespace content { | 18 namespace content { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // Returns an existing port with the given |global_id|, or null. | 65 // Returns an existing port with the given |global_id|, or null. |
65 ExtensionPort* GetPortWithGlobalId(int global_id); | 66 ExtensionPort* GetPortWithGlobalId(int global_id); |
66 | 67 |
67 // Creates a new port with the given |global_id|. MessagingBindings owns the | 68 // Creates a new port with the given |global_id|. MessagingBindings owns the |
68 // returned port. | 69 // returned port. |
69 ExtensionPort* CreateNewPortWithGlobalId(int global_id); | 70 ExtensionPort* CreateNewPortWithGlobalId(int global_id); |
70 | 71 |
71 // Removes the port with the given |local_id|. | 72 // Removes the port with the given |local_id|. |
72 void RemovePortWithLocalId(int local_id); | 73 void RemovePortWithLocalId(int local_id); |
73 | 74 |
| 75 bool DidCreatePortWithGlobalId(int global_id) const; |
| 76 |
74 base::WeakPtr<MessagingBindings> GetWeakPtr(); | 77 base::WeakPtr<MessagingBindings> GetWeakPtr(); |
75 | 78 |
76 private: | 79 private: |
77 using PortMap = std::map<int, std::unique_ptr<ExtensionPort>>; | 80 using PortMap = std::map<int, std::unique_ptr<ExtensionPort>>; |
78 | 81 |
79 // JS Exposed Function: Sends a message along the given channel. | 82 // JS Exposed Function: Sends a message along the given channel. |
80 void PostMessage(const v8::FunctionCallbackInfo<v8::Value>& args); | 83 void PostMessage(const v8::FunctionCallbackInfo<v8::Value>& args); |
81 | 84 |
82 // JS Exposed Function: Close a port, optionally forcefully (i.e. close the | 85 // JS Exposed Function: Close a port, optionally forcefully (i.e. close the |
83 // whole channel instead of just the given port). | 86 // whole channel instead of just the given port). |
(...skipping 23 matching lines...) Expand all Loading... |
107 | 110 |
108 int GetNextLocalId(); | 111 int GetNextLocalId(); |
109 | 112 |
110 // Active ports, mapped by local port id. | 113 // Active ports, mapped by local port id. |
111 PortMap ports_; | 114 PortMap ports_; |
112 | 115 |
113 // Ports which are disconnected, but haven't been fully initialized. Once | 116 // Ports which are disconnected, but haven't been fully initialized. Once |
114 // initialized and any pending messages are sent, these ports are removed. | 117 // initialized and any pending messages are sent, these ports are removed. |
115 PortMap disconnected_ports_; | 118 PortMap disconnected_ports_; |
116 | 119 |
| 120 std::set<int> created_local_port_ids_; |
| 121 std::set<int> created_global_port_ids_; |
| 122 |
117 // The next available local id for a port. | 123 // The next available local id for a port. |
118 size_t next_local_id_ = 0; | 124 size_t next_local_id_ = 0; |
119 | 125 |
120 // The number of ports created in the 'beforeunload' event handler. | 126 // The number of ports created in the 'beforeunload' event handler. |
121 size_t ports_created_in_before_unload_ = 0; | 127 size_t ports_created_in_before_unload_ = 0; |
122 | 128 |
123 // The number of ports created in the 'unload' event handler. | 129 // The number of ports created in the 'unload' event handler. |
124 size_t ports_created_in_unload_ = 0; | 130 size_t ports_created_in_unload_ = 0; |
125 | 131 |
126 // The number of ports created during during any time that isn't in the unload | 132 // The number of ports created during during any time that isn't in the unload |
127 // or beforeunload handlers. | 133 // or beforeunload handlers. |
128 int ports_created_normal_ = 0; | 134 int ports_created_normal_ = 0; |
129 | 135 |
130 base::WeakPtrFactory<MessagingBindings> weak_ptr_factory_; | 136 base::WeakPtrFactory<MessagingBindings> weak_ptr_factory_; |
131 | 137 |
132 DISALLOW_COPY_AND_ASSIGN(MessagingBindings); | 138 DISALLOW_COPY_AND_ASSIGN(MessagingBindings); |
133 }; | 139 }; |
134 | 140 |
135 } // namespace extensions | 141 } // namespace extensions |
136 | 142 |
137 #endif // EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_ | 143 #endif // EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_ |
OLD | NEW |