summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-18 23:57:59 +0000
committerjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-18 23:57:59 +0000
commit0f9c4556b26ffb55cea457dfeeec9be2924612d1 (patch)
tree5ea72169f6ebe9786491a0d445e13b1b66e44e1d
parent0cc6fc92e4440bdd6329c64e019a65f4b38edbc7 (diff)
downloadchromium_src-0f9c4556b26ffb55cea457dfeeec9be2924612d1.zip
chromium_src-0f9c4556b26ffb55cea457dfeeec9be2924612d1.tar.gz
chromium_src-0f9c4556b26ffb55cea457dfeeec9be2924612d1.tar.bz2
CrOS: Fix file_watchers_ DCHECK in SelectFileDialogExtensionBrowserTest
The CrOS file picker closes the dialog immediately, without running the page unload handler. This meant we were leaking file watcher objects, causing a DCHECK in SelectFileDialogExtensionBrowserTest. Fixed by calling it manually when needed. Also, we need to clean up the current directory's watcher, because we don't have a directory-change event in the unload handler that we can use to look up the directory path. BUG=104692,103491 TEST=browser_tests, also verify you can open a file with control-O Review URL: http://codereview.chromium.org/8602009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110789 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/resources/file_manager/js/file_manager.js51
1 files changed, 41 insertions, 10 deletions
diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js
index 69c6c38..c41b1c3 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -3166,9 +3166,15 @@ FileManager.prototype = {
}
};
- FileManager.prototype.onUnload_ = function(event) {
+ /**
+ * Unload handler for the page. May be called manually for the file picker
+ * dialog, because it closes by calling extension API functions that do not
+ * return.
+ */
+ FileManager.prototype.onUnload_ = function() {
if (this.subscribedOnDirectoryChanges_) {
- chrome.fileBrowserPrivate.removeFileWatch(event.previousDirEntry.toURL(),
+ this.subscribedOnDirectoryChanges_ = false;
+ chrome.fileBrowserPrivate.removeFileWatch(this.currentDirEntry_.toURL(),
function(result) {
if (!result) {
console.log('Failed to remove file watch');
@@ -3575,16 +3581,43 @@ FileManager.prototype = {
};
/**
- * Handle a click of the cancel button. Closes the window.
+ * Handle a click of the cancel button. Closes the window. Does not return.
+ * TODO(jamescook): Make unload handler work automatically, crbug.com/104811
*
* @param {Event} event The click event.
*/
FileManager.prototype.onCancel_ = function(event) {
+ this.onUnload_();
// Closes the window and does not return.
chrome.fileBrowserPrivate.cancelDialog();
};
/**
+ * Selects a file. Closes the window. Does not return.
+ * TODO(jamescook): Make unload handler work automatically, crbug.com/104811
+ *
+ * @param {string} fileUrl The filename as a URL.
+ * @param {number} filterIndex The integer file filter index.
+ */
+ FileManager.prototype.selectFile_ = function(fileUrl, filterIndex) {
+ this.onUnload_();
+ // Closes the window and does not return.
+ chrome.fileBrowserPrivate.selectFile(fileUrl, filterIndex);
+ };
+
+ /**
+ * Selects multiple files. Closes the window. Does not return.
+ * TODO(jamescook): Make unload handler work automatically, crbug.com/104811
+ *
+ * @param {Array.<string>} fileUrls Array of filename URLs.
+ */
+ FileManager.prototype.selectFiles_ = function(fileUrls) {
+ this.onUnload_();
+ // Closes the window and does not return.
+ chrome.fileBrowserPrivate.selectFiles(fileUrls);
+ };
+
+ /**
* Handle a click of the ok button.
*
* The ok button has different UI labels depending on the type of dialog, but
@@ -3610,9 +3643,8 @@ FileManager.prototype = {
var self = this;
function resolveCallback(victim) {
if (victim instanceof FileError) {
- // File does not exist. (NB: selectFile Closes the window and does
- // not return.)
- chrome.fileBrowserPrivate.selectFile(
+ // File does not exist. Closes the window and does not return.
+ self.selectFile_(
currentDirUrl + encodeURIComponent(filename),
self.getSelectedFilterIndex_(filename));
}
@@ -3624,7 +3656,7 @@ FileManager.prototype = {
self.confirm.show(strf('CONFIRM_OVERWRITE_FILE', filename),
function() {
// User selected Ok from the confirm dialog.
- chrome.fileBrowserPrivate.selectFile(
+ self.selectFile_(
currentDirUrl + encodeURIComponent(filename),
self.getSelectedFilterIndex_(filename));
});
@@ -3659,7 +3691,7 @@ FileManager.prototype = {
// Multi-file selection has no other restrictions.
if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) {
// Closes the window and does not return.
- chrome.fileBrowserPrivate.selectFiles(ary);
+ this.selectFiles_(ary);
return;
}
@@ -3698,8 +3730,7 @@ FileManager.prototype = {
}
// Closes the window and does not return.
- chrome.fileBrowserPrivate.selectFile(
- ary[0], this.getSelectedFilterIndex_(ary[0]));
+ this.selectFile_(ary[0], this.getSelectedFilterIndex_(ary[0]));
};
/**