OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/chrome_select_file_policy.h" | 5 #include "chrome/browser/ui/chrome_select_file_policy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/browser/api/infobars/infobar_service.h" | 10 #include "chrome/browser/api/infobars/infobar_service.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 ChromeSelectFilePolicy::~ChromeSelectFilePolicy() {} | 23 ChromeSelectFilePolicy::~ChromeSelectFilePolicy() {} |
24 | 24 |
25 bool ChromeSelectFilePolicy::CanOpenSelectFileDialog() { | 25 bool ChromeSelectFilePolicy::CanOpenSelectFileDialog() { |
26 return FileSelectDialogsAllowed(); | 26 return FileSelectDialogsAllowed(); |
27 } | 27 } |
28 | 28 |
29 void ChromeSelectFilePolicy::SelectFileDenied() { | 29 void ChromeSelectFilePolicy::SelectFileDenied() { |
30 // Show the InfoBar saying that file-selection dialogs are disabled. | 30 // Show the InfoBar saying that file-selection dialogs are disabled. |
31 if (source_contents_) { | 31 if (source_contents_) { |
32 InfoBarService* infobar_service = | 32 SimpleAlertInfoBarDelegate::Create( |
33 InfoBarService::FromWebContents(source_contents_); | 33 InfoBarService::FromWebContents(source_contents_), NULL, |
34 DCHECK(infobar_service); | 34 l10n_util::GetStringUTF16(IDS_FILE_SELECTION_DIALOG_INFOBAR), true); |
35 infobar_service->AddInfoBar(new SimpleAlertInfoBarDelegate( | |
36 infobar_service, | |
37 NULL, | |
38 l10n_util::GetStringUTF16(IDS_FILE_SELECTION_DIALOG_INFOBAR), | |
39 true)); | |
40 } else { | 35 } else { |
41 LOG(WARNING) << "File-selection dialogs are disabled but no WebContents " | 36 LOG(WARNING) << "File-selection dialogs are disabled but no WebContents " |
42 << "is given to display the InfoBar."; | 37 << "is given to display the InfoBar."; |
43 } | 38 } |
44 } | 39 } |
45 | 40 |
46 // static | 41 // static |
47 bool ChromeSelectFilePolicy::FileSelectDialogsAllowed() { | 42 bool ChromeSelectFilePolicy::FileSelectDialogsAllowed() { |
48 DCHECK(g_browser_process); | 43 DCHECK(g_browser_process); |
49 | 44 |
50 // local_state() can return NULL for tests. | 45 // local_state() can return NULL for tests. |
51 if (!g_browser_process->local_state()) | 46 if (!g_browser_process->local_state()) |
52 return false; | 47 return false; |
53 | 48 |
54 return !g_browser_process->local_state()->FindPreference( | 49 return !g_browser_process->local_state()->FindPreference( |
55 prefs::kAllowFileSelectionDialogs) || | 50 prefs::kAllowFileSelectionDialogs) || |
56 g_browser_process->local_state()->GetBoolean( | 51 g_browser_process->local_state()->GetBoolean( |
57 prefs::kAllowFileSelectionDialogs); | 52 prefs::kAllowFileSelectionDialogs); |
58 } | 53 } |
OLD | NEW |