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 /** | 7 /** |
8 * @type {string} The host id corresponding to the user's VM. The @pending | 8 * @type {string} The host id corresponding to the user's VM. The @pending |
9 * place-holder instructs the Orchestrator to abandon any pending host, | 9 * place-holder instructs the Orchestrator to abandon any pending host, |
10 * and is used if no host id is provided by the main window. | 10 * and is used if no host id is provided by the main window. |
11 */ | 11 */ |
12 var hostId = '@pending'; | 12 var hostId = '@pending'; |
13 | 13 |
14 /** | 14 /** |
15 * @type {string} The network stats at the time the feedback consent dialog | 15 * @type {string} The network stats at the time the feedback consent dialog |
16 * was shown. | 16 * was shown. |
17 */ | 17 */ |
18 var connectionStats = null; | 18 var connectionStats = ''; |
19 | 19 |
20 /** | 20 /** |
21 * @type {string} "no" => user did not request a VM reset; "yes" => VM was | 21 * @type {string} "no" => user did not request a VM reset; "yes" => VM was |
22 * successfully reset; "failed" => user requested a reset, but it failed. | 22 * successfully reset; "failed" => user requested a reset, but it failed. |
23 */ | 23 */ |
24 var abandonHost = 'no'; | 24 var abandonHost = 'no'; |
25 | 25 |
26 /** | 26 /** |
27 * @type {Window} The main application window. | 27 * @type {Window} The main application window. |
28 */ | 28 */ |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 crashServiceReportId = ''; | 95 crashServiceReportId = ''; |
96 formBody.hidden = true; | 96 formBody.hidden = true; |
97 resizeWindow(); | 97 resizeWindow(); |
98 } | 98 } |
99 | 99 |
100 /** | 100 /** |
101 * @return {string} A random string ID. | 101 * @return {string} A random string ID. |
102 */ | 102 */ |
103 function generateId() { | 103 function generateId() { |
104 var idArray = new Uint8Array(20); | 104 var idArray = new Uint8Array(20); |
105 crypto.getRandomValues(idArray); | 105 window.crypto.getRandomValues(idArray); |
106 return btoa(String.fromCharCode.apply(null, idArray)); | 106 return window.btoa(String.fromCharCode.apply(null, idArray)); |
107 } | 107 } |
108 | 108 |
109 /** | 109 /** |
110 * @param {string} token | 110 * @param {string} token |
111 */ | 111 */ |
112 function onToken(token) { | 112 function onToken(token) { |
113 var getUserInfo = function() { | 113 var getUserInfo = function() { |
114 var oauth2Api = new remoting.OAuth2ApiImpl(); | 114 var oauth2Api = new remoting.OAuth2ApiImpl(); |
115 oauth2Api.getUserInfo( | 115 oauth2Api.getUserInfo( |
116 onUserInfo, onUserInfo.bind(null, 'unknown', 'unknown'), token); | 116 onUserInfo, onUserInfo.bind(null, 'unknown', 'unknown'), token); |
117 }; | 117 }; |
118 if (!token) { | 118 if (!token) { |
119 onUserInfo('unknown', 'unknown'); | 119 onUserInfo('unknown', 'unknown'); |
120 } else { | 120 } else { |
121 if (abandonHost == 'yes') { | 121 if (abandonHost == 'yes') { |
122 var body = { | 122 var body = { |
123 'abandonHost': 'true', | 123 'abandonHost': 'true', |
124 'crashServiceReportId': crashServiceReportId | 124 'crashServiceReportId': crashServiceReportId |
125 }; | 125 }; |
126 var headers = { | |
127 'Authorization': 'OAuth ' + token, | |
128 'Content-type': 'application/json' | |
129 }; | |
130 var uri = remoting.settings.APP_REMOTING_API_BASE_URL + | 126 var uri = remoting.settings.APP_REMOTING_API_BASE_URL + |
131 '/applications/' + remoting.settings.getAppRemotingApplicationId() + | 127 '/applications/' + remoting.settings.getAppRemotingApplicationId() + |
132 '/hosts/' + hostId + | 128 '/hosts/' + hostId + |
133 '/reportIssue'; | 129 '/reportIssue'; |
134 /** @param {XMLHttpRequest} xhr */ | 130 /** @param {XMLHttpRequest} xhr */ |
135 var onDone = function(xhr) { | 131 var onDone = function(xhr) { |
136 if (xhr.status >= 200 && xhr.status < 300) { | 132 if (xhr.status >= 200 && xhr.status < 300) { |
137 getUserInfo(); | 133 getUserInfo(); |
138 } else { | 134 } else { |
139 showError(); | 135 showError(); |
140 } | 136 } |
141 }; | 137 }; |
142 remoting.xhr.post(uri, onDone, JSON.stringify(body), headers); | 138 remoting.xhr.start({ |
| 139 method: 'POST', |
| 140 url: uri, |
| 141 onDone: onDone, |
| 142 jsonContent: body, |
| 143 oauthToken: token |
| 144 }); |
143 } else { | 145 } else { |
144 getUserInfo(); | 146 getUserInfo(); |
145 } | 147 } |
146 } | 148 } |
147 } | 149 } |
148 | 150 |
149 function onOk() { | 151 function onOk() { |
150 setWaiting(true); | 152 setWaiting(true); |
151 var abandon = /** @type {HTMLInputElement} */ | 153 var abandon = /** @type {HTMLInputElement} */ |
152 (document.getElementById('abandon-host')); | 154 (document.getElementById('abandon-host')); |
(...skipping 24 matching lines...) Expand all Loading... |
177 | 179 |
178 function onToggleLogs() { | 180 function onToggleLogs() { |
179 var includeLogs = document.getElementById('include-logs'); | 181 var includeLogs = document.getElementById('include-logs'); |
180 if (includeLogs.checked) { | 182 if (includeLogs.checked) { |
181 crashServiceReportId = generateId(); | 183 crashServiceReportId = generateId(); |
182 } else { | 184 } else { |
183 crashServiceReportId = ''; | 185 crashServiceReportId = ''; |
184 } | 186 } |
185 } | 187 } |
186 | 188 |
| 189 /** @param {Event} event */ |
187 function onLearnMore(event) { | 190 function onLearnMore(event) { |
188 event.preventDefault(); // Clicking the link should not tick the checkbox. | 191 event.preventDefault(); // Clicking the link should not tick the checkbox. |
189 var learnMoreLink = document.getElementById('learn-more'); | 192 var learnMoreLink = document.getElementById('learn-more'); |
190 var learnMoreInfobox = document.getElementById('privacy-info'); | 193 var learnMoreInfobox = document.getElementById('privacy-info'); |
191 learnMoreLink.hidden = true; | 194 learnMoreLink.hidden = true; |
192 learnMoreInfobox.hidden = false; | 195 learnMoreInfobox.hidden = false; |
193 resizeWindow(); | 196 resizeWindow(); |
194 } | 197 } |
195 | 198 |
196 function resizeWindow() { | 199 function resizeWindow() { |
(...skipping 24 matching lines...) Expand all Loading... |
221 var method = /** @type {string} */ (event.data['method']); | 224 var method = /** @type {string} */ (event.data['method']); |
222 if (method == 'init') { | 225 if (method == 'init') { |
223 if (event.data['hostId']) { | 226 if (event.data['hostId']) { |
224 hostId = /** @type {string} */ (event.data['hostId']); | 227 hostId = /** @type {string} */ (event.data['hostId']); |
225 } | 228 } |
226 connectionStats = /** @type {string} */ (event.data['connectionStats']); | 229 connectionStats = /** @type {string} */ (event.data['connectionStats']); |
227 } | 230 } |
228 }; | 231 }; |
229 | 232 |
230 window.addEventListener('load', onLoad, false); | 233 window.addEventListener('load', onLoad, false); |
OLD | NEW |