| Index: extensions/renderer/messaging_bindings.h
|
| diff --git a/extensions/renderer/messaging_bindings.h b/extensions/renderer/messaging_bindings.h
|
| index 758187e1782580526f83b37fb54613e018bc186b..f21bb4adbfc9448950b2fe697f50e83dc8a308e9 100644
|
| --- a/extensions/renderer/messaging_bindings.h
|
| +++ b/extensions/renderer/messaging_bindings.h
|
| @@ -9,6 +9,7 @@
|
|
|
| #include "base/macros.h"
|
| #include "base/memory/weak_ptr.h"
|
| +#include "base/unguessable_token.h"
|
| #include "extensions/renderer/object_backed_native_handler.h"
|
|
|
| struct ExtensionMsg_ExternalConnectionInfo;
|
| @@ -21,6 +22,7 @@ class RenderFrame;
|
| namespace extensions {
|
| class ExtensionPort;
|
| struct Message;
|
| +struct PortId;
|
| class ScriptContextSet;
|
|
|
| // Manually implements JavaScript bindings for extension messaging.
|
| @@ -32,14 +34,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 +52,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);
|
| + // Returns an existing port with the given |id|, or null.
|
| + ExtensionPort* GetPortWithId(const PortId& id);
|
|
|
| - // Creates a new port with the given |global_id|. MessagingBindings owns the
|
| + // Creates a new port with the given |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 base::UnguessableToken& context_id() const { return context_id_; }
|
|
|
| base::WeakPtr<MessagingBindings> GetWeakPtr();
|
|
|
| @@ -100,32 +104,21 @@ 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_;
|
|
|
| - // Ports which are disconnected, but haven't been fully initialized. Once
|
| - // 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 number of ports created in the 'beforeunload' event handler.
|
| - size_t ports_created_in_before_unload_ = 0;
|
| + // The next available js id for a port.
|
| + size_t next_js_id_ = 0;
|
|
|
| - // The number of ports created in the 'unload' event handler.
|
| - size_t ports_created_in_unload_ = 0;
|
| + // The number of extension ports created.
|
| + size_t num_extension_ports_ = 0;
|
|
|
| - // The number of ports created during during any time that isn't in the unload
|
| - // or beforeunload handlers.
|
| - int ports_created_normal_ = 0;
|
| + // A unique identifier for this JS context.
|
| + const base::UnguessableToken context_id_;
|
|
|
| base::WeakPtrFactory<MessagingBindings> weak_ptr_factory_;
|
|
|
|
|