OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <!-- | 3 <!-- |
4 | 4 |
5 Copyright (c) 2010 The Chromium Authors. All rights reserved. | 5 Copyright (c) 2010 The Chromium Authors. All rights reserved. |
6 Use of this source code is governed by a BSD-style license that can be | 6 Use of this source code is governed by a BSD-style license that can be |
7 found in the LICENSE file. | 7 found in the LICENSE file. |
8 | 8 |
9 Extension purpose: route all Google Talk chats through the central roster | 9 Extension purpose: route all Google Talk chats through the central roster |
10 hosted in this extension. The included logic is paired with logic in Gmail | 10 hosted in this extension. The included logic is paired with logic in Gmail |
11 to route both incoming and outgoing chats through this central roster. | 11 to route both incoming and outgoing chats through this central roster. |
12 | 12 |
13 --> | 13 --> |
14 <body> | 14 <body> |
15 <iframe | 15 <iframe |
16 id='centralRoster' | 16 id='centralRoster' |
17 src='central_roster.html'>Central Roster</iframe> | 17 src='central_roster.html'>Central Roster</iframe> |
18 <script src="js/chatbridgeeventtypes.js"></script> | 18 <script src="js/chatbridgeeventtypes.js"></script> |
19 <script> | 19 <script> |
20 var centralRosterJid; | 20 var centralRosterJid; |
21 var centralRosterPort; | 21 var centralRosterPort; |
22 var centralJidListenerPorts = []; | 22 var centralJidListenerPorts = []; |
23 | 23 |
24 // Notify all port listeners of updated central roster jid. | 24 // Notify all port listeners of an event. |
25 function forwardCentralRosterJidToPortListeners() { | 25 function forwardEventToPortListeners(evtType, chatJid) { |
26 for (var listenerPort in centralJidListenerPorts) { | 26 var listenerPort; |
27 listenerPort.postMessage({jid: centralRosterJid}); | 27 for (var portIndex in centralJidListenerPorts) { |
| 28 listenerPort = centralJidListenerPorts[portIndex]; |
| 29 listenerPort.postMessage({eventType: evtType, jid: chatJid}); |
28 } | 30 } |
29 } | 31 } |
30 | 32 |
| 33 // Notify all port listeners of updated central roster jid. |
| 34 function forwardCentralRosterJidToPortListeners() { |
| 35 forwardEventToPortListeners( |
| 36 ChatBridgeEventTypes.CENTRAL_USER_UPDATE, centralRosterJid); |
| 37 } |
| 38 |
31 // Central roster jid changed. Notify all listeners. | 39 // Central roster jid changed. Notify all listeners. |
32 function centralJidUpdate(msg) { | 40 function centralJidUpdate(msg) { |
33 if (centralRosterJid != msg.jid) { | 41 if (centralRosterJid != msg.jid) { |
34 centralRosterJid = msg.jid; | 42 centralRosterJid = msg.jid; |
35 forwardCentralRosterJidToPortListeners(); | 43 forwardCentralRosterJidToPortListeners(); |
36 } | 44 } |
37 } | 45 } |
38 | 46 |
39 // Listen for content script connections. | 47 // Listen for content script connections. |
40 chrome.extension.onConnect.addListener(function(port) { | 48 chrome.extension.onConnect.addListener(function(port) { |
(...skipping 40 matching lines...) Loading... |
81 switch (request.msg) { | 89 switch (request.msg) { |
82 case ChatBridgeEventTypes.CENTRAL_USER_WATCHER: | 90 case ChatBridgeEventTypes.CENTRAL_USER_WATCHER: |
83 sendResponse({jid: centralRosterJid}); | 91 sendResponse({jid: centralRosterJid}); |
84 break; | 92 break; |
85 // For new initiated chats, forward to the central roster port. | 93 // For new initiated chats, forward to the central roster port. |
86 case ChatBridgeEventTypes.SHOW_CHAT: | 94 case ChatBridgeEventTypes.SHOW_CHAT: |
87 case ChatBridgeEventTypes.START_VIDEO: | 95 case ChatBridgeEventTypes.START_VIDEO: |
88 case ChatBridgeEventTypes.START_VOICE: | 96 case ChatBridgeEventTypes.START_VOICE: |
89 if (centralRosterPort) { | 97 if (centralRosterPort) { |
90 centralRosterPort.postMessage( | 98 centralRosterPort.postMessage( |
91 {chatType: request.msg, jid: request.jid}); | 99 {eventType: request.msg, jid: request.jid}); |
92 } else { | 100 } else { |
93 // We should not have been forwarded this message. Make sure our | 101 // We should not have been forwarded this message. Make sure our |
94 // listeners are updated with the current central roster jid. | 102 // listeners are updated with the current central roster jid. |
95 forwardCentralRosterJidToPortListeners(); | 103 forwardCentralRosterJidToPortListeners(); |
96 } | 104 } |
97 break; | 105 break; |
| 106 case ChatBridgeEventTypes.OPENED_MOLE_INCOMING: |
| 107 forwardEventToPortListeners(ChatBridgeEventTypes.OPENED_MOLE_OUTGOING, |
| 108 request.jid); |
| 109 break; |
| 110 case ChatBridgeEventTypes.CLOSED_MOLE_INCOMING: |
| 111 forwardEventToPortListeners(ChatBridgeEventTypes.CLOSED_MOLE_OUTGOING, |
| 112 request.jid); |
| 113 break; |
98 } | 114 } |
99 }); | 115 }); |
100 </script> | 116 </script> |
101 </body> | 117 </body> |
102 </html> | 118 </html> |
OLD | NEW |