| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * Responsible for showing banners in the file list. | 6 * Responsible for showing banners in the file list. |
| 7 * @param {DirectoryModel} directoryModel The model. | 7 * @param {DirectoryModel} directoryModel The model. |
| 8 * @param {VolumeManager} volumeManager The manager. | 8 * @param {VolumeManager} volumeManager The manager. |
| 9 * @param {DOMDocument} document HTML document. | 9 * @param {DOMDocument} document HTML document. |
| 10 * @constructor | 10 * @constructor |
| 11 */ | 11 */ |
| 12 function FileListBannerController(directoryModel, volumeManager, document) { | 12 function FileListBannerController(directoryModel, volumeManager, document) { |
| 13 this.directoryModel_ = directoryModel; | 13 this.directoryModel_ = directoryModel; |
| 14 this.volumeManager_ = volumeManager; | 14 this.volumeManager_ = volumeManager; |
| 15 this.document_ = document; | 15 this.document_ = document; |
| 16 this.driveEnabled_ = false; | 16 this.driveEnabled_ = false; |
| 17 | 17 |
| 18 var board = str('CHROMEOS_RELEASE_BOARD'); | 18 var board = str('CHROMEOS_RELEASE_BOARD'); |
| 19 // It is 'canary' or 'beta' for the other channels. | 19 if (board.match(/^(stumpy|lumpy)/i)) |
| 20 var releaseChannel = str('BROWSER_VERSION_MODIFIER') == ''; | 20 this.checkPromoAvailable_(); |
| 21 this.newWelcome_ = board.match(/^(stumpy|lumpy)/i) && releaseChannel; | 21 else |
| 22 this.newWelcome_ = false; |
| 22 | 23 |
| 23 var handler = this.checkSpaceAndShowBanner_.bind(this); | 24 var handler = this.checkSpaceAndShowBanner_.bind(this); |
| 24 this.directoryModel_.addEventListener('scan-completed', handler); | 25 this.directoryModel_.addEventListener('scan-completed', handler); |
| 25 this.directoryModel_.addEventListener('rescan-completed', handler); | 26 this.directoryModel_.addEventListener('rescan-completed', handler); |
| 26 this.directoryModel_.addEventListener('directory-changed', | 27 this.directoryModel_.addEventListener('directory-changed', |
| 27 this.onDirectoryChanged_.bind(this)); | 28 this.onDirectoryChanged_.bind(this)); |
| 28 | 29 |
| 29 this.unmountedPanel_ = this.document_.querySelector('#unmounted-panel'); | 30 this.unmountedPanel_ = this.document_.querySelector('#unmounted-panel'); |
| 30 this.volumeManager_.addEventListener('gdata-status-changed', | 31 this.volumeManager_.addEventListener('gdata-status-changed', |
| 31 this.updateGDataUnmountedPanel_.bind(this)); | 32 this.updateGDataUnmountedPanel_.bind(this)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 57 */ | 58 */ |
| 58 var GOOGLE_DRIVE_FAQ_URL = | 59 var GOOGLE_DRIVE_FAQ_URL = |
| 59 'https://support.google.com/chromeos/?p=filemanager_drive'; | 60 'https://support.google.com/chromeos/?p=filemanager_drive'; |
| 60 | 61 |
| 61 /** | 62 /** |
| 62 * Location of the page to buy more storage for Google Drive. | 63 * Location of the page to buy more storage for Google Drive. |
| 63 */ | 64 */ |
| 64 var GOOGLE_DRIVE_BUY_STORAGE = | 65 var GOOGLE_DRIVE_BUY_STORAGE = |
| 65 'https://www.google.com/settings/storage'; | 66 'https://www.google.com/settings/storage'; |
| 66 | 67 |
| 68 var GOOGLE_DRIVE_REDEEM = 'https://drive.google.com/redeem'; |
| 69 |
| 67 /** | 70 /** |
| 68 * Location of the FAQ about the downloads directory. | 71 * Location of the FAQ about the downloads directory. |
| 69 */ | 72 */ |
| 70 var DOWNLOADS_FAQ_URL = | 73 var DOWNLOADS_FAQ_URL = |
| 71 'http://support.google.com/chromeos/bin/answer.py?answer=1061547'; | 74 'http://support.google.com/chromeos/bin/answer.py?answer=1061547'; |
| 72 | 75 |
| 73 /** | 76 /** |
| 74 * Location of the help page about connecting to Google Drive. | 77 * Location of the help page about connecting to Google Drive. |
| 75 */ | 78 */ |
| 76 var GOOGLE_DRIVE_ERROR_HELP_URL = | 79 var GOOGLE_DRIVE_ERROR_HELP_URL = |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 } | 167 } |
| 165 | 168 |
| 166 var counter = this.getHeaderCounter_(); | 169 var counter = this.getHeaderCounter_(); |
| 167 | 170 |
| 168 if (this.directoryModel_.getFileList().length == 0 && counter == 0) { | 171 if (this.directoryModel_.getFileList().length == 0 && counter == 0) { |
| 169 // Only show the full page banner if the header banner was never shown. | 172 // Only show the full page banner if the header banner was never shown. |
| 170 // Do not increment the counter. | 173 // Do not increment the counter. |
| 171 // The timeout below is required because sometimes another | 174 // The timeout below is required because sometimes another |
| 172 // 'rescan-completed' event arrives shortly with non-empty file list. | 175 // 'rescan-completed' event arrives shortly with non-empty file list. |
| 173 var self = this; | 176 var self = this; |
| 174 setTimeout(function() { | 177 setTimeout(this.preparePromo_.bind(this, function() { |
| 175 var container = self.document_.querySelector('.dialog-container'); | 178 var container = self.document_.querySelector('.dialog-container'); |
| 176 if (self.isOnGData() && | 179 if (self.isOnGData() && |
| 177 container.getAttribute('gdrive-welcome') != 'header') | 180 container.getAttribute('gdrive-welcome') != 'header') |
| 178 self.showBanner_('page', 'GDATA_WELCOME_TEXT_LONG'); | 181 self.showBanner_('page', 'GDATA_WELCOME_TEXT_LONG'); |
| 179 }, 2000); | 182 }, 2000)); |
| 180 } else if (counter < WELCOME_HEADER_COUNTER_LIMIT) { | 183 } else if (counter < WELCOME_HEADER_COUNTER_LIMIT) { |
| 181 // We do not want to increment the counter when the user navigates | 184 // We do not want to increment the counter when the user navigates |
| 182 // between different directories on GDrive, but we increment the counter | 185 // between different directories on GDrive, but we increment the counter |
| 183 // once anyway to prevent the full page banner from showing. | 186 // once anyway to prevent the full page banner from showing. |
| 184 if (!this.previousDirWasOnGData_ || counter == 0) | 187 if (!this.previousDirWasOnGData_ || counter == 0) { |
| 185 localStorage[WELCOME_HEADER_COUNTER_KEY] = ++counter; | 188 var self = this; |
| 186 this.showBanner_('header', 'GDATA_WELCOME_TEXT_SHORT'); | 189 this.preparePromo_(function() { |
| 190 localStorage[WELCOME_HEADER_COUNTER_KEY] = ++counter; |
| 191 self.showBanner_('header', 'GDATA_WELCOME_TEXT_SHORT'); |
| 192 }); |
| 193 } |
| 187 } else { | 194 } else { |
| 188 this.closeBanner_(); | 195 this.closeBanner_(); |
| 189 } | 196 } |
| 190 this.previousDirWasOnGData_ = true; | 197 this.previousDirWasOnGData_ = true; |
| 191 }; | 198 }; |
| 192 | 199 |
| 193 /** | 200 /** |
| 194 * Show or hide the "Low Google Drive space" warning. | 201 * Show or hide the "Low Google Drive space" warning. |
| 195 * @param {boolean} show True if the box need to be shown. | 202 * @param {boolean} show True if the box need to be shown. |
| 196 * @param {object} sizeStats Size statistics. | 203 * @param {object} sizeStats Size statistics. |
| 197 * @private | 204 * @private |
| 198 */ | 205 */ |
| 199 FileListBannerController.prototype.showLowGDriveSpaceWarning_ = | 206 FileListBannerController.prototype.showLowGDriveSpaceWarning_ = |
| 200 function(show, sizeStats) { | 207 function(show, sizeStats) { |
| 201 var box = this.document_.querySelector('.gdrive-space-warning'); | 208 var box = this.document_.querySelector('.gdrive-space-warning'); |
| 202 | 209 |
| 210 // Avoid showing two banners. |
| 211 // TODO(kaznacheev): Unify the low space warning and the promo header. |
| 212 if (show) this.cleanupGDataWelcome_(); |
| 213 |
| 214 if (box.hidden == !show) return; |
| 215 |
| 203 // If the warning was dismissed before, this key stores the quota value | 216 // If the warning was dismissed before, this key stores the quota value |
| 204 // (as of the moment of dismissal). | 217 // (as of the moment of dismissal). |
| 205 // If the warning was never dismissed or was reset this key stores 0. | 218 // If the warning was never dismissed or was reset this key stores 0. |
| 206 var WARNING_DISMISSED_KEY = 'gdriveSpaceWarningDismissed'; | 219 var WARNING_DISMISSED_KEY = 'gdriveSpaceWarningDismissed'; |
| 207 var dismissed = parseInt(localStorage[WARNING_DISMISSED_KEY] || '0'); | 220 var dismissed = parseInt(localStorage[WARNING_DISMISSED_KEY] || '0'); |
| 208 | 221 |
| 209 if (dismissed) { | 222 if (dismissed) { |
| 210 if (dismissed == sizeStats.totalSizeKB && // Quota had not changed | 223 if (dismissed == sizeStats.totalSizeKB && // Quota had not changed |
| 211 sizeStats.remainingSizeKB / sizeStats.totalSizeKB < 0.15) { | 224 sizeStats.remainingSizeKB / sizeStats.totalSizeKB < 0.15) { |
| 212 // Since the last dismissal decision the quota has not changed AND | 225 // Since the last dismissal decision the quota has not changed AND |
| 213 // the user did not free up significant space. Obey the dismissal. | 226 // the user did not free up significant space. Obey the dismissal. |
| 214 show = false; | 227 show = false; |
| 215 } else { | 228 } else { |
| 216 // Forget the dismissal. Warning will be shown again. | 229 // Forget the dismissal. Warning will be shown again. |
| 217 localStorage[WARNING_DISMISSED_KEY] = 0; | 230 localStorage[WARNING_DISMISSED_KEY] = 0; |
| 218 } | 231 } |
| 219 } | 232 } |
| 220 | 233 |
| 221 // Avoid showing two banners. | |
| 222 // TODO(kaznacheev): Unify the low space warning and the promo header. | |
| 223 if (show) this.cleanupGDataWelcome_(); | |
| 224 | |
| 225 if (box.hidden == !show) return; | |
| 226 | |
| 227 box.textContent = ''; | 234 box.textContent = ''; |
| 228 if (show) { | 235 if (show) { |
| 229 var icon = this.document_.createElement('div'); | 236 var icon = this.document_.createElement('div'); |
| 230 icon.className = 'gdrive-icon'; | 237 icon.className = 'gdrive-icon'; |
| 231 box.appendChild(icon); | 238 box.appendChild(icon); |
| 232 | 239 |
| 233 var text = this.document_.createElement('div'); | 240 var text = this.document_.createElement('div'); |
| 234 text.className = 'gdrive-text'; | 241 text.className = 'gdrive-text'; |
| 235 text.textContent = strf('GDATA_SPACE_AVAILABLE_LONG', | 242 text.textContent = strf('GDATA_SPACE_AVAILABLE_LONG', |
| 236 util.bytesToSi(sizeStats.remainingSizeKB * 1024)); | 243 util.bytesToSi(sizeStats.remainingSizeKB * 1024)); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 // Stop showing the welcome banner. | 337 // Stop showing the welcome banner. |
| 331 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; | 338 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; |
| 332 }; | 339 }; |
| 333 | 340 |
| 334 /** | 341 /** |
| 335 * Shows or hides the Low Disck Space banner. | 342 * Shows or hides the Low Disck Space banner. |
| 336 * @private | 343 * @private |
| 337 */ | 344 */ |
| 338 FileListBannerController.prototype.checkSpaceAndShowBanner_ = function() { | 345 FileListBannerController.prototype.checkSpaceAndShowBanner_ = function() { |
| 339 var self = this; | 346 var self = this; |
| 340 if (this.newWelcome_ && this.isOnGData()) | 347 this.preparePromo_(function() { |
| 341 chrome.fileBrowserPrivate.getSizeStats( | 348 if (this.newWelcome_ && this.isOnGData()) |
| 342 util.makeFilesystemUrl(this.directoryModel_.getCurrentRootPath()), | 349 chrome.fileBrowserPrivate.getSizeStats( |
| 343 function(result) { | 350 util.makeFilesystemUrl(this.directoryModel_.getCurrentRootPath()), |
| 344 if (result.totalSizeKB >= 100 * 1024 * 1024) // Already >= 100 GB. | 351 function(result) { |
| 345 self.newWelcome_ = false; | 352 if (result.totalSizeKB >= 100 * 1024 * 1024) // Already >= 100 GB. |
| 346 self.maybeShowBanner_(); | 353 self.newWelcome_ = false; |
| 347 }); | 354 self.maybeShowBanner_(); |
| 348 else | 355 }); |
| 349 self.maybeShowBanner_(); | 356 else |
| 357 self.maybeShowBanner_(); |
| 358 }); |
| 350 }; | 359 }; |
| 351 | 360 |
| 352 /** | 361 /** |
| 353 * @return {boolean} True if current directory is on Drive. | 362 * @return {boolean} True if current directory is on Drive. |
| 354 */ | 363 */ |
| 355 FileListBannerController.prototype.isOnGData = function() { | 364 FileListBannerController.prototype.isOnGData = function() { |
| 356 return this.directoryModel_.getCurrentRootType() === RootType.GDATA; | 365 return this.directoryModel_.getCurrentRootType() === RootType.GDATA; |
| 357 }; | 366 }; |
| 358 | 367 |
| 359 /** | 368 /** |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 this.ensureGDataUnmountedPanelInitialized_(); | 495 this.ensureGDataUnmountedPanelInitialized_(); |
| 487 } | 496 } |
| 488 if (status == VolumeManager.GDataStatus.ERROR) | 497 if (status == VolumeManager.GDataStatus.ERROR) |
| 489 this.unmountedPanel_.classList.add('retry-enabled'); | 498 this.unmountedPanel_.classList.add('retry-enabled'); |
| 490 node.setAttribute('gdata', status); | 499 node.setAttribute('gdata', status); |
| 491 } else { | 500 } else { |
| 492 node.removeAttribute('gdata'); | 501 node.removeAttribute('gdata'); |
| 493 } | 502 } |
| 494 }; | 503 }; |
| 495 | 504 |
| 505 /** |
| 506 * Detects what type of promo should be shown. |
| 507 * @private |
| 508 */ |
| 509 FileListBannerController.prototype.checkPromoAvailable_ = function() { |
| 510 var r = new XMLHttpRequest(); |
| 511 r.open('HEAD', GOOGLE_DRIVE_REDEEM, true); |
| 512 r.onreadystatechange = function() { |
| 513 if (r.readyState != 4) |
| 514 return; |
| 515 this.newWelcome_ = r.status != 404; |
| 516 if (this.promoCallbacks_) { |
| 517 for (var i = 0; i < this.promoCallbacks_.length; i++) |
| 518 this.promoCallbacks_[i](); |
| 519 this.promoCallbacks_ = undefined; |
| 520 } |
| 521 }.bind(this); |
| 522 r.send(); |
| 523 }; |
| 524 |
| 525 /** |
| 526 * @param {Function} completeCallback To be called (may be directly) when |
| 527 * this.newWelcome_ get ready. |
| 528 * @private |
| 529 */ |
| 530 FileListBannerController.prototype.preparePromo_ = function(completeCallback) { |
| 531 if (this.newWelcome_ !== undefined) |
| 532 completeCallback(); |
| 533 else |
| 534 (this.promoCallbacks_ = this.promoCallbacks_ || []).push(completeCallback); |
| 535 }; |
| 536 |
| OLD | NEW |