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/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 | |
21 ChromeSelectFilePolicy::~ChromeSelectFilePolicy() {} | |
22 | |
23 bool ChromeSelectFilePolicy::CanOpenSelectFileDialog() { | |
24 DCHECK(g_browser_process); | |
25 | |
26 // local_state() can return NULL for tests. | |
27 if (!g_browser_process->local_state()) | |
28 return false; | |
29 | |
30 return !g_browser_process->local_state()->FindPreference( | |
31 prefs::kAllowFileSelectionDialogs) || | |
32 g_browser_process->local_state()->GetBoolean( | |
33 prefs::kAllowFileSelectionDialogs); | |
34 } | |
35 | |
36 // static | |
37 base::Closure ChromeSelectFilePolicy::DisplayInfobarCallback( | |
38 content::WebContents* source_contents) { | |
39 return base::Bind(&DisplayInfobarOrWarn, base::Unretained(source_contents)); | |
40 } | |
41 | |
42 // static | |
43 void ChromeSelectFilePolicy::DisplayInfobarOrWarn( | |
44 content::WebContents* source_contents) { | |
45 // Show the InfoBar saying that file-selection dialogs are disabled. | |
46 if (source_contents) { | |
47 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
| |
48 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); | |
49 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( | |
50 infobar_helper, | |
51 NULL, | |
52 l10n_util::GetStringUTF16(IDS_FILE_SELECTION_DIALOG_INFOBAR), | |
53 true)); | |
54 } else { | |
55 LOG(WARNING) << "File-selection dialogs are disabled but no WebContents " | |
56 << "is given to display the InfoBar."; | |
57 } | |
58 } | |
OLD | NEW |