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

Side by Side Diff: chrome/browser/ui/chrome_select_file_policy.cc

Issue 10832330: disable [add folder] button for media galleries dialog if (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/chrome_select_file_policy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/simple_alert_infobar_delegate.h" 10 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/infobars/infobar_tab_helper.h" 12 #include "chrome/browser/infobars/infobar_tab_helper.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
17 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
18 18
19 ChromeSelectFilePolicy::ChromeSelectFilePolicy( 19 ChromeSelectFilePolicy::ChromeSelectFilePolicy(
20 content::WebContents* source_contents) 20 content::WebContents* source_contents)
21 : source_contents_(source_contents) { 21 : source_contents_(source_contents) {
22 } 22 }
23 23
24 ChromeSelectFilePolicy::~ChromeSelectFilePolicy() {} 24 ChromeSelectFilePolicy::~ChromeSelectFilePolicy() {}
25 25
26 bool ChromeSelectFilePolicy::CanOpenSelectFileDialog() { 26 bool ChromeSelectFilePolicy::CanOpenSelectFileDialog() {
27 DCHECK(g_browser_process); 27 return FileSelectDialogsAllowed();
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 } 28 }
38 29
39 void ChromeSelectFilePolicy::SelectFileDenied() { 30 void ChromeSelectFilePolicy::SelectFileDenied() {
40 // Show the InfoBar saying that file-selection dialogs are disabled. 31 // Show the InfoBar saying that file-selection dialogs are disabled.
41 if (source_contents_) { 32 if (source_contents_) {
42 TabContents* tab_contents = TabContents::FromWebContents(source_contents_); 33 TabContents* tab_contents = TabContents::FromWebContents(source_contents_);
43 DCHECK(tab_contents); 34 DCHECK(tab_contents);
44 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); 35 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
45 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( 36 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate(
46 infobar_helper, 37 infobar_helper,
47 NULL, 38 NULL,
48 l10n_util::GetStringUTF16(IDS_FILE_SELECTION_DIALOG_INFOBAR), 39 l10n_util::GetStringUTF16(IDS_FILE_SELECTION_DIALOG_INFOBAR),
49 true)); 40 true));
50 } else { 41 } else {
51 LOG(WARNING) << "File-selection dialogs are disabled but no WebContents " 42 LOG(WARNING) << "File-selection dialogs are disabled but no WebContents "
52 << "is given to display the InfoBar."; 43 << "is given to display the InfoBar.";
53 } 44 }
54 } 45 }
46
47 // static
48 bool ChromeSelectFilePolicy::FileSelectDialogsAllowed() {
49 DCHECK(g_browser_process);
50
51 // local_state() can return NULL for tests.
52 if (!g_browser_process->local_state())
53 return false;
54
55 return !g_browser_process->local_state()->FindPreference(
56 prefs::kAllowFileSelectionDialogs) ||
57 g_browser_process->local_state()->GetBoolean(
58 prefs::kAllowFileSelectionDialogs);
59 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/chrome_select_file_policy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698