diff options
Diffstat (limited to 'chromium/ui/shell_dialogs')
6 files changed, 139 insertions, 9 deletions
diff --git a/chromium/ui/shell_dialogs/BUILD.gn b/chromium/ui/shell_dialogs/BUILD.gn index 1fc50d45d85..84a9a652ea9 100644 --- a/chromium/ui/shell_dialogs/BUILD.gn +++ b/chromium/ui/shell_dialogs/BUILD.gn @@ -2,6 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("//build/config/chromeos/ui_mode.gni") import("//build/config/jumbo.gni") import("//build/config/ui.gni") import("//testing/test.gni") @@ -106,6 +107,14 @@ jumbo_component("shell_dialogs") { if (is_fuchsia) { sources += [ "select_file_dialog_fuchsia.cc" ] } + + # TODO(crbug.com/1052397): Rename chromeos_is_browser_only. + if (chromeos_is_browser_only) { + sources += [ + "select_file_dialog_lacros.cc", + "select_file_dialog_lacros.h", + ] + } } test("shell_dialogs_unittests") { diff --git a/chromium/ui/shell_dialogs/select_file_dialog_android.cc b/chromium/ui/shell_dialogs/select_file_dialog_android.cc index 0a0c2989ea3..66500a99be7 100644 --- a/chromium/ui/shell_dialogs/select_file_dialog_android.cc +++ b/chromium/ui/shell_dialogs/select_file_dialog_android.cc @@ -48,7 +48,7 @@ void SelectFileDialogImpl::OnFileSelected( if (!file_name.empty()) file_info.display_name = file_name; - listener_->FileSelectedWithExtraInfo(file_info, 0, NULL); + listener_->FileSelectedWithExtraInfo(file_info, 0, nullptr); } void SelectFileDialogImpl::OnMultipleFilesSelected( @@ -83,14 +83,14 @@ void SelectFileDialogImpl::OnMultipleFilesSelected( selected_files.push_back(file_info); } - listener_->MultiFilesSelectedWithExtraInfo(selected_files, NULL); + listener_->MultiFilesSelectedWithExtraInfo(selected_files, nullptr); } void SelectFileDialogImpl::OnFileNotSelected( JNIEnv* env, const JavaParamRef<jobject>& java_object) { if (listener_) - listener_->FileSelectionCanceled(NULL); + listener_->FileSelectionCanceled(nullptr); } void SelectFileDialogImpl::OnContactsSelected( @@ -107,7 +107,7 @@ bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow) const { } void SelectFileDialogImpl::ListenerDestroyed() { - listener_ = NULL; + listener_ = nullptr; } void SelectFileDialogImpl::SelectFileImpl( diff --git a/chromium/ui/shell_dialogs/select_file_dialog_lacros.cc b/chromium/ui/shell_dialogs/select_file_dialog_lacros.cc new file mode 100644 index 00000000000..53d0cdbe8a3 --- /dev/null +++ b/chromium/ui/shell_dialogs/select_file_dialog_lacros.cc @@ -0,0 +1,60 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/shell_dialogs/select_file_dialog_lacros.h" + +#include "base/bind.h" +#include "base/notreached.h" +#include "base/task/thread_pool.h" +#include "ui/shell_dialogs/select_file_policy.h" + +namespace ui { + +SelectFileDialogLacros::Factory::Factory() = default; +SelectFileDialogLacros::Factory::~Factory() = default; + +ui::SelectFileDialog* SelectFileDialogLacros::Factory::Create( + ui::SelectFileDialog::Listener* listener, + std::unique_ptr<ui::SelectFilePolicy> policy) { + return new SelectFileDialogLacros(listener, std::move(policy)); +} + +SelectFileDialogLacros::SelectFileDialogLacros( + Listener* listener, + std::unique_ptr<ui::SelectFilePolicy> policy) + : ui::SelectFileDialog(listener, std::move(policy)) {} + +SelectFileDialogLacros::~SelectFileDialogLacros() = default; + +bool SelectFileDialogLacros::HasMultipleFileTypeChoicesImpl() { + return true; +} + +bool SelectFileDialogLacros::IsRunning(gfx::NativeWindow owning_window) const { + return true; +} + +void SelectFileDialogLacros::SelectFileImpl( + Type type, + const base::string16& title, + const base::FilePath& default_path, + const FileTypeInfo* file_types, + int file_type_index, + const base::FilePath::StringType& default_extension, + gfx::NativeWindow owning_window, + void* params) { + // TODO(https://crbug.com/1090587): Proxy the request over IPC to ash-chrome. + NOTIMPLEMENTED(); + // Until we have an implementation, pretend the user cancelled the dialog. + // Post a task to avoid reentrancy issues. |this| is ref-counted. + base::ThreadPool::PostTask( + FROM_HERE, base::BindOnce(&SelectFileDialogLacros::Cancel, this, params)); +} + +void SelectFileDialogLacros::Cancel(void* params) { + if (listener_) + listener_->FileSelectionCanceled(params); +} + +} // namespace ui diff --git a/chromium/ui/shell_dialogs/select_file_dialog_lacros.h b/chromium/ui/shell_dialogs/select_file_dialog_lacros.h new file mode 100644 index 00000000000..145781b7a7e --- /dev/null +++ b/chromium/ui/shell_dialogs/select_file_dialog_lacros.h @@ -0,0 +1,60 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_LACROS_H_ +#define UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_LACROS_H_ + +#include "ui/shell_dialogs/select_file_dialog.h" +#include "ui/shell_dialogs/select_file_dialog_factory.h" +#include "ui/shell_dialogs/shell_dialogs_export.h" + +namespace ui { + +// SelectFileDialogLacros implements file open and save dialogs for the +// lacros-chrome binary. The dialog itself is handled by the file manager in +// ash-chrome. +class SelectFileDialogLacros : public SelectFileDialog { + public: + class SHELL_DIALOGS_EXPORT Factory : public SelectFileDialogFactory { + public: + Factory(); + Factory(const Factory&) = delete; + Factory& operator=(const Factory&) = delete; + ~Factory() override; + + // SelectFileDialogFactory: + ui::SelectFileDialog* Create( + ui::SelectFileDialog::Listener* listener, + std::unique_ptr<ui::SelectFilePolicy> policy) override; + }; + + SelectFileDialogLacros(Listener* listener, + std::unique_ptr<SelectFilePolicy> policy); + SelectFileDialogLacros(const SelectFileDialogLacros&) = delete; + SelectFileDialogLacros& operator=(const SelectFileDialogLacros&) = delete; + + // SelectFileDialog: + void SelectFileImpl(Type type, + const base::string16& title, + const base::FilePath& default_path, + const FileTypeInfo* file_types, + int file_type_index, + const base::FilePath::StringType& default_extension, + gfx::NativeWindow owning_window, + void* params) override; + bool HasMultipleFileTypeChoicesImpl() override; + bool IsRunning(gfx::NativeWindow owning_window) const override; + void ListenerDestroyed() override {} + + private: + // Private because SelectFileDialog is ref-counted. + ~SelectFileDialogLacros() override; + + // Calls the listener's cancel method with |params|. + void Cancel(void* params); +}; + +} // namespace ui + +#endif // UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_LACROS_H_ diff --git a/chromium/ui/shell_dialogs/select_file_dialog_mac.mm b/chromium/ui/shell_dialogs/select_file_dialog_mac.mm index 1b48a3a0be3..9b16bab3b3b 100644 --- a/chromium/ui/shell_dialogs/select_file_dialog_mac.mm +++ b/chromium/ui/shell_dialogs/select_file_dialog_mac.mm @@ -37,7 +37,7 @@ bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow parent_window) const { } void SelectFileDialogImpl::ListenerDestroyed() { - listener_ = NULL; + listener_ = nullptr; } void SelectFileDialogImpl::FileWasSelected( diff --git a/chromium/ui/shell_dialogs/select_file_dialog_win.cc b/chromium/ui/shell_dialogs/select_file_dialog_win.cc index e85d95fc680..2ea1f94ad3b 100644 --- a/chromium/ui/shell_dialogs/select_file_dialog_win.cc +++ b/chromium/ui/shell_dialogs/select_file_dialog_win.cc @@ -41,9 +41,10 @@ bool GetRegistryDescriptionFromExtension(const base::string16& file_ext, DCHECK(reg_description); base::win::RegKey reg_ext(HKEY_CLASSES_ROOT, file_ext.c_str(), KEY_READ); base::string16 reg_app; - if (reg_ext.ReadValue(NULL, ®_app) == ERROR_SUCCESS && !reg_app.empty()) { + if (reg_ext.ReadValue(nullptr, ®_app) == ERROR_SUCCESS && + !reg_app.empty()) { base::win::RegKey reg_link(HKEY_CLASSES_ROOT, reg_app.c_str(), KEY_READ); - if (reg_link.ReadValue(NULL, reg_description) == ERROR_SUCCESS) + if (reg_link.ReadValue(nullptr, reg_description) == ERROR_SUCCESS) return true; } return false; @@ -234,7 +235,7 @@ void SelectFileDialogImpl::SelectFileImpl( std::vector<FileFilterSpec> filter = GetFilterForFileTypes(file_types); HWND owner = owning_window && owning_window->GetRootWindow() ? owning_window->GetHost()->GetAcceleratedWidget() - : NULL; + : nullptr; std::unique_ptr<RunState> run_state = BeginRun(owner); @@ -264,7 +265,7 @@ bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow owning_window) const { void SelectFileDialogImpl::ListenerDestroyed() { // Our associated listener has gone away, so we shouldn't call back to it if // our worker thread returns after the listener is dead. - listener_ = NULL; + listener_ = nullptr; } void SelectFileDialogImpl::OnSelectFileExecuted( |