Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Unified Diff: extensions/renderer/messaging_bindings.cc

Issue 2540783005: DO NOT COMMIT: Experimentation with ports
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/messaging_bindings.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « extensions/renderer/messaging_bindings.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698