diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-04 18:28:03 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-04 18:28:03 +0000 |
commit | ae90f252d04c941f8ff9e7a7cfdd20b64c98cd83 (patch) | |
tree | 64a2c51018629fb8c04c8fda563a9d21c286258d /chrome | |
parent | 331c251e8ec80f33c7bf5aea39f4afae814d1a7c (diff) | |
download | chromium_src-ae90f252d04c941f8ff9e7a7cfdd20b64c98cd83.zip chromium_src-ae90f252d04c941f8ff9e7a7cfdd20b64c98cd83.tar.gz chromium_src-ae90f252d04c941f8ff9e7a7cfdd20b64c98cd83.tar.bz2 |
Checking in chat_manager built-in extension, this time behind --enable-chat-manager flag.
Patch by seh@chromium.org
http://codereview.chromium.org/1719023/show
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1904003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46369 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_resources.grd | 1 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 8 | ||||
-rw-r--r-- | chrome/browser/resources/chat_manager/background.html | 140 | ||||
-rw-r--r-- | chrome/browser/resources/chat_manager/js/chatbridgeeventtypes.js | 15 | ||||
-rw-r--r-- | chrome/browser/resources/chat_manager/js/chatbridgehook.js | 24 | ||||
-rw-r--r-- | chrome/browser/resources/chat_manager/js/gmailbridgehook.js | 54 | ||||
-rw-r--r-- | chrome/browser/resources/chat_manager/manifest.json | 36 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 23 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 3 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 |
10 files changed, 304 insertions, 1 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index b9d2e09..ef553b8 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -47,6 +47,7 @@ without changes to the corresponding grd file. paaaae --> <include name="IDR_GMAIL_APP_MANIFEST" file="resources\gmail_app\manifest.json" type="BINDATA" /> <include name="IDR_CALENDAR_APP_MANIFEST" file="resources\calendar_app\manifest.json" type="BINDATA" /> <include name="IDR_DOCS_APP_MANIFEST" file="resources\docs_app\manifest.json" type="BINDATA" /> + <include name="IDR_CHAT_MANAGER_MANIFEST" file="resources\chat_manager\manifest.json" type="BINDATA" /> <include name="IDR_DOWNLOADS_HTML" file="resources\downloads.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_LOCAL_STRINGS_JS" file="resources\shared\js\local_strings.js" type="BINDATA" /> <include name="IDR_DOM_UI_CSS" file="resources\dom_ui.css" flattenhtml="true" type="BINDATA" /> diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index e4f2bd0..c256fee 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -739,6 +739,14 @@ void ProfileImpl::InitExtensions() { // Bookmark manager. component_extensions["bookmark_manager"] = IDR_BOOKMARKS_MANIFEST; +#if defined(OS_CHROMEOS) + // Chat manager. + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableChatManager)) { + component_extensions["chat_manager"] = IDR_CHAT_MANAGER_MANIFEST; + } +#endif + // Some sample apps to make our lives easier while we are developing extension // apps. This way we don't have to constantly install these over and over. if (CommandLine::ForCurrentProcess()->HasSwitch( diff --git a/chrome/browser/resources/chat_manager/background.html b/chrome/browser/resources/chat_manager/background.html new file mode 100644 index 0000000..06a0c96 --- /dev/null +++ b/chrome/browser/resources/chat_manager/background.html @@ -0,0 +1,140 @@ +<!DOCTYPE html> +<html> +<!-- + +Copyright (c) 2010 The Chromium Authors. All rights reserved. +Use of this source code is governed by a BSD-style license that can be +found in the LICENSE file. + +Extension purpose: route all Google Talk chats through the central roster +hosted in this extension. The included logic is paired with logic in Gmail +to route both incoming and outgoing chats through this central roster. + +--> +<body> +<style> + .talk_roster { + position: fixed; + left: 0px; + top: 0px; + } + .talk_iframe { + width: 100%; + height: 100%; + border: none; + overflow-x: hidden; + overflow-y: hidden; + } +</style> +<script> + var args = { + 'host': 'talkgadget.google.com', + 'jsmode': 'pre', + 'hl': 'en', + }; + // Read args. + var urlParts = window.location.href.split(/[?&#]/); + for (var i = 1; i < urlParts.length; i++) { + var argParts = urlParts[i].split('='); + if (argParts.length == 2) { + args[argParts[0]] = argParts[1]; + } + } + document.write('<script src="https://' + args['host'] + + '/talkgadget/notifier-js?silent=true&host=https://' + args['host'] + + '/talkgadget/notifier-js' + + (args['jsmode'] != '' ? ('&jsmode=' + args['jsmode']) : '') + + '"></scr' + 'ipt>'); +</script> +<script src="js/chatbridgeeventtypes.js"></script> +<script> + var chatClient = null; + if (window.GTalkNotifier) { + chatClient = new GTalkNotifier( + 'http://' + args['host'] + '/talkgadget/', + 'notifierclient' + + (args['jsmode'] != '' ? ('?jsmode=' + args['jsmode']) : ''), + 'ifpc_relay', + 'ifpc.js', + 'Google Talk', + { + hostCallback: function(){}, + xpcRelay: 'xpc_relay', + xpcBlank: 'xpc_blank', + locale: args['hl'], + isCentralRoster: true, + hideProfileCard: true + } + ); + } else { + document.write( + '<div class="talk_roster"><b>GTalkNotifier undefined</b></div>'); + } + var centralRosterJid; + var tabIdToGmPort = {}; + + // Notify all open Gmail pages of updated central roster jid. + function forwardCentralRosterJidToGmPorts() { + for (var tabId in tabIdToGmPort) { + var port = tabIdToGmPort[tabId]; + if (port != null) { + port.postMessage({jid: centralRosterJid}); + } + } + } + + // Observe all tab closures. Clear the corresponding Gmail tracking entry. + chrome.tabs.onRemoved.addListener(function(tabId) { + if (tabIdToGmPort[tabId] != null) { + delete tabIdToGmPort[tabId]; + } + }); + + // Listen for content script connections with Gmail pages and add a + // corresponding tracking entry. + chrome.extension.onConnect.addListener(function(port) { + if (port.name == 'centralJidWatcher') { + tabIdToGmPort[port.sender.tab.id] = port; + } + }); + + // Listen for requests from our content scripts. + chrome.extension.onRequest.addListener(function(request, sender) { + switch (request.msg) { + // For new initiated chats, forward to this page's GTalk client. + case ChatBridgeEventTypes.SHOW_CHAT: + if (chatClient != null) { + chatClient._showChat(request.jid); + } + break; + case ChatBridgeEventTypes.START_VIDEO: + if (chatClient != null) { + chatClient._startVideoChat(request.jid); + } + break; + case ChatBridgeEventTypes.START_VOICE: + if (chatClient != null) { + chatClient._startVoiceChat(request.jid); + } + break; + // For changes in the central roster, forward to all Gmail pages. + case ChatBridgeEventTypes.CENTRAL_USER_UPDATE: + if (centralRosterJid != request.jid) { + centralRosterJid = request.jid; + forwardCentralRosterJidToGmPorts(); + } + break; + // For a request of the latest central roster jid, respond back to the + // requesting port. + case ChatBridgeEventTypes.REQUEST_CENTRAL_USER: + var tabId = sender.tab.id; + var port = tabIdToGmPort[tabId]; + if (port != null) { + port.postMessage({jid: centralRosterJid}); + } + break; + } + }); +</script> +</body> +</html> diff --git a/chrome/browser/resources/chat_manager/js/chatbridgeeventtypes.js b/chrome/browser/resources/chat_manager/js/chatbridgeeventtypes.js new file mode 100644 index 0000000..e2d6223 --- /dev/null +++ b/chrome/browser/resources/chat_manager/js/chatbridgeeventtypes.js @@ -0,0 +1,15 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Chat bridge event types. + * @enum {string} + */ +var ChatBridgeEventTypes = { + SHOW_CHAT: 'showChat', + START_VIDEO: 'startVideo', + START_VOICE: 'startVoice', + CENTRAL_USER_UPDATE: 'centralJidUpdate', + REQUEST_CENTRAL_USER: 'getCentralJid' +}; diff --git a/chrome/browser/resources/chat_manager/js/chatbridgehook.js b/chrome/browser/resources/chat_manager/js/chatbridgehook.js new file mode 100644 index 0000000..5e3854c --- /dev/null +++ b/chrome/browser/resources/chat_manager/js/chatbridgehook.js @@ -0,0 +1,24 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Central user update listener triggered by a change in Chrome chat code. + * @param {MessageEvent} event the user update event. + */ +function centralUserUpdate(event) { + var centralRosterJid = event.data; + chrome.extension.sendRequest( + { + msg: ChatBridgeEventTypes.CENTRAL_USER_UPDATE, + jid: centralRosterJid + } + ); +} + +// Search for communication channel div. +var divRosterHandler = document.getElementById('roster_comm_link'); +if (divRosterHandler) { + divRosterHandler.addEventListener(ChatBridgeEventTypes.CENTRAL_USER_UPDATE, + centralUserUpdate, false); +} diff --git a/chrome/browser/resources/chat_manager/js/gmailbridgehook.js b/chrome/browser/resources/chat_manager/js/gmailbridgehook.js new file mode 100644 index 0000000..c1c4583 --- /dev/null +++ b/chrome/browser/resources/chat_manager/js/gmailbridgehook.js @@ -0,0 +1,54 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Triggered on a user initiated chat request. Forward to extension to be + * processed by the Chrome central roster. + * @param {MessageEvent} event the new chat event. + */ +function forwardChatEvent(event) { + var chatJid = event.data; + chrome.extension.sendRequest({msg: event.type, jid: chatJid}); +} + +/** + * Triggered by Gmail on startup to request the current central roster jid. + * @param {MessageEvent} event the central roster jid request event. + */ +function requestCentralUserJid(event) { + chrome.extension.sendRequest( + {msg: ChatBridgeEventTypes.REQUEST_CENTRAL_USER}); +} + +/** + * Initialize a communication channel with a Gmail chat component and the + * Chrome extension background logic. + * @param {HTMLElement} divHandler the div element used to communicate. + */ +function attachToDivGmHandler(divHandler) { + divHandler.addEventListener(ChatBridgeEventTypes.SHOW_CHAT, + forwardChatEvent, false); + divHandler.addEventListener(ChatBridgeEventTypes.START_VIDEO, + forwardChatEvent, false); + divHandler.addEventListener(ChatBridgeEventTypes.START_VOICE, + forwardChatEvent, false); + divHandler.addEventListener(ChatBridgeEventTypes.REQUEST_CENTRAL_USER, + requestCentralUserJid, false); + // Set up a direct channel with the extension to forward updated central + // roster jid's. + var port = chrome.extension.connect({name: 'centralJidWatcher'}); + port.onMessage.addListener(function(msg) { + var centralRosterJid = msg.jid; + var outgoingChatEvent = document.createEvent('MessageEvent'); + outgoingChatEvent.initMessageEvent( + ChatBridgeEventTypes.CENTRAL_USER_UPDATE, true, true, centralRosterJid); + divHandler.dispatchEvent(outgoingChatEvent); + }); +} + +// Search for communication channel div. +var divGmailHandler = document.getElementById('mainElement'); +if (divGmailHandler) { + attachToDivGmHandler(divGmailHandler); +} diff --git a/chrome/browser/resources/chat_manager/manifest.json b/chrome/browser/resources/chat_manager/manifest.json new file mode 100644 index 0000000..9d55ad4 --- /dev/null +++ b/chrome/browser/resources/chat_manager/manifest.json @@ -0,0 +1,36 @@ +{ + "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDrlwvcbUtVrbQvI7EPV1BTa63N8YkbBToHzxlMl0IzSBwOV+TUOsHE8vRq0HZWuwMAGeH8WdWVC3HRNdES8lScjlzxb1TsTQJAsF+hLXgcjgCUSSSGCfFzypvuvKsRQTx0d02yfWKJa47o0Ws5wL72NVtc7c51HujwWYg+Mz01wIDAQAB", + "name": "Gmail to Chrome chat bridge (by Google)", + "version": "1.0", + "description": "Gmail to Chrome chat bridge", + "background_page": "background.html", + "content_scripts": [ { + "js": [ + "js/chatbridgeeventtypes.js", + "js/chatbridgehook.js" + ], + "matches": [ + "http://talkgadget.google.com/*", + "https://talkgadget.google.com/*" + ], + "run_at": "document_end", + "all_frames": true + }, { + "js": [ + "js/chatbridgeeventtypes.js", + "js/gmailbridgehook.js" + ], + "matches": [ + "http://mail.google.com/*", + "https://mail.google.com/*" + ], + "run_at": "document_end" + }], + "permissions": [ + "tabs", + "http://talkgadget.google.com/*", + "https://talkgadget.google.com/*", + "http://mail.google.com/*", + "https://mail.google.com/*" + ] +} diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 125258d..91b147e 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3355,7 +3355,28 @@ 'browser/resources/docs_app/24.png', ] }, - ] + ], + 'conditions': [ + ['OS=="linux" and chromeos==1',{ + 'copies': [ + { + 'destination': '<(PRODUCT_DIR)/resources/chat_manager', + 'files': [ + 'browser/resources/chat_manager/background.html', + 'browser/resources/chat_manager/manifest.json', + ] + }, + { + 'destination': '<(PRODUCT_DIR)/resources/chat_manager/js', + 'files': [ + 'browser/resources/chat_manager/js/chatbridgeeventtypes.js', + 'browser/resources/chat_manager/js/chatbridgehook.js', + 'browser/resources/chat_manager/js/gmailbridgehook.js', + ] + }, + ] + }] + ], }, { 'target_name': 'net_internals_resources', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index c253461..7198126 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -813,6 +813,9 @@ const char kZygoteProcess[] = "zygote"; // single-sign-on cookies. const char kCookiePipe[] = "cookie-pipe"; +// Enables the chat manager component extension. +const char kEnableChatManager[] = "enable-chat-manager"; + // Enable the redirection of viewable document requests to the Google // Document Viewer. const char kEnableGView[] = "enable-gview"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index f64b0e0..aa6f67b 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -230,6 +230,7 @@ extern const char kZygoteProcess[]; #if defined(OS_CHROMEOS) extern const char kCookiePipe[]; +extern const char kEnableChatManager[]; extern const char kEnableGView[]; extern const char kEnableLoginImages[]; extern const char kLoginManager[]; |