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

Unified Diff: chrome/browser/ui/chrome_select_file_policy.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: Attempt to fix win 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/chrome_select_file_policy.cc
diff --git a/chrome/browser/ui/chrome_select_file_policy.cc b/chrome/browser/ui/chrome_select_file_policy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7f1fb4460042b0962c64e82c0b7b89814d230bfb
--- /dev/null
+++ b/chrome/browser/ui/chrome_select_file_policy.cc
@@ -0,0 +1,54 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/chrome_select_file_policy.h"
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/logging.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 "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+
+ChromeSelectFilePolicy::ChromeSelectFilePolicy(
+ content::WebContents* source_contents)
+ : source_contents_(source_contents) {
+}
+
+ChromeSelectFilePolicy::~ChromeSelectFilePolicy() {}
+
+bool ChromeSelectFilePolicy::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 ChromeSelectFilePolicy::SelectFileDenied() {
+ // Show the InfoBar saying that file-selection dialogs are disabled.
+ if (source_contents_) {
+ TabContents* tab_contents = TabContents::FromWebContents(source_contents_);
+ DCHECK(tab_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.";
+ }
+}
« no previous file with comments | « chrome/browser/ui/chrome_select_file_policy.h ('k') | chrome/browser/ui/chrome_select_file_policy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698