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

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

Issue 2479633004: Split ShowPage message into two. (Closed)
Patch Set: Fix error message 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
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
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'));
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
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: this is only for controling "RETRY" button. Remove this.
469 termsAccepted = true;
470 }
471 showPage(message.page);
472 } else if (message.action == 'showErrorPage') {
473 // TODO: this is only for controling "RETRY" button. Remove this.
474 termsAccepted = true;
475 showErrorPage(message.errorMessage, message.showSendFeedback);
480 } else if (message.action == 'setWindowBounds') { 476 } else if (message.action == 'setWindowBounds') {
481 setWindowBounds(); 477 setWindowBounds();
482 } 478 }
483 } 479 }
484 480
485 /** 481 /**
486 * Connects to ArcSupportHost. 482 * Connects to ArcSupportHost.
487 */ 483 */
488 function connectPort() { 484 function connectPort() {
489 var hostName = 'com.google.arc_support'; 485 var hostName = 'com.google.arc_support';
490 port = chrome.runtime.connectNative(hostName); 486 port = chrome.runtime.connectNative(hostName);
491 port.onMessage.addListener(onNativeMessage); 487 port.onMessage.addListener(onNativeMessage);
492 } 488 }
493 489
494 /** 490 /**
495 * Shows requested page and hide others. Show appWindow if it was hidden before. 491 * Shows requested page and hide others. Show appWindow if it was hidden before.
496 * 'none' hides all views. 492 * 'none' hides all views.
497 * @param {string} pageDivId id of divider of the page to show. 493 * @param {string} pageDivId id of divider of the page to show.
498 */ 494 */
499 function showPage(pageDivId) { 495 function showPage(pageDivId) {
500 if (!appWindow) { 496 if (!appWindow) {
501 return; 497 return;
502 } 498 }
503 499
504 hideOverlay(); 500 hideOverlay();
505 var doc = appWindow.contentWindow.document; 501 var doc = appWindow.contentWindow.document;
506 var pages = doc.getElementsByClassName('section'); 502 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++) { 503 for (var i = 0; i < pages.length; i++) {
516 pages[i].hidden = pages[i].id != pageDivId; 504 pages[i].hidden = pages[i].id != pageDivId;
517 } 505 }
518 506
519 if (pageDivId == 'lso-loading') { 507 if (pageDivId == 'lso-loading') {
520 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' + 508 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' +
521 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' + 509 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' +
522 'googleusercontent.com&response_type=code&redirect_uri=oob&' + 510 'googleusercontent.com&response_type=code&redirect_uri=oob&' +
523 'scope=https://www.google.com/accounts/OAuthLogin&' + 511 'scope=https://www.google.com/accounts/OAuthLogin&' +
524 'device_type=arc_plus_plus&device_id=' + currentDeviceId + 512 'device_type=arc_plus_plus&device_id=' + currentDeviceId +
525 '&hl=' + navigator.language; 513 '&hl=' + navigator.language;
526 } 514 }
527 appWindow.show(); 515 appWindow.show();
528 if (pageDivId == 'terms') { 516 if (pageDivId == 'terms') {
529 termsPage.onShow(); 517 termsPage.onShow();
530 } 518 }
531 } 519 }
532 520
533 /** 521 /**
534 * Sets error message. 522 * Shows an error page, with given errorMessage.
535 * @param {string} error message. 523 *
524 * @param {string} errorMessage Localized error message text.
525 * @param {?boolean} opt_showSendFeedback If set to true, show "Send feedback"
526 * button.
536 */ 527 */
537 function setErrorMessage(error) { 528 function showErrorPage(errorMessage, opt_showSendFeedback) {
538 if (!appWindow) { 529 if (!appWindow) {
539 return; 530 return;
540 } 531 }
532
541 var doc = appWindow.contentWindow.document; 533 var doc = appWindow.contentWindow.document;
542 var messageElement = doc.getElementById('error-message'); 534 var messageElement = doc.getElementById('error-message');
543 messageElement.innerText = error; 535 messageElement.innerText = errorMessage;
536
537 var sendFeedbackElement = doc.getElementById('button-send-feedback');
538 sendFeedbackElement.hidden = !opt_showSendFeedback;
539
540 showPage('error');
544 } 541 }
545 542
546 /** 543 /**
547 * Shows overlay dialog and required content. 544 * Shows overlay dialog and required content.
548 * @param {string} overlayClass Defines which content to show, 'overlay-url' for 545 * @param {string} overlayClass Defines which content to show, 'overlay-url' for
549 * webview based content and 'overlay-text' for 546 * webview based content and 'overlay-text' for
550 * simple text view. 547 * simple text view.
551 */ 548 */
552 function showOverlay(overlayClass) { 549 function showOverlay(overlayClass) {
553 var doc = appWindow.contentWindow.document; 550 var doc = appWindow.contentWindow.document;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 591
595 /** 592 /**
596 * Hides overlay dialog. 593 * Hides overlay dialog.
597 */ 594 */
598 function hideOverlay() { 595 function hideOverlay() {
599 var doc = appWindow.contentWindow.document; 596 var doc = appWindow.contentWindow.document;
600 var overlayContainer = doc.getElementById('overlay-container'); 597 var overlayContainer = doc.getElementById('overlay-container');
601 overlayContainer.hidden = true; 598 overlayContainer.hidden = true;
602 } 599 }
603 600
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() { 601 function setWindowBounds() {
631 if (!appWindow) { 602 if (!appWindow) {
632 return; 603 return;
633 } 604 }
634 605
635 var decorationWidth = appWindow.outerBounds.width - 606 var decorationWidth = appWindow.outerBounds.width -
636 appWindow.innerBounds.width; 607 appWindow.innerBounds.width;
637 var decorationHeight = appWindow.outerBounds.height - 608 var decorationHeight = appWindow.outerBounds.height -
638 appWindow.innerBounds.height; 609 appWindow.innerBounds.height;
639 610
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 646
676 var lsoError = false; 647 var lsoError = false;
677 var onLsoViewRequestResponseStarted = function(details) { 648 var onLsoViewRequestResponseStarted = function(details) {
678 if (isApprovalResponse(details.url)) { 649 if (isApprovalResponse(details.url)) {
679 showPage('arc-loading'); 650 showPage('arc-loading');
680 } 651 }
681 lsoError = false; 652 lsoError = false;
682 }; 653 };
683 654
684 var onLsoViewErrorOccurred = function(details) { 655 var onLsoViewErrorOccurred = function(details) {
685 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( 656 showErrorPage(
686 'serverError')); 657 appWindow.contentWindow.loadTimeData.getString('serverError'));
687 showPage('error');
688 lsoError = true; 658 lsoError = true;
689 }; 659 };
690 660
691 var onLsoViewContentLoad = function() { 661 var onLsoViewContentLoad = function() {
692 if (lsoError) { 662 if (lsoError) {
693 return; 663 return;
694 } 664 }
695 665
696 if (!isApprovalResponse(lsoView.src)) { 666 if (!isApprovalResponse(lsoView.src)) {
697 // Show LSO page when its content is ready. 667 // Show LSO page when its content is ready.
698 showPage('lso'); 668 showPage('lso');
699 // We have fixed width for LSO page in css file in order to prevent 669 // 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 670 // unwanted webview resize animation when it is shown first time. Now
701 // it safe to make it up to window width. 671 // it safe to make it up to window width.
702 lsoView.style.width = '100%'; 672 lsoView.style.width = '100%';
703 return; 673 return;
704 } 674 }
705 675
706 lsoView.executeScript({code: 'document.title;'}, function(results) { 676 lsoView.executeScript({code: 'document.title;'}, function(results) {
707 var authCodePrefix = 'Success code='; 677 var authCodePrefix = 'Success code=';
708 if (results && results.length == 1 && typeof results[0] == 'string' && 678 if (results && results.length == 1 && typeof results[0] == 'string' &&
709 results[0].substring(0, authCodePrefix.length) == authCodePrefix) { 679 results[0].substring(0, authCodePrefix.length) == authCodePrefix) {
710 var authCode = results[0].substring(authCodePrefix.length); 680 var authCode = results[0].substring(authCodePrefix.length);
711 sendNativeMessage('onAuthSucceeded', {code: authCode}); 681 sendNativeMessage('onAuthSucceeded', {code: authCode});
712 } else { 682 } else {
713 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( 683 showErrorMessage(
714 'authorizationFailed')); 684 appWindow.contentWindow.loadTimeData.getString(
715 showPage('error'); 685 'authorizationFailed'));
716 } 686 }
717 }); 687 });
718 }; 688 };
719 689
720 var requestFilter = { 690 var requestFilter = {
721 urls: ['<all_urls>'], 691 urls: ['<all_urls>'],
722 types: ['main_frame'] 692 types: ['main_frame']
723 }; 693 };
724 694
725 lsoView.request.onResponseStarted.addListener( 695 lsoView.request.onResponseStarted.addListener(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 type: 'chrome', 758 type: 'chrome',
789 color: '#ffffff' 759 color: '#ffffff'
790 }, 760 },
791 'innerBounds': { 761 'innerBounds': {
792 'width': INNER_WIDTH, 762 'width': INNER_WIDTH,
793 'height': INNER_HEIGHT 763 'height': INNER_HEIGHT
794 } 764 }
795 }; 765 };
796 chrome.app.window.create('main.html', options, onWindowCreated); 766 chrome.app.window.create('main.html', options, onWindowCreated);
797 }); 767 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698