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

Unified Diff: chrome/browser/ui/select_file_dialog.cc

Issue 10667026: Start consolidating cross-port file selection code into ui/base/dialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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/ui/select_file_dialog.cc
diff --git a/chrome/browser/ui/select_file_dialog.cc b/chrome/browser/ui/select_file_dialog.cc
index 4722df9c6e2c89fb42b9b6fef0c4e141d64e37c3..d7d4959225121034c34ffe09da73c70fb95fb92c 100644
--- a/chrome/browser/ui/select_file_dialog.cc
+++ b/chrome/browser/ui/select_file_dialog.cc
@@ -7,18 +7,19 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/infobars/infobar_tab_helper.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h"
-#include "chrome/browser/ui/tab_contents/tab_contents.h"
-#include "chrome/common/pref_names.h"
#include "content/public/common/selected_file_info.h"
-#include "grit/generated_resources.h"
-#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/dialogs/select_file_policy.h"
using content::WebContents;
+ui::SelectFilePolicy* SelectFileDialog::select_file_policy_ = NULL;
+
+// static
+void SelectFileDialog::SetFilePolicy(ui::SelectFilePolicy* policy) {
sky 2012/06/26 00:07:18 How come this is static and not per instance?
+ delete select_file_policy_;
+ select_file_policy_ = policy;
+}
+
SelectFileDialog::FileTypeInfo::FileTypeInfo() : include_all_files(false) {}
SelectFileDialog::FileTypeInfo::~FileTypeInfo() {}
@@ -47,44 +48,19 @@ SelectFileDialog::SelectFileDialog(Listener* listener)
SelectFileDialog::~SelectFileDialog() {}
-bool SelectFileDialog::CanOpenSelectFileDialog() {
- DCHECK(g_browser_process);
-
- // local_state() can return NULL for tests.
- if (!g_browser_process->local_state())
- return false;
-
- return !g_browser_process->local_state()->FindPreference(
- prefs::kAllowFileSelectionDialogs) ||
- g_browser_process->local_state()->GetBoolean(
- prefs::kAllowFileSelectionDialogs);
-}
-
void SelectFileDialog::SelectFile(Type type,
const string16& title,
const FilePath& default_path,
const FileTypeInfo* file_types,
int file_type_index,
const FilePath::StringType& default_extension,
- WebContents* source_contents,
+ const base::Closure& policy_denied,
gfx::NativeWindow owning_window,
void* params) {
DCHECK(listener_);
- if (!CanOpenSelectFileDialog()) {
- // Show the InfoBar saying that file-selection dialogs are disabled.
- if (source_contents) {
- TabContents* tab_contents = TabContents::FromWebContents(source_contents);
- InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
- infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate(
- infobar_helper,
- NULL,
- l10n_util::GetStringUTF16(IDS_FILE_SELECTION_DIALOG_INFOBAR),
- true));
- } else {
- LOG(WARNING) << "File-selection dialogs are disabled but no WebContents "
- << "is given to display the InfoBar.";
- }
+ if (select_file_policy_ && !select_file_policy_->CanOpenSelectFileDialog()) {
+ policy_denied.Run();
// Inform the listener that no file was selected.
// Post a task rather than calling FileSelectionCanceled directly to ensure
@@ -94,6 +70,7 @@ void SelectFileDialog::SelectFile(Type type,
params));
return;
}
+
// Call the platform specific implementation of the file selection dialog.
SelectFileImpl(type, title, default_path, file_types, file_type_index,
default_extension, owning_window, params);

Powered by Google App Engine
This is Rietveld 408576698