diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 00:01:03 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 00:01:03 +0000 |
commit | 3ca29e2d2844eef858a635a32e34e298ceea0b10 (patch) | |
tree | 3e5135001307b0110fc5e4afceec74fe5d5ebf2d /chrome/browser/extensions/extension_message_service.cc | |
parent | e0411ae51dad04edaab9365590ce47161606af0e (diff) | |
download | chromium_src-3ca29e2d2844eef858a635a32e34e298ceea0b10.zip chromium_src-3ca29e2d2844eef858a635a32e34e298ceea0b10.tar.gz chromium_src-3ca29e2d2844eef858a635a32e34e298ceea0b10.tar.bz2 |
Send port disconnect events when a frame is unloaded.
This is the other half of CL http://codereview.chromium.org/125280, which I split into http://codereview.chromium.org/147033 and this CL.
BUG=12686
TEST=no
Review URL: http://codereview.chromium.org/150125
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19686 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_message_service.cc')
-rw-r--r-- | chrome/browser/extensions/extension_message_service.cc | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc index 7a65078..0ee4579 100644 --- a/chrome/browser/extensions/extension_message_service.cc +++ b/chrome/browser/extensions/extension_message_service.cc @@ -290,13 +290,28 @@ int ExtensionMessageService::OpenAutomationChannelToExtension( return port2_id; } -void ExtensionMessageService::CloseAutomationChannel(int port_id) { +void ExtensionMessageService::CloseChannel(int port_id) { DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); - // TODO(siggi): Cleanup from the tab seems to beat this to the punch. - // DCHECK(channels_[GET_CHANNEL_ID(port_id)].port1 != NULL); - // TODO(siggi): should we notify the other side of the port? - channels_.erase(GET_CHANNEL_ID(port_id)); + // Note: The channel might be gone already, if the other side closed first. + MessageChannelMap::iterator it = channels_.find(GET_CHANNEL_ID(port_id)); + if (it != channels_.end()) + CloseChannelImpl(it, port_id); +} + +void ExtensionMessageService::CloseChannelImpl( + MessageChannelMap::iterator channel_iter, int port_id) { + DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); + + // Notify the other side. + if (port_id == GET_CHANNEL_PORT1(channel_iter->first)) { + DispatchOnDisconnect(channel_iter->second.port2, port_id); + } else { + DCHECK_EQ(port_id, GET_CHANNEL_PORT2(channel_iter->first)); + DispatchOnDisconnect(channel_iter->second.port1, port_id); + } + + channels_.erase(channel_iter); } void ExtensionMessageService::PostMessageFromRenderer( @@ -365,13 +380,9 @@ void ExtensionMessageService::Observe(NotificationType type, it != channels_.end(); ) { MessageChannelMap::iterator current = it++; if (current->second.port1 == renderer) { - DispatchOnDisconnect(current->second.port2, - GET_CHANNEL_PORT1(current->first)); - channels_.erase(current); + CloseChannelImpl(current, GET_CHANNEL_PORT1(current->first)); } else if (current->second.port2 == renderer) { - DispatchOnDisconnect(current->second.port1, - GET_CHANNEL_PORT2(current->first)); - channels_.erase(current); + CloseChannelImpl(current, GET_CHANNEL_PORT2(current->first)); } } } |