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
parent 0cc6fc92
...@@ -3166,9 +3166,15 @@ FileManager.prototype = { ...@@ -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_) { if (this.subscribedOnDirectoryChanges_) {
chrome.fileBrowserPrivate.removeFileWatch(event.previousDirEntry.toURL(), this.subscribedOnDirectoryChanges_ = false;
chrome.fileBrowserPrivate.removeFileWatch(this.currentDirEntry_.toURL(),
function(result) { function(result) {
if (!result) { if (!result) {
console.log('Failed to remove file watch'); console.log('Failed to remove file watch');
...@@ -3575,15 +3581,42 @@ FileManager.prototype = { ...@@ -3575,15 +3581,42 @@ 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. * @param {Event} event The click event.
*/ */
FileManager.prototype.onCancel_ = function(event) { FileManager.prototype.onCancel_ = function(event) {
this.onUnload_();
// Closes the window and does not return. // Closes the window and does not return.
chrome.fileBrowserPrivate.cancelDialog(); 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. * Handle a click of the ok button.
* *
...@@ -3610,9 +3643,8 @@ FileManager.prototype = { ...@@ -3610,9 +3643,8 @@ FileManager.prototype = {
var self = this; var self = this;
function resolveCallback(victim) { function resolveCallback(victim) {
if (victim instanceof FileError) { if (victim instanceof FileError) {
// File does not exist. (NB: selectFile Closes the window and does // File does not exist. Closes the window and does not return.
// not return.) self.selectFile_(
chrome.fileBrowserPrivate.selectFile(
currentDirUrl + encodeURIComponent(filename), currentDirUrl + encodeURIComponent(filename),
self.getSelectedFilterIndex_(filename)); self.getSelectedFilterIndex_(filename));
} }
...@@ -3624,7 +3656,7 @@ FileManager.prototype = { ...@@ -3624,7 +3656,7 @@ FileManager.prototype = {
self.confirm.show(strf('CONFIRM_OVERWRITE_FILE', filename), self.confirm.show(strf('CONFIRM_OVERWRITE_FILE', filename),
function() { function() {
// User selected Ok from the confirm dialog. // User selected Ok from the confirm dialog.
chrome.fileBrowserPrivate.selectFile( self.selectFile_(
currentDirUrl + encodeURIComponent(filename), currentDirUrl + encodeURIComponent(filename),
self.getSelectedFilterIndex_(filename)); self.getSelectedFilterIndex_(filename));
}); });
...@@ -3659,7 +3691,7 @@ FileManager.prototype = { ...@@ -3659,7 +3691,7 @@ FileManager.prototype = {
// Multi-file selection has no other restrictions. // Multi-file selection has no other restrictions.
if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) {
// Closes the window and does not return. // Closes the window and does not return.
chrome.fileBrowserPrivate.selectFiles(ary); this.selectFiles_(ary);
return; return;
} }
...@@ -3698,8 +3730,7 @@ FileManager.prototype = { ...@@ -3698,8 +3730,7 @@ FileManager.prototype = {
} }
// Closes the window and does not return. // Closes the window and does not return.
chrome.fileBrowserPrivate.selectFile( this.selectFile_(ary[0], this.getSelectedFilterIndex_(ary[0]));
ary[0], this.getSelectedFilterIndex_(ary[0]));
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment