Index: extensions/renderer/messaging_bindings.h |
diff --git a/extensions/renderer/messaging_bindings.h b/extensions/renderer/messaging_bindings.h |
index 758187e1782580526f83b37fb54613e018bc186b..f9aa75e8a30e695f7bd0ba38cac2c7373d420fd8 100644 |
--- a/extensions/renderer/messaging_bindings.h |
+++ b/extensions/renderer/messaging_bindings.h |
@@ -21,6 +21,7 @@ class RenderFrame; |
namespace extensions { |
class ExtensionPort; |
struct Message; |
+struct PortId; |
class ScriptContextSet; |
// Manually implements JavaScript bindings for extension messaging. |
@@ -32,14 +33,14 @@ class MessagingBindings : public ObjectBackedNativeHandler { |
// Checks whether the port exists in the given frame. If it does not, a reply |
// is sent back to the browser. |
static void ValidateMessagePort(const ScriptContextSet& context_set, |
- int port_id, |
+ const PortId& port_id, |
content::RenderFrame* render_frame); |
// Dispatches the onConnect content script messaging event to some contexts |
// in |context_set|. If |restrict_to_render_frame| is specified, only contexts |
// in that render frame will receive the message. |
static void DispatchOnConnect(const ScriptContextSet& context_set, |
- int target_port_id, |
+ const PortId& target_port_id, |
const std::string& channel_name, |
const ExtensionMsg_TabConnectionInfo& source, |
const ExtensionMsg_ExternalConnectionInfo& info, |
@@ -50,26 +51,28 @@ class MessagingBindings : public ObjectBackedNativeHandler { |
// contexts in |bindings_context_set|. If |restrict_to_render_frame| is |
// specified, only contexts in that render view will receive the message. |
static void DeliverMessage(const ScriptContextSet& context_set, |
- int target_port_id, |
+ const PortId& target_port_id, |
const Message& message, |
content::RenderFrame* restrict_to_render_frame); |
// Dispatches the onDisconnect event in response to the channel being closed. |
static void DispatchOnDisconnect( |
const ScriptContextSet& context_set, |
- int port_id, |
+ const PortId& port_id, |
const std::string& error_message, |
content::RenderFrame* restrict_to_render_frame); |
// Returns an existing port with the given |global_id|, or null. |
- ExtensionPort* GetPortWithGlobalId(int global_id); |
+ ExtensionPort* GetPortWithId(const PortId& id); |
// Creates a new port with the given |global_id|. MessagingBindings owns the |
// returned port. |
- ExtensionPort* CreateNewPortWithGlobalId(int global_id); |
+ ExtensionPort* CreateNewPortWithId(const PortId& id); |
- // Removes the port with the given |local_id|. |
- void RemovePortWithLocalId(int local_id); |
+ // Removes the port with the given |js_id|. |
+ void RemovePortWithJsId(int js_id); |
+ |
+ const std::string& context_id() const { return context_id_; } |
base::WeakPtr<MessagingBindings> GetWeakPtr(); |
@@ -100,12 +103,9 @@ class MessagingBindings : public ObjectBackedNativeHandler { |
// Helper function to close a port. See CloseChannel() for |force_close| |
// documentation. |
- void ClosePort(int port_id, bool force_close); |
- |
- // Sets the global id for the port with |local_id|. |
- void SetGlobalPortId(int local_id, int global_id); |
+ void ClosePort(int local_port_id, bool force_close); |
- int GetNextLocalId(); |
+ int GetNextJsId(); |
// Active ports, mapped by local port id. |
PortMap ports_; |
@@ -114,8 +114,8 @@ class MessagingBindings : public ObjectBackedNativeHandler { |
// initialized and any pending messages are sent, these ports are removed. |
PortMap disconnected_ports_; |
- // The next available local id for a port. |
- size_t next_local_id_ = 0; |
+ // The next available js id for a port. |
+ size_t next_js_id_ = 0; |
// The number of ports created in the 'beforeunload' event handler. |
size_t ports_created_in_before_unload_ = 0; |
@@ -127,6 +127,9 @@ class MessagingBindings : public ObjectBackedNativeHandler { |
// or beforeunload handlers. |
int ports_created_normal_ = 0; |
+ // A GUID for this context. |
+ const std::string context_id_; |
+ |
base::WeakPtrFactory<MessagingBindings> weak_ptr_factory_; |
DISALLOW_COPY_AND_ASSIGN(MessagingBindings); |