OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
10 remoting.initElementEventHandlers = function() { | 10 remoting.initElementEventHandlers = function() { |
11 var goHome = function() { | 11 var goHome = function() { |
12 remoting.setMode(remoting.AppMode.HOME); | 12 remoting.setMode(remoting.AppMode.HOME); |
13 }; | 13 }; |
14 var goFinishedIT2Me = function() { | |
15 if (remoting.currentMode == remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME) { | |
16 remoting.setMode(remoting.AppMode.CLIENT_UNCONNECTED); | |
17 } else { | |
18 goHome(); | |
19 } | |
20 }; | |
21 /** @type {Array<{event: string, id: string, fn: function(Event):void}>} */ | 14 /** @type {Array<{event: string, id: string, fn: function(Event):void}>} */ |
22 var it2me_actions = [ | 15 var it2me_actions = [ |
23 { event: 'click', id: 'cancel-share-button', fn: remoting.cancelShare }, | 16 { event: 'click', id: 'cancel-share-button', fn: remoting.cancelShare }, |
24 { event: 'click', id: 'get-started-it2me', | 17 { event: 'click', id: 'get-started-it2me', |
25 fn: remoting.showIT2MeUiAndSave }, | 18 fn: remoting.showIT2MeUiAndSave }, |
26 { event: 'click', id: 'host-finished-button', fn: goHome }, | 19 { event: 'click', id: 'host-finished-button', fn: goHome }, |
27 { event: 'click', id: 'share-button', fn: remoting.tryShare } | 20 { event: 'click', id: 'share-button', fn: remoting.tryShare } |
28 ]; | 21 ]; |
29 /** @type {Array<{event: string, id: string, fn: function(Event):void}>} */ | 22 /** @type {Array<{event: string, id: string, fn: function(Event):void}>} */ |
30 var me2me_actions = [ | 23 var me2me_actions = [ |
31 { event: 'click', id: 'daemon-pin-cancel', fn: goHome }, | 24 { event: 'click', id: 'daemon-pin-cancel', fn: goHome }, |
32 { event: 'click', id: 'get-started-me2me', | 25 { event: 'click', id: 'get-started-me2me', |
33 fn: remoting.showMe2MeUiAndSave } | 26 fn: remoting.showMe2MeUiAndSave } |
34 ]; | 27 ]; |
35 /** @type {Array<{event: string, id: string, fn: function(Event):void}>} */ | 28 /** @type {Array<{event: string, id: string, fn: function(Event):void}>} */ |
36 var host_actions = [ | 29 var host_actions = [ |
37 { event: 'click', id: 'close-paired-client-manager-dialog', fn: goHome }, | 30 { event: 'click', id: 'close-paired-client-manager-dialog', fn: goHome }, |
38 { event: 'click', id: 'host-config-done-dismiss', fn: goHome }, | 31 { event: 'click', id: 'host-config-done-dismiss', fn: goHome }, |
39 { event: 'click', id: 'host-config-error-dismiss', fn: goHome }, | 32 { event: 'click', id: 'host-config-error-dismiss', fn: goHome }, |
40 { event: 'click', id: 'open-paired-client-manager-dialog', | 33 { event: 'click', id: 'open-paired-client-manager-dialog', |
41 fn: remoting.setMode.bind(null, | 34 fn: remoting.setMode.bind(null, |
42 remoting.AppMode.HOME_MANAGE_PAIRINGS) }, | 35 remoting.AppMode.HOME_MANAGE_PAIRINGS) }, |
43 { event: 'click', id: 'stop-sharing-button', fn: remoting.cancelShare } | 36 { event: 'click', id: 'stop-sharing-button', fn: remoting.cancelShare } |
44 ]; | 37 ]; |
45 /** @type {Array<{event: string, id: string, fn: function(Event):void}>} */ | 38 /** @type {Array<{event: string, id: string, fn: function(Event):void}>} */ |
46 var auth_actions = [ | 39 var auth_actions = [ |
47 { event: 'click', id: 'cancel-connect-button', fn: goHome }, | |
48 { event: 'click', id: 'sign-out', fn:remoting.signOut }, | 40 { event: 'click', id: 'sign-out', fn:remoting.signOut }, |
49 { event: 'click', id: 'token-refresh-error-ok', fn: goHome }, | 41 { event: 'click', id: 'token-refresh-error-ok', fn: goHome }, |
50 { event: 'click', id: 'token-refresh-error-sign-in', | 42 { event: 'click', id: 'token-refresh-error-sign-in', |
51 fn: remoting.handleAuthFailureAndRelaunch } | 43 fn: remoting.handleAuthFailureAndRelaunch } |
52 ]; | 44 ]; |
53 registerEventListeners(it2me_actions); | 45 registerEventListeners(it2me_actions); |
54 registerEventListeners(me2me_actions); | 46 registerEventListeners(me2me_actions); |
55 registerEventListeners(host_actions); | 47 registerEventListeners(host_actions); |
56 registerEventListeners(auth_actions); | 48 registerEventListeners(auth_actions); |
57 } | 49 } |
58 | 50 |
59 /** | 51 /** |
60 * Sign the user out of Chromoting by clearing (and revoking, if possible) the | 52 * Sign the user out of Chromoting by clearing (and revoking, if possible) the |
61 * OAuth refresh token. | 53 * OAuth refresh token. |
62 * | 54 * |
63 * Also clear all local storage, to avoid leaking information. | 55 * Also clear all local storage, to avoid leaking information. |
64 */ | 56 */ |
65 remoting.signOut = function() { | 57 remoting.signOut = function() { |
66 remoting.oauth2.removeCachedAuthToken().then(function(){ | 58 remoting.oauth2.removeCachedAuthToken().then(function(){ |
67 chrome.storage.local.clear(); | 59 chrome.storage.local.clear(); |
68 remoting.setMode(remoting.AppMode.HOME); | 60 remoting.setMode(remoting.AppMode.HOME); |
69 window.location.reload(); | 61 window.location.reload(); |
70 }); | 62 }); |
71 }; | 63 }; |
72 | 64 |
OLD | NEW |