Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / libgtk2ui / select_file_dialog_impl.cc
blob450f2b411a7460e5d59dcf06b14c656a069ee7c7
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 // This file implements common select dialog functionality between GTK and KDE.
7 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h"
9 #include "base/environment.h"
10 #include "base/file_util.h"
11 #include "base/nix/xdg_util.h"
12 #include "base/threading/thread_restrictions.h"
13 #include "content/public/browser/browser_thread.h"
15 using content::BrowserThread;
17 namespace {
19 enum UseKdeFileDialogStatus {
20 UNKNOWN,
21 NO_KDE,
22 YES_KDE
25 UseKdeFileDialogStatus use_kde_ = UNKNOWN;
27 } // namespace
29 namespace libgtk2ui {
31 base::FilePath* SelectFileDialogImpl::last_saved_path_ = NULL;
32 base::FilePath* SelectFileDialogImpl::last_opened_path_ = NULL;
34 // static
35 ui::SelectFileDialog* SelectFileDialogImpl::Create(
36 ui::SelectFileDialog::Listener* listener,
37 ui::SelectFilePolicy* policy) {
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
39 if (use_kde_ == UNKNOWN) {
40 // Start out assumimg we are not going to use KDE.
41 use_kde_ = NO_KDE;
43 // Check to see if KDE is the desktop environment.
44 scoped_ptr<base::Environment> env(base::Environment::Create());
45 base::nix::DesktopEnvironment desktop =
46 base::nix::GetDesktopEnvironment(env.get());
47 if (desktop == base::nix::DESKTOP_ENVIRONMENT_KDE3 ||
48 desktop == base::nix::DESKTOP_ENVIRONMENT_KDE4) {
49 // Check to see if the user dislikes the KDE file dialog.
50 if (!env->HasVar("NO_CHROME_KDE_FILE_DIALOG")) {
51 // Check to see if the KDE dialog works.
52 if (SelectFileDialogImpl::CheckKDEDialogWorksOnUIThread()) {
53 use_kde_ = YES_KDE;
59 if (use_kde_ == NO_KDE)
60 return SelectFileDialogImpl::NewSelectFileDialogImplGTK(listener, policy);
62 scoped_ptr<base::Environment> env(base::Environment::Create());
63 base::nix::DesktopEnvironment desktop =
64 base::nix::GetDesktopEnvironment(env.get());
65 return SelectFileDialogImpl::NewSelectFileDialogImplKDE(
66 listener, policy, desktop);
69 SelectFileDialogImpl::SelectFileDialogImpl(Listener* listener,
70 ui::SelectFilePolicy* policy)
71 : SelectFileDialog(listener, policy),
72 file_type_index_(0),
73 type_(SELECT_NONE) {
74 if (!last_saved_path_) {
75 last_saved_path_ = new base::FilePath();
76 last_opened_path_ = new base::FilePath();
80 SelectFileDialogImpl::~SelectFileDialogImpl() { }
82 void SelectFileDialogImpl::ListenerDestroyed() {
83 listener_ = NULL;
86 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow parent_window) const {
87 return parents_.find(parent_window) != parents_.end();
90 bool SelectFileDialogImpl::CallDirectoryExistsOnUIThread(
91 const base::FilePath& path) {
92 base::ThreadRestrictions::ScopedAllowIO allow_io;
93 return base::DirectoryExists(path);
96 } // namespace libgtk2ui