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

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

Issue 2408063007: Re-sort preference update protocol between Chrome and ArcSupport. (Closed)
Patch Set: Rebase Created 4 years, 2 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 17 matching lines...) Expand all
28 */ 28 */
29 var lsoView = null; 29 var lsoView = null;
30 30
31 /** 31 /**
32 * Contains Play Store terms, loaded externally. 32 * Contains Play Store terms, loaded externally.
33 * @type {WebView} 33 * @type {WebView}
34 */ 34 */
35 var termsView = null; 35 var termsView = null;
36 36
37 /** 37 /**
38 * @type {MetricsPreferenceCheckbox}
39 */
40 var metricsCheckbox = null;
41
42 /**
43 * @type {PreferenceCheckbox}
44 */
45 var backupRestoreCheckbox = null;
46
47 /**
48 * @type {PreferenceCheckbox}
49 */
50 var locationServiceCheckbox = null;
51
52 /**
38 * Used for bidirectional communication with native code. 53 * Used for bidirectional communication with native code.
39 * @type {chrome.runtime.Port} 54 * @type {chrome.runtime.Port}
40 */ 55 */
41 var port = null; 56 var port = null;
42 57
43 /** 58 /**
44 * Stores current device id. 59 * Stores current device id.
45 * @type {string} 60 * @type {string}
46 */ 61 */
47 var currentDeviceId = null; 62 var currentDeviceId = null;
48 63
49 /** 64 /**
50 * Indicates that terms were accepted by user. 65 * Indicates that terms were accepted by user.
51 * @type {boolean} 66 * @type {boolean}
52 */ 67 */
53 var termsAccepted = false; 68 var termsAccepted = false;
54 69
55 /** 70 /**
56 * Indicates that current user has managed Arc. 71 * Indicates that current user has managed Arc.
57 * @type {boolean} 72 * @type {boolean}
58 */ 73 */
59 var arcManaged = false; 74 var arcManaged = false;
60 75
61 /** 76 /**
62 * Tooltip text used in 'controlled by policy' indicator.
63 * @type {boolean}
64 */
65 var controlledByPolicyText = '';
66
67 /**
68 * Host window inner default width. 77 * Host window inner default width.
69 * @const {number} 78 * @const {number}
70 */ 79 */
71 var INNER_WIDTH = 960; 80 var INNER_WIDTH = 960;
72 81
73 /** 82 /**
74 * Host window inner default height. 83 * Host window inner default height.
75 * @const {number} 84 * @const {number}
76 */ 85 */
77 var INNER_HEIGHT = 688; 86 var INNER_HEIGHT = 688;
78 87
79 88
80 /** 89 /**
81 * Sends a native message to ArcSupportHost. 90 * Sends a native message to ArcSupportHost.
82 * @param {string} event The event type in message. 91 * @param {string} event The event type in message.
83 * @param {Object=} opt_props Extra properties for the message. 92 * @param {Object=} opt_props Extra properties for the message.
84 */ 93 */
85 function sendNativeMessage(event, opt_props) { 94 function sendNativeMessage(event, opt_props) {
86 var message = Object.assign({'event': event}, opt_props); 95 var message = Object.assign({'event': event}, opt_props);
87 port.postMessage(message); 96 port.postMessage(message);
88 } 97 }
89 98
90 /** 99 /**
91 * Helper function that sets inner content for an option which includes text, 100 * Class to handle checkbox corresponding to a preference.
92 * link to 'learn more' section. This also creates an indicator showing that
93 * option is controlled by policy and inserts it before link element.
94 * @param {string} textId Id of the label element to process.
95 * @param {string} learnMoreLinkId Id inner link to 'learn more' element.
96 * @param {string} indicatorId Id of indicator to create.
97 * @param {string} text Inner text to set. Includes link declaration.
98 * @param {function} callback Callback to call on user action.
99 */ 101 */
100 function createConsentOption( 102 class PreferenceCheckbox {
101 textId, learnMoreLinkId, indicatorId, text, callback) {
102 var doc = appWindow.contentWindow.document;
103 var textElement = doc.getElementById(textId);
104 textElement.innerHTML = text;
105 var linkLearnMoreElement = doc.getElementById(learnMoreLinkId);
106 linkLearnMoreElement.addEventListener('click', callback);
107 103
108 // Create controlled by policy indicator. 104 /**
109 var policyIndicator = new appWindow.contentWindow.cr.ui.ControlledIndicator(); 105 * Creates a Checkbox which handles the corresponding preference update.
110 policyIndicator.id = indicatorId; 106 * @param {Element} container The container this checkbox corresponds to.
111 policyIndicator.getBubbleText = function() { 107 * The element must have <input type="checkbox" class="checkbox-option">
112 return controlledByPolicyText; 108 * for the checkbox itself, and <p class="checkbox-text"> for its label.
113 }; 109 * @param {string} learnMoreContent I18n content which is shown when "Learn
114 textElement.insertBefore(policyIndicator, linkLearnMoreElement); 110 * More" link is clicked.
115 } 111 * @param {string?} learnMoreLinkId The ID for the "Learn More" link element.
112 * TODO: Get rid of this. The element can have class so that it can be
113 * identified easily. Also, it'd be better to extract the link element
114 * (tag) from the i18n text, and let i18n focus on the content.
115 * @param {string?} policyText The content of the policy indicator.
116 */
117 constructor(container, learnMoreContent, learnMoreLinkId, policyText) {
118 this.container_ = container;
119 this.learnMoreContent_ = learnMoreContent;
120
121 this.checkbox_ = container.querySelector('.checkbox-option');
122 this.label_ = container.querySelector('.checkbox-text');
123
124 var learnMoreLink = this.label_.querySelector(learnMoreLinkId);
125 if (learnMoreLink) {
126 learnMoreLink.addEventListener(
127 'click', (event) => this.onLearnMoreLinkClicked(event));
128 }
129
130 // Create controlled indicator for policy if necessary.
131 if (policyText) {
132 this.policyIndicator_ =
133 new appWindow.contentWindow.cr.ui.ControlledIndicator();
134 this.policyIndicator_.setAttribute('textpolicy', policyText);
135 // TODO: better to have a dedicated element for this place.
136 this.label_.insertBefore(this.policyIndicator_, learnMoreLink);
137 } else {
138 this.policyIndicator_ = null;
139 }
140 }
141
142 /**
143 * Returns if the checkbox is checked or not. Note that this *may* be
144 * different from the preference value, because the user's check is
145 * not propagated to the preference until the user clicks "AGREE" button.
146 */
147 isChecked() { return this.checkbox_.checked; }
148
149 /**
150 * Called when the preference value in native code is updated.
151 */
152 onPreferenceChanged(isEnabled, isManaged) {
153 this.checkbox_.checked = isEnabled;
154 this.checkbox_.disabled = isManaged;
155 this.label_.disabled = isManaged;
156
157 if (this.policyIndicator_) {
158 if (isManaged) {
159 this.policyIndicator_.setAttribute('controlled-by', 'policy');
160 } else {
161 this.policyIndicator_.removeAttribute('controlled-by');
162 }
163 }
164 }
165
166 /**
167 * Called when the "Learn More" link is clicked.
168 */
169 onLearnMoreLinkClicked() {
170 showLearnMoreOverlay(this.learnMoreContent_);
171 }
172 };
173
174 /**
175 * Handles the checkbox action of metrics preference.
176 * This has special customization e.g. show/hide the checkbox based on
177 * the native preference.
178 */
179 class MetricsPreferenceCheckbox extends PreferenceCheckbox {
180 constructor(
181 container, learnMoreContent, learnMoreLinkId, isOwner,
182 textDisabled, textEnabled, textManagedDisabled, textManagedEnabled) {
183 // Do not use policy indicator.
184 // Learn More link handling is done by this class.
185 // So pass |null| intentionally.
186 super(container, learnMoreContent, null, null);
187
188 this.learnMoreLinkId_ = learnMoreLinkId;
189 this.isOwner_ = isOwner;
190
191 // Two dimensional array. First dimension is whether it is managed or not,
192 // the second one is whether it is enabled or not.
193 this.texts_ = [
194 [textDisabled, textEnabled],
195 [textManagedDisabled, textManagedEnabled]
196 ];
197 }
198
199 onPreferenceChanged(isEnabled, isManaged) {
200 isManaged = isManaged || !this.isOwner_;
201 super.onPreferenceChanged(isEnabled, isManaged);
202
203 // Hide the checkbox if it is not allowed to (re-)enable.
204 var canEnable = !isEnabled && !isManaged;
205 this.checkbox_.hidden = !canEnable;
206
207 // Update the label.
208 this.label_.innerHTML = this.texts_[isManaged ? 1 : 0][isEnabled ? 1 : 0];
209
210 // Work around for the current translation text.
211 // The translation text has tags for following links, although those
212 // tags are not the target of the translation (but those content text is
213 // the translation target).
214 // So, meanwhile, we set the link everytime we update the text.
215 // TODO: fix the translation text, and main html.
216 var learnMoreLink = this.label_.querySelector(this.learnMoreLinkId_);
217 learnMoreLink.addEventListener(
218 'click', (event) => this.onLearnMoreLinkClicked(event));
219 var settingsLink = this.label_.querySelector('#settings-link');
220 settingsLink.addEventListener(
221 'click', (event) => this.onSettingsLinkClicked(event));
222
223 // Applying metrics mode changes page layout, update terms height.
224 updateTermsHeight();
225 }
226
227 /** Called when "settings" link is clicked. */
228 onSettingsLinkClicked(event) {
229 chrome.browser.openTab({'url': 'chrome://settings'}, function() {});
230 event.preventDefault();
231 }
232 };
233
116 234
117 /** 235 /**
118 * Applies localization for html content and sets terms webview. 236 * Applies localization for html content and sets terms webview.
119 * @param {!Object} data Localized strings and relevant information. 237 * @param {!Object} data Localized strings and relevant information.
120 * @param {string} deviceId Current device id. 238 * @param {string} deviceId Current device id.
121 */ 239 */
122 function initialize(data, deviceId) { 240 function initialize(data, deviceId) {
123 currentDeviceId = deviceId; 241 currentDeviceId = deviceId;
124 var doc = appWindow.contentWindow.document; 242 var doc = appWindow.contentWindow.document;
125 var loadTimeData = appWindow.contentWindow.loadTimeData; 243 var loadTimeData = appWindow.contentWindow.loadTimeData;
126 loadTimeData.data = data; 244 loadTimeData.data = data;
127 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData); 245 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData);
246
247 // Initialize preference connected checkboxes in terms of service page.
248 metricsCheckbox = new MetricsPreferenceCheckbox(
249 doc.getElementById('metrics-preference'),
250 data.learnMoreStatistics,
251 '#learn-more-link-metrics',
252 data.isOwnerProfile,
253 data.textMetricsDisabled,
254 data.textMetricsEnabled,
255 data.textMetricsManagedDisabled,
256 data.textMetricsManagedEnabled);
257 backupRestoreCheckbox = new PreferenceCheckbox(
258 doc.getElementById('backup-restore-preference'),
259 data.learnMoreBackupAndRestore,
260 '#learn-more-link-backup-restore',
261 data.controlledByPolicy);
262 locationServiceCheckbox = new PreferenceCheckbox(
263 doc.getElementById('location-service-preference'),
264 data.learnMoreLocationServices,
265 '#learn-more-link-location-service',
266 data.controlledByPolicy);
267
268 // Initialize terms of service view.
128 var countryCode = data.countryCode.toLowerCase(); 269 var countryCode = data.countryCode.toLowerCase();
129 controlledByPolicyText = data.controlledByPolicy;
130 arcManaged = data.arcManaged;
131 setTermsVisible(!arcManaged);
132
133 createConsentOption('text-backup-restore',
134 'learn-more-link-backup-restore',
135 'policy-indicator-backup-restore',
136 data.textBackupRestore,
137 onLearnMoreBackupAndRestore);
138 createConsentOption('text-location-service',
139 'learn-more-link-location-service',
140 'policy-indicator-location-service',
141 data.textLocationService,
142 onLearnMoreLocationServices);
143
144 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';'; 270 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';';
145 termsView.addContentScripts([ 271 termsView.addContentScripts([
146 { name: 'preProcess', 272 { name: 'preProcess',
147 matches: ['https://play.google.com/*'], 273 matches: ['https://play.google.com/*'],
148 js: { code: scriptSetCountryCode }, 274 js: { code: scriptSetCountryCode },
149 run_at: 'document_start' 275 run_at: 'document_start'
150 }, 276 },
151 { name: 'postProcess', 277 { name: 'postProcess',
152 matches: ['https://play.google.com/*'], 278 matches: ['https://play.google.com/*'],
153 css: { files: ['playstore.css'] }, 279 css: { files: ['playstore.css'] },
154 js: { files: ['playstore.js'] }, 280 js: { files: ['playstore.js'] },
155 run_at: 'document_end' 281 run_at: 'document_end'
156 }]); 282 }]);
283 arcManaged = data.arcManaged;
284 setTermsVisible(!arcManaged);
157 } 285 }
158 286
159 /** 287 /**
160 * Handles the event when the user clicks on a learn more metrics link. Opens
161 * the pop up dialog with a help.
162 */
163 var onLearnMoreMetrics = function() {
164 var loadTimeData = appWindow.contentWindow.loadTimeData;
165 showLearnModeOverlay(loadTimeData.getString('learnMoreStatistics'));
166 };
167
168 /**
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.
171 */
172 var onLearnMoreBackupAndRestore = function() {
173 var loadTimeData = appWindow.contentWindow.loadTimeData;
174 showLearnModeOverlay(loadTimeData.getString('learnMoreBackupAndRestore'));
175 };
176
177 /**
178 * Handles the event when the user clicks on a learn more location services
179 * link. Opens the pop up dialog with a help.
180 */
181 var onLearnMoreLocationServices = function() {
182 var loadTimeData = appWindow.contentWindow.loadTimeData;
183 showLearnModeOverlay(loadTimeData.getString('learnMoreLocationServices'));
184 };
185
186 /**
187 * Sets current metrics mode.
188 * @param {string} text Describes current metrics state.
189 * @param {boolean} canEnable Defines if user is allowed to change this metrics
190 * option.
191 * @param {boolean} on Defines if metrics are active currently.
192 */
193 function setMetricsMode(text, canEnable, on) {
194 var doc = appWindow.contentWindow.document;
195 var enableMetrics = doc.getElementById('enable-metrics');
196 enableMetrics.hidden = !canEnable;
197 enableMetrics.checked = on;
198
199 var onSettings = function(event) {
200 chrome.browser.openTab({'url': 'chrome://settings'}, function() {});
201 event.preventDefault();
202 };
203
204 doc.getElementById('text-metrics').innerHTML = text;
205 doc.getElementById('settings-link').addEventListener('click', onSettings);
206 doc.getElementById('learn-more-link-metrics').addEventListener('click',
207 onLearnMoreMetrics);
208
209 // Applying metrics mode changes page layout, update terms height.
210 updateTermsHeight();
211 }
212
213 /**
214 * Sets current backup and restore mode.
215 * @param {boolean} enabled Defines the value for backup and restore checkbox.
216 * @param {boolean} managed Defines whether this setting is set by policy.
217 */
218 function setBackupRestoreMode(enabled, managed) {
219 var doc = appWindow.contentWindow.document;
220 doc.getElementById('enable-backup-restore').checked = enabled;
221 doc.getElementById('enable-backup-restore').disabled = managed;
222 doc.getElementById('text-backup-restore').disabled = managed;
223 var policyIconElement = doc.getElementById('policy-indicator-backup-restore');
224 if (managed) {
225 policyIconElement.setAttribute('controlled-by', 'policy');
226 } else {
227 policyIconElement.removeAttribute('controlled-by');
228 }
229 }
230
231 /**
232 * Sets current usage of location service opt in mode.
233 * @param {boolean} enabled Defines the value for location service opt in.
234 * @param {boolean} managed Defines whether this setting is set by policy.
235 */
236 function setLocationServiceMode(enabled, managed) {
237 var doc = appWindow.contentWindow.document;
238 doc.getElementById('enable-location-service').checked = enabled;
239 doc.getElementById('enable-location-service').disabled = managed;
240 doc.getElementById('text-location-service').disabled = managed;
241 var policyIconElement = doc.getElementById(
242 'policy-indicator-location-service');
243 if (managed) {
244 policyIconElement.setAttribute('controlled-by', 'policy');
245 } else {
246 policyIconElement.removeAttribute('controlled-by');
247 }
248 }
249
250 /**
251 * Sets visibility of Terms of Service. 288 * Sets visibility of Terms of Service.
252 * @param {boolean} visible Whether the Terms of Service visible or not. 289 * @param {boolean} visible Whether the Terms of Service visible or not.
253 */ 290 */
254 function setTermsVisible(visible) { 291 function setTermsVisible(visible) {
255 var doc = appWindow.contentWindow.document; 292 var doc = appWindow.contentWindow.document;
256 var styleVisibility = visible ? 'visible' : 'hidden'; 293 var styleVisibility = visible ? 'visible' : 'hidden';
257 doc.getElementById('terms-title').style.visibility = styleVisibility; 294 doc.getElementById('terms-title').style.visibility = styleVisibility;
258 doc.getElementById('terms-container').style.visibility = styleVisibility; 295 doc.getElementById('terms-container').style.visibility = styleVisibility;
259 } 296 }
260 297
(...skipping 25 matching lines...) Expand all
286 } 323 }
287 324
288 if (!appWindow) { 325 if (!appWindow) {
289 console.warn('Received native message when window is not available.'); 326 console.warn('Received native message when window is not available.');
290 return; 327 return;
291 } 328 }
292 329
293 if (message.action == 'initialize') { 330 if (message.action == 'initialize') {
294 initialize(message.data, message.deviceId); 331 initialize(message.data, message.deviceId);
295 } else if (message.action == 'setMetricsMode') { 332 } else if (message.action == 'setMetricsMode') {
296 setMetricsMode(message.text, message.canEnable, message.on); 333 metricsCheckbox.onPreferenceChanged(message.enabled, message.managed);
297 } else if (message.action == 'setBackupAndRestoreMode') { 334 } else if (message.action == 'setBackupAndRestoreMode') {
298 setBackupRestoreMode(message.enabled, message.managed); 335 backupRestoreCheckbox.onPreferenceChanged(message.enabled, message.managed);
299 } else if (message.action == 'setLocationServiceMode') { 336 } else if (message.action == 'setLocationServiceMode') {
300 setLocationServiceMode(message.enabled, message.managed); 337 locationServiceCheckbox.onPreferenceChanged(
338 message.enabled, message.managed);
301 } else if (message.action == 'closeWindow') { 339 } else if (message.action == 'closeWindow') {
302 if (appWindow) { 340 if (appWindow) {
303 appWindow.close(); 341 appWindow.close();
304 } 342 }
305 } else if (message.action == 'showPage') { 343 } else if (message.action == 'showPage') {
306 showPageWithStatus(message.page, message.status); 344 showPageWithStatus(message.page, message.status);
307 } else if (message.action == 'setWindowBounds') { 345 } else if (message.action == 'setWindowBounds') {
308 setWindowBounds(); 346 setWindowBounds();
309 } 347 }
310 } 348 }
(...skipping 10 matching lines...) Expand all
321 /** 359 /**
322 * 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.
323 * 'none' hides all views. 361 * 'none' hides all views.
324 * @param {string} pageDivId id of divider of the page to show. 362 * @param {string} pageDivId id of divider of the page to show.
325 */ 363 */
326 function showPage(pageDivId) { 364 function showPage(pageDivId) {
327 if (!appWindow) { 365 if (!appWindow) {
328 return; 366 return;
329 } 367 }
330 368
331 hideLearnModeOverlay(); 369 hideLearnMoreOverlay();
332 var doc = appWindow.contentWindow.document; 370 var doc = appWindow.contentWindow.document;
333 var pages = doc.getElementsByClassName('section'); 371 var pages = doc.getElementsByClassName('section');
334 var sendFeedbackElement = doc.getElementById('button-send-feedback'); 372 var sendFeedbackElement = doc.getElementById('button-send-feedback');
335 if (pageDivId == 'error-with-feedback') { 373 if (pageDivId == 'error-with-feedback') {
336 // Only show feedback button if the pageDivId is 'error-with-feedback'. 374 // Only show feedback button if the pageDivId is 'error-with-feedback'.
337 sendFeedbackElement.hidden = false; 375 sendFeedbackElement.hidden = false;
338 pageDivId = 'error'; 376 pageDivId = 'error';
339 } else { 377 } else {
340 sendFeedbackElement.hidden = true; 378 sendFeedbackElement.hidden = true;
341 } 379 }
(...skipping 25 matching lines...) Expand all
367 } 405 }
368 var doc = appWindow.contentWindow.document; 406 var doc = appWindow.contentWindow.document;
369 var messageElement = doc.getElementById('error-message'); 407 var messageElement = doc.getElementById('error-message');
370 messageElement.innerText = error; 408 messageElement.innerText = error;
371 } 409 }
372 410
373 /** 411 /**
374 * Sets learn more content text and shows it as overlay dialog. 412 * Sets learn more content text and shows it as overlay dialog.
375 * @param {string} content HTML formatted text to show. 413 * @param {string} content HTML formatted text to show.
376 */ 414 */
377 function showLearnModeOverlay(content) { 415 function showLearnMoreOverlay(content) {
378 var doc = appWindow.contentWindow.document; 416 var doc = appWindow.contentWindow.document;
379 var learnMoreContainer = doc.getElementById('learn-more-container'); 417 var learnMoreContainer = doc.getElementById('learn-more-container');
380 var learnMoreContent = doc.getElementById('learn-more-content'); 418 var learnMoreContent = doc.getElementById('learn-more-content');
381 learnMoreContent.innerHTML = content; 419 learnMoreContent.innerHTML = content;
382 learnMoreContainer.hidden = false; 420 learnMoreContainer.hidden = false;
383 } 421 }
384 422
385 /** 423 /**
386 * Hides learn more overlay dialog. 424 * Hides learn more overlay dialog.
387 */ 425 */
388 function hideLearnModeOverlay() { 426 function hideLearnMoreOverlay() {
389 var doc = appWindow.contentWindow.document; 427 var doc = appWindow.contentWindow.document;
390 var learnMoreContainer = doc.getElementById('learn-more-container'); 428 var learnMoreContainer = doc.getElementById('learn-more-container');
391 learnMoreContainer.hidden = true; 429 learnMoreContainer.hidden = true;
392 } 430 }
393 431
394 /** 432 /**
395 * Shows requested page. 433 * Shows requested page.
396 * @param {int} pageId Index of the page to show. Must be in the array range of 434 * @param {int} pageId Index of the page to show. Must be in the array range of
397 * UI_PAGES. 435 * UI_PAGES.
398 * @param {string} status associated with page string status, error message for 436 * @param {string} status associated with page string status, error message for
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 // webview is not allowed to open links in the new window. Hook these events 602 // webview is not allowed to open links in the new window. Hook these events
565 // and open links in context of main page. 603 // and open links in context of main page.
566 termsView.addEventListener('newwindow', function(event) { 604 termsView.addEventListener('newwindow', function(event) {
567 event.preventDefault(); 605 event.preventDefault();
568 chrome.browser.openTab({'url': event.targetUrl}, function() {}); 606 chrome.browser.openTab({'url': event.targetUrl}, function() {});
569 }); 607 });
570 608
571 var onAgree = function() { 609 var onAgree = function() {
572 termsAccepted = true; 610 termsAccepted = true;
573 611
574 var enableMetrics = doc.getElementById('enable-metrics');
575 var enableBackupRestore = doc.getElementById('enable-backup-restore');
576 var enableLocationService = doc.getElementById('enable-location-service');
577 sendNativeMessage('onAgreed', { 612 sendNativeMessage('onAgreed', {
578 isMetricsEnabled: enableMetrics.checked, 613 isMetricsEnabled: metricsCheckbox.isChecked(),
hidehiko 2016/10/17 13:12:45 Ugrrr... I mistakenly uploaded an older revision (
579 isBackupRestoreEnabled: enableBackupRestore.checked, 614 isBackupRestoreEnabled: backupRestoreCheckbox.isChecked(),
580 isLocationServiceEnabled: enableLocationService.checked 615 isLocationServiceEnabled: locationServiceCheckbox.isChecked()
581 }); 616 });
582 }; 617 };
583 618
584 var onCancel = function() { 619 var onCancel = function() {
585 if (appWindow) { 620 if (appWindow) {
586 appWindow.close(); 621 appWindow.close();
587 } 622 }
588 }; 623 };
589 624
590 var onRetry = function() { 625 var onRetry = function() {
591 if (termsAccepted) { 626 if (termsAccepted) {
592 // Reuse the onAgree() in case that the user has already accepted 627 // Reuse the onAgree() in case that the user has already accepted
593 // the ToS. 628 // the ToS.
594 onAgree(); 629 onAgree();
595 } else { 630 } else {
596 loadInitialTerms(); 631 loadInitialTerms();
597 } 632 }
598 }; 633 };
599 634
600 var onSendFeedback = function() { 635 var onSendFeedback = function() {
601 sendNativeMessage('onSendFeedbackClicked'); 636 sendNativeMessage('onSendFeedbackClicked');
602 }; 637 };
603 638
604 doc.getElementById('button-agree').addEventListener('click', onAgree); 639 doc.getElementById('button-agree').addEventListener('click', onAgree);
605 doc.getElementById('button-cancel').addEventListener('click', onCancel); 640 doc.getElementById('button-cancel').addEventListener('click', onCancel);
606 doc.getElementById('button-retry').addEventListener('click', onRetry); 641 doc.getElementById('button-retry').addEventListener('click', onRetry);
607 doc.getElementById('button-send-feedback') 642 doc.getElementById('button-send-feedback')
608 .addEventListener('click', onSendFeedback); 643 .addEventListener('click', onSendFeedback);
609 doc.getElementById('learn-more-close').addEventListener('click', 644 doc.getElementById('learn-more-close').addEventListener(
610 hideLearnModeOverlay); 645 'click', hideLearnMoreOverlay);
611 646
612 var overlay = doc.getElementById('learn-more-container'); 647 var overlay = doc.getElementById('learn-more-container');
613 appWindow.contentWindow.cr.ui.overlay.setupOverlay(overlay); 648 appWindow.contentWindow.cr.ui.overlay.setupOverlay(overlay);
614 appWindow.contentWindow.cr.ui.overlay.globalInitialization(); 649 appWindow.contentWindow.cr.ui.overlay.globalInitialization();
615 overlay.addEventListener('cancelOverlay', hideLearnModeOverlay); 650 overlay.addEventListener('cancelOverlay', hideLearnMoreOverlay);
616 651
617 connectPort(); 652 connectPort();
618 }; 653 };
619 654
620 var onWindowCreated = function(createdWindow) { 655 var onWindowCreated = function(createdWindow) {
621 appWindow = createdWindow; 656 appWindow = createdWindow;
622 appWindow.contentWindow.onload = onAppContentLoad; 657 appWindow.contentWindow.onload = onAppContentLoad;
623 appWindow.onClosed.addListener(onWindowClosed); 658 appWindow.onClosed.addListener(onWindowClosed);
624 659
625 setWindowBounds(); 660 setWindowBounds();
(...skipping 20 matching lines...) Expand all
646 type: 'chrome', 681 type: 'chrome',
647 color: '#ffffff' 682 color: '#ffffff'
648 }, 683 },
649 'innerBounds': { 684 'innerBounds': {
650 'width': INNER_WIDTH, 685 'width': INNER_WIDTH,
651 'height': INNER_HEIGHT 686 'height': INNER_HEIGHT
652 } 687 }
653 }; 688 };
654 chrome.app.window.create('main.html', options, onWindowCreated); 689 chrome.app.window.create('main.html', options, onWindowCreated);
655 }); 690 });
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_support_host.cc ('k') | chrome/browser/resources/chromeos/arc_support/main.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698