Chromium Code Reviews| 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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 this.state_ = LoadState.LOADED; | 347 this.state_ = LoadState.LOADED; |
| 361 this.showContent_(); | 348 this.showContent_(); |
| 362 } | 349 } |
| 363 } | 350 } |
| 364 | 351 |
| 365 /** Called when the terms-view loading is aborted. */ | 352 /** Called when the terms-view loading is aborted. */ |
| 366 onTermsViewLoadAborted_(reason) { | 353 onTermsViewLoadAborted_(reason) { |
| 367 console.error('TermsView loading is aborted: ' + reason); | 354 console.error('TermsView loading is aborted: ' + reason); |
| 368 // Mark ABORTED so that onTermsViewLoaded_() won't show the content view. | 355 // Mark ABORTED so that onTermsViewLoaded_() won't show the content view. |
| 369 this.state_ = LoadState.ABORTED; | 356 this.state_ = LoadState.ABORTED; |
| 370 setErrorMessage( | 357 showErrorPage( |
| 371 appWindow.contentWindow.loadTimeData.getString('serverError')); | 358 appWindow.contentWindow.loadTimeData.getString('serverError'), false); |
| 372 showPage('error'); | |
| 373 } | 359 } |
| 374 | 360 |
| 375 /** Called when "AGREE" button is clicked. */ | 361 /** Called when "AGREE" button is clicked. */ |
| 376 onAgree() { | 362 onAgree() { |
| 377 termsAccepted = true; | 363 termsAccepted = true; |
| 378 | 364 |
| 379 sendNativeMessage('onAgreed', { | 365 sendNativeMessage('onAgreed', { |
| 380 isMetricsEnabled: this.metricsCheckbox_.isChecked(), | 366 isMetricsEnabled: this.metricsCheckbox_.isChecked(), |
| 381 isBackupRestoreEnabled: this.backupRestoreCheckbox_.isChecked(), | 367 isBackupRestoreEnabled: this.backupRestoreCheckbox_.isChecked(), |
| 382 isLocationServiceEnabled: this.locationServiceCheckbox_.isChecked() | 368 isLocationServiceEnabled: this.locationServiceCheckbox_.isChecked() |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 termsPage.onBackupRestorePreferenceChanged( | 455 termsPage.onBackupRestorePreferenceChanged( |
| 470 message.enabled, message.managed); | 456 message.enabled, message.managed); |
| 471 } else if (message.action == 'setLocationServiceMode') { | 457 } else if (message.action == 'setLocationServiceMode') { |
| 472 termsPage.onLocationServicePreferenceChanged( | 458 termsPage.onLocationServicePreferenceChanged( |
| 473 message.enabled, message.managed); | 459 message.enabled, message.managed); |
| 474 } else if (message.action == 'closeWindow') { | 460 } else if (message.action == 'closeWindow') { |
| 475 if (appWindow) { | 461 if (appWindow) { |
| 476 appWindow.close(); | 462 appWindow.close(); |
| 477 } | 463 } |
| 478 } else if (message.action == 'showPage') { | 464 } else if (message.action == 'showPage') { |
| 479 showPageWithStatus(message.page, message.status); | 465 if (message.page != 'terms') { |
| 466 // Explicit request to start not from start page. Assume terms are | |
| 467 // accepted in this case. | |
| 468 // TODO(hidehiko): this is only for controling "RETRY" button. Remove | |
| 469 // this. | |
| 470 termsAccepted = true; | |
| 471 } | |
| 472 showPage(message.page); | |
| 473 } else if (message.action == 'showErrorPage') { | |
| 474 // TODO(hidehiko): this is only for controling "RETRY" button. Remove | |
| 475 // this. | |
| 476 termsAccepted = true; | |
| 477 showErrorPage(message.errorMessage, message.showFeedbackButton); | |
| 480 } else if (message.action == 'setWindowBounds') { | 478 } else if (message.action == 'setWindowBounds') { |
| 481 setWindowBounds(); | 479 setWindowBounds(); |
| 482 } | 480 } |
| 483 } | 481 } |
| 484 | 482 |
| 485 /** | 483 /** |
| 486 * Connects to ArcSupportHost. | 484 * Connects to ArcSupportHost. |
| 487 */ | 485 */ |
| 488 function connectPort() { | 486 function connectPort() { |
| 489 var hostName = 'com.google.arc_support'; | 487 var hostName = 'com.google.arc_support'; |
| 490 port = chrome.runtime.connectNative(hostName); | 488 port = chrome.runtime.connectNative(hostName); |
| 491 port.onMessage.addListener(onNativeMessage); | 489 port.onMessage.addListener(onNativeMessage); |
| 492 } | 490 } |
| 493 | 491 |
| 494 /** | 492 /** |
| 495 * Shows requested page and hide others. Show appWindow if it was hidden before. | 493 * Shows requested page and hide others. Show appWindow if it was hidden before. |
| 496 * 'none' hides all views. | 494 * 'none' hides all views. |
| 497 * @param {string} pageDivId id of divider of the page to show. | 495 * @param {string} pageDivId id of divider of the page to show. |
| 498 */ | 496 */ |
| 499 function showPage(pageDivId) { | 497 function showPage(pageDivId) { |
| 500 if (!appWindow) { | 498 if (!appWindow) { |
| 501 return; | 499 return; |
| 502 } | 500 } |
| 503 | 501 |
| 504 hideOverlay(); | 502 hideOverlay(); |
| 505 var doc = appWindow.contentWindow.document; | 503 var doc = appWindow.contentWindow.document; |
| 506 var pages = doc.getElementsByClassName('section'); | 504 var pages = doc.getElementsByClassName("section"); |
| 507 var sendFeedbackElement = doc.getElementById('button-send-feedback'); | |
| 508 if (pageDivId == 'error-with-feedback') { | |
| 509 // Only show feedback button if the pageDivId is 'error-with-feedback'. | |
| 510 sendFeedbackElement.hidden = false; | |
| 511 pageDivId = 'error'; | |
| 512 } else { | |
| 513 sendFeedbackElement.hidden = true; | |
| 514 } | |
| 515 for (var i = 0; i < pages.length; i++) { | 505 for (var i = 0; i < pages.length; i++) { |
| 516 pages[i].hidden = pages[i].id != pageDivId; | 506 pages[i].hidden = pages[i].id != pageDivId; |
| 517 } | 507 } |
| 518 | 508 |
| 519 if (pageDivId == 'lso-loading') { | 509 if (pageDivId == 'lso-loading') { |
|
Luis Héctor Chávez
2016/11/04 17:08:55
Are this and L528 also candidates for splitting?
| |
| 520 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' + | 510 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' + |
| 521 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' + | 511 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' + |
| 522 'googleusercontent.com&response_type=code&redirect_uri=oob&' + | 512 'googleusercontent.com&response_type=code&redirect_uri=oob&' + |
| 523 'scope=https://www.google.com/accounts/OAuthLogin&' + | 513 'scope=https://www.google.com/accounts/OAuthLogin&' + |
| 524 'device_type=arc_plus_plus&device_id=' + currentDeviceId + | 514 'device_type=arc_plus_plus&device_id=' + currentDeviceId + |
| 525 '&hl=' + navigator.language; | 515 '&hl=' + navigator.language; |
| 526 } | 516 } |
| 527 appWindow.show(); | 517 appWindow.show(); |
| 528 if (pageDivId == 'terms') { | 518 if (pageDivId == 'terms') { |
| 529 termsPage.onShow(); | 519 termsPage.onShow(); |
| 530 } | 520 } |
| 531 } | 521 } |
| 532 | 522 |
| 533 /** | 523 /** |
| 524 * Shows the error page with setting the given error message. | |
| 525 * @param {string} errorMessage L10n error message text. | |
| 526 * @param {boolean} showFeedbackButton true if feedback button should be shown. | |
| 527 */ | |
| 528 function showErrorPage(errorMessage, showFeedbackButton) { | |
| 529 if (!appWindow) { | |
| 530 return; | |
| 531 } | |
| 532 | |
| 533 // Set error text. | |
| 534 var doc = appWindow.contentWindow.document; | |
| 535 var messageElement = doc.getElementById('error-message'); | |
| 536 messageElement.innerText = error; | |
| 537 | |
| 538 // Set visibility of the feedback button. | |
| 539 var sendFeedbackElement = doc.getElementById('button-send-feedback'); | |
| 540 sendFeedbackElement.hidden = !showFeedbackButton; | |
| 541 | |
| 542 showPage('error'); | |
| 543 } | |
| 544 | |
| 545 /** | |
| 534 * Sets error message. | 546 * Sets error message. |
| 535 * @param {string} error message. | 547 * @param {string} error message. |
| 536 */ | 548 */ |
| 537 function setErrorMessage(error) { | 549 function setErrorMessage(error) { |
| 538 if (!appWindow) { | 550 if (!appWindow) { |
| 539 return; | 551 return; |
| 540 } | 552 } |
| 541 var doc = appWindow.contentWindow.document; | 553 var doc = appWindow.contentWindow.document; |
| 542 var messageElement = doc.getElementById('error-message'); | 554 var messageElement = doc.getElementById('error-message'); |
| 543 messageElement.innerText = error; | 555 messageElement.innerText = error; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 | 606 |
| 595 /** | 607 /** |
| 596 * Hides overlay dialog. | 608 * Hides overlay dialog. |
| 597 */ | 609 */ |
| 598 function hideOverlay() { | 610 function hideOverlay() { |
| 599 var doc = appWindow.contentWindow.document; | 611 var doc = appWindow.contentWindow.document; |
| 600 var overlayContainer = doc.getElementById('overlay-container'); | 612 var overlayContainer = doc.getElementById('overlay-container'); |
| 601 overlayContainer.hidden = true; | 613 overlayContainer.hidden = true; |
| 602 } | 614 } |
| 603 | 615 |
| 604 /** | |
| 605 * Shows requested page. | |
| 606 * @param {int} pageId Index of the page to show. Must be in the array range of | |
| 607 * UI_PAGES. | |
| 608 * @param {string} status associated with page string status, error message for | |
| 609 * example. | |
| 610 */ | |
| 611 function showPageWithStatus(pageId, status) { | |
| 612 if (!appWindow) { | |
| 613 return; | |
| 614 } | |
| 615 | |
| 616 if (UI_PAGES[pageId] != 'terms') { | |
| 617 // Explicit request to start not from start page. Assume terms are | |
| 618 // accepted in this case. | |
| 619 // TODO: this is only for controling "RETRY" button. Remove this. | |
| 620 termsAccepted = true; | |
| 621 } | |
| 622 | |
| 623 if (UI_PAGES[pageId] == 'error' || | |
| 624 UI_PAGES[pageId] == 'error-with-feedback') { | |
| 625 setErrorMessage(status); | |
| 626 } | |
| 627 showPage(UI_PAGES[pageId]); | |
| 628 } | |
| 629 | |
| 630 function setWindowBounds() { | 616 function setWindowBounds() { |
| 631 if (!appWindow) { | 617 if (!appWindow) { |
| 632 return; | 618 return; |
| 633 } | 619 } |
| 634 | 620 |
| 635 var decorationWidth = appWindow.outerBounds.width - | 621 var decorationWidth = appWindow.outerBounds.width - |
| 636 appWindow.innerBounds.width; | 622 appWindow.innerBounds.width; |
| 637 var decorationHeight = appWindow.outerBounds.height - | 623 var decorationHeight = appWindow.outerBounds.height - |
| 638 appWindow.innerBounds.height; | 624 appWindow.innerBounds.height; |
| 639 | 625 |
| 640 var outerWidth = INNER_WIDTH + decorationWidth; | 626 var outerWidth = INNER_WIDTH + decorationWidth; |
| 641 var outerHeight = INNER_HEIGHT + decorationHeight; | 627 var outerHeight = INNER_HEIGHT + decorationHeight; |
| 642 if (outerWidth > screen.availWidth) { | 628 if (outerWidth > screen.availWidth) { |
| 643 outerWidth = screen.availWidth; | 629 outerWidth = screen.availWidth; |
| 644 } | 630 } |
| 645 if (outerHeight > screen.availHeight) { | 631 if (outerHeight > screen.availHeight) { |
| 646 outerHeight = screen.availHeight; | 632 outerHeight = screen.availHeight; |
| 647 } | 633 } |
| 648 if (appWindow.outerBounds.width == outerWidth && | 634 if (appWindow.outerBounds.width == outerWidth && |
| 649 appWindow.outerBounds.height == outerHeight) { | 635 appWindow.outerBounds.height == outerHeight) { |
| 650 return; | 636 return; |
| 651 } | 637 } |
| 652 | 638 |
| 653 appWindow.outerBounds.width = outerWidth; | 639 appWindow.outerBounds.width = outerWidth; |
| 654 appWindow.outerBounds.height = outerHeight; | 640 appWindow.outerBounds.height = outerHeight; |
| 655 appWindow.outerBounds.left = Math.ceil((screen.availWidth - outerWidth) / 2); | 641 appWindow.outerBounds.left = Math.ceil((screen.availWidth - outerWidth) / 2); |
| 656 appWindow.outerBounds.top = | 642 appWindow.outerBounds.top = |
| 657 Math.ceil((screen.availHeight - outerHeight) / 2); | 643 Math.ceil((screen.availHeight - outerHeight) / 2); |
| 658 } | 644 } |
| 659 | 645 |
| 660 chrome.app.runtime.onLaunched.addListener(function() { | 646 chrome.app.runtime.onLaunched.addListener(function() { |
| 661 var onAppContentLoad = function() { | 647 var onAppContentLoad = function() { |
| 662 var doc = appWindow.contentWindow.document; | 648 var doc = appWindow.contentWindow.document; |
| 663 lsoView = doc.getElementById('arc-support'); | 649 lsoView = doc.getElementById('arc-support'); |
| 664 lsoView.addContentScripts([ | 650 lsoView.addContentScripts([ |
| 665 { name: 'postProcess', | 651 { name: 'postProcess', |
| 666 matches: ['https://accounts.google.com/*'], | 652 matches: ['https://accounts.google.com/*'], |
| 667 css: { files: ['lso.css'] }, | 653 css: { files: ['lso.css'] }, |
| 668 run_at: 'document_end' | 654 run_at: 'document_end' |
| 669 }]); | 655 }]); |
| 670 | 656 |
| 671 var isApprovalResponse = function(url) { | 657 var isApprovalResponse = function(url) { |
| 672 var resultUrlPrefix = 'https://accounts.google.com/o/oauth2/approval?'; | 658 var resultUrlPrefix = 'https://accounts.google.com/o/oauth2/approval?'; |
| 673 return url.substring(0, resultUrlPrefix.length) == resultUrlPrefix; | 659 return url.substring(0, resultUrlPrefix.length) == resultUrlPrefix; |
| 674 }; | 660 }; |
| 675 | 661 |
| 676 var lsoError = false; | 662 var lsoError = false; |
| 677 var onLsoViewRequestResponseStarted = function(details) { | 663 var onLsoViewRequestResponseStarted = function(details) { |
| 678 if (isApprovalResponse(details.url)) { | 664 if (isApprovalResponse(details.url)) { |
| 679 showPage('arc-loading'); | 665 showPage('arc-loading'); |
| 680 } | 666 } |
| 681 lsoError = false; | 667 lsoError = false; |
| 682 }; | 668 }; |
| 683 | 669 |
| 684 var onLsoViewErrorOccurred = function(details) { | 670 var onLsoViewErrorOccurred = function(details) { |
| 685 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( | 671 showErrorPage( |
| 686 'serverError')); | 672 appWindow.contentWindow.loadTimeData.getString('serverError'), |
| 687 showPage('error'); | 673 false); |
| 688 lsoError = true; | 674 lsoError = true; |
| 689 }; | 675 }; |
| 690 | 676 |
| 691 var onLsoViewContentLoad = function() { | 677 var onLsoViewContentLoad = function() { |
| 692 if (lsoError) { | 678 if (lsoError) { |
| 693 return; | 679 return; |
| 694 } | 680 } |
| 695 | 681 |
| 696 if (!isApprovalResponse(lsoView.src)) { | 682 if (!isApprovalResponse(lsoView.src)) { |
| 697 // Show LSO page when its content is ready. | 683 // Show LSO page when its content is ready. |
| 698 showPage('lso'); | 684 showPage('lso'); |
| 699 // We have fixed width for LSO page in css file in order to prevent | 685 // We have fixed width for LSO page in css file in order to prevent |
| 700 // unwanted webview resize animation when it is shown first time. Now | 686 // unwanted webview resize animation when it is shown first time. Now |
| 701 // it safe to make it up to window width. | 687 // it safe to make it up to window width. |
| 702 lsoView.style.width = '100%'; | 688 lsoView.style.width = '100%'; |
| 703 return; | 689 return; |
| 704 } | 690 } |
| 705 | 691 |
| 706 lsoView.executeScript({code: 'document.title;'}, function(results) { | 692 lsoView.executeScript({code: 'document.title;'}, function(results) { |
| 707 var authCodePrefix = 'Success code='; | 693 var authCodePrefix = 'Success code='; |
| 708 if (results && results.length == 1 && typeof results[0] == 'string' && | 694 if (results && results.length == 1 && typeof results[0] == 'string' && |
| 709 results[0].substring(0, authCodePrefix.length) == authCodePrefix) { | 695 results[0].substring(0, authCodePrefix.length) == authCodePrefix) { |
| 710 var authCode = results[0].substring(authCodePrefix.length); | 696 var authCode = results[0].substring(authCodePrefix.length); |
| 711 sendNativeMessage('onAuthSucceeded', {code: authCode}); | 697 sendNativeMessage('onAuthSucceeded', {code: authCode}); |
| 712 } else { | 698 } else { |
| 713 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( | 699 showErrorPage( |
| 714 'authorizationFailed')); | 700 appWindow.contentWindow.loadTimeData.getString( |
| 715 showPage('error'); | 701 'authorizationFailed'), |
| 702 false); | |
| 716 } | 703 } |
| 717 }); | 704 }); |
| 718 }; | 705 }; |
| 719 | 706 |
| 720 var requestFilter = { | 707 var requestFilter = { |
| 721 urls: ['<all_urls>'], | 708 urls: ['<all_urls>'], |
| 722 types: ['main_frame'] | 709 types: ['main_frame'] |
| 723 }; | 710 }; |
| 724 | 711 |
| 725 lsoView.request.onResponseStarted.addListener( | 712 lsoView.request.onResponseStarted.addListener( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 type: 'chrome', | 775 type: 'chrome', |
| 789 color: '#ffffff' | 776 color: '#ffffff' |
| 790 }, | 777 }, |
| 791 'innerBounds': { | 778 'innerBounds': { |
| 792 'width': INNER_WIDTH, | 779 'width': INNER_WIDTH, |
| 793 'height': INNER_HEIGHT | 780 'height': INNER_HEIGHT |
| 794 } | 781 } |
| 795 }; | 782 }; |
| 796 chrome.app.window.create('main.html', options, onWindowCreated); | 783 chrome.app.window.create('main.html', options, onWindowCreated); |
| 797 }); | 784 }); |
| OLD | NEW |