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.
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/files/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
;
19 enum UseKdeFileDialogStatus
{
25 UseKdeFileDialogStatus use_kde_
= UNKNOWN
;
31 base::FilePath
* SelectFileDialogImpl::last_saved_path_
= NULL
;
32 base::FilePath
* SelectFileDialogImpl::last_opened_path_
= NULL
;
35 ui::SelectFileDialog
* SelectFileDialogImpl::Create(
36 ui::SelectFileDialog::Listener
* listener
,
37 ui::SelectFilePolicy
* policy
) {
38 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
39 if (use_kde_
== UNKNOWN
) {
40 // Start out assumimg we are not going to use 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()) {
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
),
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() {
86 bool SelectFileDialogImpl::CallDirectoryExistsOnUIThread(
87 const base::FilePath
& path
) {
88 base::ThreadRestrictions::ScopedAllowIO allow_io
;
89 return base::DirectoryExists(path
);
92 } // namespace libgtk2ui