Chromium Code Reviews| 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 {DOMDocument} document HTML document. | 8 * @param {DOMDocument} document HTML document. |
| 9 * @constructor | 9 * @constructor |
| 10 */ | 10 */ |
| 11 function FileListBannerController(directoryModel, document) { | 11 function FileListBannerController(directoryModel, document) { |
| 12 this.directoryModel_ = directoryModel; | 12 this.directoryModel_ = directoryModel; |
| 13 this.document_ = document; | 13 this.document_ = document; |
| 14 this.driveEnabled_ = false; | 14 this.driveEnabled_ = false; |
| 15 | 15 |
| 16 var board = str('CHROMEOS_RELEASE_BOARD'); | 16 var board = str('CHROMEOS_RELEASE_BOARD'); |
| 17 // It is 'canary' or 'beta' for the other channels. | 17 if (board.match(/^(stumpy|lumpy)/i)) |
| 18 var releaseChannel = str('BROWSER_VERSION_MODIFIER') == ''; | 18 this.checkPromoAvailable_(); |
| 19 this.newWelcome_ = board.match(/^(stumpy|lumpy)/i) && releaseChannel; | 19 else |
| 20 this.newWelcome_ = false; | |
| 20 | 21 |
| 21 var handler = this.checkSpaceAndShowBanner_.bind(this); | 22 var handler = this.checkSpaceAndShowBanner_.bind(this); |
| 22 this.directoryModel_.addEventListener('scan-completed', handler); | 23 this.directoryModel_.addEventListener('scan-completed', handler); |
| 23 this.directoryModel_.addEventListener('rescan-completed', handler); | 24 this.directoryModel_.addEventListener('rescan-completed', handler); |
| 24 this.directoryModel_.addEventListener('directory-changed', | 25 this.directoryModel_.addEventListener('directory-changed', |
| 25 this.onDirectoryChanged_.bind(this)); | 26 this.onDirectoryChanged_.bind(this)); |
| 26 } | 27 } |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * FileListBannerController extends cr.EventTarget. | 30 * FileListBannerController extends cr.EventTarget. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 51 */ | 52 */ |
| 52 var GOOGLE_DRIVE_FAQ_URL = | 53 var GOOGLE_DRIVE_FAQ_URL = |
| 53 'https://support.google.com/chromeos/?p=filemanager_drive'; | 54 'https://support.google.com/chromeos/?p=filemanager_drive'; |
| 54 | 55 |
| 55 /** | 56 /** |
| 56 * Location of the page to buy more storage for Google Drive. | 57 * Location of the page to buy more storage for Google Drive. |
| 57 */ | 58 */ |
| 58 var GOOGLE_DRIVE_BUY_STORAGE = | 59 var GOOGLE_DRIVE_BUY_STORAGE = |
| 59 'https://www.google.com/settings/storage'; | 60 'https://www.google.com/settings/storage'; |
| 60 | 61 |
| 62 var GOOGLE_DRIVE_REDEEM = 'https://drive.google.com/redeem'; | |
| 63 | |
| 61 /** | 64 /** |
| 62 * Location of the FAQ about the downloads directory. | 65 * Location of the FAQ about the downloads directory. |
| 63 */ | 66 */ |
| 64 var DOWNLOADS_FAQ_URL = | 67 var DOWNLOADS_FAQ_URL = |
| 65 'http://support.google.com/chromeos/bin/answer.py?answer=1061547'; | 68 'http://support.google.com/chromeos/bin/answer.py?answer=1061547'; |
| 66 | 69 |
| 67 /** | 70 /** |
| 68 * @return {number} How many times the Drive Welcome header banner has shown. | 71 * @return {number} How many times the Drive Welcome header banner has shown. |
| 69 * @private | 72 * @private |
| 70 */ | 73 */ |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 } | 155 } |
| 153 | 156 |
| 154 var counter = this.getHeaderCounter_(); | 157 var counter = this.getHeaderCounter_(); |
| 155 | 158 |
| 156 if (this.directoryModel_.getFileList().length == 0 && counter == 0) { | 159 if (this.directoryModel_.getFileList().length == 0 && counter == 0) { |
| 157 // Only show the full page banner if the header banner was never shown. | 160 // Only show the full page banner if the header banner was never shown. |
| 158 // Do not increment the counter. | 161 // Do not increment the counter. |
| 159 // The timeout below is required because sometimes another | 162 // The timeout below is required because sometimes another |
| 160 // 'rescan-completed' event arrives shortly with non-empty file list. | 163 // 'rescan-completed' event arrives shortly with non-empty file list. |
| 161 var self = this; | 164 var self = this; |
| 162 setTimeout(function() { | 165 setTimeout(this.preparePromo_.bind(this, function() { |
| 163 var container = self.document_.querySelector('.dialog-container'); | 166 var container = self.document_.querySelector('.dialog-container'); |
| 164 if (self.isOnGData() && | 167 if (self.isOnGData() && |
| 165 container.getAttribute('gdrive-welcome') != 'header') | 168 container.getAttribute('gdrive-welcome') != 'header') |
| 166 self.showBanner_('page', 'GDATA_WELCOME_TEXT_LONG'); | 169 self.showBanner_('page', 'GDATA_WELCOME_TEXT_LONG'); |
| 167 }, 2000); | 170 }, 2000)); |
| 168 } else if (counter < WELCOME_HEADER_COUNTER_LIMIT) { | 171 } else if (counter < WELCOME_HEADER_COUNTER_LIMIT) { |
| 169 // We do not want to increment the counter when the user navigates | 172 // We do not want to increment the counter when the user navigates |
| 170 // between different directories on GDrive, but we increment the counter | 173 // between different directories on GDrive, but we increment the counter |
| 171 // once anyway to prevent the full page banner from showing. | 174 // once anyway to prevent the full page banner from showing. |
| 172 if (!this.previousDirWasOnGData_ || counter == 0) | 175 if (!this.previousDirWasOnGData_ || counter == 0) { |
| 173 localStorage[WELCOME_HEADER_COUNTER_KEY] = ++counter; | 176 var self = this; |
| 174 this.showBanner_('header', 'GDATA_WELCOME_TEXT_SHORT'); | 177 this.preparePromo_(function() { |
| 178 localStorage[WELCOME_HEADER_COUNTER_KEY] = ++counter; | |
| 179 self.showBanner_('header', 'GDATA_WELCOME_TEXT_SHORT'); | |
| 180 }); | |
| 181 } | |
| 175 } else { | 182 } else { |
| 176 this.closeBanner_(); | 183 this.closeBanner_(); |
| 177 } | 184 } |
| 178 this.previousDirWasOnGData_ = true; | 185 this.previousDirWasOnGData_ = true; |
| 179 }; | 186 }; |
| 180 | 187 |
| 181 /** | 188 /** |
| 182 * Show or hide the "Low Google Drive space" warning. | 189 * Show or hide the "Low Google Drive space" warning. |
| 183 * @param {boolean} show True if the box need to be shown. | 190 * @param {boolean} show True if the box need to be shown. |
| 184 * @param {object} sizeStats Size statistics. | 191 * @param {object} sizeStats Size statistics. |
| 185 * @private | 192 * @private |
| 186 */ | 193 */ |
| 187 FileListBannerController.prototype.showLowGDriveSpaceWarning_ = | 194 FileListBannerController.prototype.showLowGDriveSpaceWarning_ = |
| 188 function(show, sizeStats) { | 195 function(show, sizeStats) { |
| 189 var box = this.document_.querySelector('.gdrive-space-warning'); | 196 var box = this.document_.querySelector('.gdrive-space-warning'); |
| 190 | 197 |
| 198 // Avoid showing two banners. | |
| 199 // TODO(kaznacheev): Unify the low space warning and the promo header. | |
| 200 if (show) this.cleanupGDataWelcome_(); | |
| 201 | |
| 202 if (box.hidden == !show) return; | |
| 203 | |
| 191 // If the warning was dismissed before, this key stores the quota value | 204 // If the warning was dismissed before, this key stores the quota value |
| 192 // (as of the moment of dismissal). | 205 // (as of the moment of dismissal). |
| 193 // If the warning was never dismissed or was reset this key stores 0. | 206 // If the warning was never dismissed or was reset this key stores 0. |
| 194 var WARNING_DISMISSED_KEY = 'gdriveSpaceWarningDismissed'; | 207 var WARNING_DISMISSED_KEY = 'gdriveSpaceWarningDismissed'; |
| 195 var dismissed = parseInt(localStorage[WARNING_DISMISSED_KEY] || '0'); | 208 var dismissed = parseInt(localStorage[WARNING_DISMISSED_KEY] || '0'); |
| 196 | 209 |
| 197 if (dismissed) { | 210 if (dismissed) { |
| 198 if (dismissed == sizeStats.totalSizeKB && // Quota had not changed | 211 if (dismissed == sizeStats.totalSizeKB && // Quota had not changed |
| 199 sizeStats.remainingSizeKB / sizeStats.totalSizeKB < 0.15) { | 212 sizeStats.remainingSizeKB / sizeStats.totalSizeKB < 0.15) { |
| 200 // Since the last dismissal decision the quota has not changed AND | 213 // Since the last dismissal decision the quota has not changed AND |
| 201 // the user did not free up significant space. Obey the dismissal. | 214 // the user did not free up significant space. Obey the dismissal. |
| 202 show = false; | 215 show = false; |
| 203 } else { | 216 } else { |
| 204 // Forget the dismissal. Warning will be shown again. | 217 // Forget the dismissal. Warning will be shown again. |
| 205 localStorage[WARNING_DISMISSED_KEY] = 0; | 218 localStorage[WARNING_DISMISSED_KEY] = 0; |
| 206 } | 219 } |
| 207 } | 220 } |
| 208 | 221 |
| 209 // Avoid showing two banners. | |
| 210 // TODO(kaznacheev): Unify the low space warning and the promo header. | |
| 211 if (show) this.cleanupGDataWelcome_(); | |
| 212 | |
| 213 if (box.hidden == !show) return; | |
| 214 | |
| 215 box.textContent = ''; | 222 box.textContent = ''; |
| 216 if (show) { | 223 if (show) { |
| 217 var icon = this.document_.createElement('div'); | 224 var icon = this.document_.createElement('div'); |
| 218 icon.className = 'gdrive-icon'; | 225 icon.className = 'gdrive-icon'; |
| 219 box.appendChild(icon); | 226 box.appendChild(icon); |
| 220 | 227 |
| 221 var text = this.document_.createElement('div'); | 228 var text = this.document_.createElement('div'); |
| 222 text.className = 'gdrive-text'; | 229 text.className = 'gdrive-text'; |
| 223 text.textContent = strf('GDATA_SPACE_AVAILABLE_LONG', | 230 text.textContent = strf('GDATA_SPACE_AVAILABLE_LONG', |
| 224 util.bytesToSi(sizeStats.remainingSizeKB * 1024)); | 231 util.bytesToSi(sizeStats.remainingSizeKB * 1024)); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 // Stop showing the welcome banner. | 325 // Stop showing the welcome banner. |
| 319 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; | 326 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; |
| 320 }; | 327 }; |
| 321 | 328 |
| 322 /** | 329 /** |
| 323 * Shows or hides the Low Disck Space banner. | 330 * Shows or hides the Low Disck Space banner. |
| 324 * @private | 331 * @private |
| 325 */ | 332 */ |
| 326 FileListBannerController.prototype.checkSpaceAndShowBanner_ = function() { | 333 FileListBannerController.prototype.checkSpaceAndShowBanner_ = function() { |
| 327 var self = this; | 334 var self = this; |
| 328 if (this.newWelcome_ && this.isOnGData()) | 335 this.preparePromo_(function() { |
| 329 chrome.fileBrowserPrivate.getSizeStats( | 336 if (this.newWelcome_ && this.isOnGData()) |
| 330 util.makeFilesystemUrl(this.directoryModel_.getCurrentRootPath()), | 337 chrome.fileBrowserPrivate.getSizeStats( |
| 331 function(result) { | 338 util.makeFilesystemUrl(this.directoryModel_.getCurrentRootPath()), |
| 332 if (result.totalSizeKB >= 100 * 1024 * 1024) // Already >= 100 GB. | 339 function(result) { |
| 333 self.newWelcome_ = false; | 340 if (result.totalSizeKB >= 100 * 1024 * 1024) // Already >= 100 GB. |
| 334 self.maybeShowBanner_(); | 341 self.newWelcome_ = false; |
| 335 }); | 342 self.maybeShowBanner_(); |
| 336 else | 343 }); |
| 337 self.maybeShowBanner_(); | 344 else |
| 345 self.maybeShowBanner_(); | |
| 346 }); | |
| 338 }; | 347 }; |
| 339 | 348 |
| 340 /** | 349 /** |
| 341 * @return {boolean} True if current directory is on Drive. | 350 * @return {boolean} True if current directory is on Drive. |
| 342 */ | 351 */ |
| 343 FileListBannerController.prototype.isOnGData = function() { | 352 FileListBannerController.prototype.isOnGData = function() { |
| 344 return this.directoryModel_.getCurrentRootType() === RootType.GDATA; | 353 return this.directoryModel_.getCurrentRootType() === RootType.GDATA; |
| 345 }; | 354 }; |
| 346 | 355 |
| 347 /** | 356 /** |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 var link = box.querySelector('a'); | 416 var link = box.querySelector('a'); |
| 408 link.href = DOWNLOADS_FAQ_URL; | 417 link.href = DOWNLOADS_FAQ_URL; |
| 409 } else { | 418 } else { |
| 410 box.innerHTML = ''; | 419 box.innerHTML = ''; |
| 411 } | 420 } |
| 412 | 421 |
| 413 box.hidden = !show; | 422 box.hidden = !show; |
| 414 this.requestRelayout_(100); | 423 this.requestRelayout_(100); |
| 415 }; | 424 }; |
| 416 | 425 |
| 426 /** | |
| 427 * Detects what type of promo should be shown. | |
| 428 * @private | |
| 429 */ | |
| 430 FileListBannerController.prototype.checkPromoAvailable_ = function() { | |
| 431 var r = new XMLHttpRequest(); | |
| 432 var self = this; | |
|
Vladislav Kaznacheev
2012/09/14 12:18:45
Why not bind(this)? It would save you 1 line of th
SeRya
2012/09/14 14:36:23
Done.
| |
| 433 r.open('HEAD', GOOGLE_DRIVE_REDEEM, true); | |
| 434 r.onreadystatechange = function() { | |
| 435 if (r.readyState != 4) | |
| 436 return; | |
| 437 self.newWelcome_ = r.status == 404; | |
|
Vladislav Kaznacheev
2012/09/14 12:18:45
It will show you the new welcome today, right?
I t
SeRya
2012/09/14 14:36:23
Done.
| |
| 438 if (self.promoCallbacks_) { | |
| 439 for (var i = 0; i < self.promoCallbacks_.length; i++) | |
| 440 self.promoCallbacks_[i](); | |
| 441 self.promoCallbacks_ = undefined; | |
| 442 } | |
| 443 }; | |
| 444 r.send(); | |
| 445 }; | |
| 446 | |
| 447 /** | |
| 448 * @param {Function} completeCallback To be called (may be directly) when | |
| 449 * this.newWelcome_ get ready. | |
| 450 * @private | |
| 451 */ | |
| 452 FileListBannerController.prototype.preparePromo_ = function(completeCallback) { | |
| 453 if (this.newWelcome_ !== undefined) | |
| 454 completeCallback(); | |
| 455 else | |
| 456 (this.promoCallbacks_ = this.promoCallbacks_ || []).push(completeCallback); | |
| 457 }; | |
| 458 | |
| OLD | NEW |