Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Mark opener extension port as opened after creation
Browse files Browse the repository at this point in the history
Mark an opener port as opened upon creation, to prevent an error from
showing up when all receiver ports are implicitly closed (e.g. by
navigation).

BUG=580882

Review URL: https://codereview.chromium.org/1625993002

Cr-Commit-Position: refs/heads/master@{#371303}
  • Loading branch information
Rob--W authored and Commit bot committed Jan 25, 2016
1 parent b7204f8 commit 2d89d17
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions chrome/browser/extensions/api/messaging/message_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions chrome/test/data/extensions/api_test/messaging/connect/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2d89d17

Please sign in to comment.