| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 run_at: 'document_end' | 155 run_at: 'document_end' |
| 156 }]); | 156 }]); |
| 157 } | 157 } |
| 158 | 158 |
| 159 /** | 159 /** |
| 160 * Handles the event when the user clicks on a learn more metrics link. Opens | 160 * Handles the event when the user clicks on a learn more metrics link. Opens |
| 161 * the pop up dialog with a help. | 161 * the pop up dialog with a help. |
| 162 */ | 162 */ |
| 163 var onLearnMoreMetrics = function() { | 163 var onLearnMoreMetrics = function() { |
| 164 var loadTimeData = appWindow.contentWindow.loadTimeData; | 164 var loadTimeData = appWindow.contentWindow.loadTimeData; |
| 165 showLearnModeOverlay(loadTimeData.getString('learnMoreStatistics')); | 165 showTextOverlay(loadTimeData.getString('learnMoreStatistics')); |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * Handles the event when the user clicks on a learn more backup and restore | 169 * Handles the event when the user clicks on a learn more backup and restore |
| 170 * link. Opens the pop up dialog with a help. | 170 * link. Opens the pop up dialog with a help. |
| 171 */ | 171 */ |
| 172 var onLearnMoreBackupAndRestore = function() { | 172 var onLearnMoreBackupAndRestore = function() { |
| 173 var loadTimeData = appWindow.contentWindow.loadTimeData; | 173 var loadTimeData = appWindow.contentWindow.loadTimeData; |
| 174 showLearnModeOverlay(loadTimeData.getString('learnMoreBackupAndRestore')); | 174 showTextOverlay(loadTimeData.getString('learnMoreBackupAndRestore')); |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 /** | 177 /** |
| 178 * Handles the event when the user clicks on a learn more location services | 178 * Handles the event when the user clicks on a learn more location services |
| 179 * link. Opens the pop up dialog with a help. | 179 * link. Opens the pop up dialog with a help. |
| 180 */ | 180 */ |
| 181 var onLearnMoreLocationServices = function() { | 181 var onLearnMoreLocationServices = function() { |
| 182 var loadTimeData = appWindow.contentWindow.loadTimeData; | 182 var loadTimeData = appWindow.contentWindow.loadTimeData; |
| 183 showLearnModeOverlay(loadTimeData.getString('learnMoreLocationServices')); | 183 showTextOverlay(loadTimeData.getString('learnMoreLocationServices')); |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 /** | 186 /** |
| 187 * Sets current metrics mode. | 187 * Sets current metrics mode. |
| 188 * @param {string} text Describes current metrics state. | 188 * @param {string} text Describes current metrics state. |
| 189 * @param {boolean} canEnable Defines if user is allowed to change this metrics | 189 * @param {boolean} canEnable Defines if user is allowed to change this metrics |
| 190 * option. | 190 * option. |
| 191 * @param {boolean} on Defines if metrics are active currently. | 191 * @param {boolean} on Defines if metrics are active currently. |
| 192 */ | 192 */ |
| 193 function setMetricsMode(text, canEnable, on) { | 193 function setMetricsMode(text, canEnable, on) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 /** | 321 /** |
| 322 * Shows requested page and hide others. Show appWindow if it was hidden before. | 322 * Shows requested page and hide others. Show appWindow if it was hidden before. |
| 323 * 'none' hides all views. | 323 * 'none' hides all views. |
| 324 * @param {string} pageDivId id of divider of the page to show. | 324 * @param {string} pageDivId id of divider of the page to show. |
| 325 */ | 325 */ |
| 326 function showPage(pageDivId) { | 326 function showPage(pageDivId) { |
| 327 if (!appWindow) { | 327 if (!appWindow) { |
| 328 return; | 328 return; |
| 329 } | 329 } |
| 330 | 330 |
| 331 hideLearnModeOverlay(); | 331 hideOverlay(); |
| 332 var doc = appWindow.contentWindow.document; | 332 var doc = appWindow.contentWindow.document; |
| 333 var pages = doc.getElementsByClassName('section'); | 333 var pages = doc.getElementsByClassName('section'); |
| 334 var sendFeedbackElement = doc.getElementById('button-send-feedback'); | 334 var sendFeedbackElement = doc.getElementById('button-send-feedback'); |
| 335 if (pageDivId == 'error-with-feedback') { | 335 if (pageDivId == 'error-with-feedback') { |
| 336 // Only show feedback button if the pageDivId is 'error-with-feedback'. | 336 // Only show feedback button if the pageDivId is 'error-with-feedback'. |
| 337 sendFeedbackElement.hidden = false; | 337 sendFeedbackElement.hidden = false; |
| 338 pageDivId = 'error'; | 338 pageDivId = 'error'; |
| 339 } else { | 339 } else { |
| 340 sendFeedbackElement.hidden = true; | 340 sendFeedbackElement.hidden = true; |
| 341 } | 341 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 364 function setErrorMessage(error) { | 364 function setErrorMessage(error) { |
| 365 if (!appWindow) { | 365 if (!appWindow) { |
| 366 return; | 366 return; |
| 367 } | 367 } |
| 368 var doc = appWindow.contentWindow.document; | 368 var doc = appWindow.contentWindow.document; |
| 369 var messageElement = doc.getElementById('error-message'); | 369 var messageElement = doc.getElementById('error-message'); |
| 370 messageElement.innerText = error; | 370 messageElement.innerText = error; |
| 371 } | 371 } |
| 372 | 372 |
| 373 /** | 373 /** |
| 374 * Sets learn more content text and shows it as overlay dialog. | 374 * Shows overlay dialog and required content. |
| 375 * @param {string} content HTML formatted text to show. | 375 * @param {string} overlayClass Defines which content to show, 'overlay-url' for |
| 376 * webview based content and 'overlay-text' for |
| 377 * simple text view. |
| 376 */ | 378 */ |
| 377 function showLearnModeOverlay(content) { | 379 function showOverlay(overlayClass) { |
| 378 var doc = appWindow.contentWindow.document; | 380 var doc = appWindow.contentWindow.document; |
| 379 var learnMoreContainer = doc.getElementById('learn-more-container'); | 381 var overlayContainer = doc.getElementById('overlay-container'); |
| 380 var learnMoreContent = doc.getElementById('learn-more-content'); | 382 overlayContainer.className = 'overlay ' + overlayClass; |
| 381 learnMoreContent.innerHTML = content; | 383 overlayContainer.hidden = false; |
| 382 learnMoreContainer.hidden = false; | |
| 383 } | 384 } |
| 384 | 385 |
| 385 /** | 386 /** |
| 386 * Hides learn more overlay dialog. | 387 * Opens overlay dialog and shows formatted text content there. |
| 388 * @param {string} content HTML formatted text to show. |
| 387 */ | 389 */ |
| 388 function hideLearnModeOverlay() { | 390 function showTextOverlay(content) { |
| 389 var doc = appWindow.contentWindow.document; | 391 var doc = appWindow.contentWindow.document; |
| 390 var learnMoreContainer = doc.getElementById('learn-more-container'); | 392 var textContent = doc.getElementById('overlay-text-content'); |
| 391 learnMoreContainer.hidden = true; | 393 textContent.innerHTML = content; |
| 394 showOverlay('overlay-text'); |
| 392 } | 395 } |
| 393 | 396 |
| 394 /** | 397 /** |
| 398 * Opens overlay dialog and shows external URL there. |
| 399 * @param {string} url Target URL to open in overlay dialog. |
| 400 */ |
| 401 function showURLOverlay(url) { |
| 402 var doc = appWindow.contentWindow.document; |
| 403 var overlayWebview = doc.getElementById('overlay-url'); |
| 404 overlayWebview.src = url; |
| 405 showOverlay('overlay-url'); |
| 406 } |
| 407 |
| 408 /** |
| 409 * Hides overlay dialog. |
| 410 */ |
| 411 function hideOverlay() { |
| 412 var doc = appWindow.contentWindow.document; |
| 413 var overlayContainer = doc.getElementById('overlay-container'); |
| 414 overlayContainer.hidden = true; |
| 415 } |
| 416 |
| 417 |
| 418 /** |
| 395 * Shows requested page. | 419 * Shows requested page. |
| 396 * @param {int} pageId Index of the page to show. Must be in the array range of | 420 * @param {int} pageId Index of the page to show. Must be in the array range of |
| 397 * UI_PAGES. | 421 * UI_PAGES. |
| 398 * @param {string} status associated with page string status, error message for | 422 * @param {string} status associated with page string status, error message for |
| 399 * example. | 423 * example. |
| 400 */ | 424 */ |
| 401 function showPageWithStatus(pageId, status) { | 425 function showPageWithStatus(pageId, status) { |
| 402 if (!appWindow) { | 426 if (!appWindow) { |
| 403 return; | 427 return; |
| 404 } | 428 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 }; | 579 }; |
| 556 | 580 |
| 557 termsView.request.onBeforeRequest.addListener(onTermsViewBeforeRequest, | 581 termsView.request.onBeforeRequest.addListener(onTermsViewBeforeRequest, |
| 558 requestFilter); | 582 requestFilter); |
| 559 termsView.request.onErrorOccurred.addListener(onTermsViewErrorOccurred, | 583 termsView.request.onErrorOccurred.addListener(onTermsViewErrorOccurred, |
| 560 requestFilter); | 584 requestFilter); |
| 561 termsView.addEventListener('contentload', onTermsViewContentLoad); | 585 termsView.addEventListener('contentload', onTermsViewContentLoad); |
| 562 | 586 |
| 563 | 587 |
| 564 // webview is not allowed to open links in the new window. Hook these events | 588 // webview is not allowed to open links in the new window. Hook these events |
| 565 // and open links in context of main page. | 589 // and open links in overlay dialog. |
| 566 termsView.addEventListener('newwindow', function(event) { | 590 termsView.addEventListener('newwindow', function(event) { |
| 567 event.preventDefault(); | 591 event.preventDefault(); |
| 568 chrome.browser.openTab({'url': event.targetUrl}, function() {}); | 592 showURLOverlay(event.targetUrl); |
| 569 }); | 593 }); |
| 570 | 594 |
| 571 var onAgree = function() { | 595 var onAgree = function() { |
| 572 termsAccepted = true; | 596 termsAccepted = true; |
| 573 | 597 |
| 574 var enableMetrics = doc.getElementById('enable-metrics'); | 598 var enableMetrics = doc.getElementById('enable-metrics'); |
| 575 var enableBackupRestore = doc.getElementById('enable-backup-restore'); | 599 var enableBackupRestore = doc.getElementById('enable-backup-restore'); |
| 576 var enableLocationService = doc.getElementById('enable-location-service'); | 600 var enableLocationService = doc.getElementById('enable-location-service'); |
| 577 sendNativeMessage('onAgreed', { | 601 sendNativeMessage('onAgreed', { |
| 578 isMetricsEnabled: enableMetrics.checked, | 602 isMetricsEnabled: enableMetrics.checked, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 599 | 623 |
| 600 var onSendFeedback = function() { | 624 var onSendFeedback = function() { |
| 601 sendNativeMessage('onSendFeedbackClicked'); | 625 sendNativeMessage('onSendFeedbackClicked'); |
| 602 }; | 626 }; |
| 603 | 627 |
| 604 doc.getElementById('button-agree').addEventListener('click', onAgree); | 628 doc.getElementById('button-agree').addEventListener('click', onAgree); |
| 605 doc.getElementById('button-cancel').addEventListener('click', onCancel); | 629 doc.getElementById('button-cancel').addEventListener('click', onCancel); |
| 606 doc.getElementById('button-retry').addEventListener('click', onRetry); | 630 doc.getElementById('button-retry').addEventListener('click', onRetry); |
| 607 doc.getElementById('button-send-feedback') | 631 doc.getElementById('button-send-feedback') |
| 608 .addEventListener('click', onSendFeedback); | 632 .addEventListener('click', onSendFeedback); |
| 609 doc.getElementById('learn-more-close').addEventListener('click', | 633 doc.getElementById('overlay-close').addEventListener('click', |
| 610 hideLearnModeOverlay); | 634 hideOverlay); |
| 611 | 635 |
| 612 var overlay = doc.getElementById('learn-more-container'); | 636 var overlay = doc.getElementById('overlay-container'); |
| 613 appWindow.contentWindow.cr.ui.overlay.setupOverlay(overlay); | 637 appWindow.contentWindow.cr.ui.overlay.setupOverlay(overlay); |
| 614 appWindow.contentWindow.cr.ui.overlay.globalInitialization(); | 638 appWindow.contentWindow.cr.ui.overlay.globalInitialization(); |
| 615 overlay.addEventListener('cancelOverlay', hideLearnModeOverlay); | 639 overlay.addEventListener('cancelOverlay', hideOverlay); |
| 616 | 640 |
| 617 connectPort(); | 641 connectPort(); |
| 618 }; | 642 }; |
| 619 | 643 |
| 620 var onWindowCreated = function(createdWindow) { | 644 var onWindowCreated = function(createdWindow) { |
| 621 appWindow = createdWindow; | 645 appWindow = createdWindow; |
| 622 appWindow.contentWindow.onload = onAppContentLoad; | 646 appWindow.contentWindow.onload = onAppContentLoad; |
| 623 appWindow.onClosed.addListener(onWindowClosed); | 647 appWindow.onClosed.addListener(onWindowClosed); |
| 624 | 648 |
| 625 setWindowBounds(); | 649 setWindowBounds(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 646 type: 'chrome', | 670 type: 'chrome', |
| 647 color: '#ffffff' | 671 color: '#ffffff' |
| 648 }, | 672 }, |
| 649 'innerBounds': { | 673 'innerBounds': { |
| 650 'width': INNER_WIDTH, | 674 'width': INNER_WIDTH, |
| 651 'height': INNER_HEIGHT | 675 'height': INNER_HEIGHT |
| 652 } | 676 } |
| 653 }; | 677 }; |
| 654 chrome.app.window.create('main.html', options, onWindowCreated); | 678 chrome.app.window.create('main.html', options, onWindowCreated); |
| 655 }); | 679 }); |
| OLD | NEW |