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

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

Issue 2104893003: Adds a new checkbox for backup and restore in opt-in flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds a new checkbox for backup and restore in opt-in flow. Created 4 years, 5 months 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 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 * @param {!Object} data Localized strings and relevant information. 83 * @param {!Object} data Localized strings and relevant information.
84 * @param {string} deviceId Current device id. 84 * @param {string} deviceId Current device id.
85 */ 85 */
86 function initialize(data, deviceId) { 86 function initialize(data, deviceId) {
87 currentDeviceId = deviceId; 87 currentDeviceId = deviceId;
88 var doc = appWindow.contentWindow.document; 88 var doc = appWindow.contentWindow.document;
89 var loadTimeData = appWindow.contentWindow.loadTimeData; 89 var loadTimeData = appWindow.contentWindow.loadTimeData;
90 loadTimeData.data = data; 90 loadTimeData.data = data;
91 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData); 91 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData);
92 var countryCode = data.countryCode.toLowerCase(); 92 var countryCode = data.countryCode.toLowerCase();
93 setBackupRestoreMode(data.textBackupRestore, data.backupRestoreEnabled);
93 94
94 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';'; 95 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';';
95 termsView.addContentScripts([ 96 termsView.addContentScripts([
96 { name: 'preProcess', 97 { name: 'preProcess',
97 matches: ['https://play.google.com/*'], 98 matches: ['https://play.google.com/*'],
98 js: { code: scriptSetCountryCode }, 99 js: { code: scriptSetCountryCode },
99 run_at: 'document_start' 100 run_at: 'document_start'
100 }, 101 },
101 { name: 'postProcess', 102 { name: 'postProcess',
102 matches: ['https://play.google.com/*'], 103 matches: ['https://play.google.com/*'],
103 css: { files: ['playstore.css'] }, 104 css: { files: ['playstore.css'] },
104 js: { files: ['playstore.js'] }, 105 js: { files: ['playstore.js'] },
105 run_at: 'document_end' 106 run_at: 'document_end'
106 }]); 107 }]);
107 108
108 // Applying localization changes page layout, update terms height. 109 // Applying localization changes page layout, update terms height.
109 updateTermsHeight(); 110 updateTermsHeight();
110 } 111 }
111 112
112 /** 113 /**
114 * Handles the event when the user clicks on a learn more link. Opens the
115 * support page for the user.
116 * @param {Event} event
117 */
118 var onLearnMore = function(event) {
119 var url = 'https://support.google.com/chromebook?p=playapps';
120 chrome.browser.openTab({'url': url}, function() {});
121 event.preventDefault();
122 };
123
124 /**
113 * Sets current metrics mode. 125 * Sets current metrics mode.
114 * @param {string} text Describes current metrics state. 126 * @param {string} text Describes current metrics state.
115 * @param {boolean} canEnable Defines if user is allowed to change this metrics 127 * @param {boolean} canEnable Defines if user is allowed to change this metrics
116 * option. 128 * option.
117 * @param {boolean} on Defines if metrics are active currently. 129 * @param {boolean} on Defines if metrics are active currently.
118 */ 130 */
119 function setMetricsMode(text, canEnable, on) { 131 function setMetricsMode(text, canEnable, on) {
120 var doc = appWindow.contentWindow.document; 132 var doc = appWindow.contentWindow.document;
121 var enableMetrics = doc.getElementById('enable-metrics'); 133 var enableMetrics = doc.getElementById('enable-metrics');
122 enableMetrics.hidden = !canEnable; 134 enableMetrics.hidden = !canEnable;
123 enableMetrics.checked = on; 135 enableMetrics.checked = on;
124 136
125 var onSettings = function(event) { 137 var onSettings = function(event) {
126 chrome.browser.openTab({'url': 'chrome://settings'}, function() {}); 138 chrome.browser.openTab({'url': 'chrome://settings'}, function() {});
127 event.preventDefault(); 139 event.preventDefault();
128 }; 140 };
129 141
130 var onLearnMore = function(event) {
131 var url = 'https://support.google.com/chromebook?p=playapps';
132 chrome.browser.openTab({'url': url}, function() {});
133 event.preventDefault();
134 };
135
136 doc.getElementById('text-metrics').innerHTML = text; 142 doc.getElementById('text-metrics').innerHTML = text;
137 doc.getElementById('settings-link').addEventListener('click', onSettings); 143 doc.getElementById('settings-link').addEventListener('click', onSettings);
138 doc.getElementById('learn-more-link').addEventListener('click', onLearnMore); 144 doc.getElementById('learn-more-link-metrics').addEventListener('click',
145 onLearnMore);
139 146
140 // Applying metrics mode changes page layout, update terms height. 147 // Applying metrics mode changes page layout, update terms height.
141 updateTermsHeight(); 148 updateTermsHeight();
142 } 149 }
143 150
144 /** 151 /**
152 * Sets current metrics mode.
153 * @param {string} text String used to display next to checkbox.
154 * @param {boolean} isChecked Defines if backup and restore option is active.
155 */
156 function setBackupRestoreMode(text, isChecked) {
elijahtaylor1 2016/06/30 04:52:34 nit: isChecked seems to indicate the current state
malaykeshav 2016/06/30 18:25:46 Renaming to defaultCheckValue
157 var doc = appWindow.contentWindow.document;
158 var enableBackupRestoreEl = doc.getElementById('enable-backup-restore');
159 enableBackupRestoreEl.checked = isChecked;
elijahtaylor1 2016/06/30 04:52:34 this could be a one-liner: doc.getElementById('en
malaykeshav 2016/06/30 18:25:46 Done
160
161 doc.getElementById('text-backup-restore').innerHTML = text;
162 doc.getElementById('learn-more-link-backup-restore').addEventListener('click',
163 onLearnMore);
164 }
165
166 /**
145 * Updates terms view height manually because webview is not automatically 167 * Updates terms view height manually because webview is not automatically
146 * resized in case parent div element gets resized. 168 * resized in case parent div element gets resized.
147 */ 169 */
148 function updateTermsHeight() { 170 function updateTermsHeight() {
149 var setTermsHeight = function() { 171 var setTermsHeight = function() {
150 var doc = appWindow.contentWindow.document; 172 var doc = appWindow.contentWindow.document;
151 var termsContainer = doc.getElementById('terms-container'); 173 var termsContainer = doc.getElementById('terms-container');
152 var style = window.getComputedStyle(termsContainer, null); 174 var style = window.getComputedStyle(termsContainer, null);
153 var height = style.getPropertyValue('height'); 175 var height = style.getPropertyValue('height');
154 termsView.style.height = height; 176 termsView.style.height = height;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 371
350 // webview is not allowed to open links in the new window. Hook these events 372 // webview is not allowed to open links in the new window. Hook these events
351 // and open links in context of main page. 373 // and open links in context of main page.
352 termsView.addEventListener('newwindow', function(event) { 374 termsView.addEventListener('newwindow', function(event) {
353 event.preventDefault(); 375 event.preventDefault();
354 chrome.browser.openTab({'url': event.targetUrl}, function() {}); 376 chrome.browser.openTab({'url': event.targetUrl}, function() {});
355 }); 377 });
356 378
357 var onAgree = function() { 379 var onAgree = function() {
358 var enableMetrics = doc.getElementById('enable-metrics'); 380 var enableMetrics = doc.getElementById('enable-metrics');
359 if (!enableMetrics.hidden && enableMetrics.checked) { 381 if (!enableMetrics.hidden) {
360 sendNativeMessage('enableMetrics'); 382 sendNativeMessage('enableMetrics', {
383 'enabled': enableMetrics.checked
384 });
361 } 385 }
386
387 var enableBackupRestore = doc.getElementById('enable-backup-restore');
388 sendNativeMessage('setBackupRestore', {
389 'enabled': enableBackupRestore.checked
390 });
391
362 sendNativeMessage('startLso'); 392 sendNativeMessage('startLso');
363 }; 393 };
364 394
365 var onCancel = function() { 395 var onCancel = function() {
366 if (appWindow) { 396 if (appWindow) {
367 windowClosedInternally = false; 397 windowClosedInternally = false;
368 appWindow.close(); 398 appWindow.close();
369 appWindow = null; 399 appWindow = null;
370 } 400 }
371 }; 401 };
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 type: 'chrome', 444 type: 'chrome',
415 color: '#ffffff' 445 color: '#ffffff'
416 }, 446 },
417 'innerBounds': { 447 'innerBounds': {
418 'width': 960, 448 'width': 960,
419 'height': 688 449 'height': 688
420 } 450 }
421 }; 451 };
422 chrome.app.window.create('main.html', options, onWindowCreated); 452 chrome.app.window.create('main.html', options, onWindowCreated);
423 }); 453 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698