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 // This file implements common select dialog functionality between GTK and KDE. | 5 // This file implements common select dialog functionality between GTK and KDE. |
6 | 6 |
7 #include "chrome/browser/ui/gtk/select_file_dialog_impl.h" | 7 #include "chrome/browser/ui/gtk/select_file_dialog_impl.h" |
8 | 8 |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 }; | 23 }; |
24 | 24 |
25 UseKdeFileDialogStatus use_kde_ = UNKNOWN; | 25 UseKdeFileDialogStatus use_kde_ = UNKNOWN; |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 FilePath* SelectFileDialogImpl::last_saved_path_ = NULL; | 29 FilePath* SelectFileDialogImpl::last_saved_path_ = NULL; |
30 FilePath* SelectFileDialogImpl::last_opened_path_ = NULL; | 30 FilePath* SelectFileDialogImpl::last_opened_path_ = NULL; |
31 | 31 |
32 // static | 32 // static |
33 SelectFileDialog* SelectFileDialog::Create(Listener* listener) { | 33 SelectFileDialog* SelectFileDialog::Create(Listener* listener, |
| 34 ui::SelectFilePolicy* policy) { |
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
35 if (use_kde_ == UNKNOWN) { | 36 if (use_kde_ == UNKNOWN) { |
36 // Start out assumimg we are not going to use KDE. | 37 // Start out assumimg we are not going to use KDE. |
37 use_kde_ = NO_KDE; | 38 use_kde_ = NO_KDE; |
38 | 39 |
39 // Check to see if KDE is the desktop environment. | 40 // Check to see if KDE is the desktop environment. |
40 scoped_ptr<base::Environment> env(base::Environment::Create()); | 41 scoped_ptr<base::Environment> env(base::Environment::Create()); |
41 base::nix::DesktopEnvironment desktop = | 42 base::nix::DesktopEnvironment desktop = |
42 base::nix::GetDesktopEnvironment(env.get()); | 43 base::nix::GetDesktopEnvironment(env.get()); |
43 if (desktop == base::nix::DESKTOP_ENVIRONMENT_KDE3 || | 44 if (desktop == base::nix::DESKTOP_ENVIRONMENT_KDE3 || |
44 desktop == base::nix::DESKTOP_ENVIRONMENT_KDE4) { | 45 desktop == base::nix::DESKTOP_ENVIRONMENT_KDE4) { |
45 // Check to see if the user dislikes the KDE file dialog. | 46 // Check to see if the user dislikes the KDE file dialog. |
46 if (!env->HasVar("NO_CHROME_KDE_FILE_DIALOG")) { | 47 if (!env->HasVar("NO_CHROME_KDE_FILE_DIALOG")) { |
47 // Check to see if the KDE dialog works. | 48 // Check to see if the KDE dialog works. |
48 if (SelectFileDialogImpl::CheckKDEDialogWorksOnUIThread()) { | 49 if (SelectFileDialogImpl::CheckKDEDialogWorksOnUIThread()) { |
49 use_kde_ = YES_KDE; | 50 use_kde_ = YES_KDE; |
50 } | 51 } |
51 } | 52 } |
52 } | 53 } |
53 } | 54 } |
54 | 55 |
55 if (use_kde_ == NO_KDE) | 56 if (use_kde_ == NO_KDE) |
56 return SelectFileDialogImpl::NewSelectFileDialogImplGTK(listener); | 57 return SelectFileDialogImpl::NewSelectFileDialogImplGTK(listener, policy); |
57 | 58 |
58 scoped_ptr<base::Environment> env(base::Environment::Create()); | 59 scoped_ptr<base::Environment> env(base::Environment::Create()); |
59 base::nix::DesktopEnvironment desktop = | 60 base::nix::DesktopEnvironment desktop = |
60 base::nix::GetDesktopEnvironment(env.get()); | 61 base::nix::GetDesktopEnvironment(env.get()); |
61 return SelectFileDialogImpl::NewSelectFileDialogImplKDE(listener, desktop); | 62 return SelectFileDialogImpl::NewSelectFileDialogImplKDE( |
| 63 listener, policy, desktop); |
62 } | 64 } |
63 | 65 |
64 SelectFileDialogImpl::SelectFileDialogImpl(Listener* listener) | 66 SelectFileDialogImpl::SelectFileDialogImpl(Listener* listener, |
65 : SelectFileDialog(listener), | 67 ui::SelectFilePolicy* policy) |
| 68 : SelectFileDialog(listener, policy), |
66 file_type_index_(0), | 69 file_type_index_(0), |
67 type_(SELECT_NONE) { | 70 type_(SELECT_NONE) { |
68 if (!last_saved_path_) { | 71 if (!last_saved_path_) { |
69 last_saved_path_ = new FilePath(); | 72 last_saved_path_ = new FilePath(); |
70 last_opened_path_ = new FilePath(); | 73 last_opened_path_ = new FilePath(); |
71 } | 74 } |
72 } | 75 } |
73 | 76 |
74 SelectFileDialogImpl::~SelectFileDialogImpl() { } | 77 SelectFileDialogImpl::~SelectFileDialogImpl() { } |
75 | 78 |
76 void SelectFileDialogImpl::ListenerDestroyed() { | 79 void SelectFileDialogImpl::ListenerDestroyed() { |
77 listener_ = NULL; | 80 listener_ = NULL; |
78 } | 81 } |
79 | 82 |
80 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow parent_window) const { | 83 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow parent_window) const { |
81 return parents_.find(parent_window) != parents_.end(); | 84 return parents_.find(parent_window) != parents_.end(); |
82 } | 85 } |
83 | 86 |
84 bool SelectFileDialogImpl::CallDirectoryExistsOnUIThread(const FilePath& path) { | 87 bool SelectFileDialogImpl::CallDirectoryExistsOnUIThread(const FilePath& path) { |
85 base::ThreadRestrictions::ScopedAllowIO allow_io; | 88 base::ThreadRestrictions::ScopedAllowIO allow_io; |
86 return file_util::DirectoryExists(path); | 89 return file_util::DirectoryExists(path); |
87 } | 90 } |
OLD | NEW |