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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 * @param {string} deviceId Current device id. | 104 * @param {string} deviceId Current device id. |
| 105 */ | 105 */ |
| 106 function initialize(data, deviceId) { | 106 function initialize(data, deviceId) { |
| 107 currentDeviceId = deviceId; | 107 currentDeviceId = deviceId; |
| 108 var doc = appWindow.contentWindow.document; | 108 var doc = appWindow.contentWindow.document; |
| 109 var loadTimeData = appWindow.contentWindow.loadTimeData; | 109 var loadTimeData = appWindow.contentWindow.loadTimeData; |
| 110 loadTimeData.data = data; | 110 loadTimeData.data = data; |
| 111 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData); | 111 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData); |
| 112 var countryCode = data.countryCode.toLowerCase(); | 112 var countryCode = data.countryCode.toLowerCase(); |
| 113 setBackupRestoreMode(data.textBackupRestore, data.backupRestoreEnabled); | 113 setBackupRestoreMode(data.textBackupRestore, data.backupRestoreEnabled); |
| 114 setLocationServiceMode(data.textLocationService, data.locationServiceEnabled); | |
| 114 | 115 |
| 115 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';'; | 116 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';'; |
| 116 termsView.addContentScripts([ | 117 termsView.addContentScripts([ |
| 117 { name: 'preProcess', | 118 { name: 'preProcess', |
| 118 matches: ['https://play.google.com/*'], | 119 matches: ['https://play.google.com/*'], |
| 119 js: { code: scriptSetCountryCode }, | 120 js: { code: scriptSetCountryCode }, |
| 120 run_at: 'document_start' | 121 run_at: 'document_start' |
| 121 }, | 122 }, |
| 122 { name: 'postProcess', | 123 { name: 'postProcess', |
| 123 matches: ['https://play.google.com/*'], | 124 matches: ['https://play.google.com/*'], |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 141 /** | 142 /** |
| 142 * Sets current metrics mode. | 143 * Sets current metrics mode. |
| 143 * @param {string} text Describes current metrics state. | 144 * @param {string} text Describes current metrics state. |
| 144 * @param {boolean} canEnable Defines if user is allowed to change this metrics | 145 * @param {boolean} canEnable Defines if user is allowed to change this metrics |
| 145 * option. | 146 * option. |
| 146 * @param {boolean} on Defines if metrics are active currently. | 147 * @param {boolean} on Defines if metrics are active currently. |
| 147 */ | 148 */ |
| 148 function setMetricsMode(text, canEnable, on) { | 149 function setMetricsMode(text, canEnable, on) { |
| 149 var doc = appWindow.contentWindow.document; | 150 var doc = appWindow.contentWindow.document; |
| 150 var enableMetrics = doc.getElementById('enable-metrics'); | 151 var enableMetrics = doc.getElementById('enable-metrics'); |
| 151 enableMetrics.hidden = !canEnable; | 152 var enableMetricsContainer = doc.getElementById('enable-metrics-container'); |
|
khmel
2016/07/25 22:48:48
One we use wrapping we need to hide div, to avoid
| |
| 153 enableMetricsContainer.hidden = !canEnable; | |
| 152 enableMetrics.checked = on; | 154 enableMetrics.checked = on; |
| 153 | 155 |
| 154 var onSettings = function(event) { | 156 var onSettings = function(event) { |
| 155 chrome.browser.openTab({'url': 'chrome://settings'}, function() {}); | 157 chrome.browser.openTab({'url': 'chrome://settings'}, function() {}); |
| 156 event.preventDefault(); | 158 event.preventDefault(); |
| 157 }; | 159 }; |
| 158 | 160 |
| 159 doc.getElementById('text-metrics').innerHTML = text; | 161 doc.getElementById('text-metrics').innerHTML = text; |
| 160 doc.getElementById('settings-link').addEventListener('click', onSettings); | 162 doc.getElementById('settings-link').addEventListener('click', onSettings); |
| 161 doc.getElementById('learn-more-link-metrics').addEventListener('click', | 163 doc.getElementById('learn-more-link-metrics').addEventListener('click', |
| 162 onLearnMore); | 164 onLearnMore); |
| 163 | 165 |
| 164 // Applying metrics mode changes page layout, update terms height. | 166 // Applying metrics mode changes page layout, update terms height. |
| 165 updateTermsHeight(); | 167 updateTermsHeight(); |
| 166 } | 168 } |
| 167 | 169 |
| 168 /** | 170 /** |
| 169 * Sets current metrics mode. | 171 * Sets current backup and restore mode. |
| 170 * @param {string} text String used to display next to checkbox. | 172 * @param {string} text String used to display next to checkbox. |
| 171 * @param {boolean} defaultCheckValue Defines the default value for backup and | 173 * @param {boolean} defaultCheckValue Defines the default value for backup and |
| 172 * restore checkbox. | 174 * restore checkbox. |
| 173 */ | 175 */ |
| 174 function setBackupRestoreMode(text, defaultCheckValue) { | 176 function setBackupRestoreMode(text, defaultCheckValue) { |
| 175 var doc = appWindow.contentWindow.document; | 177 var doc = appWindow.contentWindow.document; |
| 176 doc.getElementById('enable-backup-restore').checked = defaultCheckValue; | 178 doc.getElementById('enable-backup-restore').checked = defaultCheckValue; |
| 177 | 179 |
| 178 doc.getElementById('text-backup-restore').innerHTML = text; | 180 doc.getElementById('text-backup-restore').innerHTML = text; |
| 179 doc.getElementById('learn-more-link-backup-restore').addEventListener('click', | 181 doc.getElementById('learn-more-link-backup-restore').addEventListener('click', |
| 180 onLearnMore); | 182 onLearnMore); |
| 181 } | 183 } |
| 182 | 184 |
| 183 /** | 185 /** |
| 186 * Sets current usage of location service opt in mode. | |
| 187 * @param {string} text String used to display next to checkbox. | |
| 188 * @param {boolean} defaultCheckValue Defines the default value for location | |
| 189 * service opt in. | |
| 190 */ | |
| 191 function setLocationServiceMode(text, defaultCheckValue) { | |
| 192 var doc = appWindow.contentWindow.document; | |
| 193 doc.getElementById('enable-location-service').checked = defaultCheckValue; | |
| 194 | |
| 195 doc.getElementById('text-location-service').innerHTML = text; | |
| 196 doc.getElementById('learn-more-link-location-service'). | |
| 197 addEventListener('click', onLearnMore); | |
| 198 } | |
| 199 | |
| 200 /** | |
| 184 * Updates terms view height manually because webview is not automatically | 201 * Updates terms view height manually because webview is not automatically |
| 185 * resized in case parent div element gets resized. | 202 * resized in case parent div element gets resized. |
| 186 */ | 203 */ |
| 187 function updateTermsHeight() { | 204 function updateTermsHeight() { |
| 188 var setTermsHeight = function() { | 205 var setTermsHeight = function() { |
| 189 var doc = appWindow.contentWindow.document; | 206 var doc = appWindow.contentWindow.document; |
| 190 var termsContainer = doc.getElementById('terms-container'); | 207 var termsContainer = doc.getElementById('terms-container'); |
| 191 // Reset terms-view height in order to stabilize style computation. For | 208 // Reset terms-view height in order to stabilize style computation. For |
| 192 // some reason, child webview affects final result. | 209 // some reason, child webview affects final result. |
| 193 termsView.style.height = '0px'; | 210 termsView.style.height = '0px'; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 // and open links in context of main page. | 475 // and open links in context of main page. |
| 459 termsView.addEventListener('newwindow', function(event) { | 476 termsView.addEventListener('newwindow', function(event) { |
| 460 event.preventDefault(); | 477 event.preventDefault(); |
| 461 chrome.browser.openTab({'url': event.targetUrl}, function() {}); | 478 chrome.browser.openTab({'url': event.targetUrl}, function() {}); |
| 462 }); | 479 }); |
| 463 | 480 |
| 464 var onAgree = function() { | 481 var onAgree = function() { |
| 465 termsAccepted = true; | 482 termsAccepted = true; |
| 466 | 483 |
| 467 var enableMetrics = doc.getElementById('enable-metrics'); | 484 var enableMetrics = doc.getElementById('enable-metrics'); |
| 468 if (!enableMetrics.hidden) { | 485 var enableMetricsContainer = |
| 486 doc.getElementById('enable-metrics-container'); | |
| 487 if (!enableMetricsContainer.hidden) { | |
| 469 sendNativeMessage('enableMetrics', { | 488 sendNativeMessage('enableMetrics', { |
| 470 'enabled': enableMetrics.checked | 489 'enabled': enableMetrics.checked |
| 471 }); | 490 }); |
| 472 } | 491 } |
| 473 | 492 |
| 474 var enableBackupRestore = doc.getElementById('enable-backup-restore'); | 493 var enableBackupRestore = doc.getElementById('enable-backup-restore'); |
| 475 sendNativeMessage('setBackupRestore', { | 494 sendNativeMessage('setBackupRestore', { |
| 476 'enabled': enableBackupRestore.checked | 495 'enabled': enableBackupRestore.checked |
| 477 }); | 496 }); |
| 478 | 497 |
| 498 var enableLocationService = doc.getElementById('enable-location-service'); | |
| 499 sendNativeMessage('setLocationService', { | |
| 500 'enabled': enableLocationService.checked | |
| 501 }); | |
| 502 | |
| 479 sendNativeMessage('startLso'); | 503 sendNativeMessage('startLso'); |
| 480 }; | 504 }; |
| 481 | 505 |
| 482 var onCancel = function() { | 506 var onCancel = function() { |
| 483 if (appWindow) { | 507 if (appWindow) { |
| 484 windowClosedInternally = false; | 508 windowClosedInternally = false; |
| 485 appWindow.close(); | 509 appWindow.close(); |
| 486 appWindow = null; | 510 appWindow = null; |
| 487 } | 511 } |
| 488 }; | 512 }; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 type: 'chrome', | 562 type: 'chrome', |
| 539 color: '#ffffff' | 563 color: '#ffffff' |
| 540 }, | 564 }, |
| 541 'innerBounds': { | 565 'innerBounds': { |
| 542 'width': INNER_WIDTH, | 566 'width': INNER_WIDTH, |
| 543 'height': INNER_HEIGHT | 567 'height': INNER_HEIGHT |
| 544 } | 568 } |
| 545 }; | 569 }; |
| 546 chrome.app.window.create('main.html', options, onWindowCreated); | 570 chrome.app.window.create('main.html', options, onWindowCreated); |
| 547 }); | 571 }); |
| OLD | NEW |