| Index: extensions/renderer/messaging_bindings.cc
|
| diff --git a/extensions/renderer/messaging_bindings.cc b/extensions/renderer/messaging_bindings.cc
|
| index b82e84b113e571242a45d951dc5e0db6c9fb67e4..a887fdc97b33d76801f83e9d897cb71aa25c8a60 100644
|
| --- a/extensions/renderer/messaging_bindings.cc
|
| +++ b/extensions/renderer/messaging_bindings.cc
|
| @@ -79,7 +79,8 @@ void DispatchOnConnectToScriptContext(
|
| DCHECK(bindings);
|
|
|
| int opposite_port_id = global_target_port_id ^ 1;
|
| - if (bindings->GetPortWithGlobalId(opposite_port_id))
|
| + if (bindings->GetPortWithGlobalId(opposite_port_id) ||
|
| + bindings->DidCreatePortWithGlobalId(opposite_port_id))
|
| return; // The channel was opened by this same context; ignore it.
|
|
|
| ExtensionPort* port =
|
| @@ -376,6 +377,10 @@ void MessagingBindings::RemovePortWithLocalId(int local_id) {
|
| ports_.erase(local_id);
|
| }
|
|
|
| +bool MessagingBindings::DidCreatePortWithGlobalId(int global_id) const {
|
| + return created_global_port_ids_.count(global_id) > 0;
|
| +}
|
| +
|
| base::WeakPtr<MessagingBindings> MessagingBindings::GetWeakPtr() {
|
| return weak_ptr_factory_.GetWeakPtr();
|
| }
|
| @@ -479,12 +484,14 @@ void MessagingBindings::OpenChannelToExtension(
|
| int global_id = frame_helper->RequestSyncPortId(info, channel_name,
|
| include_tls_channel_id);
|
| ports_[local_id]->SetGlobalId(global_id);
|
| + created_global_port_ids_.insert(global_id);
|
| } else {
|
| ++ports_created_normal_;
|
| frame_helper->RequestPortId(
|
| info, channel_name, include_tls_channel_id,
|
| base::Bind(&MessagingBindings::SetGlobalPortId,
|
| weak_ptr_factory_.GetWeakPtr(), local_id));
|
| + created_local_port_ids_.insert(local_id);
|
| }
|
|
|
| args.GetReturnValue().Set(static_cast<int32_t>(local_id));
|
| @@ -551,6 +558,7 @@ void MessagingBindings::OpenChannelToTab(
|
| info, extension_id, channel_name,
|
| base::Bind(&MessagingBindings::SetGlobalPortId,
|
| weak_ptr_factory_.GetWeakPtr(), local_id));
|
| + created_local_port_ids_.insert(local_id);
|
|
|
| args.GetReturnValue().Set(static_cast<int32_t>(local_id));
|
| }
|
| @@ -575,6 +583,9 @@ void MessagingBindings::ClosePort(int local_port_id, bool force_close) {
|
| }
|
|
|
| void MessagingBindings::SetGlobalPortId(int local_id, int global_id) {
|
| + if (created_local_port_ids_.erase(local_id))
|
| + created_global_port_ids_.insert(global_id);
|
| +
|
| auto iter = ports_.find(local_id);
|
| if (iter != ports_.end()) {
|
| iter->second->SetGlobalId(global_id);
|
|
|