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 | 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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 /** | 359 /** |
| 360 * Shows requested page and hide others. Show appWindow if it was hidden before. | 360 * Shows requested page and hide others. Show appWindow if it was hidden before. |
| 361 * 'none' hides all views. | 361 * 'none' hides all views. |
| 362 * @param {string} pageDivId id of divider of the page to show. | 362 * @param {string} pageDivId id of divider of the page to show. |
| 363 */ | 363 */ |
| 364 function showPage(pageDivId) { | 364 function showPage(pageDivId) { |
| 365 if (!appWindow) { | 365 if (!appWindow) { |
| 366 return; | 366 return; |
| 367 } | 367 } |
| 368 | 368 |
| 369 hideLearnMoreOverlay(); | 369 hideOverlay(); |
| 370 var doc = appWindow.contentWindow.document; | 370 var doc = appWindow.contentWindow.document; |
| 371 var pages = doc.getElementsByClassName('section'); | 371 var pages = doc.getElementsByClassName('section'); |
| 372 var sendFeedbackElement = doc.getElementById('button-send-feedback'); | 372 var sendFeedbackElement = doc.getElementById('button-send-feedback'); |
| 373 if (pageDivId == 'error-with-feedback') { | 373 if (pageDivId == 'error-with-feedback') { |
| 374 // Only show feedback button if the pageDivId is 'error-with-feedback'. | 374 // Only show feedback button if the pageDivId is 'error-with-feedback'. |
| 375 sendFeedbackElement.hidden = false; | 375 sendFeedbackElement.hidden = false; |
| 376 pageDivId = 'error'; | 376 pageDivId = 'error'; |
| 377 } else { | 377 } else { |
| 378 sendFeedbackElement.hidden = true; | 378 sendFeedbackElement.hidden = true; |
| 379 } | 379 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 402 function setErrorMessage(error) { | 402 function setErrorMessage(error) { |
| 403 if (!appWindow) { | 403 if (!appWindow) { |
| 404 return; | 404 return; |
| 405 } | 405 } |
| 406 var doc = appWindow.contentWindow.document; | 406 var doc = appWindow.contentWindow.document; |
| 407 var messageElement = doc.getElementById('error-message'); | 407 var messageElement = doc.getElementById('error-message'); |
| 408 messageElement.innerText = error; | 408 messageElement.innerText = error; |
| 409 } | 409 } |
| 410 | 410 |
| 411 /** | 411 /** |
| 412 * Shows overlay dialog and required content. | |
| 413 * @param {string} overlayClass Defines which content to show, 'overlay-url' for | |
| 414 * webview based content and 'overlay-text' for | |
| 415 * simple text view. | |
| 416 */ | |
| 417 function showOverlay(overlayClass) { | |
| 418 var doc = appWindow.contentWindow.document; | |
| 419 var overlayContainer = doc.getElementById('overlay-container'); | |
| 420 overlayContainer.className = 'overlay ' + overlayClass; | |
| 421 overlayContainer.hidden = false; | |
| 422 } | |
| 423 | |
| 424 /** | |
| 412 * Sets learn more content text and shows it as overlay dialog. | 425 * Sets learn more content text and shows it as overlay dialog. |
| 413 * @param {string} content HTML formatted text to show. | 426 * @param {string} content HTML formatted text to show. |
| 414 */ | 427 */ |
| 415 function showLearnMoreOverlay(content) { | 428 function showLearnMoreOverlay(content) { |
| 416 var doc = appWindow.contentWindow.document; | 429 var doc = appWindow.contentWindow.document; |
| 417 var learnMoreContainer = doc.getElementById('learn-more-container'); | |
| 418 var learnMoreContent = doc.getElementById('learn-more-content'); | 430 var learnMoreContent = doc.getElementById('learn-more-content'); |
| 419 learnMoreContent.innerHTML = content; | 431 learnMoreContent.innerHTML = content; |
| 420 learnMoreContainer.hidden = false; | 432 showOverlay('overlay-text'); |
|
xiyuan
2016/10/18 21:26:07
Do we need to worry about the text content being s
khmel
2016/10/18 22:18:12
I added css rule as:
.overlay-text webview {
di
xiyuan
2016/10/18 22:21:50
You are right. Mis-read that.
| |
| 421 } | 433 } |
| 422 | 434 |
| 423 /** | 435 /** |
| 424 * Hides learn more overlay dialog. | 436 * Opens overlay dialog and shows external URL there. |
| 437 * @param {string} url Target URL to open in overlay dialog. | |
| 425 */ | 438 */ |
| 426 function hideLearnMoreOverlay() { | 439 function showURLOverlay(url) { |
| 427 var doc = appWindow.contentWindow.document; | 440 var doc = appWindow.contentWindow.document; |
| 428 var learnMoreContainer = doc.getElementById('learn-more-container'); | 441 var overlayWebview = doc.getElementById('overlay-url'); |
| 429 learnMoreContainer.hidden = true; | 442 overlayWebview.src = url; |
| 443 showOverlay('overlay-url'); | |
| 430 } | 444 } |
| 431 | 445 |
| 432 /** | 446 /** |
| 447 * Hides overlay dialog. | |
| 448 */ | |
| 449 function hideOverlay() { | |
| 450 var doc = appWindow.contentWindow.document; | |
| 451 var overlayContainer = doc.getElementById('overlay-container'); | |
| 452 overlayContainer.hidden = true; | |
| 453 } | |
| 454 | |
| 455 /** | |
| 433 * Shows requested page. | 456 * Shows requested page. |
| 434 * @param {int} pageId Index of the page to show. Must be in the array range of | 457 * @param {int} pageId Index of the page to show. Must be in the array range of |
| 435 * UI_PAGES. | 458 * UI_PAGES. |
| 436 * @param {string} status associated with page string status, error message for | 459 * @param {string} status associated with page string status, error message for |
| 437 * example. | 460 * example. |
| 438 */ | 461 */ |
| 439 function showPageWithStatus(pageId, status) { | 462 function showPageWithStatus(pageId, status) { |
| 440 if (!appWindow) { | 463 if (!appWindow) { |
| 441 return; | 464 return; |
| 442 } | 465 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 }; | 616 }; |
| 594 | 617 |
| 595 termsView.request.onBeforeRequest.addListener(onTermsViewBeforeRequest, | 618 termsView.request.onBeforeRequest.addListener(onTermsViewBeforeRequest, |
| 596 requestFilter); | 619 requestFilter); |
| 597 termsView.request.onErrorOccurred.addListener(onTermsViewErrorOccurred, | 620 termsView.request.onErrorOccurred.addListener(onTermsViewErrorOccurred, |
| 598 requestFilter); | 621 requestFilter); |
| 599 termsView.addEventListener('contentload', onTermsViewContentLoad); | 622 termsView.addEventListener('contentload', onTermsViewContentLoad); |
| 600 | 623 |
| 601 | 624 |
| 602 // webview is not allowed to open links in the new window. Hook these events | 625 // webview is not allowed to open links in the new window. Hook these events |
| 603 // and open links in context of main page. | 626 // and open links in overlay dialog. |
| 604 termsView.addEventListener('newwindow', function(event) { | 627 termsView.addEventListener('newwindow', function(event) { |
| 605 event.preventDefault(); | 628 event.preventDefault(); |
| 606 chrome.browser.openTab({'url': event.targetUrl}, function() {}); | 629 showURLOverlay(event.targetUrl); |
| 607 }); | 630 }); |
| 608 | 631 |
| 609 var onAgree = function() { | 632 var onAgree = function() { |
| 610 termsAccepted = true; | 633 termsAccepted = true; |
| 611 | 634 |
| 612 sendNativeMessage('onAgreed', { | 635 sendNativeMessage('onAgreed', { |
| 613 isMetricsEnabled: metricsCheckbox.isChecked(), | 636 isMetricsEnabled: metricsCheckbox.isChecked(), |
| 614 isBackupRestoreEnabled: backupRestoreCheckbox.isChecked(), | 637 isBackupRestoreEnabled: backupRestoreCheckbox.isChecked(), |
| 615 isLocationServiceEnabled: locationServiceCheckbox.isChecked() | 638 isLocationServiceEnabled: locationServiceCheckbox.isChecked() |
| 616 }); | 639 }); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 634 | 657 |
| 635 var onSendFeedback = function() { | 658 var onSendFeedback = function() { |
| 636 sendNativeMessage('onSendFeedbackClicked'); | 659 sendNativeMessage('onSendFeedbackClicked'); |
| 637 }; | 660 }; |
| 638 | 661 |
| 639 doc.getElementById('button-agree').addEventListener('click', onAgree); | 662 doc.getElementById('button-agree').addEventListener('click', onAgree); |
| 640 doc.getElementById('button-cancel').addEventListener('click', onCancel); | 663 doc.getElementById('button-cancel').addEventListener('click', onCancel); |
| 641 doc.getElementById('button-retry').addEventListener('click', onRetry); | 664 doc.getElementById('button-retry').addEventListener('click', onRetry); |
| 642 doc.getElementById('button-send-feedback') | 665 doc.getElementById('button-send-feedback') |
| 643 .addEventListener('click', onSendFeedback); | 666 .addEventListener('click', onSendFeedback); |
| 644 doc.getElementById('learn-more-close').addEventListener( | 667 doc.getElementById('overlay-close').addEventListener('click', hideOverlay); |
| 645 'click', hideLearnMoreOverlay); | |
| 646 | 668 |
| 647 var overlay = doc.getElementById('learn-more-container'); | 669 var overlay = doc.getElementById('overlay-container'); |
| 648 appWindow.contentWindow.cr.ui.overlay.setupOverlay(overlay); | 670 appWindow.contentWindow.cr.ui.overlay.setupOverlay(overlay); |
| 649 appWindow.contentWindow.cr.ui.overlay.globalInitialization(); | 671 appWindow.contentWindow.cr.ui.overlay.globalInitialization(); |
| 650 overlay.addEventListener('cancelOverlay', hideLearnMoreOverlay); | 672 overlay.addEventListener('cancelOverlay', hideOverlay); |
| 651 | 673 |
| 652 connectPort(); | 674 connectPort(); |
| 653 }; | 675 }; |
| 654 | 676 |
| 655 var onWindowCreated = function(createdWindow) { | 677 var onWindowCreated = function(createdWindow) { |
| 656 appWindow = createdWindow; | 678 appWindow = createdWindow; |
| 657 appWindow.contentWindow.onload = onAppContentLoad; | 679 appWindow.contentWindow.onload = onAppContentLoad; |
| 658 appWindow.onClosed.addListener(onWindowClosed); | 680 appWindow.onClosed.addListener(onWindowClosed); |
| 659 | 681 |
| 660 setWindowBounds(); | 682 setWindowBounds(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 681 type: 'chrome', | 703 type: 'chrome', |
| 682 color: '#ffffff' | 704 color: '#ffffff' |
| 683 }, | 705 }, |
| 684 'innerBounds': { | 706 'innerBounds': { |
| 685 'width': INNER_WIDTH, | 707 'width': INNER_WIDTH, |
| 686 'height': INNER_HEIGHT | 708 'height': INNER_HEIGHT |
| 687 } | 709 } |
| 688 }; | 710 }; |
| 689 chrome.app.window.create('main.html', options, onWindowCreated); | 711 chrome.app.window.create('main.html', options, onWindowCreated); |
| 690 }); | 712 }); |
| OLD | NEW |