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

Unified Diff: chrome/browser/resources/chromeos/wallpaper_manager/js/butter_bar.js

Issue 10909125: Add butter bar for wallpapaer manager(show downloading progress or error message) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/wallpaper_manager/js/butter_bar.js
diff --git a/chrome/browser/resources/file_manager/js/butter_bar.js b/chrome/browser/resources/chromeos/wallpaper_manager/js/butter_bar.js
similarity index 60%
copy from chrome/browser/resources/file_manager/js/butter_bar.js
copy to chrome/browser/resources/chromeos/wallpaper_manager/js/butter_bar.js
index dcbb37f3750e170e517e08e94364125f9bf86fb2..1106dc4b46b36ac6fa60134cb0a661b5800b25e1 100644
--- a/chrome/browser/resources/file_manager/js/butter_bar.js
+++ b/chrome/browser/resources/chromeos/wallpaper_manager/js/butter_bar.js
@@ -10,25 +10,28 @@
var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300;
/**
- * Butter bar is shown on top of the file list and is used to show the copy
- * progress and other messages.
+ * Butter bar is shown on top of the wallpaper manager and is used to show the
+ * downloading progress and other messages.
* @constructor
- * @param {HTMLElement} dialogDom FileManager top-level div.
- * @param {FileCopyManagerWrapper} copyManager The copy manager.
+ * @param {HTMLElement} dialogDom Wallpaper manager body tag.
*/
-function ButterBar(dialogDom, copyManager) {
+function ButterBar(dialogDom) {
this.dialogDom_ = dialogDom;
this.butter_ = this.dialogDom_.querySelector('#butter-bar');
this.document_ = this.butter_.ownerDocument;
- this.copyManager_ = copyManager;
this.hideTimeout_ = null;
this.showTimeout_ = null;
this.lastShowTime_ = 0;
-
- this.copyManager_.addEventListener('copy-progress',
- this.onCopyProgress_.bind(this));
}
+// Functions may be reused for general butter bar : ----------------------------
+
+// These functions are copied from butter_bar.js in file manager. We will
+// revisit it to see if we can share some code after butter bar is integrated
+// with Photo Editor.
+// See http://codereview.chromium.org/10916149/ for details.
+// TODO(bshe): Remove these functions if we can share code with file manager.
+
/**
* @return {boolean} True if visible.
* @private
@@ -45,7 +48,7 @@ ButterBar.prototype.isError_ = function() {
return this.butter_.classList.contains('error');
};
- /**
+/**
* Show butter bar.
* @param {string} message The message to be shown.
* @param {object} opt_options Options: 'actions', 'progress', 'timeout'.
@@ -182,99 +185,97 @@ ButterBar.prototype.clearHideTimeout_ = function() {
}
};
+// Functions specific to WallpaperManager butter bar : -------------------------
+
/**
- * @private
- * @return {string?} The type of operation.
+ * Sets the XMLHttpRequest object that we want to show progress.
+ * @param {XMLHttpRequest} xhr The XMLHttpRequest.
*/
-ButterBar.prototype.transferType_ = function() {
- var progress = this.progress_;
- if (!progress ||
- progress.pendingMoves === 0 && progress.pendingCopies === 0)
- return 'TRANSFER';
-
- if (progress.pendingMoves > 0) {
- if (progress.pendingCopies > 0)
- return 'TRANSFER';
- return 'MOVE';
- }
-
- return 'COPY';
+ButterBar.prototype.setRequest = function(xhr) {
+ if (this.xhr_)
Vladislav Kaznacheev 2012/09/12 13:45:12 Formatting: extra space after this.xhr everywhere
bshe 2012/09/12 18:48:58 you mean this.xhr_? I dont think I have an extra s
+ this.xhr_.abort();
+ this.xhr_ = xhr;
+ this.xhr_.addEventListener('loadstart',
+ this.onDownloadStart_.bind(this));
+ this.xhr_.addEventListener('progress',
+ this.onDownloadProgress_.bind(this));
+ this.xhr_.addEventListener('abort',
+ this.onDownloadAbort_.bind(this));
+ this.xhr_.addEventListener('error',
+ this.onDownloadError_.bind(this));
+ this.xhr_.addEventListener('load',
+ this.onDownloadComplete_.bind(this));
};
/**
- * Set up butter bar for showing copy progress.
+ * Sets the options and strings and shows progress on butter bar.
* @private
*/
ButterBar.prototype.showProgress_ = function() {
- this.progress_ = this.copyManager_.getStatus();
- var options = {progress: this.progress_.percentage, actions: {}, timeout: 0};
+ var options = {progress: this.percentComplete_, actions: {},
+ timeout: 0};
- var type = this.transferType_();
- var progressString = (this.progress_.pendingItems === 1) ?
- strf(type + '_FILE_NAME', this.progress_.filename) :
- strf(type + '_ITEMS_REMAINING', this.progress_.pendingItems);
+ var progressString = 'Downloading';
if (this.isVisible_()) {
this.update_(progressString, options);
} else {
- options.actions[str('CANCEL_LABEL')] =
- this.copyManager_.requestCancel.bind(this.copyManager_);
+ options.actions['Cancel'] = function() {
+ this.xhr_.abort();
+ };
this.show(progressString, options);
}
};
/**
- * 'copy-progress' event handler. Show progress or an appropriate message.
+ * Sets a timeout to show a butter bar when wallpaper downloading starts.
* @private
- * @param {cr.Event} event A 'copy-progress' event from FileCopyManager.
+ * @param {ProgressEvent} e A loadstart ProgressEvent from XMLHttpRequest.
*/
-ButterBar.prototype.onCopyProgress_ = function(event) {
- if (event.reason != 'PROGRESS')
- this.clearShowTimeout_();
-
- switch (event.reason) {
- case 'BEGIN':
- this.showTimeout_ = setTimeout(function() {
- this.showTimeout_ = null;
- this.showProgress_();
- }.bind(this), 500);
- break;
-
- case 'PROGRESS':
- this.showProgress_();
- break;
-
- case 'SUCCESS':
- this.hide_();
- break;
-
- case 'CANCELLED':
- this.show(str(this.transferType_() + '_CANCELLED'), {timeout: 1000});
- break;
-
- case 'ERROR':
- if (event.error.reason === 'TARGET_EXISTS') {
- var name = event.error.data.name;
- if (event.error.data.isDirectory)
- name += '/';
- this.showError_(strf(this.transferType_() +
- '_TARGET_EXISTS_ERROR', name));
- } else if (event.error.reason === 'FILESYSTEM_ERROR') {
- if (event.error.data.toGDrive &&
- event.error.data.code === FileError.QUOTA_EXCEEDED_ERR) {
- // The alert will be shown in FileManager.onCopyProgress_.
- this.hide_();
- } else {
- this.showError_(strf(this.transferType_() + '_FILESYSTEM_ERROR',
- util.getFileErrorString(event.error.data.code)));
- }
- } else {
- this.showError_(strf(this.transferType_() + '_UNEXPECTED_ERROR',
- event.error));
- }
- break;
-
- default:
- console.log('Unknown "copy-progress" event reason: ' + event.reason);
+ButterBar.prototype.onDownloadStart_ = function(e) {
+ this.percentComplete_ = 0;
+ this.showTimeout_ = setTimeout(function() {
+ this.showTimeout_ = null;
+ this.showProgress_();
+ }.bind(this), 500);
+};
+
+/**
+ * Shows abort message in butter bar for 1 second if wallpaper downloading
+ * aborted.
+ * @private
+ * @param {ProgressEvent} e An abort ProgressEvent from XMLHttpRequest.
+ */
+ButterBar.prototype. onDownloadAbort_ = function(e) {
+ this.show('Downloading aborted', {timeout: 1000});
+};
+
+/**
+ * Hides butter bar when download complete.
+ * @private
+ * @param {ProgressEvent} e A load ProgressEvent from XMLHttpRequest.
+ */
+ButterBar.prototype. onDownloadComplete_ = function(e) {
+ this.hide_();
+};
+
+/**
+ * Shows error message when receiving an error event.
+ * @private
+ * @param {ProgressEvent} e An error ProgressEvent from XMLHttpRequest.
+ */
+ButterBar.prototype. onDownloadError_ = function(e) {
+ this.showError_('An error occured while downloading wallpaper');
+};
+
+/**
+ * Calculates downloading percentage and shows downloading progress.
+ * @private
+ * @param {ProgressEvent} e A progress ProgressEvent from XMLHttpRequest.
Vladislav Kaznacheev 2012/09/12 13:45:12 The description does not parse.
bshe 2012/09/12 18:48:58 Done.
+ */
+ButterBar.prototype.onDownloadProgress_ = function(e) {
+ if (e.lengthComputable) {
+ this.percentComplete_ = e.loaded / e.total;
}
+ this.showProgress_();
};

Powered by Google App Engine
This is Rietveld 408576698