diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-18 00:54:02 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-18 00:54:02 +0000 |
commit | 0815da72e7a85a810ba3841b30eb4f357d8e54f9 (patch) | |
tree | 877aeac5c14d290908c1937d1fb96f8a71f5ba08 /remoting | |
parent | 7e3abea471f42bff8d1e4275e3193bb983b24f61 (diff) | |
download | chromium_src-0815da72e7a85a810ba3841b30eb4f357d8e54f9.zip chromium_src-0815da72e7a85a810ba3841b30eb4f357d8e54f9.tar.gz chromium_src-0815da72e7a85a810ba3841b30eb4f357d8e54f9.tar.bz2 |
Make chromoting connect always work
There was a race condition in the chromoting extension javascript. We wait
for OnUpdated() in order to send the chromoting tab a request for connection.
However OnUpdated() is insufficient for the chromoting tab is fully loaded.
And thus sending a request may not always work. This change will wait for the
tab to go to a "complete" status before a request is sent.
BUG=73202
TEST=Click on chromoting connect, it should always connect
Review URL: http://codereview.chromium.org/6532042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75341 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/client/extension/background.js | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/remoting/client/extension/background.js b/remoting/client/extension/background.js index b8b400d..f417407 100644 --- a/remoting/client/extension/background.js +++ b/remoting/client/extension/background.js @@ -63,11 +63,29 @@ function openChromotingTab(hostName, hostJid) { " hostName='" + request.hostName + "'" + " hostJid='" + request.hostJid + "'" + " auth_token='" + request.xmppAuth + "'"); - navigate(newTabUrl, function(tab) { - console.log("We're trying now to send to " + tab.id); - chrome.tabs.sendRequest( - tab.id, request, function() { - console.log('Tab finished connect.'); - }); - }); + + var sendRequestFunc = function (tab) { + console.log("We're trying now to send to " + tab.id); + chrome.tabs.sendRequest( + tab.id, request, function() { + console.log('Tab finished connect.'); + }); + }; + + // This function will run when after the url for the tab is updated. If + // the tab is not yet loaded it will wait for another 500ms to inspect + // again. + var checkStatusFunc = function (tab) { + if (tab.status == "complete") { + sendRequestFunc(tab); + return; + } + + // Wait for 500ms and then get the tab and check its status. + setTimeout(function() { + chrome.tabs.get(tab.id, checkStatusFunc); + }, 500); + } + + navigate(newTabUrl, checkStatusFunc); } |