OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback.h" |
| 9 #include "base/logging.h" |
| 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 15 #include "chrome/common/pref_names.h" |
| 16 #include "grit/generated_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" |
| 18 |
| 19 ChromeSelectFilePolicy::ChromeSelectFilePolicy( |
| 20 content::WebContents* source_contents) |
| 21 : source_contents_(source_contents) { |
| 22 } |
| 23 |
| 24 ChromeSelectFilePolicy::~ChromeSelectFilePolicy() {} |
| 25 |
| 26 bool ChromeSelectFilePolicy::CanOpenSelectFileDialog() { |
| 27 DCHECK(g_browser_process); |
| 28 |
| 29 // local_state() can return NULL for tests. |
| 30 if (!g_browser_process->local_state()) |
| 31 return false; |
| 32 |
| 33 return !g_browser_process->local_state()->FindPreference( |
| 34 prefs::kAllowFileSelectionDialogs) || |
| 35 g_browser_process->local_state()->GetBoolean( |
| 36 prefs::kAllowFileSelectionDialogs); |
| 37 } |
| 38 |
| 39 void ChromeSelectFilePolicy::SelectFileDenied() { |
| 40 // Show the InfoBar saying that file-selection dialogs are disabled. |
| 41 if (source_contents_) { |
| 42 TabContents* tab_contents = TabContents::FromWebContents(source_contents_); |
| 43 DCHECK(tab_contents); |
| 44 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
| 45 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 46 infobar_helper, |
| 47 NULL, |
| 48 l10n_util::GetStringUTF16(IDS_FILE_SELECTION_DIALOG_INFOBAR), |
| 49 true)); |
| 50 } else { |
| 51 LOG(WARNING) << "File-selection dialogs are disabled but no WebContents " |
| 52 << "is given to display the InfoBar."; |
| 53 } |
| 54 } |
OLD | NEW |