diff options
Diffstat (limited to 'chrome/browser/resources/chat_manager')
-rw-r--r-- | chrome/browser/resources/chat_manager/16.png | bin | 0 -> 909 bytes | |||
-rw-r--r-- | chrome/browser/resources/chat_manager/_locales/en/messages.json | 1 | ||||
-rw-r--r-- | chrome/browser/resources/chat_manager/background.html | 30 | ||||
-rw-r--r-- | chrome/browser/resources/chat_manager/central_roster.html | 61 | ||||
-rw-r--r-- | chrome/browser/resources/chat_manager/central_roster_viewer.html | 10 | ||||
-rw-r--r-- | chrome/browser/resources/chat_manager/js/chatbridgeeventtypes.js | 3 | ||||
-rw-r--r-- | chrome/browser/resources/chat_manager/js/chatbridgehook.js | 12 | ||||
-rw-r--r-- | chrome/browser/resources/chat_manager/manifest.json | 8 |
8 files changed, 93 insertions, 32 deletions
diff --git a/chrome/browser/resources/chat_manager/16.png b/chrome/browser/resources/chat_manager/16.png Binary files differnew file mode 100644 index 0000000..acd4e72 --- /dev/null +++ b/chrome/browser/resources/chat_manager/16.png diff --git a/chrome/browser/resources/chat_manager/_locales/en/messages.json b/chrome/browser/resources/chat_manager/_locales/en/messages.json new file mode 100644 index 0000000..d4788ae --- /dev/null +++ b/chrome/browser/resources/chat_manager/_locales/en/messages.json @@ -0,0 +1 @@ +{"chat_manager_name":{"message":"Google Talk"},"chat_manager_description":{"message":"Use Google Talk extension to chat with friends."},"chat_manager_could_not_connect":{"message":"Could not connect to Google Talk."},"chat_manager_retry_now":{"message":"Retry Now"},"chat_manager_retrying_in":{"message":"Retrying in $1:$2","placeholders":{"1":{"content":"$1"},"2":{"content":"$2"}}}} diff --git a/chrome/browser/resources/chat_manager/background.html b/chrome/browser/resources/chat_manager/background.html index 964db68..b776cf2 100644 --- a/chrome/browser/resources/chat_manager/background.html +++ b/chrome/browser/resources/chat_manager/background.html @@ -14,7 +14,7 @@ to route both incoming and outgoing chats through this central roster. <body> <iframe id='centralRoster' - src='central_roster.html'>Central Roster</iframe> + src='central_roster.html'></iframe> <script src="js/chatbridgeeventtypes.js"></script> <script> var centralRosterJid; @@ -44,12 +44,37 @@ to route both incoming and outgoing chats through this central roster. } } + // Focus a chat popup. + function focusMole(hostId) { + findMole(hostId, function(win) { + chrome.windows.update(win.id, {focused: true}); + }); + } + + // Find a chat popup from a chat's hostId and executes callback with it. + function findMole(hostId, callback) { + var matchUrlIdRegExp = new RegExp('[&?]id=' + hostId + '(&|$)', 'i'); + chrome.windows.getAll({populate: true}, function(wins) { + for (var winIdx = 0, win = wins[winIdx]; win; win = wins[++winIdx]) { + var tabs = win.tabs; + for (var tabIdx = 0, tab = tabs[tabIdx]; tab; tab = tabs[++tabIdx]) { + if ((tab.url).match(matchUrlIdRegExp)) { + callback(win); + return; + } + } + } + }); + } + // Listen for content script connections. chrome.extension.onConnect.addListener(function(port) { // New central jid listener. // Update with current central roster jid, and add to tracking array. if (port.name == 'centralJidListener') { centralJidListenerPorts.push(port); + port.postMessage({eventType: ChatBridgeEventTypes.CENTRAL_USER_UPDATE, + jid: centralRosterJid}); // Clear tracking array entry when content script closes. port.onDisconnect.addListener(function(port) { @@ -111,6 +136,9 @@ to route both incoming and outgoing chats through this central roster. forwardEventToPortListeners(ChatBridgeEventTypes.CLOSED_MOLE_OUTGOING, request.jid); break; + case ChatBridgeEventTypes.MOLE_FOCUSED: + focusMole(request.jid); + break; } }); </script> diff --git a/chrome/browser/resources/chat_manager/central_roster.html b/chrome/browser/resources/chat_manager/central_roster.html index aa68798..3dfe173 100644 --- a/chrome/browser/resources/chat_manager/central_roster.html +++ b/chrome/browser/resources/chat_manager/central_roster.html @@ -27,9 +27,8 @@ Central roster: hosting all Google Talk chats in ChromeOS. } </style> <script> - var MIN_RETRY_MILLISECONDS = 15 * 1000; + var MIN_RETRY_MILLISECONDS = 1 * 1000; var MAX_RETRY_MILLISECONDS = 4 * 60 * 1000; - var retryStartTime = 0; var retryTime; var retryTimer; var chatClient = null; @@ -38,8 +37,9 @@ Central roster: hosting all Google Talk chats in ChromeOS. 'protocol': 'https', 'host': 'talkgadget.google.com', 'jsmode': 'pre', - 'hl': 'en', + 'hl': chrome.i18n.getMessage('@@ui_locale'), }; + // Read args. var urlParts = window.location.href.split(/[?&#]/); for (var i = 1; i < urlParts.length; i++) { @@ -63,19 +63,17 @@ Central roster: hosting all Google Talk chats in ChromeOS. document.body.appendChild(script); } function retryConnection() { - if (retryTimer) { - clearTimeout(retryTimer); - retryTimer = null; - } - runGTalkScript(); + location.reload(); } function retryConnectionCountdown() { var seconds = retryTime / 1000; var minutes = Math.floor(seconds / 60); seconds -= minutes * 60; - document.getElementById('retryStatus').textContent = - 'Retrying in ' + minutes + ':' + (seconds < 10 ? '0' : '') + seconds; + document.getElementById('retryStatus').textContent = + chrome.i18n.getMessage('CHAT_MANAGER_RETRYING_IN', + [minutes, (seconds < 10 ? '0' : '') + seconds]); + if (retryTime <= 0) { retryConnection(); } else { @@ -86,39 +84,58 @@ Central roster: hosting all Google Talk chats in ChromeOS. function loadGTalk() { if (window.GTalkNotifier) { document.getElementById('retryInfo').style.display = 'none'; + var baseUrl = args['protocol'] + '://' + args['host'] + '/talkgadget/'; chatClient = new window.GTalkNotifier( { - 'clientBaseUrl': - args['protocol'] + '://' + args['host'] + '/talkgadget/', + 'clientBaseUrl': baseUrl, 'clientUrl': 'notifierclient' + (args['jsmode'] != '' ? ('?jsmode=' + args['jsmode']) : ''), 'propertyName': 'ChromeOS', - 'xpcRelay': 'xpc_relay', - 'xpcBlank': 'xpc_blank', + 'xpcRelay': baseUrl + 'xpc_relay', + 'xpcBlank': baseUrl + 'xpc_blank', 'locale': args['hl'], 'isCentralRoster': true, 'hideProfileCard': true, 'isFullFrame': true } ); + delete localStorage.retryStartTime; } else { - if (retryStartTime == 0) { - retryStartTime = MIN_RETRY_MILLISECONDS; - } else if (retryStartTime < MAX_RETRY_MILLISECONDS) { - retryStartTime = Math.min(retryStartTime * 2, MAX_RETRY_MILLISECONDS); + if (!localStorage.retryStartTime) { + localStorage.retryStartTime = MIN_RETRY_MILLISECONDS; + } else if (localStorage.retryStartTime < MAX_RETRY_MILLISECONDS) { + localStorage.retryStartTime = Math.min(localStorage.retryStartTime * 2, + MAX_RETRY_MILLISECONDS); } - retryTime = retryStartTime; + retryTime = localStorage.retryStartTime; document.getElementById('retryInfo').style.display = 'inline'; retryConnectionCountdown(); } } + function onPageLoaded() { + // localize the page + document.getElementById('retryMessage').textContent = + chrome.i18n.getMessage('CHAT_MANAGER_COULD_NOT_CONNECT'); + document.getElementById('retryButton').value = + chrome.i18n.getMessage('CHAT_MANAGER_RETRY_NOW'); + + if (localStorage.hasOpenedInViewer) { + runGTalkScript(); + } + } + function onOpenedInViewer() { + if (!localStorage.hasOpenedInViewer) { + localStorage.hasOpenedInViewer = true; + runGTalkScript(); + } + } </script> </head> -<body onload='runGTalkScript()'> +<body onload='onPageLoaded()'> <div id='retryInfo' style='display:none'> - <p>Could not connect to Google Talk</p> + <p id='retryMessage'></p> <p id='retryStatus'></p> - <input type='button' value='Retry Now' onclick='retryConnection()'/> + <input id='retryButton' type='button' value='' onclick='retryConnection()'/> </div> </body> </html> diff --git a/chrome/browser/resources/chat_manager/central_roster_viewer.html b/chrome/browser/resources/chat_manager/central_roster_viewer.html index bab1cdf..fb62dbf 100644 --- a/chrome/browser/resources/chat_manager/central_roster_viewer.html +++ b/chrome/browser/resources/chat_manager/central_roster_viewer.html @@ -8,7 +8,7 @@ found in the LICENSE file. --> <head> - <title>Google Talk</title> + <title></title> <!-- Set height to 98% to get around bug in css calculation that triggers a vertical scroll bar. --> <style> @@ -21,6 +21,8 @@ found in the LICENSE file. } </style> <script> + document.title = chrome.i18n.getMessage('CHAT_MANAGER_NAME'); + function reparentCentralRosterToWindow() { var backgroundWindow = chrome.extension.getBackgroundPage(); if (backgroundWindow) { @@ -33,7 +35,13 @@ found in the LICENSE file. document.adoptNode(iframe); } document.body.appendChild(iframe); + iframe.contentWindow.onOpenedInViewer(); } + } else { + // Could not locate central roster. Close this blank window. + // Workaround since Chrome extensions cannot be singletons. + // Reference: http://crbug.com/45816 + window.close(); } } } diff --git a/chrome/browser/resources/chat_manager/js/chatbridgeeventtypes.js b/chrome/browser/resources/chat_manager/js/chatbridgeeventtypes.js index 8607fe8..3397115 100644 --- a/chrome/browser/resources/chat_manager/js/chatbridgeeventtypes.js +++ b/chrome/browser/resources/chat_manager/js/chatbridgeeventtypes.js @@ -18,5 +18,6 @@ var ChatBridgeEventTypes = { OPENED_MOLE_INCOMING: 'onMoleOpened', OPENED_MOLE_OUTGOING: 'onCentralMoleOpened', CLOSED_MOLE_INCOMING: 'onMoleClosed', - CLOSED_MOLE_OUTGOING: 'onCentralMoleClosed' + CLOSED_MOLE_OUTGOING: 'onCentralMoleClosed', + MOLE_FOCUSED: '*mfo' }; diff --git a/chrome/browser/resources/chat_manager/js/chatbridgehook.js b/chrome/browser/resources/chat_manager/js/chatbridgehook.js index afbe0be..9549a83 100644 --- a/chrome/browser/resources/chat_manager/js/chatbridgehook.js +++ b/chrome/browser/resources/chat_manager/js/chatbridgehook.js @@ -43,10 +43,11 @@ function forwardChatEvent(event) { } /** - * Triggered on opening/closing a central roster chat. Forward to extension. + * Forward mole events to extension. + * Triggered on opening/closing/focus a central roster chat. * @param {MessageEvent} event the opened/closed event. */ -function moleOpenedClosed(event) { +function forwardMoleEvent(event) { var eventType = event.type; var chatJid = event.data; chrome.extension.sendRequest({msg: eventType, jid: chatJid}); @@ -132,10 +133,13 @@ function onPageLoaded() { setupCentralRosterJidListener, false); divRosterHandler.addEventListener( ChatBridgeEventTypes.OPENED_MOLE_INCOMING, - moleOpenedClosed, false); + forwardMoleEvent, false); divRosterHandler.addEventListener( ChatBridgeEventTypes.CLOSED_MOLE_INCOMING, - moleOpenedClosed, false); + forwardMoleEvent, false); + divRosterHandler.addEventListener( + ChatBridgeEventTypes.MOLE_FOCUSED, + forwardMoleEvent, false); } } diff --git a/chrome/browser/resources/chat_manager/manifest.json b/chrome/browser/resources/chat_manager/manifest.json index df65666..982dcb6 100644 --- a/chrome/browser/resources/chat_manager/manifest.json +++ b/chrome/browser/resources/chat_manager/manifest.json @@ -1,14 +1,16 @@ { "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDrlwvcbUtVrbQvI7EPV1BTa63N8YkbBToHzxlMl0IzSBwOV+TUOsHE8vRq0HZWuwMAGeH8WdWVC3HRNdES8lScjlzxb1TsTQJAsF+hLXgcjgCUSSSGCfFzypvuvKsRQTx0d02yfWKJa47o0Ws5wL72NVtc7c51HujwWYg+Mz01wIDAQAB", - "name": "Google Talk", - "version": "1.0.13", + "name": "__MSG_CHAT_MANAGER_NAME__", + "version": "1.0.17", "icons": { "128": "128.png", + "16": "16.png", "24": "24.png", "32": "32.png", "48": "48.png" }, - "description": "Google Talk", + "description": "__MSG_CHAT_MANAGER_DESCRIPTION__", + "default_locale": "en", "background_page": "background.html", "options_page": "options.html", "content_scripts": [ { |