OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 cr.define('help', function() { | 5 cr.define('help', function() { |
6 var Page = cr.ui.pageManager.Page; | 6 var Page = cr.ui.pageManager.Page; |
7 var PageManager = cr.ui.pageManager.PageManager; | 7 var PageManager = cr.ui.pageManager.PageManager; |
8 | 8 |
9 /** | 9 /** |
10 * Encapsulated handling of the About page. Called 'help' internally to avoid | 10 * Encapsulated handling of the About page. Called 'help' internally to avoid |
11 * confusion with generic AboutUI (about:memory, about:sandbox, etc.). | 11 * confusion with generic AboutUI (about:memory, about:sandbox, etc.). |
12 */ | 12 */ |
13 function HelpPage() { | 13 function HelpPage() { |
14 var id = loadTimeData.valueExists('aboutOverlayTabTitle') ? | 14 var id = loadTimeData.valueExists('aboutOverlayTabTitle') ? |
15 'aboutOverlayTabTitle' : 'aboutTitle'; | 15 'aboutOverlayTabTitle' : 'aboutTitle'; |
16 Page.call(this, 'help', loadTimeData.getString(id), 'help-page'); | 16 Page.call(this, 'help', loadTimeData.getString(id), 'help-page'); |
17 } | 17 } |
18 | 18 |
19 cr.addSingletonGetter(HelpPage); | 19 cr.addSingletonGetter(HelpPage); |
20 | 20 |
21 HelpPage.prototype = { | 21 HelpPage.prototype = { |
22 __proto__: Page.prototype, | 22 __proto__: Page.prototype, |
23 | 23 |
24 /** | 24 /** |
25 * True if after update powerwash button should be displayed. | 25 * List of the channel names. Should be ordered in increasing level of |
26 * @private | 26 * stability. |
27 */ | |
28 powerwashAfterUpdate_: false, | |
29 | |
30 /** | |
31 * List of the channel names. | |
32 * @private | 27 * @private |
33 */ | 28 */ |
34 channelList_: ['dev-channel', 'beta-channel', 'stable-channel'], | 29 channelList_: ['dev-channel', 'beta-channel', 'stable-channel'], |
35 | 30 |
36 /** | 31 /** |
37 * Name of the channel the device is currently on. | 32 * Name of the channel the device is currently on. |
38 * @private | 33 * @private |
39 */ | 34 */ |
40 currentChannel_: null, | 35 currentChannel_: null, |
41 | 36 |
42 /** | 37 /** |
43 * Name of the channel the device is supposed to be on. | 38 * Name of the channel the device is supposed to be on. |
44 * @private | 39 * @private |
45 */ | 40 */ |
46 targetChannel_: null, | 41 targetChannel_: null, |
47 | 42 |
| 43 /** |
| 44 * Last status received from the version updater. |
| 45 * @private |
| 46 */ |
| 47 status_: null, |
| 48 |
| 49 /** |
| 50 * Last message received from the version updater. |
| 51 * @private |
| 52 */ |
| 53 message_: null, |
| 54 |
48 /** @override */ | 55 /** @override */ |
49 initializePage: function() { | 56 initializePage: function() { |
50 Page.prototype.initializePage.call(this); | 57 Page.prototype.initializePage.call(this); |
51 | 58 |
52 $('product-license').innerHTML = loadTimeData.getString('productLicense'); | 59 $('product-license').innerHTML = loadTimeData.getString('productLicense'); |
53 if (cr.isChromeOS) { | 60 if (cr.isChromeOS) { |
54 $('product-os-license').innerHTML = | 61 $('product-os-license').innerHTML = |
55 loadTimeData.getString('productOsLicense'); | 62 loadTimeData.getString('productOsLicense'); |
56 } | 63 } |
57 | 64 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 * not equal. | 224 * not equal. |
218 * @private | 225 * @private |
219 */ | 226 */ |
220 channelsDiffer_: function() { | 227 channelsDiffer_: function() { |
221 var current = this.currentChannel_; | 228 var current = this.currentChannel_; |
222 var target = this.targetChannel_; | 229 var target = this.targetChannel_; |
223 return (current != null && target != null && current != target); | 230 return (current != null && target != null && current != target); |
224 }, | 231 }, |
225 | 232 |
226 /** | 233 /** |
| 234 * @return {boolean} True if target channel is more stable than the current |
| 235 * one, and false otherwise. |
| 236 * @private |
| 237 */ |
| 238 targetChannelIsMoreStable_: function() { |
| 239 var current = this.currentChannel_; |
| 240 var target = this.targetChannel_; |
| 241 if (current == null || target == null) |
| 242 return false; |
| 243 var currentIndex = this.channelList_.indexOf(current); |
| 244 var targetIndex = this.channelList_.indexOf(target); |
| 245 if (currentIndex < 0 || targetIndex < 0) |
| 246 return false; |
| 247 return currentIndex < targetIndex; |
| 248 }, |
| 249 |
| 250 /** |
227 * @param {string} status The status of the update. | 251 * @param {string} status The status of the update. |
228 * @param {string} message Failure message to display. | 252 * @param {string} message Failure message to display. |
229 * @private | 253 * @private |
230 */ | 254 */ |
231 setUpdateStatus_: function(status, message) { | 255 setUpdateStatus_: function(status, message) { |
| 256 this.status_ = status; |
| 257 this.message_ = message; |
| 258 |
| 259 this.updateUI_(); |
| 260 }, |
| 261 |
| 262 /** |
| 263 * Updates UI elements on the page according to current state. |
| 264 * @private |
| 265 */ |
| 266 updateUI_: function() { |
| 267 var status = this.status_; |
| 268 var message = this.message_; |
| 269 var channel = this.targetChannel_; |
| 270 |
| 271 if (this.channelList_.indexOf(channel) >= 0) { |
| 272 $('current-channel').textContent = loadTimeData.getStringF( |
| 273 'currentChannel', this.channelTable_[channel].label); |
| 274 this.updateChannelChangePageContainerVisibility_(); |
| 275 } |
| 276 |
| 277 if (status == null) |
| 278 return; |
| 279 |
232 if (cr.isMac && | 280 if (cr.isMac && |
233 $('update-status-message') && | 281 $('update-status-message') && |
234 $('update-status-message').hidden) { | 282 $('update-status-message').hidden) { |
235 // Chrome has reached the end of the line on this system. The | 283 // Chrome has reached the end of the line on this system. The |
236 // update-obsolete-system message is displayed. No other auto-update | 284 // update-obsolete-system message is displayed. No other auto-update |
237 // status should be displayed. | 285 // status should be displayed. |
238 return; | 286 return; |
239 } | 287 } |
240 | 288 |
241 var channel = this.targetChannel_; | |
242 if (status == 'checking') { | 289 if (status == 'checking') { |
243 this.setUpdateImage_('working'); | 290 this.setUpdateImage_('working'); |
244 $('update-status-message').innerHTML = | 291 $('update-status-message').innerHTML = |
245 loadTimeData.getString('updateCheckStarted'); | 292 loadTimeData.getString('updateCheckStarted'); |
246 } else if (status == 'updating') { | 293 } else if (status == 'updating') { |
247 this.setUpdateImage_('working'); | 294 this.setUpdateImage_('working'); |
248 if (this.channelsDiffer_()) { | 295 if (this.channelsDiffer_()) { |
249 $('update-status-message').innerHTML = | 296 $('update-status-message').innerHTML = |
250 loadTimeData.getStringF('updatingChannelSwitch', | 297 loadTimeData.getStringF('updatingChannelSwitch', |
251 this.channelTable_[channel].label); | 298 this.channelTable_[channel].label); |
(...skipping 20 matching lines...) Expand all Loading... |
272 } | 319 } |
273 | 320 |
274 // Following invariant must be established at the end of this function: | 321 // Following invariant must be established at the end of this function: |
275 // { ~$('relaunch_and_powerwash').hidden -> $('relaunch').hidden } | 322 // { ~$('relaunch_and_powerwash').hidden -> $('relaunch').hidden } |
276 var relaunchAndPowerwashHidden = true; | 323 var relaunchAndPowerwashHidden = true; |
277 if ($('relaunch-and-powerwash')) { | 324 if ($('relaunch-and-powerwash')) { |
278 // It's allowed to do powerwash only for customer devices, | 325 // It's allowed to do powerwash only for customer devices, |
279 // when user explicitly decides to update to a more stable | 326 // when user explicitly decides to update to a more stable |
280 // channel. | 327 // channel. |
281 relaunchAndPowerwashHidden = | 328 relaunchAndPowerwashHidden = |
282 !this.powerwashAfterUpdate_ || status != 'nearly_updated'; | 329 !this.targetChannelIsMoreStable_() || status != 'nearly_updated'; |
283 $('relaunch-and-powerwash').hidden = relaunchAndPowerwashHidden; | 330 $('relaunch-and-powerwash').hidden = relaunchAndPowerwashHidden; |
284 } | 331 } |
285 | 332 |
286 if (cr.isChromeOS) { | 333 if (cr.isChromeOS) { |
287 // Only enable the update button if it hasn't been used yet or the | 334 // Only enable the update button if it hasn't been used yet or the |
288 // status isn't 'updated'. | 335 // status isn't 'updated'. |
289 if (!$('request-update').disabled || status != 'updated') { | 336 if (!$('request-update').disabled || status != 'updated') { |
290 // Disable the button if an update is already in progress. | 337 // Disable the button if an update is already in progress. |
291 $('request-update').disabled = | 338 $('request-update').disabled = |
292 ['checking', 'updating', 'nearly_updated'].indexOf(status) > -1; | 339 ['checking', 'updating', 'nearly_updated'].indexOf(status) > -1; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 */ | 447 */ |
401 setOSFirmware_: function(firmware) { | 448 setOSFirmware_: function(firmware) { |
402 if (!cr.isChromeOS) | 449 if (!cr.isChromeOS) |
403 console.error('OS firmware unsupported on non-CrOS'); | 450 console.error('OS firmware unsupported on non-CrOS'); |
404 | 451 |
405 $('firmware').parentNode.hidden = (firmware == ''); | 452 $('firmware').parentNode.hidden = (firmware == ''); |
406 $('firmware').textContent = firmware; | 453 $('firmware').textContent = firmware; |
407 }, | 454 }, |
408 | 455 |
409 /** | 456 /** |
| 457 * Updates page UI according to device owhership policy. |
| 458 * @param {boolean} isEnterpriseManaged True if the device is |
| 459 * enterprise managed. |
| 460 * @private |
| 461 */ |
| 462 updateIsEnterpriseManaged_: function(isEnterpriseManaged) { |
| 463 help.ChannelChangePage.updateIsEnterpriseManaged(isEnterpriseManaged); |
| 464 this.updateUI_(); |
| 465 }, |
| 466 |
| 467 /** |
410 * Updates name of the current channel, i.e. the name of the | 468 * Updates name of the current channel, i.e. the name of the |
411 * channel the device is currently on. | 469 * channel the device is currently on. |
412 * @param {string} channel The name of the current channel. | 470 * @param {string} channel The name of the current channel. |
413 * @private | 471 * @private |
414 */ | 472 */ |
415 updateCurrentChannel_: function(channel) { | 473 updateCurrentChannel_: function(channel) { |
416 if (this.channelList_.indexOf(channel) < 0) | 474 if (this.channelList_.indexOf(channel) < 0) |
417 return; | 475 return; |
418 $('current-channel').textContent = loadTimeData.getStringF( | |
419 'currentChannel', this.channelTable_[channel].label); | |
420 this.currentChannel_ = channel; | 476 this.currentChannel_ = channel; |
421 help.ChannelChangePage.updateCurrentChannel(channel); | 477 help.ChannelChangePage.updateCurrentChannel(channel); |
| 478 this.updateUI_(); |
422 }, | 479 }, |
423 | 480 |
424 /** | 481 /** |
| 482 * Updates name of the target channel, i.e. the name of the |
| 483 * channel the device is supposed to be. |
| 484 * @param {string} channel The name of the target channel. |
| 485 * @private |
| 486 */ |
| 487 updateTargetChannel_: function(channel) { |
| 488 if (this.channelList_.indexOf(channel) < 0) |
| 489 return; |
| 490 this.targetChannel_ = channel; |
| 491 help.ChannelChangePage.updateTargetChannel(channel); |
| 492 this.updateUI_(); |
| 493 }, |
| 494 |
| 495 /** |
425 * @param {boolean} enabled True if the release channel can be enabled. | 496 * @param {boolean} enabled True if the release channel can be enabled. |
426 * @private | 497 * @private |
427 */ | 498 */ |
428 updateEnableReleaseChannel_: function(enabled) { | 499 updateEnableReleaseChannel_: function(enabled) { |
429 this.updateChannelChangerContainerVisibility_(enabled); | 500 this.updateChannelChangerContainerVisibility_(enabled); |
430 $('change-channel').disabled = !enabled; | 501 $('change-channel').disabled = !enabled; |
431 $('channel-change-disallowed-icon').hidden = enabled; | 502 $('channel-change-disallowed-icon').hidden = enabled; |
432 }, | 503 }, |
433 | 504 |
434 /** | 505 /** |
435 * Sets the device target channel. | 506 * Sets the device target channel. |
436 * @param {string} channel The name of the target channel. | 507 * @param {string} channel The name of the target channel. |
437 * @param {boolean} isPowerwashAllowed True iff powerwash is allowed. | 508 * @param {boolean} isPowerwashAllowed True iff powerwash is allowed. |
438 * @private | 509 * @private |
439 */ | 510 */ |
440 setChannel_: function(channel, isPowerwashAllowed) { | 511 setChannel_: function(channel, isPowerwashAllowed) { |
441 this.powerwashAfterUpdate_ = isPowerwashAllowed; | |
442 this.targetChannel_ = channel; | |
443 chrome.send('setChannel', [channel, isPowerwashAllowed]); | 512 chrome.send('setChannel', [channel, isPowerwashAllowed]); |
444 $('channel-change-confirmation').hidden = false; | 513 $('channel-change-confirmation').hidden = false; |
445 $('channel-change-confirmation').textContent = loadTimeData.getStringF( | 514 $('channel-change-confirmation').textContent = loadTimeData.getStringF( |
446 'channel-changed', this.channelTable_[channel].name); | 515 'channel-changed', this.channelTable_[channel].name); |
| 516 this.updateTargetChannel_(channel); |
447 }, | 517 }, |
448 | 518 |
449 /** | 519 /** |
450 * Sets the value of the "Build Date" field of the "More Info" section. | 520 * Sets the value of the "Build Date" field of the "More Info" section. |
451 * @param {string} buildDate The date of the build. | 521 * @param {string} buildDate The date of the build. |
452 * @private | 522 * @private |
453 */ | 523 */ |
454 setBuildDate_: function(buildDate) { | 524 setBuildDate_: function(buildDate) { |
455 $('build-date-container').classList.remove('empty'); | 525 $('build-date-container').classList.remove('empty'); |
456 $('build-date').textContent = buildDate; | 526 $('build-date').textContent = buildDate; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 HelpPage.getInstance().setOSVersion_(version); | 589 HelpPage.getInstance().setOSVersion_(version); |
520 }; | 590 }; |
521 | 591 |
522 HelpPage.setOSFirmware = function(firmware) { | 592 HelpPage.setOSFirmware = function(firmware) { |
523 HelpPage.getInstance().setOSFirmware_(firmware); | 593 HelpPage.getInstance().setOSFirmware_(firmware); |
524 }; | 594 }; |
525 | 595 |
526 HelpPage.updateIsEnterpriseManaged = function(isEnterpriseManaged) { | 596 HelpPage.updateIsEnterpriseManaged = function(isEnterpriseManaged) { |
527 if (!cr.isChromeOS) | 597 if (!cr.isChromeOS) |
528 return; | 598 return; |
529 help.ChannelChangePage.updateIsEnterpriseManaged(isEnterpriseManaged); | 599 HelpPage.getInstance().updateIsEnterpriseManaged_(isEnterpriseManaged); |
530 }; | 600 }; |
531 | 601 |
532 HelpPage.updateCurrentChannel = function(channel) { | 602 HelpPage.updateCurrentChannel = function(channel) { |
533 if (!cr.isChromeOS) | 603 if (!cr.isChromeOS) |
534 return; | 604 return; |
535 HelpPage.getInstance().updateCurrentChannel_(channel); | 605 HelpPage.getInstance().updateCurrentChannel_(channel); |
536 }; | 606 }; |
537 | 607 |
538 HelpPage.updateTargetChannel = function(channel) { | 608 HelpPage.updateTargetChannel = function(channel) { |
539 if (!cr.isChromeOS) | 609 if (!cr.isChromeOS) |
540 return; | 610 return; |
541 help.ChannelChangePage.updateTargetChannel(channel); | 611 HelpPage.getInstance().updateTargetChannel_(channel); |
542 }; | 612 }; |
543 | 613 |
544 HelpPage.updateEnableReleaseChannel = function(enabled) { | 614 HelpPage.updateEnableReleaseChannel = function(enabled) { |
545 HelpPage.getInstance().updateEnableReleaseChannel_(enabled); | 615 HelpPage.getInstance().updateEnableReleaseChannel_(enabled); |
546 }; | 616 }; |
547 | 617 |
548 HelpPage.setChannel = function(channel, isPowerwashAllowed) { | 618 HelpPage.setChannel = function(channel, isPowerwashAllowed) { |
549 HelpPage.getInstance().setChannel_(channel, isPowerwashAllowed); | 619 HelpPage.getInstance().setChannel_(channel, isPowerwashAllowed); |
550 }; | 620 }; |
551 | 621 |
552 HelpPage.setBuildDate = function(buildDate) { | 622 HelpPage.setBuildDate = function(buildDate) { |
553 HelpPage.getInstance().setBuildDate_(buildDate); | 623 HelpPage.getInstance().setBuildDate_(buildDate); |
554 }; | 624 }; |
555 | 625 |
556 HelpPage.updateChannelChangePageContainerVisibility = function() { | |
557 HelpPage.getInstance().updateChannelChangePageContainerVisibility_(); | |
558 }; | |
559 | |
560 // Export | 626 // Export |
561 return { | 627 return { |
562 HelpPage: HelpPage | 628 HelpPage: HelpPage |
563 }; | 629 }; |
564 }); | 630 }); |
OLD | NEW |