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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 /** | 73 /** |
74 * Host window inner default height. | 74 * Host window inner default height. |
75 * @const {number} | 75 * @const {number} |
76 */ | 76 */ |
77 var INNER_HEIGHT = 688; | 77 var INNER_HEIGHT = 688; |
78 | 78 |
79 | 79 |
80 /** | 80 /** |
81 * Sends a native message to ArcSupportHost. | 81 * Sends a native message to ArcSupportHost. |
82 * @param {string} code The action code in message. | 82 * @param {string} event The event type in message. |
83 * @param {Object=} opt_Props Extra properties for the message. | 83 * @param {Object=} opt_props Extra properties for the message. |
84 */ | 84 */ |
85 function sendNativeMessage(code, opt_Props) { | 85 function sendNativeMessage(event, opt_props) { |
86 var message = Object.assign({'action': code}, opt_Props); | 86 var message = Object.assign({'event': event}, opt_props); |
87 port.postMessage(message); | 87 port.postMessage(message); |
88 } | 88 } |
89 | 89 |
90 /** | 90 /** |
91 * Helper function that sets inner content for an option which includes text, | 91 * Helper function that sets inner content for an option which includes text, |
92 * link to 'learn more' section. This also creates an indicator showing that | 92 * link to 'learn more' section. This also creates an indicator showing that |
93 * option is controlled by policy and inserts it before link element. | 93 * option is controlled by policy and inserts it before link element. |
94 * @param {string} textId Id of the label element to process. | 94 * @param {string} textId Id of the label element to process. |
95 * @param {string} learnMoreLinkId Id inner link to 'learn more' element. | 95 * @param {string} learnMoreLinkId Id inner link to 'learn more' element. |
96 * @param {string} indicatorId Id of indicator to create. | 96 * @param {string} indicatorId Id of indicator to create. |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 // it safe to make it up to window width. | 504 // it safe to make it up to window width. |
505 lsoView.style.width = '100%'; | 505 lsoView.style.width = '100%'; |
506 return; | 506 return; |
507 } | 507 } |
508 | 508 |
509 lsoView.executeScript({code: 'document.title;'}, function(results) { | 509 lsoView.executeScript({code: 'document.title;'}, function(results) { |
510 var authCodePrefix = 'Success code='; | 510 var authCodePrefix = 'Success code='; |
511 if (results && results.length == 1 && typeof results[0] == 'string' && | 511 if (results && results.length == 1 && typeof results[0] == 'string' && |
512 results[0].substring(0, authCodePrefix.length) == authCodePrefix) { | 512 results[0].substring(0, authCodePrefix.length) == authCodePrefix) { |
513 var authCode = results[0].substring(authCodePrefix.length); | 513 var authCode = results[0].substring(authCodePrefix.length); |
514 sendNativeMessage('setAuthCode', {code: authCode}); | 514 sendNativeMessage('onAuthSucceeded', {code: authCode}); |
515 } else { | 515 } else { |
516 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( | 516 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( |
517 'authorizationFailed')); | 517 'authorizationFailed')); |
518 showPage('error'); | 518 showPage('error'); |
519 } | 519 } |
520 }); | 520 }); |
521 }; | 521 }; |
522 | 522 |
523 var requestFilter = { | 523 var requestFilter = { |
524 urls: ['<all_urls>'], | 524 urls: ['<all_urls>'], |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 // and open links in context of main page. | 565 // and open links in context of main page. |
566 termsView.addEventListener('newwindow', function(event) { | 566 termsView.addEventListener('newwindow', function(event) { |
567 event.preventDefault(); | 567 event.preventDefault(); |
568 chrome.browser.openTab({'url': event.targetUrl}, function() {}); | 568 chrome.browser.openTab({'url': event.targetUrl}, function() {}); |
569 }); | 569 }); |
570 | 570 |
571 var onAgree = function() { | 571 var onAgree = function() { |
572 termsAccepted = true; | 572 termsAccepted = true; |
573 | 573 |
574 var enableMetrics = doc.getElementById('enable-metrics'); | 574 var enableMetrics = doc.getElementById('enable-metrics'); |
575 if (!enableMetrics.hidden) { | |
576 sendNativeMessage('enableMetrics', { | |
577 'enabled': enableMetrics.checked | |
578 }); | |
579 } | |
580 | |
581 var enableBackupRestore = doc.getElementById('enable-backup-restore'); | 575 var enableBackupRestore = doc.getElementById('enable-backup-restore'); |
582 sendNativeMessage('setBackupRestore', { | 576 var enableLocationService = doc.getElementById('enable-location-service'); |
583 'enabled': enableBackupRestore.checked | 577 sendNativeMessage('onAgreed', { |
| 578 isMetricsEnabled: !enableMetrics.hidden && enableMetrics.checked, |
| 579 isBackupRestoreEnabled: enableBackupRestore.checked, |
| 580 isLocationServiceEnabled: enableLocationService.checked |
584 }); | 581 }); |
585 | |
586 var enableLocationService = doc.getElementById('enable-location-service'); | |
587 sendNativeMessage('setLocationService', { | |
588 'enabled': enableLocationService.checked | |
589 }); | |
590 | |
591 sendNativeMessage('startLso'); | |
592 }; | 582 }; |
593 | 583 |
594 var onCancel = function() { | 584 var onCancel = function() { |
595 if (appWindow) { | 585 if (appWindow) { |
596 appWindow.close(); | 586 appWindow.close(); |
597 } | 587 } |
598 }; | 588 }; |
599 | 589 |
600 var onRetry = function() { | 590 var onRetry = function() { |
601 if (termsAccepted) { | 591 if (termsAccepted) { |
602 sendNativeMessage('startLso'); | 592 // Reuse the onAgree() in case that the user has already accepted |
| 593 // the ToS. |
| 594 onAgree(); |
603 } else { | 595 } else { |
604 loadInitialTerms(); | 596 loadInitialTerms(); |
605 } | 597 } |
606 }; | 598 }; |
607 | 599 |
608 var onSendFeedback = function() { | 600 var onSendFeedback = function() { |
609 sendNativeMessage('sendFeedback'); | 601 sendNativeMessage('onSendFeedbackClicked'); |
610 }; | 602 }; |
611 | 603 |
612 doc.getElementById('button-agree').addEventListener('click', onAgree); | 604 doc.getElementById('button-agree').addEventListener('click', onAgree); |
613 doc.getElementById('button-cancel').addEventListener('click', onCancel); | 605 doc.getElementById('button-cancel').addEventListener('click', onCancel); |
614 doc.getElementById('button-retry').addEventListener('click', onRetry); | 606 doc.getElementById('button-retry').addEventListener('click', onRetry); |
615 doc.getElementById('button-send-feedback') | 607 doc.getElementById('button-send-feedback') |
616 .addEventListener('click', onSendFeedback); | 608 .addEventListener('click', onSendFeedback); |
617 doc.getElementById('learn-more-close').addEventListener('click', | 609 doc.getElementById('learn-more-close').addEventListener('click', |
618 hideLearnModeOverlay); | 610 hideLearnModeOverlay); |
619 | 611 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 type: 'chrome', | 646 type: 'chrome', |
655 color: '#ffffff' | 647 color: '#ffffff' |
656 }, | 648 }, |
657 'innerBounds': { | 649 'innerBounds': { |
658 'width': INNER_WIDTH, | 650 'width': INNER_WIDTH, |
659 'height': INNER_HEIGHT | 651 'height': INNER_HEIGHT |
660 } | 652 } |
661 }; | 653 }; |
662 chrome.app.window.create('main.html', options, onWindowCreated); | 654 chrome.app.window.create('main.html', options, onWindowCreated); |
663 }); | 655 }); |
OLD | NEW |