diff options
author | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-18 22:56:58 +0000 |
---|---|---|
committer | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-18 22:56:58 +0000 |
commit | 1f70f0ca51d1c61d3a775507b2b69dcdf60e77df (patch) | |
tree | 41659daa24b3e9af8996b2782dffead89fdcc63c /chrome/browser/extensions/extension_message_service.cc | |
parent | 11de3e98153ad8dcb9e6628e527f7bfb2ca0a8ed (diff) | |
download | chromium_src-1f70f0ca51d1c61d3a775507b2b69dcdf60e77df.zip chromium_src-1f70f0ca51d1c61d3a775507b2b69dcdf60e77df.tar.gz chromium_src-1f70f0ca51d1c61d3a775507b2b69dcdf60e77df.tar.bz2 |
Send port-closed notification when a frame with ports unloads.
Also add onLoad and onUnload chrome Event to our bindings, so we can add
listeners to these events without needing a DOM. These don't hook into the
window "unload" event, so we no longer prevent Chrome's sudden termination of
tabs on shutdown.
BUG=12686
TEST=no
Review URL: http://codereview.chromium.org/125280
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18765 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 33fbcf2..85f8146 100644 --- a/chrome/browser/extensions/extension_message_service.cc +++ b/chrome/browser/extensions/extension_message_service.cc @@ -291,13 +291,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( @@ -366,13 +381,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)); } } } |