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

Unified Diff: chrome/browser/extensions/api/messaging/message_service.cc

Issue 1588533002: Never connect a port to the same frame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also rename invocation of WillConnectToPort Created 4 years, 11 months 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
Index: chrome/browser/extensions/api/messaging/message_service.cc
diff --git a/chrome/browser/extensions/api/messaging/message_service.cc b/chrome/browser/extensions/api/messaging/message_service.cc
index 11ec6922b2efcbb9ac098ff60c3801d6907e992b..0cc7aa2e2433fa9ad16a7f48c459306d79318856 100644
--- a/chrome/browser/extensions/api/messaging/message_service.cc
+++ b/chrome/browser/extensions/api/messaging/message_service.cc
@@ -193,6 +193,13 @@ static content::RenderProcessHost* GetExtensionProcess(
} // namespace
+void MessageService::MessagePort::RemoveCommonFrames(const MessagePort& port) {}
+
+bool MessageService::MessagePort::HasFrame(
+ content::RenderFrameHost* rfh) const {
+ return false;
+}
+
// static
void MessageService::AllocatePortIdPair(int* port1, int* port2) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -569,6 +576,12 @@ void MessageService::OpenChannelImpl(BrowserContext* browser_context,
if (!opener->IsValidPort())
return;
+ params->receiver->RemoveCommonFrames(*opener);
+ if (!params->receiver->IsValidPort()) {
+ opener->DispatchOnDisconnect(kReceivingEndDoesntExistError);
+ return;
+ }
+
MessageChannel* channel(new MessageChannel());
channel->opener.reset(opener.release());
channel->receiver.reset(params->receiver.release());
@@ -708,6 +721,9 @@ void MessageService::CloseChannelImpl(
DCHECK_CURRENTLY_ON(BrowserThread::UI);
MessageChannel* channel = channel_iter->second;
+ // Remove from map to make sure that it is impossible for CloseChannelImpl to
+ // run twice for the same channel.
+ channels_.erase(channel_iter);
// Notify the other side.
if (notify_other_port) {
@@ -720,8 +736,7 @@ void MessageService::CloseChannelImpl(
channel->opener->DecrementLazyKeepaliveCount();
channel->receiver->DecrementLazyKeepaliveCount();
- delete channel_iter->second;
- channels_.erase(channel_iter);
+ delete channel;
}
void MessageService::PostMessage(int source_port_id, const Message& message) {
« no previous file with comments | « chrome/browser/extensions/api/messaging/message_service.h ('k') | chrome/browser/extensions/extension_messages_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698