Index: chrome/browser/chrome_select_file_policy.cc |
diff --git a/chrome/browser/chrome_select_file_policy.cc b/chrome/browser/chrome_select_file_policy.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5c04716666d1becda6797d6a558d73fc41a01ae6 |
--- /dev/null |
+++ b/chrome/browser/chrome_select_file_policy.cc |
@@ -0,0 +1,58 @@ |
+// 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/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() {} |
+ |
+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); |
+} |
+ |
+// static |
+base::Closure ChromeSelectFilePolicy::DisplayInfobarCallback( |
+ content::WebContents* source_contents) { |
+ return base::Bind(&DisplayInfobarOrWarn, base::Unretained(source_contents)); |
+} |
+ |
+// static |
+void ChromeSelectFilePolicy::DisplayInfobarOrWarn( |
+ content::WebContents* source_contents) { |
+ // Show the InfoBar saying that file-selection dialogs are disabled. |
+ if (source_contents) { |
+ TabContents* tab_contents = TabContents::FromWebContents(source_contents); |
sky
2012/06/26 00:07:18
Can't this return NULL?
Elliot Glaysher
2012/06/28 20:09:53
It can return NULL only if |source_contents| is in
|
+ 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."; |
+ } |
+} |