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

Side by Side Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 8602009: CrOS: Fix file_watchers_ DCHECK in SelectFileDialogExtensionBrowserTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Setting the src of an img to an empty string can crash the browser, so we 5 // Setting the src of an img to an empty string can crash the browser, so we
6 // use an empty 1x1 gif instead. 6 // use an empty 1x1 gif instead.
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,'
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D';
9 9
10 var g_slideshow_data = null; 10 var g_slideshow_data = null;
(...skipping 3148 matching lines...) Expand 10 before | Expand all | Expand 10 after
3159 if (event.button != 1) 3159 if (event.button != 1)
3160 return; 3160 return;
3161 3161
3162 var li = this.findListItem_(event); 3162 var li = this.findListItem_(event);
3163 if (!li) { 3163 if (!li) {
3164 console.log('li not found', event); 3164 console.log('li not found', event);
3165 return; 3165 return;
3166 } 3166 }
3167 }; 3167 };
3168 3168
3169 FileManager.prototype.onUnload_ = function(event) { 3169 /**
3170 * Unload handler for the page. May be called manually for the file picker
3171 * dialog, because it closes by calling extension API functions that do not
3172 * return.
3173 */
3174 FileManager.prototype.onUnload_ = function() {
3170 if (this.subscribedOnDirectoryChanges_) { 3175 if (this.subscribedOnDirectoryChanges_) {
3171 chrome.fileBrowserPrivate.removeFileWatch(event.previousDirEntry.toURL(), 3176 this.subscribedOnDirectoryChanges_ = false;
3177 chrome.fileBrowserPrivate.removeFileWatch(this.currentDirEntry_.toURL(),
3172 function(result) { 3178 function(result) {
3173 if (!result) { 3179 if (!result) {
3174 console.log('Failed to remove file watch'); 3180 console.log('Failed to remove file watch');
3175 } 3181 }
3176 }); 3182 });
3177 } 3183 }
3178 }; 3184 };
3179 3185
3180 FileManager.prototype.onFileChanged_ = function(event) { 3186 FileManager.prototype.onFileChanged_ = function(event) {
3181 // We receive a lot of events even in folders we are not interested in. 3187 // We receive a lot of events even in folders we are not interested in.
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
3568 if (name.substring(0, text.length).toLowerCase() == text) { 3574 if (name.substring(0, text.length).toLowerCase() == text) {
3569 this.currentList_.selectionModel.selectedIndexes = [index]; 3575 this.currentList_.selectionModel.selectedIndexes = [index];
3570 return; 3576 return;
3571 } 3577 }
3572 } 3578 }
3573 3579
3574 this.textSearchState_.text = ''; 3580 this.textSearchState_.text = '';
3575 }; 3581 };
3576 3582
3577 /** 3583 /**
3578 * Handle a click of the cancel button. Closes the window. 3584 * Handle a click of the cancel button. Closes the window. Does not return.
3585 * TODO(jamescook): Make unload handler work automatically, crbug.com/104811
3579 * 3586 *
3580 * @param {Event} event The click event. 3587 * @param {Event} event The click event.
3581 */ 3588 */
3582 FileManager.prototype.onCancel_ = function(event) { 3589 FileManager.prototype.onCancel_ = function(event) {
3590 this.onUnload_();
3583 // Closes the window and does not return. 3591 // Closes the window and does not return.
3584 chrome.fileBrowserPrivate.cancelDialog(); 3592 chrome.fileBrowserPrivate.cancelDialog();
3585 }; 3593 };
3586 3594
3587 /** 3595 /**
3596 * Selects a file. Closes the window. Does not return.
3597 * TODO(jamescook): Make unload handler work automatically, crbug.com/104811
3598 *
3599 * @param {string} fileUrl The filename as a URL.
3600 * @param {number} filterIndex The integer file filter index.
3601 */
3602 FileManager.prototype.selectFile_ = function(fileUrl, filterIndex) {
3603 this.onUnload_();
3604 // Closes the window and does not return.
3605 chrome.fileBrowserPrivate.selectFile(fileUrl, filterIndex);
3606 };
3607
3608 /**
3609 * Selects multiple files. Closes the window. Does not return.
3610 * TODO(jamescook): Make unload handler work automatically, crbug.com/104811
3611 *
3612 * @param {Array.<string>} fileUrls Array of filename URLs.
3613 */
3614 FileManager.prototype.selectFiles_ = function(fileUrls) {
3615 this.onUnload_();
3616 // Closes the window and does not return.
3617 chrome.fileBrowserPrivate.selectFiles(fileUrls);
3618 };
3619
3620 /**
3588 * Handle a click of the ok button. 3621 * Handle a click of the ok button.
3589 * 3622 *
3590 * The ok button has different UI labels depending on the type of dialog, but 3623 * The ok button has different UI labels depending on the type of dialog, but
3591 * in code it's always referred to as 'ok'. 3624 * in code it's always referred to as 'ok'.
3592 * 3625 *
3593 * @param {Event} event The click event. 3626 * @param {Event} event The click event.
3594 */ 3627 */
3595 FileManager.prototype.onOk_ = function(event) { 3628 FileManager.prototype.onOk_ = function(event) {
3596 var currentDirUrl = this.currentDirEntry_.toURL(); 3629 var currentDirUrl = this.currentDirEntry_.toURL();
3597 3630
3598 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') 3631 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/')
3599 currentDirUrl += '/'; 3632 currentDirUrl += '/';
3600 3633
3601 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { 3634 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) {
3602 // Save-as doesn't require a valid selection from the list, since 3635 // Save-as doesn't require a valid selection from the list, since
3603 // we're going to take the filename from the text input. 3636 // we're going to take the filename from the text input.
3604 var filename = this.filenameInput_.value; 3637 var filename = this.filenameInput_.value;
3605 if (!filename) 3638 if (!filename)
3606 throw new Error('Missing filename!'); 3639 throw new Error('Missing filename!');
3607 if (!this.validateFileName_(filename)) 3640 if (!this.validateFileName_(filename))
3608 return; 3641 return;
3609 3642
3610 var self = this; 3643 var self = this;
3611 function resolveCallback(victim) { 3644 function resolveCallback(victim) {
3612 if (victim instanceof FileError) { 3645 if (victim instanceof FileError) {
3613 // File does not exist. (NB: selectFile Closes the window and does 3646 // File does not exist. Closes the window and does not return.
3614 // not return.) 3647 self.selectFile_(
3615 chrome.fileBrowserPrivate.selectFile(
3616 currentDirUrl + encodeURIComponent(filename), 3648 currentDirUrl + encodeURIComponent(filename),
3617 self.getSelectedFilterIndex_(filename)); 3649 self.getSelectedFilterIndex_(filename));
3618 } 3650 }
3619 3651
3620 if (victim.isDirectory) { 3652 if (victim.isDirectory) {
3621 // Do not allow to overwrite directory. 3653 // Do not allow to overwrite directory.
3622 self.alert.show(strf('DIRECTORY_ALREADY_EXISTS', filename)); 3654 self.alert.show(strf('DIRECTORY_ALREADY_EXISTS', filename));
3623 } else { 3655 } else {
3624 self.confirm.show(strf('CONFIRM_OVERWRITE_FILE', filename), 3656 self.confirm.show(strf('CONFIRM_OVERWRITE_FILE', filename),
3625 function() { 3657 function() {
3626 // User selected Ok from the confirm dialog. 3658 // User selected Ok from the confirm dialog.
3627 chrome.fileBrowserPrivate.selectFile( 3659 self.selectFile_(
3628 currentDirUrl + encodeURIComponent(filename), 3660 currentDirUrl + encodeURIComponent(filename),
3629 self.getSelectedFilterIndex_(filename)); 3661 self.getSelectedFilterIndex_(filename));
3630 }); 3662 });
3631 } 3663 }
3632 return; 3664 return;
3633 } 3665 }
3634 3666
3635 this.resolvePath(this.currentDirEntry_.fullPath + '/' + filename, 3667 this.resolvePath(this.currentDirEntry_.fullPath + '/' + filename,
3636 resolveCallback, resolveCallback); 3668 resolveCallback, resolveCallback);
3637 return; 3669 return;
(...skipping 14 matching lines...) Expand all
3652 console.log('Error locating selected file at index: ' + i); 3684 console.log('Error locating selected file at index: ' + i);
3653 continue; 3685 continue;
3654 } 3686 }
3655 3687
3656 ary.push(currentDirUrl + encodeURIComponent(entry.name)); 3688 ary.push(currentDirUrl + encodeURIComponent(entry.name));
3657 } 3689 }
3658 3690
3659 // Multi-file selection has no other restrictions. 3691 // Multi-file selection has no other restrictions.
3660 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { 3692 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) {
3661 // Closes the window and does not return. 3693 // Closes the window and does not return.
3662 chrome.fileBrowserPrivate.selectFiles(ary); 3694 this.selectFiles_(ary);
3663 return; 3695 return;
3664 } 3696 }
3665 3697
3666 // In full screen mode, open all files for vieweing. 3698 // In full screen mode, open all files for vieweing.
3667 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { 3699 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) {
3668 if (this.galleryTask_) { 3700 if (this.galleryTask_) {
3669 var urls = []; 3701 var urls = [];
3670 for (i = 0; i < selectedIndexes.length; i++) { 3702 for (i = 0; i < selectedIndexes.length; i++) {
3671 var entry = this.dataModel_.item(selectedIndexes[i]); 3703 var entry = this.dataModel_.item(selectedIndexes[i]);
3672 if (this.getFileType(entry).type != 'image') 3704 if (this.getFileType(entry).type != 'image')
(...skipping 18 matching lines...) Expand all
3691 3723
3692 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { 3724 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) {
3693 if (!selectedEntry.isDirectory) 3725 if (!selectedEntry.isDirectory)
3694 throw new Error('Selected entry is not a folder!'); 3726 throw new Error('Selected entry is not a folder!');
3695 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { 3727 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) {
3696 if (!selectedEntry.isFile) 3728 if (!selectedEntry.isFile)
3697 throw new Error('Selected entry is not a file!'); 3729 throw new Error('Selected entry is not a file!');
3698 } 3730 }
3699 3731
3700 // Closes the window and does not return. 3732 // Closes the window and does not return.
3701 chrome.fileBrowserPrivate.selectFile( 3733 this.selectFile_(ary[0], this.getSelectedFilterIndex_(ary[0]));
3702 ary[0], this.getSelectedFilterIndex_(ary[0]));
3703 }; 3734 };
3704 3735
3705 /** 3736 /**
3706 * Verifies the user entered name for file or folder to be created or 3737 * Verifies the user entered name for file or folder to be created or
3707 * renamed to. Name restrictions must correspond to File API restrictions 3738 * renamed to. Name restrictions must correspond to File API restrictions
3708 * (see DOMFilePath::isValidPath). Curernt WebKit implementation is 3739 * (see DOMFilePath::isValidPath). Curernt WebKit implementation is
3709 * out of date (spec is 3740 * out of date (spec is
3710 * http://dev.w3.org/2009/dap/file-system/file-dir-sys.html, 8.3) and going to 3741 * http://dev.w3.org/2009/dap/file-system/file-dir-sys.html, 8.3) and going to
3711 * be fixed. Shows message box if the name is invalid. 3742 * be fixed. Shows message box if the name is invalid.
3712 * 3743 *
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
3783 }); 3814 });
3784 }, onError); 3815 }, onError);
3785 3816
3786 function onError(err) { 3817 function onError(err) {
3787 console.log('Error while checking free space: ' + err); 3818 console.log('Error while checking free space: ' + err);
3788 setTimeout(doCheck, 1000 * 60); 3819 setTimeout(doCheck, 1000 * 60);
3789 } 3820 }
3790 } 3821 }
3791 } 3822 }
3792 })(); 3823 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698