OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
6 * UI Pages. Note the order must be in sync with the ArcAuthService::UIPage | 6 * UI Pages. Note the order must be in sync with the ArcAuthService::UIPage |
7 * enum. | 7 * enum. |
8 * @type {Array<string>} | 8 * @type {Array<string>} |
9 */ | 9 */ |
10 var UI_PAGES = ['none', | 10 var UI_PAGES = ['none', |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 */ | 59 */ |
60 var currentDeviceId = null; | 60 var currentDeviceId = null; |
61 | 61 |
62 /** | 62 /** |
63 * Indicates that terms were accepted by user. | 63 * Indicates that terms were accepted by user. |
64 * @type {boolean} | 64 * @type {boolean} |
65 */ | 65 */ |
66 var termsAccepted = false; | 66 var termsAccepted = false; |
67 | 67 |
68 /** | 68 /** |
69 * Indicates that current user has managed Arc. | |
70 * @type {boolean} | |
71 */ | |
72 var arcManaged = false; | |
73 | |
74 /** | |
75 * Tooltip text used in 'controlled by policy' indicator. | |
76 * @type {boolean} | |
77 */ | |
78 var controlledByPolicyText = ''; | |
79 | |
80 /** | |
69 * Host window inner default width. | 81 * Host window inner default width. |
70 * @const {number} | 82 * @const {number} |
71 */ | 83 */ |
72 var INNER_WIDTH = 960; | 84 var INNER_WIDTH = 960; |
73 | 85 |
74 /** | 86 /** |
75 * Host window inner default height. | 87 * Host window inner default height. |
76 * @const {number} | 88 * @const {number} |
77 */ | 89 */ |
78 var INNER_HEIGHT = 688; | 90 var INNER_HEIGHT = 688; |
(...skipping 13 matching lines...) Expand all Loading... | |
92 * Sends a native message to ArcSupportHost. | 104 * Sends a native message to ArcSupportHost. |
93 * @param {string} code The action code in message. | 105 * @param {string} code The action code in message. |
94 * @param {Object=} opt_Props Extra properties for the message. | 106 * @param {Object=} opt_Props Extra properties for the message. |
95 */ | 107 */ |
96 function sendNativeMessage(code, opt_Props) { | 108 function sendNativeMessage(code, opt_Props) { |
97 var message = Object.assign({'action': code}, opt_Props); | 109 var message = Object.assign({'action': code}, opt_Props); |
98 port.postMessage(message); | 110 port.postMessage(message); |
99 } | 111 } |
100 | 112 |
101 /** | 113 /** |
114 * Helper function that sets inner content for an option which includes text, | |
115 * link to 'learn more' section. This also creates an indicator showing that | |
116 * option is controlled by policy and inserts it before link element. | |
117 * @param {string} textId Id of the label element to process. | |
118 * @param {string} learnMoreLinkId Id inner link to 'learn more' element. | |
119 * @param {string} indicatorId Id of indicator to create. | |
120 * @param {string} text Inner text to set. Includes link declaration. | |
121 */ | |
122 function createConsentOption(textId, learnMoreLinkId, indicatorId, text) { | |
123 var doc = appWindow.contentWindow.document; | |
124 var textElement = doc.getElementById(textId); | |
125 textElement.innerHTML = text; | |
126 var linkLearnMoreElement = doc.getElementById(learnMoreLinkId); | |
127 linkLearnMoreElement.addEventListener('click', onLearnMore); | |
128 | |
129 // Create controlled by policy indicator. | |
130 var policyIndicator = new appWindow.contentWindow.cr.ui.ControlledIndicator(); | |
131 policyIndicator.id = indicatorId; | |
132 policyIndicator.getBubbleText = function() { | |
133 return controlledByPolicyText; | |
134 }; | |
135 textElement.insertBefore(policyIndicator, linkLearnMoreElement); | |
136 } | |
137 | |
138 /** | |
102 * Applies localization for html content and sets terms webview. | 139 * Applies localization for html content and sets terms webview. |
103 * @param {!Object} data Localized strings and relevant information. | 140 * @param {!Object} data Localized strings and relevant information. |
104 * @param {string} deviceId Current device id. | 141 * @param {string} deviceId Current device id. |
105 */ | 142 */ |
106 function initialize(data, deviceId) { | 143 function initialize(data, deviceId) { |
107 currentDeviceId = deviceId; | 144 currentDeviceId = deviceId; |
108 var doc = appWindow.contentWindow.document; | 145 var doc = appWindow.contentWindow.document; |
109 var loadTimeData = appWindow.contentWindow.loadTimeData; | 146 var loadTimeData = appWindow.contentWindow.loadTimeData; |
110 loadTimeData.data = data; | 147 loadTimeData.data = data; |
111 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData); | 148 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData); |
112 var countryCode = data.countryCode.toLowerCase(); | 149 var countryCode = data.countryCode.toLowerCase(); |
113 setBackupRestoreMode(data.textBackupRestore, data.backupRestoreEnabled); | 150 controlledByPolicyText = data.controlledByPolicy; |
114 setLocationServiceMode(data.textLocationService, data.locationServiceEnabled); | 151 arcManaged = data.arcManaged; |
152 setTermsVisible(!arcManaged); | |
153 | |
154 createConsentOption('text-backup-restore', | |
155 'learn-more-link-backup-restore', | |
156 'policy-indicator-backup-restore', | |
157 data.textBackupRestore); | |
158 createConsentOption('text-location-service', | |
159 'learn-more-link-location-service', | |
160 'policy-indicator-location-service', | |
161 data.textLocationService); | |
115 | 162 |
116 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';'; | 163 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';'; |
117 termsView.addContentScripts([ | 164 termsView.addContentScripts([ |
118 { name: 'preProcess', | 165 { name: 'preProcess', |
119 matches: ['https://play.google.com/*'], | 166 matches: ['https://play.google.com/*'], |
120 js: { code: scriptSetCountryCode }, | 167 js: { code: scriptSetCountryCode }, |
121 run_at: 'document_start' | 168 run_at: 'document_start' |
122 }, | 169 }, |
123 { name: 'postProcess', | 170 { name: 'postProcess', |
124 matches: ['https://play.google.com/*'], | 171 matches: ['https://play.google.com/*'], |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 doc.getElementById('settings-link').addEventListener('click', onSettings); | 209 doc.getElementById('settings-link').addEventListener('click', onSettings); |
163 doc.getElementById('learn-more-link-metrics').addEventListener('click', | 210 doc.getElementById('learn-more-link-metrics').addEventListener('click', |
164 onLearnMore); | 211 onLearnMore); |
165 | 212 |
166 // Applying metrics mode changes page layout, update terms height. | 213 // Applying metrics mode changes page layout, update terms height. |
167 updateTermsHeight(); | 214 updateTermsHeight(); |
168 } | 215 } |
169 | 216 |
170 /** | 217 /** |
171 * Sets current backup and restore mode. | 218 * Sets current backup and restore mode. |
172 * @param {string} text String used to display next to checkbox. | 219 * @param {boolean} enabled Defines the value for backup and restore checkbox. |
173 * @param {boolean} defaultCheckValue Defines the default value for backup and | 220 * @param {boolean} managed Defines whether this setting is set by policy. |
174 * restore checkbox. | |
175 */ | 221 */ |
176 function setBackupRestoreMode(text, defaultCheckValue) { | 222 function setBackupRestoreMode(enabled, managed) { |
177 var doc = appWindow.contentWindow.document; | 223 var doc = appWindow.contentWindow.document; |
178 doc.getElementById('enable-backup-restore').checked = defaultCheckValue; | 224 doc.getElementById('enable-backup-restore').checked = enabled; |
179 | 225 doc.getElementById('enable-backup-restore').disabled = managed; |
180 doc.getElementById('text-backup-restore').innerHTML = text; | 226 doc.getElementById('text-backup-restore').disabled = managed; |
181 doc.getElementById('learn-more-link-backup-restore').addEventListener('click', | 227 var policyIconElement = doc.getElementById('policy-indicator-backup-restore'); |
182 onLearnMore); | 228 if (managed) { |
229 policyIconElement.setAttribute('controlled-by', 'policy'); | |
230 } else { | |
231 policyIconElement.removeAttribute('controlled-by'); | |
232 } | |
183 } | 233 } |
184 | 234 |
185 /** | 235 /** |
186 * Sets current usage of location service opt in mode. | 236 * Sets current usage of location service opt in mode. |
187 * @param {string} text String used to display next to checkbox. | 237 * @param {boolean} enabled Defines the value for location service opt in. |
188 * @param {boolean} defaultCheckValue Defines the default value for location | 238 * @param {boolean} managed Defines whether this setting is set by policy. |
189 * service opt in. | |
190 */ | 239 */ |
191 function setLocationServiceMode(text, defaultCheckValue) { | 240 function setLocationServiceMode(enabled, managed) { |
192 var doc = appWindow.contentWindow.document; | 241 var doc = appWindow.contentWindow.document; |
193 doc.getElementById('enable-location-service').checked = defaultCheckValue; | 242 doc.getElementById('enable-location-service').checked = enabled; |
194 | 243 doc.getElementById('enable-location-service').disabled = managed; |
195 doc.getElementById('text-location-service').innerHTML = text; | 244 doc.getElementById('text-location-service').disabled = managed; |
196 doc.getElementById('learn-more-link-location-service'). | 245 var policyIconElement = doc.getElementById( |
197 addEventListener('click', onLearnMore); | 246 'policy-indicator-location-service'); |
247 if (managed) { | |
248 policyIconElement.setAttribute('controlled-by', 'policy'); | |
249 } else { | |
250 policyIconElement.removeAttribute('controlled-by'); | |
251 } | |
198 } | 252 } |
199 | 253 |
200 /** | 254 /** |
255 * Sets visibility of Terms of Service. | |
256 * @param {boolean} visible Whether the Terms of Service visible or not. | |
257 */ | |
258 function setTermsVisible(visible) { | |
259 var doc = appWindow.contentWindow.document; | |
260 var styleVisibility = visible ? 'visible' : 'hidden'; | |
261 doc.getElementById('terms-title').style.visibility = styleVisibility; | |
262 doc.getElementById('terms-container').style.visibility = styleVisibility; | |
263 } | |
264 | |
265 /** | |
201 * Updates terms view height manually because webview is not automatically | 266 * Updates terms view height manually because webview is not automatically |
202 * resized in case parent div element gets resized. | 267 * resized in case parent div element gets resized. |
203 */ | 268 */ |
204 function updateTermsHeight() { | 269 function updateTermsHeight() { |
205 var setTermsHeight = function() { | 270 var setTermsHeight = function() { |
206 var doc = appWindow.contentWindow.document; | 271 var doc = appWindow.contentWindow.document; |
207 var termsContainer = doc.getElementById('terms-container'); | 272 var termsContainer = doc.getElementById('terms-container'); |
208 // Reset terms-view height in order to stabilize style computation. For | 273 // Reset terms-view height in order to stabilize style computation. For |
209 // some reason, child webview affects final result. | 274 // some reason, child webview affects final result. |
210 termsView.style.height = '0px'; | 275 termsView.style.height = '0px'; |
(...skipping 15 matching lines...) Expand all Loading... | |
226 | 291 |
227 if (!appWindow) { | 292 if (!appWindow) { |
228 console.warn('Received native message when window is not available.'); | 293 console.warn('Received native message when window is not available.'); |
229 return; | 294 return; |
230 } | 295 } |
231 | 296 |
232 if (message.action == 'initialize') { | 297 if (message.action == 'initialize') { |
233 initialize(message.data, message.deviceId); | 298 initialize(message.data, message.deviceId); |
234 } else if (message.action == 'setMetricsMode') { | 299 } else if (message.action == 'setMetricsMode') { |
235 setMetricsMode(message.text, message.canEnable, message.on); | 300 setMetricsMode(message.text, message.canEnable, message.on); |
301 } else if (message.action == 'setBackupAndRestoreMode') { | |
302 setBackupRestoreMode(message.enabled, message.managed); | |
303 } else if (message.action == 'setLocationServiceMode') { | |
304 setLocationServiceMode(message.enabled, message.managed); | |
236 } else if (message.action == 'closeUI') { | 305 } else if (message.action == 'closeUI') { |
237 closeWindowInternally(); | 306 closeWindowInternally(); |
238 } else if (message.action == 'showPage') { | 307 } else if (message.action == 'showPage') { |
239 showPageWithStatus(message.page, message.status); | 308 showPageWithStatus(message.page, message.status); |
240 } else if (message.action == 'setWindowBounds') { | 309 } else if (message.action == 'setWindowBounds') { |
241 setWindowBounds(); | 310 setWindowBounds(); |
242 } | 311 } |
243 } | 312 } |
244 | 313 |
245 /** | 314 /** |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 | 351 |
283 if (pageDivId == 'lso-loading') { | 352 if (pageDivId == 'lso-loading') { |
284 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' + | 353 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' + |
285 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' + | 354 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' + |
286 'googleusercontent.com&response_type=code&redirect_uri=oob&' + | 355 'googleusercontent.com&response_type=code&redirect_uri=oob&' + |
287 'scope=https://www.google.com/accounts/OAuthLogin&' + | 356 'scope=https://www.google.com/accounts/OAuthLogin&' + |
288 'device_type=arc_plus_plus&device_id=' + currentDeviceId + | 357 'device_type=arc_plus_plus&device_id=' + currentDeviceId + |
289 '&hl=' + navigator.language; | 358 '&hl=' + navigator.language; |
290 } | 359 } |
291 appWindow.show(); | 360 appWindow.show(); |
361 if (pageDivId == 'terms') { | |
khmel
2016/08/12 20:33:23
Now showing 'terms' is called from 2 places. So I
| |
362 updateTermsHeight(); | |
363 } | |
292 } | 364 } |
293 | 365 |
294 /** | 366 /** |
295 * Sets error message. | 367 * Sets error message. |
296 * @param {string} error message. | 368 * @param {string} error message. |
297 */ | 369 */ |
298 function setErrorMessage(error) { | 370 function setErrorMessage(error) { |
299 if (!appWindow) { | 371 if (!appWindow) { |
300 return; | 372 return; |
301 } | 373 } |
302 var doc = appWindow.contentWindow.document; | 374 var doc = appWindow.contentWindow.document; |
303 var messageElement = doc.getElementById('error-message'); | 375 var messageElement = doc.getElementById('error-message'); |
304 messageElement.innerText = error; | 376 messageElement.innerText = error; |
305 } | 377 } |
306 | 378 |
307 /** | 379 /** |
308 * Shows requested page. | 380 * Shows requested page. |
309 * @param {int} pageId Index of the page to show. Must be in the array range of | 381 * @param {int} pageId Index of the page to show. Must be in the array range of |
310 * UI_PAGES. | 382 * UI_PAGES. |
311 * @param {string} status associated with page string status, error message for | 383 * @param {string} status associated with page string status, error message for |
312 * example. | 384 * example. |
313 */ | 385 */ |
314 function showPageWithStatus(pageId, status) { | 386 function showPageWithStatus(pageId, status) { |
315 if (!appWindow) { | 387 if (!appWindow) { |
316 return; | 388 return; |
317 } | 389 } |
318 | 390 |
319 if (UI_PAGES[pageId] == 'terms-loading') { | 391 if (UI_PAGES[pageId] == 'terms-loading') { |
320 termsAccepted = false; | 392 termsAccepted = arcManaged; |
393 if (termsAccepted) { | |
394 showPage('terms'); | |
395 return; | |
396 } | |
321 loadInitialTerms(); | 397 loadInitialTerms(); |
322 } else { | 398 } else { |
323 // Explicit request to start not from start page. Assume terms are | 399 // Explicit request to start not from start page. Assume terms are |
324 // accepted in this case. | 400 // accepted in this case. |
325 termsAccepted = true; | 401 termsAccepted = true; |
326 } | 402 } |
327 | 403 |
328 if (UI_PAGES[pageId] == 'error' || | 404 if (UI_PAGES[pageId] == 'error' || |
329 UI_PAGES[pageId] == 'error-with-feedback') { | 405 UI_PAGES[pageId] == 'error-with-feedback') { |
330 setErrorMessage(status); | 406 setErrorMessage(status); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 'serverError')); | 530 'serverError')); |
455 showPage('error'); | 531 showPage('error'); |
456 termsError = true; | 532 termsError = true; |
457 }; | 533 }; |
458 | 534 |
459 var onTermsViewContentLoad = function() { | 535 var onTermsViewContentLoad = function() { |
460 if (termsError) { | 536 if (termsError) { |
461 return; | 537 return; |
462 } | 538 } |
463 showPage('terms'); | 539 showPage('terms'); |
464 updateTermsHeight(); | |
465 }; | 540 }; |
466 | 541 |
467 termsView.request.onBeforeRequest.addListener(onTermsViewBeforeRequest, | 542 termsView.request.onBeforeRequest.addListener(onTermsViewBeforeRequest, |
468 requestFilter); | 543 requestFilter); |
469 termsView.request.onErrorOccurred.addListener(onTermsViewErrorOccurred, | 544 termsView.request.onErrorOccurred.addListener(onTermsViewErrorOccurred, |
470 requestFilter); | 545 requestFilter); |
471 termsView.addEventListener('contentload', onTermsViewContentLoad); | 546 termsView.addEventListener('contentload', onTermsViewContentLoad); |
472 | 547 |
473 | 548 |
474 // webview is not allowed to open links in the new window. Hook these events | 549 // webview is not allowed to open links in the new window. Hook these events |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 type: 'chrome', | 637 type: 'chrome', |
563 color: '#ffffff' | 638 color: '#ffffff' |
564 }, | 639 }, |
565 'innerBounds': { | 640 'innerBounds': { |
566 'width': INNER_WIDTH, | 641 'width': INNER_WIDTH, |
567 'height': INNER_HEIGHT | 642 'height': INNER_HEIGHT |
568 } | 643 } |
569 }; | 644 }; |
570 chrome.app.window.create('main.html', options, onWindowCreated); | 645 chrome.app.window.create('main.html', options, onWindowCreated); |
571 }); | 646 }); |
OLD | NEW |