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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 * @param {boolean} silentMode Indicates if OptIn started in silent mode. | 99 * @param {boolean} silentMode Indicates if OptIn started in silent mode. |
| 100 */ | 100 */ |
| 101 function initialize(data, deviceId, silentMode) { | 101 function initialize(data, deviceId, silentMode) { |
| 102 currentDeviceId = deviceId; | 102 currentDeviceId = deviceId; |
| 103 window.silentMode = silentMode; | 103 window.silentMode = silentMode; |
| 104 var doc = appWindow.contentWindow.document; | 104 var doc = appWindow.contentWindow.document; |
| 105 var loadTimeData = appWindow.contentWindow.loadTimeData; | 105 var loadTimeData = appWindow.contentWindow.loadTimeData; |
| 106 loadTimeData.data = data; | 106 loadTimeData.data = data; |
| 107 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData); | 107 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData); |
| 108 var countryCode = data.countryCode.toLowerCase(); | 108 var countryCode = data.countryCode.toLowerCase(); |
| 109 setBackupRestoreMode(data.textBackupRestore); | |
| 109 | 110 |
| 110 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';'; | 111 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';'; |
| 111 termsView.addContentScripts([ | 112 termsView.addContentScripts([ |
| 112 { name: 'preProcess', | 113 { name: 'preProcess', |
| 113 matches: ['https://play.google.com/*'], | 114 matches: ['https://play.google.com/*'], |
| 114 js: { code: scriptSetCountryCode }, | 115 js: { code: scriptSetCountryCode }, |
| 115 run_at: 'document_start' | 116 run_at: 'document_start' |
| 116 }, | 117 }, |
| 117 { name: 'postProcess', | 118 { name: 'postProcess', |
| 118 matches: ['https://play.google.com/*'], | 119 matches: ['https://play.google.com/*'], |
| 119 css: { files: ['playstore.css'] }, | 120 css: { files: ['playstore.css'] }, |
| 120 js: { files: ['playstore.js'] }, | 121 js: { files: ['playstore.js'] }, |
| 121 run_at: 'document_end' | 122 run_at: 'document_end' |
| 122 }]); | 123 }]); |
| 123 | 124 |
| 124 // Applying localization changes page layout, update terms height. | 125 // Applying localization changes page layout, update terms height. |
| 125 updateTermsHeight(); | 126 updateTermsHeight(); |
| 126 } | 127 } |
| 127 | 128 |
| 128 /** | 129 /** |
| 130 * Handles the event when the user clicks on a learn more link. Opens the | |
| 131 * support page for the user. | |
| 132 * @param {Event} event | |
| 133 */ | |
| 134 var onLearnMore = function(event) { | |
| 135 var url = 'https://support.google.com/chromebook?p=playapps'; | |
| 136 chrome.browser.openTab({'url': url}, function() {}); | |
| 137 event.preventDefault(); | |
| 138 }; | |
| 139 | |
| 140 /** | |
| 129 * Sets current metrics mode. | 141 * Sets current metrics mode. |
| 130 * @param {string} text Describes current metrics state. | 142 * @param {string} text Describes current metrics state. |
| 131 * @param {boolean} canEnable Defines if user is allowed to change this metrics | 143 * @param {boolean} canEnable Defines if user is allowed to change this metrics |
| 132 * option. | 144 * option. |
| 133 * @param {boolean} on Defines if metrics are active currently. | 145 * @param {boolean} on Defines if metrics are active currently. |
| 134 */ | 146 */ |
| 135 function setMetricsMode(text, canEnable, on) { | 147 function setMetricsMode(text, canEnable, on) { |
| 136 var doc = appWindow.contentWindow.document; | 148 var doc = appWindow.contentWindow.document; |
| 137 var enableMetrics = doc.getElementById('enable-metrics'); | 149 var enableMetrics = doc.getElementById('enable-metrics'); |
| 138 enableMetrics.hidden = !canEnable; | 150 enableMetrics.hidden = !canEnable; |
| 139 enableMetrics.checked = on; | 151 enableMetrics.checked = on; |
| 140 | 152 |
| 141 var onSettings = function(event) { | 153 var onSettings = function(event) { |
| 142 chrome.browser.openTab({'url': 'chrome://settings'}, function() {}); | 154 chrome.browser.openTab({'url': 'chrome://settings'}, function() {}); |
| 143 event.preventDefault(); | 155 event.preventDefault(); |
| 144 }; | 156 }; |
| 145 | 157 |
| 146 var onLearnMore = function(event) { | |
| 147 var url = 'https://support.google.com/chromebook?p=playapps'; | |
| 148 chrome.browser.openTab({'url': url}, function() {}); | |
| 149 event.preventDefault(); | |
| 150 }; | |
| 151 | |
| 152 doc.getElementById('text-metrics').innerHTML = text; | 158 doc.getElementById('text-metrics').innerHTML = text; |
| 153 doc.getElementById('settings-link').addEventListener('click', onSettings); | 159 doc.getElementById('settings-link').addEventListener('click', onSettings); |
| 154 doc.getElementById('learn-more-link').addEventListener('click', onLearnMore); | 160 doc.getElementById('learn-more-link-metrics').addEventListener('click', |
| 161 onLearnMore); | |
| 155 | 162 |
| 156 // Applying metrics mode changes page layout, update terms height. | 163 // Applying metrics mode changes page layout, update terms height. |
| 157 updateTermsHeight(); | 164 updateTermsHeight(); |
| 158 } | 165 } |
| 159 | 166 |
| 160 /** | 167 /** |
| 168 * Sets current metrics mode. | |
| 169 * @param {string} text String used to display next to checkbox. | |
| 170 */ | |
| 171 function setBackupRestoreMode(text) { | |
| 172 var doc = appWindow.contentWindow.document; | |
| 173 var enableBackupRestoreEl = doc.getElementById('enable-backup-restore'); | |
| 174 enableBackupRestoreEl.checked = true; | |
|
xiyuan
2016/06/29 21:36:38
We should take the on/off value passed in from Arc
malaykeshav
2016/06/30 02:46:19
The default value if always checked.
| |
| 175 | |
| 176 doc.getElementById('text-backup-restore').innerHTML = text; | |
| 177 doc.getElementById('learn-more-link-backup-restore').addEventListener('click', | |
| 178 onLearnMore); | |
| 179 } | |
| 180 | |
| 181 /** | |
| 161 * Updates terms view height manually because webview is not automatically | 182 * Updates terms view height manually because webview is not automatically |
| 162 * resized in case parent div element gets resized. | 183 * resized in case parent div element gets resized. |
| 163 */ | 184 */ |
| 164 function updateTermsHeight() { | 185 function updateTermsHeight() { |
| 165 var setTermsHeight = function() { | 186 var setTermsHeight = function() { |
| 166 var doc = appWindow.contentWindow.document; | 187 var doc = appWindow.contentWindow.document; |
| 167 var termsContainer = doc.getElementById('terms-container'); | 188 var termsContainer = doc.getElementById('terms-container'); |
| 168 var style = window.getComputedStyle(termsContainer, null); | 189 var style = window.getComputedStyle(termsContainer, null); |
| 169 var height = style.getPropertyValue('height'); | 190 var height = style.getPropertyValue('height'); |
| 170 termsView.style.height = height; | 191 termsView.style.height = height; |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 termsView.addEventListener('newwindow', function(event) { | 429 termsView.addEventListener('newwindow', function(event) { |
| 409 event.preventDefault(); | 430 event.preventDefault(); |
| 410 chrome.browser.openTab({'url': event.targetUrl}, function() {}); | 431 chrome.browser.openTab({'url': event.targetUrl}, function() {}); |
| 411 }); | 432 }); |
| 412 | 433 |
| 413 var onAgree = function() { | 434 var onAgree = function() { |
| 414 var enableMetrics = doc.getElementById('enable-metrics'); | 435 var enableMetrics = doc.getElementById('enable-metrics'); |
| 415 if (!enableMetrics.hidden && enableMetrics.checked) { | 436 if (!enableMetrics.hidden && enableMetrics.checked) { |
| 416 sendNativeMessage('enableMetrics'); | 437 sendNativeMessage('enableMetrics'); |
| 417 } | 438 } |
| 439 | |
| 440 var enableBackupRestore = doc.getElementById('enable-backup-restore'); | |
| 441 if (enableBackupRestore.checked) { | |
| 442 sendNativeMessage('enableBackupRestore'); | |
| 443 } | |
| 444 | |
| 418 sendNativeMessage('startLso'); | 445 sendNativeMessage('startLso'); |
| 419 }; | 446 }; |
| 420 | 447 |
| 421 var onCancel = function() { | 448 var onCancel = function() { |
| 422 if (appWindow) { | 449 if (appWindow) { |
| 423 windowClosedInternally = false; | 450 windowClosedInternally = false; |
| 424 appWindow.close(); | 451 appWindow.close(); |
| 425 appWindow = null; | 452 appWindow = null; |
| 426 } | 453 } |
| 427 }; | 454 }; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 type: 'chrome', | 498 type: 'chrome', |
| 472 color: '#ffffff' | 499 color: '#ffffff' |
| 473 }, | 500 }, |
| 474 'innerBounds': { | 501 'innerBounds': { |
| 475 'width': 960, | 502 'width': 960, |
| 476 'height': 688 | 503 'height': 688 |
| 477 } | 504 } |
| 478 }; | 505 }; |
| 479 chrome.app.window.create('main.html', options, onWindowCreated); | 506 chrome.app.window.create('main.html', options, onWindowCreated); |
| 480 }); | 507 }); |
| OLD | NEW |