diff --git a/chrome/browser/extensions/api/messaging/message_service.cc b/chrome/browser/extensions/api/messaging/message_service.cc index 0cc7aa2e2433f..06cd62891ffd0 100644 --- a/chrome/browser/extensions/api/messaging/message_service.cc +++ b/chrome/browser/extensions/api/messaging/message_service.cc @@ -449,6 +449,7 @@ void MessageService::OpenChannelToNativeApp( source_extension_id, source, false)); if (!channel->opener->IsValidPort()) return; + channel->opener->OpenPort(source_process_id, source_routing_id); // Get handle of the native view and pass it to the native messaging host. gfx::NativeView native_view = source ? source->GetNativeView() : nullptr; @@ -575,6 +576,7 @@ void MessageService::OpenChannelImpl(BrowserContext* browser_context, params->source_extension_id, source, false)); if (!opener->IsValidPort()) return; + opener->OpenPort(params->source_process_id, params->source_routing_id); params->receiver->RemoveCommonFrames(*opener); if (!params->receiver->IsValidPort()) { diff --git a/chrome/test/data/extensions/api_test/messaging/connect/page.js b/chrome/test/data/extensions/api_test/messaging/connect/page.js index bf122e7a9157e..eef9fc6ddae32 100644 --- a/chrome/test/data/extensions/api_test/messaging/connect/page.js +++ b/chrome/test/data/extensions/api_test/messaging/connect/page.js @@ -40,7 +40,10 @@ chrome.runtime.onConnect.addListener(function onConnect(port) { chrome.test.assertFalse(chrome.runtime.onConnect.hasListeners()); testConnectChildFrameAndNavigateSetup(); } else if (msg.testDisconnectOnClose) { - window.location = "about:blank"; + chrome.runtime.connect().onMessage.addListener(function(msg) { + chrome.test.assertEq('unloadTabContent', msg); + window.location = 'about:blank'; + }); } else if (msg.testPortName) { port.postMessage({portName:port.name}); } else if (msg.testSendMessageFromTabError) { diff --git a/chrome/test/data/extensions/api_test/messaging/connect/test.js b/chrome/test/data/extensions/api_test/messaging/connect/test.js index 356f3d69505d3..6956e82191273 100644 --- a/chrome/test/data/extensions/api_test/messaging/connect/test.js +++ b/chrome/test/data/extensions/api_test/messaging/connect/test.js @@ -275,8 +275,26 @@ chrome.test.getConfig(function(config) { .postMessage({testConnectChildFrameAndNavigateSetup: true}); }, + // The previous test removed the onConnect listener. Add it back. + function reloadTabForTest() { + var doneListening = listenForever(chrome.tabs.onUpdated, + function(tabId, info) { + if (tabId === testTab.id && info.status == 'complete') { + doneListening(); + } + }); + chrome.tabs.reload(testTab.id); + }, + // Tests that we get the disconnect event when the tab context closes. function disconnectOnClose() { + listenOnce(chrome.runtime.onConnect, function(portFromTab) { + listenOnce(portFromTab.onDisconnect, function() { + chrome.test.assertNoLastError(); + }); + portFromTab.postMessage('unloadTabContent'); + }); + var port = chrome.tabs.connect(testTab.id); port.postMessage({testDisconnectOnClose: true}); listenOnce(port.onDisconnect, function() {