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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 // it safe to make it up to window width. | 462 // it safe to make it up to window width. |
463 lsoView.style.width = '100%'; | 463 lsoView.style.width = '100%'; |
464 return; | 464 return; |
465 } | 465 } |
466 | 466 |
467 lsoView.executeScript({code: 'document.title;'}, function(results) { | 467 lsoView.executeScript({code: 'document.title;'}, function(results) { |
468 var authCodePrefix = 'Success code='; | 468 var authCodePrefix = 'Success code='; |
469 if (results && results.length == 1 && typeof results[0] == 'string' && | 469 if (results && results.length == 1 && typeof results[0] == 'string' && |
470 results[0].substring(0, authCodePrefix.length) == authCodePrefix) { | 470 results[0].substring(0, authCodePrefix.length) == authCodePrefix) { |
471 var authCode = results[0].substring(authCodePrefix.length); | 471 var authCode = results[0].substring(authCodePrefix.length); |
472 sendNativeMessage('setAuthCode', {code: authCode}); | 472 sendNativeMessage('onAuthSucceeded', {'code': authCode}); |
Luis Héctor Chávez
2016/10/03 20:40:16
Google's JavaScript style guide indicate that obje
hidehiko
2016/10/04 04:48:19
Updated as you suggested.
| |
473 } else { | 473 } else { |
474 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( | 474 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( |
475 'authorizationFailed')); | 475 'authorizationFailed')); |
476 showPage('error'); | 476 showPage('error'); |
477 } | 477 } |
478 }); | 478 }); |
479 }; | 479 }; |
480 | 480 |
481 var requestFilter = { | 481 var requestFilter = { |
482 urls: ['<all_urls>'], | 482 urls: ['<all_urls>'], |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 // webview is not allowed to open links in the new window. Hook these events | 522 // webview is not allowed to open links in the new window. Hook these events |
523 // and open links in context of main page. | 523 // and open links in context of main page. |
524 termsView.addEventListener('newwindow', function(event) { | 524 termsView.addEventListener('newwindow', function(event) { |
525 event.preventDefault(); | 525 event.preventDefault(); |
526 chrome.browser.openTab({'url': event.targetUrl}, function() {}); | 526 chrome.browser.openTab({'url': event.targetUrl}, function() {}); |
527 }); | 527 }); |
528 | 528 |
529 var onAgree = function() { | 529 var onAgree = function() { |
530 termsAccepted = true; | 530 termsAccepted = true; |
531 | 531 |
532 var data = {}; | |
532 var enableMetrics = doc.getElementById('enable-metrics'); | 533 var enableMetrics = doc.getElementById('enable-metrics'); |
533 if (!enableMetrics.hidden) { | 534 if (!enableMetrics.hidden) { |
534 sendNativeMessage('enableMetrics', { | 535 data['isMetricsEnabled'] = enableMetrics.checked; |
Luis Héctor Chávez
2016/10/03 20:40:16
I'm not _entirely_ sure that this particular rule
hidehiko
2016/10/04 04:48:19
Done.
| |
535 'enabled': enableMetrics.checked | |
536 }); | |
537 } | 536 } |
538 | |
539 var enableBackupRestore = doc.getElementById('enable-backup-restore'); | 537 var enableBackupRestore = doc.getElementById('enable-backup-restore'); |
540 sendNativeMessage('setBackupRestore', { | 538 data['isBackupRestoreEnabled'] = enableBackupRestore.checked; |
541 'enabled': enableBackupRestore.checked | |
542 }); | |
543 | 539 |
544 var enableLocationService = doc.getElementById('enable-location-service'); | 540 var enableLocationService = doc.getElementById('enable-location-service'); |
545 sendNativeMessage('setLocationService', { | 541 data['isLocationServiceEnabled'] = enableLocationService.checked; |
546 'enabled': enableLocationService.checked | |
547 }); | |
548 | 542 |
549 sendNativeMessage('startLso'); | 543 sendNativeMessage('onAgreed', data); |
550 }; | 544 }; |
551 | 545 |
552 var onCancel = function() { | 546 var onCancel = function() { |
553 if (appWindow) { | 547 if (appWindow) { |
554 appWindow.close(); | 548 appWindow.close(); |
555 } | 549 } |
556 }; | 550 }; |
557 | 551 |
558 var onRetry = function() { | 552 var onRetry = function() { |
559 if (termsAccepted) { | 553 if (termsAccepted) { |
560 sendNativeMessage('startLso'); | 554 // Reuse the onAgree() in case that the user has already accepted |
555 // the ToS. | |
556 onAgree(); | |
561 } else { | 557 } else { |
562 loadInitialTerms(); | 558 loadInitialTerms(); |
563 } | 559 } |
564 }; | 560 }; |
565 | 561 |
566 var onSendFeedback = function() { | 562 var onSendFeedback = function() { |
567 sendNativeMessage('sendFeedback'); | 563 sendNativeMessage('onSendFeedbackClicked'); |
568 }; | 564 }; |
569 | 565 |
570 doc.getElementById('button-agree').addEventListener('click', onAgree); | 566 doc.getElementById('button-agree').addEventListener('click', onAgree); |
571 doc.getElementById('button-cancel').addEventListener('click', onCancel); | 567 doc.getElementById('button-cancel').addEventListener('click', onCancel); |
572 doc.getElementById('button-retry').addEventListener('click', onRetry); | 568 doc.getElementById('button-retry').addEventListener('click', onRetry); |
573 doc.getElementById('button-send-feedback') | 569 doc.getElementById('button-send-feedback') |
574 .addEventListener('click', onSendFeedback); | 570 .addEventListener('click', onSendFeedback); |
575 | 571 |
576 connectPort(); | 572 connectPort(); |
577 }; | 573 }; |
(...skipping 27 matching lines...) Expand all Loading... | |
605 type: 'chrome', | 601 type: 'chrome', |
606 color: '#ffffff' | 602 color: '#ffffff' |
607 }, | 603 }, |
608 'innerBounds': { | 604 'innerBounds': { |
609 'width': INNER_WIDTH, | 605 'width': INNER_WIDTH, |
610 'height': INNER_HEIGHT | 606 'height': INNER_HEIGHT |
611 } | 607 } |
612 }; | 608 }; |
613 chrome.app.window.create('main.html', options, onWindowCreated); | 609 chrome.app.window.create('main.html', options, onWindowCreated); |
614 }); | 610 }); |
OLD | NEW |