OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * If there is already a tab with the given URL, switch focus to it. Otherwise, | 6 * If there is already a tab with the given URL, switch focus to it. Otherwise, |
7 * create a new tab and open the URL. | 7 * create a new tab and open the URL. |
8 * | 8 * |
9 * @param url The URL to open. | 9 * @param url The URL to open. |
10 */ | 10 */ |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 xmppAuth: getCookie('xmpp_auth'), | 56 xmppAuth: getCookie('xmpp_auth'), |
57 hostName: hostName, | 57 hostName: hostName, |
58 hostJid: hostJid, | 58 hostJid: hostJid, |
59 }; | 59 }; |
60 | 60 |
61 console.log("Attempt to connect with" + | 61 console.log("Attempt to connect with" + |
62 " username='" + request.username + "'" + | 62 " username='" + request.username + "'" + |
63 " hostName='" + request.hostName + "'" + | 63 " hostName='" + request.hostName + "'" + |
64 " hostJid='" + request.hostJid + "'" + | 64 " hostJid='" + request.hostJid + "'" + |
65 " auth_token='" + request.xmppAuth + "'"); | 65 " auth_token='" + request.xmppAuth + "'"); |
66 navigate(newTabUrl, function(tab) { | 66 |
67 console.log("We're trying now to send to " + tab.id); | 67 var sendRequestFunc = function (tab) { |
68 chrome.tabs.sendRequest( | 68 console.log("We're trying now to send to " + tab.id); |
69 tab.id, request, function() { | 69 chrome.tabs.sendRequest( |
70 console.log('Tab finished connect.'); | 70 tab.id, request, function() { |
71 }); | 71 console.log('Tab finished connect.'); |
72 }); | 72 }); |
| 73 }; |
| 74 |
| 75 // This function will run when after the url for the tab is updated. If |
| 76 // the tab is not yet loaded it will wait for another 500ms to inspect |
| 77 // again. |
| 78 var checkStatusFunc = function (tab) { |
| 79 if (tab.status == "complete") { |
| 80 sendRequestFunc(tab); |
| 81 return; |
| 82 } |
| 83 |
| 84 // Wait for 500ms and then get the tab and check its status. |
| 85 setTimeout(function() { |
| 86 chrome.tabs.get(tab.id, checkStatusFunc); |
| 87 }, 500); |
| 88 } |
| 89 |
| 90 navigate(newTabUrl, checkStatusFunc); |
73 } | 91 } |
OLD | NEW |