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

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: Fix compiler error mistake. 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',
Luis Héctor Chávez 2016/10/17 02:26:01 not your fault, but can this be const instead of v
hidehiko 2016/10/17 09:27:56 Unfortunately, the lint warns it. Instead @const i
Luis Héctor Chávez 2016/10/17 10:44:07 sgtm
11 'terms-loading', 11 'terms-loading',
12 'terms', 12 'terms',
13 'lso-loading', 13 'lso-loading',
14 'lso', 14 'lso',
15 'arc-loading', 15 'arc-loading',
16 'error', 16 'error',
17 'error-with-feedback']; 17 'error-with-feedback'];
18 18
19 /** 19 /**
20 * Chrome window that hosts UI. Only one window is allowed. 20 * Chrome window that hosts UI. Only one window is allowed.
21 * @type {chrome.app.window.AppWindow} 21 * @type {chrome.app.window.AppWindow}
22 */ 22 */
23 var appWindow = null; 23 var appWindow = null;
24 24
25 /** 25 /**
26 * Contains Web content provided by Google authorization server. 26 * Contains Web content provided by Google authorization server.
27 * @type {WebView} 27 * @type {WebView}
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;
Luis Héctor Chávez 2016/10/17 02:26:00 can this and the height be const as well?
hidehiko 2016/10/17 09:27:57 Acknowledged.
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} div The container this checkbox corresponds to.
Luis Héctor Chávez 2016/10/17 02:26:01 nit: I'd rather call this |container| rather than
hidehiko 2016/10/17 09:27:57 Done.
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(div, learnMoreContent, learnMoreLinkId, policyText) {
118 this.div_ = div;
119 this.learnMoreContent_ = learnMoreContent;
120
121 this.checkbox_ = div.querySelector('.checkbox-option');
122 // TODO: Send the event to update the preference so that the extension's
123 // state and the native state can be in sync.
khmel 2016/10/13 15:12:43 What do you mean by this? Do you want to change pr
hidehiko 2016/10/13 16:04:31 Oh, is it intentional behavior? It looks a (small)
xiyuan 2016/10/13 21:28:59 Not a lawyer but think this is intentional similar
hidehiko 2016/10/17 09:27:57 Thank you for clarification. Done.
124
125 this.label_ = div.querySelector('.checkbox-text');
126
127 var learnMoreLink = this.label_.querySelector(learnMoreLinkId);
128 if (learnMoreLink) {
129 learnMoreLink.addEventListener(
130 'click', (event) => this.onLearnMoreLinkClicked(event));
131 }
132
133 // Create controlled indicator for policy if necessary.
134 if (policyText) {
135 this.policyIndicator_ =
136 new appWindow.contentWindow.cr.ui.ControlledIndicator();
137 this.policyIndicator_.setAttribute('textpolicy', policyText);
138 // TODO: better to have a dedicated element for this place.
139 this.label_.insertBefore(this.policyIndicator_, learnMoreLink);
140 } else {
141 this.policyIndicator_ = null;
142 }
143 }
144
145 isEnabled() { return this.checkbox_.checked; }
Luis Héctor Chávez 2016/10/17 02:26:01 This was a bit confusing, since "enabled" means di
hidehiko 2016/10/17 09:27:57 Renamed to isChecked and added comments.
146
147 /**
148 * Called when the preference value in native code is updated.
149 */
150 onPreferenceChanged(isEnabled, isManaged) {
151 this.checkbox_.checked = isEnabled;
152 this.checkbox_.disabled = isManaged;
153 this.label_.disabled = isManaged;
154
155 if (this.policyIndicator_) {
156 if (isManaged) {
157 this.policyIndicator_.setAttribute('controlled-by', 'policy');
158 } else {
159 this.policyIndicator_.removeAttribute('controlled-by');
160 }
161 }
162 }
163
164 /**
165 * Called when the "Learn More" link is clicked.
166 */
167 onLearnMoreLinkClicked() {
168 showLearnMoreOverlay(this.learnMoreContent_);
169 }
170 };
171
172 /**
173 * Handles the checkbox action of metrics preference.
174 * This has special customization e.g. show/hide the checkbox based on
175 * the native preference.
176 */
177 class MetricsPreferenceCheckbox extends PreferenceCheckbox {
178 constructor(
179 div, learnMoreContent, learnMoreLinkId, isOwned,
180 textDisabled, textEnabled, textManagedDisabled, textManagedEnabled) {
181 // Do not use policy indicator.
182 // Learn More link handling is done by this class.
183 // So pass |null| intentionally.
184 super(div, learnMoreContent, null, null);
185
186 this.learnMoreLinkId_ = learnMoreLinkId;
187 this.isOwned_ = isOwned;
xiyuan 2016/10/13 21:28:59 nit: isOwned -> isOwner to be more clear
hidehiko 2016/10/17 09:27:57 Done.
188
189 // Build a text array. The index is "isManaged * 2 + isEnabled". See
Luis Héctor Chávez 2016/10/17 02:26:01 nit: Isn't it better to build a multi-dimensional
hidehiko 2016/10/17 09:27:57 Done.
190 // also onPreferenceChanged, too.
191 this.texts_ =
192 [textDisabled, textEnabled, textManagedDisabled, textManagedEnabled];
193 }
194
195 onPreferenceChanged(isEnabled, isManaged) {
196 isManaged = isManaged || !this.isOwned_;
197 super.onPreferenceChanged(isEnabled, isManaged);
198
199 // Hide the checkbox if it is not allowed to (re-)enable.
200 var canEnable = !isEnabled && !isManaged;
201 this.checkbox_.hidden = !canEnable;
202
203 // Update the label.
204 var index = 2 * isManaged + isEnabled;
205 this.label_.innerHTML = this.texts_[index];
206
207 // Work around for the current translation text.
208 // The translation text has tags for following links, although those
209 // tags are not the target of the translation (but those content text is
210 // the translation target).
211 // So, meanwhile, we set the link everytime we update the text.
212 // TODO: fix the translation text, and main html.
213 var learnMoreLink = this.label_.querySelector(this.learnMoreLinkId_);
214 learnMoreLink.addEventListener(
215 'click', (event) => this.onLearnMoreLinkClicked(event));
216 var settingsLink = this.label_.querySelector('#settings-link');
217 console.error(settingsLink);
xiyuan 2016/10/13 21:28:59 nit: remove debugging log?
hidehiko 2016/10/17 09:27:57 Oops. Removed.
218 settingsLink.addEventListener(
219 'click', (event) => this.onSettingsLinkClicked(event));
220
221 // Applying metrics mode changes page layout, update terms height.
222 updateTermsHeight();
223 }
224
225 /** Called when "settings" link is clicked. */
226 onSettingsLinkClicked(event) {
227 chrome.browser.openTab({'url': 'chrome://settings'}, function() {});
228 event.preventDefault();
229 }
230 };
231
116 232
117 /** 233 /**
118 * Applies localization for html content and sets terms webview. 234 * Applies localization for html content and sets terms webview.
119 * @param {!Object} data Localized strings and relevant information. 235 * @param {!Object} data Localized strings and relevant information.
120 * @param {string} deviceId Current device id. 236 * @param {string} deviceId Current device id.
121 */ 237 */
122 function initialize(data, deviceId) { 238 function initialize(data, deviceId) {
123 currentDeviceId = deviceId; 239 currentDeviceId = deviceId;
124 var doc = appWindow.contentWindow.document; 240 var doc = appWindow.contentWindow.document;
125 var loadTimeData = appWindow.contentWindow.loadTimeData; 241 var loadTimeData = appWindow.contentWindow.loadTimeData;
126 loadTimeData.data = data; 242 loadTimeData.data = data;
127 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData); 243 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData);
244
245 // Initialize preference connected checkboxes in terms of service page.
246 metricsCheckbox = new MetricsPreferenceCheckbox(
247 doc.getElementById('metrics-preference'),
248 data.learnMoreStatistics,
249 '#learn-more-link-metrics',
250 data.isOwnerProfile,
251 data.textMetricsDisabled,
252 data.textMetricsEnabled,
253 data.textMetricsManagedDisabled,
254 data.textMetricsManagedEnabled);
255 backupRestoreCheckbox = new PreferenceCheckbox(
256 doc.getElementById('backup-restore-preference'),
257 data.learnMoreBackupAndRestore,
258 '#learn-more-link-backup-restore',
259 data.controlledByPolicy);
260 locationServiceCheckbox = new PreferenceCheckbox(
261 doc.getElementById('location-service-preference'),
262 data.learnMoreLocationServices,
263 '#learn-more-link-location-service',
264 data.controlledByPolicy);
265
266 // Initialize terms of service view.
128 var countryCode = data.countryCode.toLowerCase(); 267 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 + '\';'; 268 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';';
145 termsView.addContentScripts([ 269 termsView.addContentScripts([
146 { name: 'preProcess', 270 { name: 'preProcess',
147 matches: ['https://play.google.com/*'], 271 matches: ['https://play.google.com/*'],
148 js: { code: scriptSetCountryCode }, 272 js: { code: scriptSetCountryCode },
149 run_at: 'document_start' 273 run_at: 'document_start'
150 }, 274 },
151 { name: 'postProcess', 275 { name: 'postProcess',
152 matches: ['https://play.google.com/*'], 276 matches: ['https://play.google.com/*'],
153 css: { files: ['playstore.css'] }, 277 css: { files: ['playstore.css'] },
154 js: { files: ['playstore.js'] }, 278 js: { files: ['playstore.js'] },
155 run_at: 'document_end' 279 run_at: 'document_end'
156 }]); 280 }]);
281 arcManaged = data.arcManaged;
282 setTermsVisible(!arcManaged);
157 } 283 }
158 284
159 /** 285 /**
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. 286 * Sets visibility of Terms of Service.
252 * @param {boolean} visible Whether the Terms of Service visible or not. 287 * @param {boolean} visible Whether the Terms of Service visible or not.
253 */ 288 */
254 function setTermsVisible(visible) { 289 function setTermsVisible(visible) {
255 var doc = appWindow.contentWindow.document; 290 var doc = appWindow.contentWindow.document;
256 var styleVisibility = visible ? 'visible' : 'hidden'; 291 var styleVisibility = visible ? 'visible' : 'hidden';
257 doc.getElementById('terms-title').style.visibility = styleVisibility; 292 doc.getElementById('terms-title').style.visibility = styleVisibility;
258 doc.getElementById('terms-container').style.visibility = styleVisibility; 293 doc.getElementById('terms-container').style.visibility = styleVisibility;
259 } 294 }
260 295
(...skipping 25 matching lines...) Expand all
286 } 321 }
287 322
288 if (!appWindow) { 323 if (!appWindow) {
289 console.warn('Received native message when window is not available.'); 324 console.warn('Received native message when window is not available.');
290 return; 325 return;
291 } 326 }
292 327
293 if (message.action == 'initialize') { 328 if (message.action == 'initialize') {
294 initialize(message.data, message.deviceId); 329 initialize(message.data, message.deviceId);
295 } else if (message.action == 'setMetricsMode') { 330 } else if (message.action == 'setMetricsMode') {
296 setMetricsMode(message.text, message.canEnable, message.on); 331 metricsCheckbox.onPreferenceChanged(message.enabled, message.managed);
297 } else if (message.action == 'setBackupAndRestoreMode') { 332 } else if (message.action == 'setBackupAndRestoreMode') {
298 setBackupRestoreMode(message.enabled, message.managed); 333 backupRestoreCheckbox.onPreferenceChanged(message.enabled, message.managed);
299 } else if (message.action == 'setLocationServiceMode') { 334 } else if (message.action == 'setLocationServiceMode') {
300 setLocationServiceMode(message.enabled, message.managed); 335 locationServiceCheckbox.onPreferenceChanged(
336 message.enabled, message.managed);
301 } else if (message.action == 'closeWindow') { 337 } else if (message.action == 'closeWindow') {
302 if (appWindow) { 338 if (appWindow) {
303 appWindow.close(); 339 appWindow.close();
304 } 340 }
305 } else if (message.action == 'showPage') { 341 } else if (message.action == 'showPage') {
306 showPageWithStatus(message.page, message.status); 342 showPageWithStatus(message.page, message.status);
307 } else if (message.action == 'setWindowBounds') { 343 } else if (message.action == 'setWindowBounds') {
308 setWindowBounds(); 344 setWindowBounds();
309 } 345 }
310 } 346 }
(...skipping 10 matching lines...) Expand all
321 /** 357 /**
322 * Shows requested page and hide others. Show appWindow if it was hidden before. 358 * Shows requested page and hide others. Show appWindow if it was hidden before.
323 * 'none' hides all views. 359 * 'none' hides all views.
324 * @param {string} pageDivId id of divider of the page to show. 360 * @param {string} pageDivId id of divider of the page to show.
325 */ 361 */
326 function showPage(pageDivId) { 362 function showPage(pageDivId) {
327 if (!appWindow) { 363 if (!appWindow) {
328 return; 364 return;
329 } 365 }
330 366
331 hideLearnModeOverlay(); 367 hideLearnMoreOverlay();
332 var doc = appWindow.contentWindow.document; 368 var doc = appWindow.contentWindow.document;
333 var pages = doc.getElementsByClassName('section'); 369 var pages = doc.getElementsByClassName('section');
334 var sendFeedbackElement = doc.getElementById('button-send-feedback'); 370 var sendFeedbackElement = doc.getElementById('button-send-feedback');
335 if (pageDivId == 'error-with-feedback') { 371 if (pageDivId == 'error-with-feedback') {
336 // Only show feedback button if the pageDivId is 'error-with-feedback'. 372 // Only show feedback button if the pageDivId is 'error-with-feedback'.
337 sendFeedbackElement.hidden = false; 373 sendFeedbackElement.hidden = false;
338 pageDivId = 'error'; 374 pageDivId = 'error';
339 } else { 375 } else {
340 sendFeedbackElement.hidden = true; 376 sendFeedbackElement.hidden = true;
341 } 377 }
(...skipping 25 matching lines...) Expand all
367 } 403 }
368 var doc = appWindow.contentWindow.document; 404 var doc = appWindow.contentWindow.document;
369 var messageElement = doc.getElementById('error-message'); 405 var messageElement = doc.getElementById('error-message');
370 messageElement.innerText = error; 406 messageElement.innerText = error;
371 } 407 }
372 408
373 /** 409 /**
374 * Sets learn more content text and shows it as overlay dialog. 410 * Sets learn more content text and shows it as overlay dialog.
375 * @param {string} content HTML formatted text to show. 411 * @param {string} content HTML formatted text to show.
376 */ 412 */
377 function showLearnModeOverlay(content) { 413 function showLearnMoreOverlay(content) {
378 var doc = appWindow.contentWindow.document; 414 var doc = appWindow.contentWindow.document;
379 var learnMoreContainer = doc.getElementById('learn-more-container'); 415 var learnMoreContainer = doc.getElementById('learn-more-container');
380 var learnMoreContent = doc.getElementById('learn-more-content'); 416 var learnMoreContent = doc.getElementById('learn-more-content');
381 learnMoreContent.innerHTML = content; 417 learnMoreContent.innerHTML = content;
382 learnMoreContainer.hidden = false; 418 learnMoreContainer.hidden = false;
383 } 419 }
384 420
385 /** 421 /**
386 * Hides learn more overlay dialog. 422 * Hides learn more overlay dialog.
387 */ 423 */
388 function hideLearnModeOverlay() { 424 function hideLearnMoreOverlay() {
389 var doc = appWindow.contentWindow.document; 425 var doc = appWindow.contentWindow.document;
390 var learnMoreContainer = doc.getElementById('learn-more-container'); 426 var learnMoreContainer = doc.getElementById('learn-more-container');
391 learnMoreContainer.hidden = true; 427 learnMoreContainer.hidden = true;
392 } 428 }
393 429
394 /** 430 /**
395 * Shows requested page. 431 * Shows requested page.
396 * @param {int} pageId Index of the page to show. Must be in the array range of 432 * @param {int} pageId Index of the page to show. Must be in the array range of
397 * UI_PAGES. 433 * UI_PAGES.
398 * @param {string} status associated with page string status, error message for 434 * @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 600 // webview is not allowed to open links in the new window. Hook these events
565 // and open links in context of main page. 601 // and open links in context of main page.
566 termsView.addEventListener('newwindow', function(event) { 602 termsView.addEventListener('newwindow', function(event) {
567 event.preventDefault(); 603 event.preventDefault();
568 chrome.browser.openTab({'url': event.targetUrl}, function() {}); 604 chrome.browser.openTab({'url': event.targetUrl}, function() {});
569 }); 605 });
570 606
571 var onAgree = function() { 607 var onAgree = function() {
572 termsAccepted = true; 608 termsAccepted = true;
573 609
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', { 610 sendNativeMessage('onAgreed', {
578 isMetricsEnabled: !enableMetrics.hidden && enableMetrics.checked, 611 isMetricsEnabled: metricsCheckbox.isEnabled(),
579 isBackupRestoreEnabled: enableBackupRestore.checked, 612 isBackupRestoreEnabled: backupRestoreCheckbox.isEnabled(),
580 isLocationServiceEnabled: enableLocationService.checked 613 isLocationServiceEnabled: locationServiceCheckbox.isEnabled()
581 }); 614 });
582 }; 615 };
583 616
584 var onCancel = function() { 617 var onCancel = function() {
585 if (appWindow) { 618 if (appWindow) {
586 appWindow.close(); 619 appWindow.close();
587 } 620 }
588 }; 621 };
589 622
590 var onRetry = function() { 623 var onRetry = function() {
591 if (termsAccepted) { 624 if (termsAccepted) {
592 // Reuse the onAgree() in case that the user has already accepted 625 // Reuse the onAgree() in case that the user has already accepted
593 // the ToS. 626 // the ToS.
594 onAgree(); 627 onAgree();
595 } else { 628 } else {
596 loadInitialTerms(); 629 loadInitialTerms();
597 } 630 }
598 }; 631 };
599 632
600 var onSendFeedback = function() { 633 var onSendFeedback = function() {
601 sendNativeMessage('onSendFeedbackClicked'); 634 sendNativeMessage('onSendFeedbackClicked');
602 }; 635 };
603 636
604 doc.getElementById('button-agree').addEventListener('click', onAgree); 637 doc.getElementById('button-agree').addEventListener('click', onAgree);
605 doc.getElementById('button-cancel').addEventListener('click', onCancel); 638 doc.getElementById('button-cancel').addEventListener('click', onCancel);
606 doc.getElementById('button-retry').addEventListener('click', onRetry); 639 doc.getElementById('button-retry').addEventListener('click', onRetry);
607 doc.getElementById('button-send-feedback') 640 doc.getElementById('button-send-feedback')
608 .addEventListener('click', onSendFeedback); 641 .addEventListener('click', onSendFeedback);
609 doc.getElementById('learn-more-close').addEventListener('click', 642 doc.getElementById('learn-more-close').addEventListener(
610 hideLearnModeOverlay); 643 'click', hideLearnMoreOverlay);
611 644
612 var overlay = doc.getElementById('learn-more-container'); 645 var overlay = doc.getElementById('learn-more-container');
613 appWindow.contentWindow.cr.ui.overlay.setupOverlay(overlay); 646 appWindow.contentWindow.cr.ui.overlay.setupOverlay(overlay);
614 appWindow.contentWindow.cr.ui.overlay.globalInitialization(); 647 appWindow.contentWindow.cr.ui.overlay.globalInitialization();
615 overlay.addEventListener('cancelOverlay', hideLearnModeOverlay); 648 overlay.addEventListener('cancelOverlay', hideLearnMoreOverlay);
616 649
617 connectPort(); 650 connectPort();
618 }; 651 };
619 652
620 var onWindowCreated = function(createdWindow) { 653 var onWindowCreated = function(createdWindow) {
621 appWindow = createdWindow; 654 appWindow = createdWindow;
622 appWindow.contentWindow.onload = onAppContentLoad; 655 appWindow.contentWindow.onload = onAppContentLoad;
623 appWindow.onClosed.addListener(onWindowClosed); 656 appWindow.onClosed.addListener(onWindowClosed);
624 657
625 setWindowBounds(); 658 setWindowBounds();
(...skipping 20 matching lines...) Expand all
646 type: 'chrome', 679 type: 'chrome',
647 color: '#ffffff' 680 color: '#ffffff'
648 }, 681 },
649 'innerBounds': { 682 'innerBounds': {
650 'width': INNER_WIDTH, 683 'width': INNER_WIDTH,
651 'height': INNER_HEIGHT 684 'height': INNER_HEIGHT
652 } 685 }
653 }; 686 };
654 chrome.app.window.create('main.html', options, onWindowCreated); 687 chrome.app.window.create('main.html', options, onWindowCreated);
655 }); 688 });
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