Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: chrome/browser/resources/chromeos/arc_support/background.js

Issue 2450823002: Remove async load concept for ToS from native code. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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',
11 'terms-loading',
12 'terms', 11 'terms',
13 'lso-loading', 12 'lso-loading',
14 'lso', 13 'lso',
15 'arc-loading', 14 'arc-loading',
16 'error', 15 'error',
17 'error-with-feedback']; 16 'error-with-feedback'];
18 17
19 /** 18 /**
20 * Chrome window that hosts UI. Only one window is allowed. 19 * Chrome window that hosts UI. Only one window is allowed.
21 * @type {chrome.app.window.AppWindow} 20 * @type {chrome.app.window.AppWindow}
22 */ 21 */
23 var appWindow = null; 22 var appWindow = null;
24 23
25 /** 24 /**
26 * Contains Web content provided by Google authorization server. 25 * Contains Web content provided by Google authorization server.
27 * @type {WebView} 26 * @type {WebView}
28 */ 27 */
29 var lsoView = null; 28 var lsoView = null;
30 29
31 /** 30 /** @type {TermsOfServicePage} */
32 * Contains Play Store terms, loaded externally. 31 var termsPage = null;
33 * @type {WebView}
34 */
35 var termsView = null;
36
37 /**
38 * @type {MetricsPreferenceCheckbox}
39 */
40 var metricsCheckbox = null;
41
42 /**
43 * @type {PreferenceCheckbox}
44 */
45 var backupRestoreCheckbox = null;
46
47 /**
48 * @type {PreferenceCheckbox}
49 */
50 var locationServiceCheckbox = null;
51 32
52 /** 33 /**
53 * Used for bidirectional communication with native code. 34 * Used for bidirectional communication with native code.
54 * @type {chrome.runtime.Port} 35 * @type {chrome.runtime.Port}
55 */ 36 */
56 var port = null; 37 var port = null;
57 38
58 /** 39 /**
59 * Stores current device id. 40 * Stores current device id.
60 * @type {string} 41 * @type {string}
61 */ 42 */
62 var currentDeviceId = null; 43 var currentDeviceId = null;
63 44
64 /** 45 /**
65 * Indicates that terms were accepted by user. 46 * Indicates that terms were accepted by user.
66 * @type {boolean} 47 * @type {boolean}
48 * TODO: This should be a part of TermsOfServicePage.
67 */ 49 */
68 var termsAccepted = false; 50 var termsAccepted = false;
69 51
70 /** 52 /**
71 * Indicates that current user has managed Arc.
72 * @type {boolean}
73 */
74 var arcManaged = false;
75
76 /**
77 * Host window inner default width. 53 * Host window inner default width.
78 * @const {number} 54 * @const {number}
79 */ 55 */
80 var INNER_WIDTH = 960; 56 var INNER_WIDTH = 960;
81 57
82 /** 58 /**
83 * Host window inner default height. 59 * Host window inner default height.
84 * @const {number} 60 * @const {number}
85 */ 61 */
86 var INNER_HEIGHT = 688; 62 var INNER_HEIGHT = 688;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 // tags are not the target of the translation (but those content text is 188 // tags are not the target of the translation (but those content text is
213 // the translation target). 189 // the translation target).
214 // So, meanwhile, we set the link everytime we update the text. 190 // So, meanwhile, we set the link everytime we update the text.
215 // TODO: fix the translation text, and main html. 191 // TODO: fix the translation text, and main html.
216 var learnMoreLink = this.label_.querySelector(this.learnMoreLinkId_); 192 var learnMoreLink = this.label_.querySelector(this.learnMoreLinkId_);
217 learnMoreLink.addEventListener( 193 learnMoreLink.addEventListener(
218 'click', (event) => this.onLearnMoreLinkClicked(event)); 194 'click', (event) => this.onLearnMoreLinkClicked(event));
219 var settingsLink = this.label_.querySelector('#settings-link'); 195 var settingsLink = this.label_.querySelector('#settings-link');
220 settingsLink.addEventListener( 196 settingsLink.addEventListener(
221 'click', (event) => this.onSettingsLinkClicked(event)); 197 'click', (event) => this.onSettingsLinkClicked(event));
222
223 // Applying metrics mode changes page layout, update terms height.
224 updateTermsHeight();
225 } 198 }
226 199
227 /** Called when "settings" link is clicked. */ 200 /** Called when "settings" link is clicked. */
228 onSettingsLinkClicked(event) { 201 onSettingsLinkClicked(event) {
229 chrome.browser.openTab({'url': 'chrome://settings'}, function() {}); 202 chrome.browser.openTab({'url': 'chrome://settings'}, function() {});
230 event.preventDefault(); 203 event.preventDefault();
231 } 204 }
232 }; 205 };
233 206
207 /**
208 * Represents the page loading state.
209 * @enum {number}
210 */
211 var LoadState = {
212 UNLOADED: 0,
213 LOADING: 1,
214 ABORTED: 2,
215 LOADED: 3,
216 };
234 217
235 /** 218 /**
236 * Applies localization for html content and sets terms webview. 219 * Handles events for Terms-Of-Service page. Also this implements the async
237 * @param {!Object} data Localized strings and relevant information. 220 * loading of Terms-Of-Service content.
238 * @param {string} deviceId Current device id.
239 */ 221 */
240 function initialize(data, deviceId) { 222 class TermsOfServicePage {
241 currentDeviceId = deviceId;
242 var doc = appWindow.contentWindow.document;
243 var loadTimeData = appWindow.contentWindow.loadTimeData;
244 loadTimeData.data = data;
245 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData);
246 223
247 // Initialize preference connected checkboxes in terms of service page. 224 /**
248 metricsCheckbox = new MetricsPreferenceCheckbox( 225 * @param {Element} container The container of the page.
249 doc.getElementById('metrics-preference'), 226 * @param {boolean} isManaged Set true if ARC is under managed.
250 data.learnMoreStatistics, 227 * @param {string} countryCode The country code for the terms of service.
251 '#learn-more-link-metrics', 228 * @param {MetricsPreferenceCheckbox} metricsCheckbox. The checkbox for the
252 data.isOwnerProfile, 229 * metrics preference.
253 data.textMetricsDisabled, 230 * @param {PreferenceCheckbox} backupRestoreCheckbox The checkbox for the
254 data.textMetricsEnabled, 231 * backup-restore preference.
255 data.textMetricsManagedDisabled, 232 * @param {PreferenceCheckbox} locationServiceCheckbox The checkbox for the
256 data.textMetricsManagedEnabled); 233 * location service.
257 backupRestoreCheckbox = new PreferenceCheckbox( 234 */
258 doc.getElementById('backup-restore-preference'), 235 constructor(
259 data.learnMoreBackupAndRestore, 236 container, isManaged, countryCode,
260 '#learn-more-link-backup-restore', 237 metricsCheckbox, backupRestoreCheckbox, locationServiceCheckbox) {
261 data.controlledByPolicy); 238 this.loadingContainer_ =
262 locationServiceCheckbox = new PreferenceCheckbox( 239 container.querySelector('#terms-of-service-loading');
263 doc.getElementById('location-service-preference'), 240 this.contentContainer_ =
264 data.learnMoreLocationServices, 241 container.querySelector('#terms-of-service-content');
265 '#learn-more-link-location-service',
266 data.controlledByPolicy);
267 242
268 // Initialize terms of service view. 243 this.metricsCheckbox_ = metricsCheckbox;
269 var countryCode = data.countryCode.toLowerCase(); 244 this.backupRestoreCheckbox_ = backupRestoreCheckbox;
270 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';'; 245 this.locationServiceCheckbox_ = locationServiceCheckbox;
271 termsView.addContentScripts([ 246
247 this.isManaged_ = isManaged;
248
249 // Set event listener for webview loading.
250 this.termsView_ = container.querySelector('#terms-view');
251 this.termsView_.addEventListener(
252 'contentload', () => this.onTermsViewLoaded_());
253 this.termsView_.addEventListener(
254 'loadabort', (event) => this.onTermsViewLoadAborted_(event.reason));
255
256 var scriptSetCountryCode =
257 'document.countryCode = \'' + countryCode.toLowerCase() + '\';';
258 this.termsView_.addContentScripts([
272 { name: 'preProcess', 259 { name: 'preProcess',
273 matches: ['https://play.google.com/*'], 260 matches: ['https://play.google.com/*'],
274 js: { code: scriptSetCountryCode }, 261 js: { code: scriptSetCountryCode },
275 run_at: 'document_start' 262 run_at: 'document_start'
276 }, 263 },
277 { name: 'postProcess', 264 { name: 'postProcess',
278 matches: ['https://play.google.com/*'], 265 matches: ['https://play.google.com/*'],
279 css: { files: ['playstore.css'] }, 266 css: { files: ['playstore.css'] },
280 js: { files: ['playstore.js'] }, 267 js: { files: ['playstore.js'] },
281 run_at: 'document_end' 268 run_at: 'document_end'
282 }]); 269 }]);
283 arcManaged = data.arcManaged; 270
284 setTermsVisible(!arcManaged); 271 // webview is not allowed to open links in the new window. Hook these
272 // events and open links in overlay dialog.
273 this.termsView_.addEventListener('newwindow', function(event) {
274 event.preventDefault();
275 showURLOverlay(event.targetUrl);
276 });
277 this.state_ = LoadState.UNLOADED;
278
279 // On managed case, do not show TermsOfService section. Note that the
280 // checkbox for the prefereces are still visible.
281 var visibility = isManaged ? 'hidden' : 'visible';
282 container.querySelector('#terms-title').style.visibility = visibility;
283 container.querySelector('#terms-container').style.visibility = visibility;
284
285 // Set event handler for buttons.
286 container.querySelector('#button-agree')
287 .addEventListener('click', () => this.onAgree());
288 container.querySelector('#button-cancel')
289 .addEventListener('click', () => this.onCancel_());
290 }
291
292 /** Called when the TermsOfService page is shown. */
293 onShow() {
294 termsAccepted = false;
295
296 if (this.isManaged_ || this.state_ == LoadState.LOADED) {
297 // Note: in managed case, because it does not show the contents of terms
298 // of service, it is ok to show the content container immediately.
299 this.showContent_();
300 } else {
301 this.startTermsViewLoading();
302 }
303 }
304
305 /** Shows the loaded terms-of-service content. */
306 showContent_() {
307 this.loadingContainer_.hidden = true;
308 this.contentContainer_.hidden = false;
309 this.updateTermsHeight_();
310 }
311
312 /**
313 * Updates terms view height manually because webview is not automatically
314 * resized in case parent div element gets resized.
315 */
316 updateTermsHeight_() {
317 setTimeout(function() {
hidehiko 2016/10/25 15:52:14 khmel@, this is introduced in your CL. Could you t
khmel 2016/10/25 15:59:12 setTimeout is used to async update webview style t
hidehiko 2016/10/27 07:55:51 Thanks! Commented.
Luis Héctor Chávez 2016/10/27 15:58:03 Re: git cl presubmit failing to parse something. T
318 var doc = appWindow.contentWindow.document;
319 // Reset terms-view height in order to stabilize style computation. For
320 // some reason, child webview affects final result.
321 this.termsView_.style.height = '0px';
322 var termsContainer =
323 this.contentContainer_.querySelector('#terms-container');
324 var style = window.getComputedStyle(termsContainer, null);
325 this.termsView_.style.height = style.getPropertyValue('height');
326 }.bind(this), 0);
327 }
328
329 /** Starts to load the terms of service webview content. */
330 startTermsViewLoading() {
331 if (this.state_ == LoadState.LOADING) {
332 // If there already is inflight loading task, do nothing.
333 return;
334 }
335 this.state_ = LoadState.LOADING;
336
337 // Show loading page.
338 this.loadingContainer_.hidden = false;
339 this.contentContainer_.hidden = true;
340
341 this.termsView_.src = 'https://play.google.com/about/play-terms.html';
342 }
343
344 /** Called when the terms-view is loaded. */
345 onTermsViewLoaded_() {
346 // This is called also when the loading is failed.
347 // In such a case, onTermsViewLoadAborted_() is called in advance, and
348 // state_ is set to ABORTED. Here, switch the view only for the
349 // successful loading case.
350 if (this.state_ == LoadState.LOADING) {
351 this.state_ = LoadState.LOADED;
352 this.showContent_();
353 }
354 }
355
356 /** Called when the terms-view loading is aborted. */
357 onTermsViewLoadAborted_(reason) {
358 console.error('TermsView loading is aborted: ' + reason);
359 // Mark ABORTED so that onTermsViewLoaded_() won't show the content view.
360 this.state_ = LoadState.ABORTED;
361 setErrorMessage(
362 appWindow.contentWindow.loadTimeData.getString('serverError'));
363 showPage('error');
364 }
365
366 /** Called when "AGREE" button is clicked. */
367 onAgree() {
368 termsAccepted = true;
369
370 sendNativeMessage('onAgreed', {
371 isMetricsEnabled: this.metricsCheckbox_.isChecked(),
372 isBackupRestoreEnabled: this.backupRestoreCheckbox_.isChecked(),
373 isLocationServiceEnabled: this.locationServiceCheckbox_.isChecked()
374 });
375 }
376
377 /** Called when "CANCEL" button is clicked. */
378 onCancel_() {
379 if (appWindow) {
380 appWindow.close();
381 }
382 }
383
384 /** Called when metrics preference is updated. */
385 onMetricxPreferenceChanged(isEnabled, isManaged) {
386 this.metricsCheckbox_.onPreferenceChanged(isEnabled, isManaged);
387
388 // Applying metrics mode may change page layout, update terms height.
389 this.updateTermsHeight_();
390 }
391
392 /** Called when backup-restore preference is updated. */
393 onBackupRestorePreferenceChanged(isEnabled, isManaged) {
394 this.backupRestoreCheckbox_.onPreferenceChanged(isEnabled, isManaged);
395 }
396
397 /** Called when location service preference is updated. */
398 onLocationServicePreferenceChanged(isEnabled, isManaged) {
399 this.locationServiceCheckbox_.onPreferenceChanged(isEnabled, isManaged);
400 }
401 };
402
403 /**
404 * Applies localization for html content and sets terms webview.
405 * @param {!Object} data Localized strings and relevant information.
406 * @param {string} deviceId Current device id.
407 */
408 function initialize(data, deviceId) {
409 currentDeviceId = deviceId;
410 var doc = appWindow.contentWindow.document;
411 var loadTimeData = appWindow.contentWindow.loadTimeData;
412 loadTimeData.data = data;
413 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData);
414
415 // Initialize preference connected checkboxes in terms of service page.
416 termsPage = new TermsOfServicePage(
417 doc.getElementById('terms'),
418 data.arcManaged,
419 data.countryCode,
420 new MetricsPreferenceCheckbox(
421 doc.getElementById('metrics-preference'),
422 data.learnMoreStatistics,
423 '#learn-more-link-metrics',
424 data.isOwnerProfile,
425 data.textMetricsDisabled,
426 data.textMetricsEnabled,
427 data.textMetricsManagedDisabled,
428 data.textMetricsManagedEnabled),
429 new PreferenceCheckbox(
430 doc.getElementById('backup-restore-preference'),
431 data.learnMoreBackupAndRestore,
432 '#learn-more-link-backup-restore',
433 data.controlledByPolicy),
434 new PreferenceCheckbox(
435 doc.getElementById('location-service-preference'),
436 data.learnMoreLocationServices,
437 '#learn-more-link-location-service',
438 data.controlledByPolicy));
285 } 439 }
286 440
287 /** 441 /**
288 * Sets visibility of Terms of Service.
289 * @param {boolean} visible Whether the Terms of Service visible or not.
290 */
291 function setTermsVisible(visible) {
292 var doc = appWindow.contentWindow.document;
293 var styleVisibility = visible ? 'visible' : 'hidden';
294 doc.getElementById('terms-title').style.visibility = styleVisibility;
295 doc.getElementById('terms-container').style.visibility = styleVisibility;
296 }
297
298 /**
299 * Updates terms view height manually because webview is not automatically
300 * resized in case parent div element gets resized.
301 */
302 function updateTermsHeight() {
303 var setTermsHeight = function() {
304 var doc = appWindow.contentWindow.document;
305 var termsContainer = doc.getElementById('terms-container');
306 // Reset terms-view height in order to stabilize style computation. For
307 // some reason, child webview affects final result.
308 termsView.style.height = '0px';
309 var style = window.getComputedStyle(termsContainer, null);
310 var height = style.getPropertyValue('height');
311 termsView.style.height = height;
312 };
313 setTimeout(setTermsHeight, 0);
314 }
315
316 /**
317 * Handles native messages received from ArcSupportHost. 442 * Handles native messages received from ArcSupportHost.
318 * @param {!Object} message The message received. 443 * @param {!Object} message The message received.
319 */ 444 */
320 function onNativeMessage(message) { 445 function onNativeMessage(message) {
321 if (!message.action) { 446 if (!message.action) {
322 return; 447 return;
323 } 448 }
324 449
325 if (!appWindow) { 450 if (!appWindow) {
326 console.warn('Received native message when window is not available.'); 451 console.warn('Received native message when window is not available.');
327 return; 452 return;
328 } 453 }
329 454
330 if (message.action == 'initialize') { 455 if (message.action == 'initialize') {
331 initialize(message.data, message.deviceId); 456 initialize(message.data, message.deviceId);
332 } else if (message.action == 'setMetricsMode') { 457 } else if (message.action == 'setMetricsMode') {
333 metricsCheckbox.onPreferenceChanged(message.enabled, message.managed); 458 termsPage.onMetricxPreferenceChanged(message.enabled, message.managed);
334 } else if (message.action == 'setBackupAndRestoreMode') { 459 } else if (message.action == 'setBackupAndRestoreMode') {
335 backupRestoreCheckbox.onPreferenceChanged(message.enabled, message.managed); 460 termsPage.onBackupRestorePreferenceChanged(
461 message.enabled, message.managed);
336 } else if (message.action == 'setLocationServiceMode') { 462 } else if (message.action == 'setLocationServiceMode') {
337 locationServiceCheckbox.onPreferenceChanged( 463 termsPage.onLocationServicePreferenceChanged(
338 message.enabled, message.managed); 464 message.enabled, message.managed);
339 } else if (message.action == 'closeWindow') { 465 } else if (message.action == 'closeWindow') {
340 if (appWindow) { 466 if (appWindow) {
341 appWindow.close(); 467 appWindow.close();
342 } 468 }
343 } else if (message.action == 'showPage') { 469 } else if (message.action == 'showPage') {
344 showPageWithStatus(message.page, message.status); 470 showPageWithStatus(message.page, message.status);
345 } else if (message.action == 'setWindowBounds') { 471 } else if (message.action == 'setWindowBounds') {
346 setWindowBounds(); 472 setWindowBounds();
347 } 473 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 if (pageDivId == 'lso-loading') { 510 if (pageDivId == 'lso-loading') {
385 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' + 511 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' +
386 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' + 512 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' +
387 'googleusercontent.com&response_type=code&redirect_uri=oob&' + 513 'googleusercontent.com&response_type=code&redirect_uri=oob&' +
388 'scope=https://www.google.com/accounts/OAuthLogin&' + 514 'scope=https://www.google.com/accounts/OAuthLogin&' +
389 'device_type=arc_plus_plus&device_id=' + currentDeviceId + 515 'device_type=arc_plus_plus&device_id=' + currentDeviceId +
390 '&hl=' + navigator.language; 516 '&hl=' + navigator.language;
391 } 517 }
392 appWindow.show(); 518 appWindow.show();
393 if (pageDivId == 'terms') { 519 if (pageDivId == 'terms') {
394 updateTermsHeight(); 520 termsPage.onShow();
395 } 521 }
396 } 522 }
397 523
398 /** 524 /**
399 * Sets error message. 525 * Sets error message.
400 * @param {string} error message. 526 * @param {string} error message.
401 */ 527 */
402 function setErrorMessage(error) { 528 function setErrorMessage(error) {
403 if (!appWindow) { 529 if (!appWindow) {
404 return; 530 return;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 * @param {int} pageId Index of the page to show. Must be in the array range of 597 * @param {int} pageId Index of the page to show. Must be in the array range of
472 * UI_PAGES. 598 * UI_PAGES.
473 * @param {string} status associated with page string status, error message for 599 * @param {string} status associated with page string status, error message for
474 * example. 600 * example.
475 */ 601 */
476 function showPageWithStatus(pageId, status) { 602 function showPageWithStatus(pageId, status) {
477 if (!appWindow) { 603 if (!appWindow) {
478 return; 604 return;
479 } 605 }
480 606
481 if (UI_PAGES[pageId] == 'terms-loading') { 607 if (UI_PAGES[pageId] != 'terms') {
482 termsAccepted = arcManaged;
483 if (termsAccepted) {
484 showPage('terms');
485 return;
486 }
487 loadInitialTerms();
488 } else {
489 // Explicit request to start not from start page. Assume terms are 608 // Explicit request to start not from start page. Assume terms are
490 // accepted in this case. 609 // accepted in this case.
610 // TODO: this is only for controling "RETRY" button. Remove this.
491 termsAccepted = true; 611 termsAccepted = true;
492 } 612 }
493 613
494 if (UI_PAGES[pageId] == 'error' || 614 if (UI_PAGES[pageId] == 'error' ||
495 UI_PAGES[pageId] == 'error-with-feedback') { 615 UI_PAGES[pageId] == 'error-with-feedback') {
496 setErrorMessage(status); 616 setErrorMessage(status);
497 } 617 }
498 showPage(UI_PAGES[pageId]); 618 showPage(UI_PAGES[pageId]);
499 } 619 }
500 620
501 /**
502 * Loads initial Play Store terms.
503 */
504 function loadInitialTerms() {
505 termsView.src = 'https://play.google.com/about/play-terms.html';
506 }
507
508 function setWindowBounds() { 621 function setWindowBounds() {
509 if (!appWindow) { 622 if (!appWindow) {
510 return; 623 return;
511 } 624 }
512 625
513 var decorationWidth = appWindow.outerBounds.width - 626 var decorationWidth = appWindow.outerBounds.width -
514 appWindow.innerBounds.width; 627 appWindow.innerBounds.width;
515 var decorationHeight = appWindow.outerBounds.height - 628 var decorationHeight = appWindow.outerBounds.height -
516 appWindow.innerBounds.height; 629 appWindow.innerBounds.height;
517 630
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 urls: ['<all_urls>'], 712 urls: ['<all_urls>'],
600 types: ['main_frame'] 713 types: ['main_frame']
601 }; 714 };
602 715
603 lsoView.request.onResponseStarted.addListener( 716 lsoView.request.onResponseStarted.addListener(
604 onLsoViewRequestResponseStarted, requestFilter); 717 onLsoViewRequestResponseStarted, requestFilter);
605 lsoView.request.onErrorOccurred.addListener( 718 lsoView.request.onErrorOccurred.addListener(
606 onLsoViewErrorOccurred, requestFilter); 719 onLsoViewErrorOccurred, requestFilter);
607 lsoView.addEventListener('contentload', onLsoViewContentLoad); 720 lsoView.addEventListener('contentload', onLsoViewContentLoad);
608 721
609 termsView = doc.getElementById('terms-view');
610
611 var termsError = false;
612 var onTermsViewBeforeRequest = function(details) {
613 showPage('terms-loading');
614 termsError = false;
615 };
616
617 var onTermsViewErrorOccurred = function(details) {
618 termsAccepted = false;
619 setErrorMessage(appWindow.contentWindow.loadTimeData.getString(
620 'serverError'));
621 showPage('error');
622 termsError = true;
623 };
624
625 var onTermsViewContentLoad = function() {
626 if (termsError) {
627 return;
628 }
629 showPage('terms');
630 };
631
632 termsView.request.onBeforeRequest.addListener(onTermsViewBeforeRequest,
633 requestFilter);
634 termsView.request.onErrorOccurred.addListener(onTermsViewErrorOccurred,
635 requestFilter);
636 termsView.addEventListener('contentload', onTermsViewContentLoad);
637
638
639 // webview is not allowed to open links in the new window. Hook these events
640 // and open links in overlay dialog.
641 termsView.addEventListener('newwindow', function(event) {
642 event.preventDefault();
643 showURLOverlay(event.targetUrl);
644 });
645
646 var onAgree = function() {
647 termsAccepted = true;
648
649 sendNativeMessage('onAgreed', {
650 isMetricsEnabled: metricsCheckbox.isChecked(),
651 isBackupRestoreEnabled: backupRestoreCheckbox.isChecked(),
652 isLocationServiceEnabled: locationServiceCheckbox.isChecked()
653 });
654 };
655
656 var onCancel = function() {
657 if (appWindow) {
658 appWindow.close();
659 }
660 };
661
662 var onRetry = function() { 722 var onRetry = function() {
663 if (termsAccepted) { 723 if (termsAccepted) {
664 // Reuse the onAgree() in case that the user has already accepted 724 // Reuse the onAgree() in case that the user has already accepted
665 // the ToS. 725 // the ToS.
666 onAgree(); 726 termsPage.onAgree();
667 } else { 727 } else {
668 loadInitialTerms(); 728 // Here 'error' page should be visible. So switch to 'terms' page
729 // to show the progress page, and start reloading.
730 showPage('terms');
731 termsPage.startTermsViewLoading();
669 } 732 }
670 }; 733 };
671 734
672 var onSendFeedback = function() { 735 var onSendFeedback = function() {
673 sendNativeMessage('onSendFeedbackClicked'); 736 sendNativeMessage('onSendFeedbackClicked');
674 }; 737 };
675 738
676 doc.getElementById('button-agree').addEventListener('click', onAgree);
677 doc.getElementById('button-cancel').addEventListener('click', onCancel);
678 doc.getElementById('button-retry').addEventListener('click', onRetry); 739 doc.getElementById('button-retry').addEventListener('click', onRetry);
679 doc.getElementById('button-send-feedback') 740 doc.getElementById('button-send-feedback')
680 .addEventListener('click', onSendFeedback); 741 .addEventListener('click', onSendFeedback);
681 doc.getElementById('overlay-close').addEventListener('click', hideOverlay); 742 doc.getElementById('overlay-close').addEventListener('click', hideOverlay);
682 doc.getElementById('privacy-policy-link').addEventListener( 743 doc.getElementById('privacy-policy-link').addEventListener(
683 'click', showPrivacyPolicyOverlay); 744 'click', showPrivacyPolicyOverlay);
684 745
685 var overlay = doc.getElementById('overlay-container'); 746 var overlay = doc.getElementById('overlay-container');
686 appWindow.contentWindow.cr.ui.overlay.setupOverlay(overlay); 747 appWindow.contentWindow.cr.ui.overlay.setupOverlay(overlay);
687 appWindow.contentWindow.cr.ui.overlay.globalInitialization(); 748 appWindow.contentWindow.cr.ui.overlay.globalInitialization();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 type: 'chrome', 780 type: 'chrome',
720 color: '#ffffff' 781 color: '#ffffff'
721 }, 782 },
722 'innerBounds': { 783 'innerBounds': {
723 'width': INNER_WIDTH, 784 'width': INNER_WIDTH,
724 'height': INNER_HEIGHT 785 'height': INNER_HEIGHT
725 } 786 }
726 }; 787 };
727 chrome.app.window.create('main.html', options, onWindowCreated); 788 chrome.app.window.create('main.html', options, onWindowCreated);
728 }); 789 });
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.cc ('k') | chrome/browser/resources/chromeos/arc_support/main.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698