summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-11 04:14:55 +0000
committerjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-11 04:14:55 +0000
commitc0cadc385982fd9a9b2a9f8e57c9d01495d348ce (patch)
tree0cd09080991b7ec713283a8a6d0f46e8ed17bc6f
parent89f5fbb75f989d12dffeffa1ca0a7bb40c603706 (diff)
downloadchromium_src-c0cadc385982fd9a9b2a9f8e57c9d01495d348ce.zip
chromium_src-c0cadc385982fd9a9b2a9f8e57c9d01495d348ce.tar.gz
chromium_src-c0cadc385982fd9a9b2a9f8e57c9d01495d348ce.tar.bz2
CrOS - Fix crash when pressing Enter in file browser dialog
If focus is on the cancel button, pressing enter will both cancel the dialog and attempt to select a file. Fix by ensuring that SelectFileDialog::Listener objects are invoked exactly once (some listeners delete themselves after being invoked). BUG=chromium-os:16349 TEST=manual, see bug. Also browsertest FileManagerDialogTest.* Review URL: http://codereview.chromium.org/7108066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88759 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_file_browser_private_api.cc9
-rw-r--r--chrome/browser/extensions/extension_file_browser_private_api.h3
-rw-r--r--chrome/browser/resources/file_manager/js/file_manager.js2
-rw-r--r--chrome/browser/ui/views/file_manager_dialog.cc25
4 files changed, 34 insertions, 5 deletions
diff --git a/chrome/browser/extensions/extension_file_browser_private_api.cc b/chrome/browser/extensions/extension_file_browser_private_api.cc
index 964d441..7261407 100644
--- a/chrome/browser/extensions/extension_file_browser_private_api.cc
+++ b/chrome/browser/extensions/extension_file_browser_private_api.cc
@@ -909,6 +909,12 @@ const FileDialogFunction::Callback& FileDialogFunction::GetCallback() const {
return Callback::Find(GetTabId());
}
+void FileDialogFunction::RemoveCallback() {
+ // Listeners expect to be invoked exactly once, so we need to remove our
+ // callback objects afterwards.
+ Callback::Remove(GetTabId());
+}
+
// GetFileSystemRootPathOnFileThread can only be called from the file thread,
// so here we are. This function takes a vector of virtual paths, converts
// them to local paths and calls GetLocalPathsResponseOnUIThread with the
@@ -995,6 +1001,7 @@ void SelectFileFunction::GetLocalPathsResponseOnUIThread(
callback.listener()->FileSelected(files[0],
index,
callback.params());
+ RemoveCallback(); // Listeners expect to be invoked exactly once.
}
SendResponse(true);
}
@@ -1089,6 +1096,7 @@ void SelectFilesFunction::GetLocalPathsResponseOnUIThread(
DCHECK(!callback.IsNull());
if (!callback.IsNull()) {
callback.listener()->MultiFilesSelected(files, callback.params());
+ RemoveCallback(); // Listeners expect to be invoked exactly once.
}
SendResponse(true);
}
@@ -1098,6 +1106,7 @@ bool CancelFileDialogFunction::RunImpl() {
DCHECK(!callback.IsNull());
if (!callback.IsNull()) {
callback.listener()->FileSelectionCanceled(callback.params());
+ RemoveCallback(); // Listeners expect to be invoked exactly once.
}
SendResponse(true);
return true;
diff --git a/chrome/browser/extensions/extension_file_browser_private_api.h b/chrome/browser/extensions/extension_file_browser_private_api.h
index 152f5cdbf..2650906 100644
--- a/chrome/browser/extensions/extension_file_browser_private_api.h
+++ b/chrome/browser/extensions/extension_file_browser_private_api.h
@@ -167,6 +167,9 @@ class FileDialogFunction
// Get the callback for the hosting tab.
const Callback& GetCallback() const;
+ // Remove the callback for the hosting tab.
+ void RemoveCallback();
+
private:
// Figure out the tab_id of the hosting tab.
int32 GetTabId() const;
diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js
index 9c4f5bc..53128e2 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -2012,8 +2012,10 @@ FileManager.prototype = {
if (this.selection.totalCount == 1 &&
this.selection.leadEntry.isDirectory &&
this.dialogType_ != FileManager.SELECT_FOLDER) {
+ event.preventDefault();
this.changeDirectory(this.selection.leadEntry.fullPath);
} else if (!this.okButton_.disabled) {
+ event.preventDefault();
this.onOk_();
}
break;
diff --git a/chrome/browser/ui/views/file_manager_dialog.cc b/chrome/browser/ui/views/file_manager_dialog.cc
index fbc1895..d2da11e 100644
--- a/chrome/browser/ui/views/file_manager_dialog.cc
+++ b/chrome/browser/ui/views/file_manager_dialog.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/extensions/file_manager_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/extensions/extension_dialog.h"
#include "chrome/browser/ui/views/window.h"
#include "content/browser/browser_thread.h"
@@ -21,8 +22,21 @@ namespace {
const int kFileManagerWidth = 720; // pixels
const int kFileManagerHeight = 580; // pixels
+// Returns the browser represented by |window| or NULL if not found.
+// TODO(jamescook): Move this to browser_list.h.
+Browser* FindBrowserWithWindow(gfx::NativeWindow window) {
+ for (BrowserList::const_iterator it = BrowserList::begin();
+ it != BrowserList::end();
+ ++it) {
+ Browser* browser = *it;
+ if (browser->window() && browser->window()->GetNativeHandle() == window)
+ return browser;
+ }
+ return NULL;
}
+} // namespace
+
// Linking this implementation of SelectFileDialog::Create into the target
// selects FileManagerDialog as the dialog of choice.
// static
@@ -80,20 +94,21 @@ void FileManagerDialog::SelectFileImpl(
LOG(ERROR) << "File dialog already in use!";
return;
}
- Browser* active_browser = BrowserList::GetLastActive();
- if (!active_browser)
+ Browser* owner_browser = FindBrowserWithWindow(owner_window);
+ if (!owner_browser) {
+ NOTREACHED() << "Can't find owning browser";
return;
+ }
GURL file_browser_url = FileManagerUtil::GetFileBrowserUrlWithParams(
type, title, default_path, file_types, file_type_index,
default_extension);
extension_dialog_ = ExtensionDialog::Show(file_browser_url,
- active_browser, kFileManagerWidth, kFileManagerHeight,
+ owner_browser, kFileManagerWidth, kFileManagerHeight,
this /* ExtensionDialog::Observer */);
// Connect our listener to FileDialogFunction's per-tab callbacks.
- Browser* extension_browser = extension_dialog_->host()->view()->browser();
- TabContents* contents = extension_browser->GetSelectedTabContents();
+ TabContents* contents = owner_browser->GetSelectedTabContents();
int32 tab_id = (contents ? contents->controller().session_id().id() : 0);
FileDialogFunction::Callback::Add(tab_id, listener_, params);