| 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 | |
| 7 * enum. | |
| 8 * @type {Array<string>} | |
| 9 */ | |
| 10 var UI_PAGES = ['none', | |
| 11 'terms', | |
| 12 'lso-loading', | |
| 13 'lso', | |
| 14 'arc-loading', | |
| 15 'error', | |
| 16 'error-with-feedback']; | |
| 17 | |
| 18 /** | |
| 19 * Chrome window that hosts UI. Only one window is allowed. | 6 * Chrome window that hosts UI. Only one window is allowed. |
| 20 * @type {chrome.app.window.AppWindow} | 7 * @type {chrome.app.window.AppWindow} |
| 21 */ | 8 */ |
| 22 var appWindow = null; | 9 var appWindow = null; |
| 23 | 10 |
| 24 /** | 11 /** |
| 25 * Contains Web content provided by Google authorization server. | 12 * Contains Web content provided by Google authorization server. |
| 26 * @type {WebView} | 13 * @type {WebView} |
| 27 */ | 14 */ |
| 28 var lsoView = null; | 15 var lsoView = null; |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 this.state_ = LoadState.LOADED; | 354 this.state_ = LoadState.LOADED; |
| 368 this.showContent_(); | 355 this.showContent_(); |
| 369 } | 356 } |
| 370 } | 357 } |
| 371 | 358 |
| 372 /** Called when the terms-view loading is aborted. */ | 359 /** Called when the terms-view loading is aborted. */ |
| 373 onTermsViewLoadAborted_(reason) { | 360 onTermsViewLoadAborted_(reason) { |
| 374 console.error('TermsView loading is aborted: ' + reason); | 361 console.error('TermsView loading is aborted: ' + reason); |
| 375 // Mark ABORTED so that onTermsViewLoaded_() won't show the content view. | 362 // Mark ABORTED so that onTermsViewLoaded_() won't show the content view. |
| 376 this.state_ = LoadState.ABORTED; | 363 this.state_ = LoadState.ABORTED; |
| 377 setErrorMessage( | 364 showErrorPage( |
| 378 appWindow.contentWindow.loadTimeData.getString('serverError')); | 365 appWindow.contentWindow.loadTimeData.getString('serverError')); |
| 379 showPage('error'); | |
| 380 } | 366 } |
| 381 | 367 |
| 382 /** Called when "AGREE" button is clicked. */ | 368 /** Called when "AGREE" button is clicked. */ |
| 383 onAgree() { | 369 onAgree() { |
| 384 termsAccepted = true; | 370 termsAccepted = true; |
| 385 | 371 |
| 386 sendNativeMessage('onAgreed', { | 372 sendNativeMessage('onAgreed', { |
| 387 isMetricsEnabled: this.metricsCheckbox_.isChecked(), | 373 isMetricsEnabled: this.metricsCheckbox_.isChecked(), |
| 388 isBackupRestoreEnabled: this.backupRestoreCheckbox_.isChecked(), | 374 isBackupRestoreEnabled: this.backupRestoreCheckbox_.isChecked(), |
| 389 isLocationServiceEnabled: this.locationServiceCheckbox_.isChecked() | 375 isLocationServiceEnabled: this.locationServiceCheckbox_.isChecked() |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 termsPage.onBackupRestorePreferenceChanged( | 462 termsPage.onBackupRestorePreferenceChanged( |
| 477 message.enabled, message.managed); | 463 message.enabled, message.managed); |
| 478 } else if (message.action == 'setLocationServiceMode') { | 464 } else if (message.action == 'setLocationServiceMode') { |
| 479 termsPage.onLocationServicePreferenceChanged( | 465 termsPage.onLocationServicePreferenceChanged( |
| 480 message.enabled, message.managed); | 466 message.enabled, message.managed); |
| 481 } else if (message.action == 'closeWindow') { | 467 } else if (message.action == 'closeWindow') { |
| 482 if (appWindow) { | 468 if (appWindow) { |
| 483 appWindow.close(); | 469 appWindow.close(); |
| 484 } | 470 } |
| 485 } else if (message.action == 'showPage') { | 471 } else if (message.action == 'showPage') { |
| 486 showPageWithStatus(message.page, message.status); | 472 if (message.page != 'terms') { |
| 473 // Explicit request to start not from start page. Assume terms are |
| 474 // accepted in this case. |
| 475 // TODO: this is only for controling "RETRY" button. Remove this. |
| 476 termsAccepted = true; |
| 477 } |
| 478 showPage(message.page); |
| 479 } else if (message.action == 'showErrorPage') { |
| 480 // TODO: this is only for controling "RETRY" button. Remove this. |
| 481 termsAccepted = true; |
| 482 showErrorPage(message.errorMessage, message.shouldShowSendFeedback); |
| 487 } else if (message.action == 'setWindowBounds') { | 483 } else if (message.action == 'setWindowBounds') { |
| 488 setWindowBounds(); | 484 setWindowBounds(); |
| 489 } | 485 } |
| 490 } | 486 } |
| 491 | 487 |
| 492 /** | 488 /** |
| 493 * Connects to ArcSupportHost. | 489 * Connects to ArcSupportHost. |
| 494 */ | 490 */ |
| 495 function connectPort() { | 491 function connectPort() { |
| 496 var hostName = 'com.google.arc_support'; | 492 var hostName = 'com.google.arc_support'; |
| 497 port = chrome.runtime.connectNative(hostName); | 493 port = chrome.runtime.connectNative(hostName); |
| 498 port.onMessage.addListener(onNativeMessage); | 494 port.onMessage.addListener(onNativeMessage); |
| 499 } | 495 } |
| 500 | 496 |
| 501 /** | 497 /** |
| 502 * Shows requested page and hide others. Show appWindow if it was hidden before. | 498 * Shows requested page and hide others. Show appWindow if it was hidden before. |
| 503 * 'none' hides all views. | 499 * 'none' hides all views. |
| 504 * @param {string} pageDivId id of divider of the page to show. | 500 * @param {string} pageDivId id of divider of the page to show. |
| 505 */ | 501 */ |
| 506 function showPage(pageDivId) { | 502 function showPage(pageDivId) { |
| 507 if (!appWindow) { | 503 if (!appWindow) { |
| 508 return; | 504 return; |
| 509 } | 505 } |
| 510 | 506 |
| 511 hideOverlay(); | 507 hideOverlay(); |
| 512 var doc = appWindow.contentWindow.document; | 508 var doc = appWindow.contentWindow.document; |
| 513 var pages = doc.getElementsByClassName('section'); | 509 var pages = doc.getElementsByClassName('section'); |
| 514 var sendFeedbackElement = doc.getElementById('button-send-feedback'); | |
| 515 if (pageDivId == 'error-with-feedback') { | |
| 516 // Only show feedback button if the pageDivId is 'error-with-feedback'. | |
| 517 sendFeedbackElement.hidden = false; | |
| 518 pageDivId = 'error'; | |
| 519 } else { | |
| 520 sendFeedbackElement.hidden = true; | |
| 521 } | |
| 522 for (var i = 0; i < pages.length; i++) { | 510 for (var i = 0; i < pages.length; i++) { |
| 523 pages[i].hidden = pages[i].id != pageDivId; | 511 pages[i].hidden = pages[i].id != pageDivId; |
| 524 } | 512 } |
| 525 | 513 |
| 526 if (pageDivId == 'lso-loading') { | 514 if (pageDivId == 'lso-loading') { |
| 527 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' + | 515 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' + |
| 528 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' + | 516 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' + |
| 529 'googleusercontent.com&response_type=code&redirect_uri=oob&' + | 517 'googleusercontent.com&response_type=code&redirect_uri=oob&' + |
| 530 'scope=https://www.google.com/accounts/OAuthLogin&' + | 518 'scope=https://www.google.com/accounts/OAuthLogin&' + |
| 531 'device_type=arc_plus_plus&device_id=' + currentDeviceId + | 519 'device_type=arc_plus_plus&device_id=' + currentDeviceId + |
| 532 '&hl=' + navigator.language; | 520 '&hl=' + navigator.language; |
| 533 } | 521 } |
| 534 appWindow.show(); | 522 appWindow.show(); |
| 535 if (pageDivId == 'terms') { | 523 if (pageDivId == 'terms') { |
| 536 termsPage.onShow(); | 524 termsPage.onShow(); |
| 537 } | 525 } |
| 538 } | 526 } |
| 539 | 527 |
| 540 /** | 528 /** |
| 541 * Sets error message. | 529 * Shows an error page, with given errorMessage. |
| 542 * @param {string} error message. | 530 * |
| 531 * @param {string} errorMessage Localized error message text. |
| 532 * @param {?boolean} opt_shouldShowSendFeedback If set to true, show "Send |
| 533 * feedback" button. |
| 543 */ | 534 */ |
| 544 function setErrorMessage(error) { | 535 function showErrorPage(errorMessage, opt_shouldShowSendFeedback) { |
| 545 if (!appWindow) { | 536 if (!appWindow) { |
| 546 return; | 537 return; |
| 547 } | 538 } |
| 539 |
| 548 var doc = appWindow.contentWindow.document; | 540 var doc = appWindow.contentWindow.document; |
| 549 var messageElement = doc.getElementById('error-message'); | 541 var messageElement = doc.getElementById('error-message'); |
| 550 messageElement.innerText = error; | 542 messageElement.innerText = errorMessage; |
| 543 |
| 544 var sendFeedbackElement = doc.getElementById('button-send-feedback'); |
| 545 sendFeedbackElement.hidden = !opt_shouldShowSendFeedback; |
| 546 |
| 547 showPage('error'); |
| 551 } | 548 } |
| 552 | 549 |
| 553 /** | 550 /** |
| 554 * Shows overlay dialog and required content. | 551 * Shows overlay dialog and required content. |
| 555 * @param {string} overlayClass Defines which content to show, 'overlay-url' for | 552 * @param {string} overlayClass Defines which content to show, 'overlay-url' for |
| 556 * webview based content and 'overlay-text' for | 553 * webview based content and 'overlay-text' for |
| 557 * simple text view. | 554 * simple text view. |
| 558 */ | 555 */ |
| 559 function showOverlay(overlayClass) { | 556 function showOverlay(overlayClass) { |
| 560 var doc = appWindow.contentWindow.document; | 557 var doc = appWindow.contentWindow.document; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 | 598 |
| 602 /** | 599 /** |
| 603 * Hides overlay dialog. | 600 * Hides overlay dialog. |
| 604 */ | 601 */ |
| 605 function hideOverlay() { | 602 function hideOverlay() { |
| 606 var doc = appWindow.contentWindow.document; | 603 var doc = appWindow.contentWindow.document; |
| 607 var overlayContainer = doc.getElementById('overlay-container'); | 604 var overlayContainer = doc.getElementById('overlay-container'); |
| 608 overlayContainer.hidden = true; | 605 overlayContainer.hidden = true; |
| 609 } | 606 } |
| 610 | 607 |
| 611 /** | |
| 612 * Shows requested page. | |
| 613 * @param {int} pageId Index of the page to show. Must be in the array range of | |
| 614 * UI_PAGES. | |
| 615 * @param {string} status associated with page string status, error message for | |
| 616 * example. | |
| 617 */ | |
| 618 function showPageWithStatus(pageId, status) { | |
| 619 if (!appWindow) { | |
| 620 return; | |
| 621 } | |
| 622 | |
| 623 if (UI_PAGES[pageId] != 'terms') { | |
| 624 // Explicit request to start not from start page. Assume terms are | |
| 625 // accepted in this case. | |
| 626 // TODO: this is only for controling "RETRY" button. Remove this. | |
| 627 termsAccepted = true; | |
| 628 } | |
| 629 | |
| 630 if (UI_PAGES[pageId] == 'error' || | |
| 631 UI_PAGES[pageId] == 'error-with-feedback') { | |
| 632 setErrorMessage(status); | |
| 633 } | |
| 634 showPage(UI_PAGES[pageId]); | |
| 635 } | |
| 636 | |
| 637 function setWindowBounds() { | 608 function setWindowBounds() { |
| 638 if (!appWindow) { | 609 if (!appWindow) { |
| 639 return; | 610 return; |
| 640 } | 611 } |
| 641 | 612 |
| 642 var decorationWidth = appWindow.outerBounds.width - | 613 var decorationWidth = appWindow.outerBounds.width - |
| 643 appWindow.innerBounds.width; | 614 appWindow.innerBounds.width; |
| 644 var decorationHeight = appWindow.outerBounds.height - | 615 var decorationHeight = appWindow.outerBounds.height - |
| 645 appWindow.innerBounds.height; | 616 appWindow.innerBounds.height; |
| 646 | 617 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 | 653 |
| 683 var lsoError = false; | 654 var lsoError = false; |
| 684 var onLsoViewRequestResponseStarted = function(details) { | 655 var onLsoViewRequestResponseStarted = function(details) { |
| 685 if (isApprovalResponse(details.url)) { | 656 if (isApprovalResponse(details.url)) { |
| 686 showPage('arc-loading'); | 657 showPage('arc-loading'); |
| 687 } | 658 } |
| 688 lsoError = false; | 659 lsoError = false; |
| 689 }; | 660 }; |
| 690 | 661 |
| 691 var onLsoViewErrorOccurred = function(details) { | 662 var onLsoViewErrorOccurred = function(details) { |
| 692 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( | 663 showErrorPage( |
| 693 'serverError')); | 664 appWindow.contentWindow.loadTimeData.getString('serverError')); |
| 694 showPage('error'); | |
| 695 lsoError = true; | 665 lsoError = true; |
| 696 }; | 666 }; |
| 697 | 667 |
| 698 var onLsoViewContentLoad = function() { | 668 var onLsoViewContentLoad = function() { |
| 699 if (lsoError) { | 669 if (lsoError) { |
| 700 return; | 670 return; |
| 701 } | 671 } |
| 702 | 672 |
| 703 if (!isApprovalResponse(lsoView.src)) { | 673 if (!isApprovalResponse(lsoView.src)) { |
| 704 // Show LSO page when its content is ready. | 674 // Show LSO page when its content is ready. |
| 705 showPage('lso'); | 675 showPage('lso'); |
| 706 // We have fixed width for LSO page in css file in order to prevent | 676 // We have fixed width for LSO page in css file in order to prevent |
| 707 // unwanted webview resize animation when it is shown first time. Now | 677 // unwanted webview resize animation when it is shown first time. Now |
| 708 // it safe to make it up to window width. | 678 // it safe to make it up to window width. |
| 709 lsoView.style.width = '100%'; | 679 lsoView.style.width = '100%'; |
| 710 return; | 680 return; |
| 711 } | 681 } |
| 712 | 682 |
| 713 lsoView.executeScript({code: 'document.title;'}, function(results) { | 683 lsoView.executeScript({code: 'document.title;'}, function(results) { |
| 714 var authCodePrefix = 'Success code='; | 684 var authCodePrefix = 'Success code='; |
| 715 if (results && results.length == 1 && typeof results[0] == 'string' && | 685 if (results && results.length == 1 && typeof results[0] == 'string' && |
| 716 results[0].substring(0, authCodePrefix.length) == authCodePrefix) { | 686 results[0].substring(0, authCodePrefix.length) == authCodePrefix) { |
| 717 var authCode = results[0].substring(authCodePrefix.length); | 687 var authCode = results[0].substring(authCodePrefix.length); |
| 718 sendNativeMessage('onAuthSucceeded', {code: authCode}); | 688 sendNativeMessage('onAuthSucceeded', {code: authCode}); |
| 719 } else { | 689 } else { |
| 720 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( | 690 showErrorMessage( |
| 721 'authorizationFailed')); | 691 appWindow.contentWindow.loadTimeData.getString( |
| 722 showPage('error'); | 692 'authorizationFailed')); |
| 723 } | 693 } |
| 724 }); | 694 }); |
| 725 }; | 695 }; |
| 726 | 696 |
| 727 var requestFilter = { | 697 var requestFilter = { |
| 728 urls: ['<all_urls>'], | 698 urls: ['<all_urls>'], |
| 729 types: ['main_frame'] | 699 types: ['main_frame'] |
| 730 }; | 700 }; |
| 731 | 701 |
| 732 lsoView.request.onResponseStarted.addListener( | 702 lsoView.request.onResponseStarted.addListener( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 type: 'chrome', | 765 type: 'chrome', |
| 796 color: '#ffffff' | 766 color: '#ffffff' |
| 797 }, | 767 }, |
| 798 'innerBounds': { | 768 'innerBounds': { |
| 799 'width': INNER_WIDTH, | 769 'width': INNER_WIDTH, |
| 800 'height': INNER_HEIGHT | 770 'height': INNER_HEIGHT |
| 801 } | 771 } |
| 802 }; | 772 }; |
| 803 chrome.app.window.create('main.html', options, onWindowCreated); | 773 chrome.app.window.create('main.html', options, onWindowCreated); |
| 804 }); | 774 }); |
| OLD | NEW |