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 #include "chrome/browser/extensions/api/developer_private/entry_picker.h"
8 #include "base/files/file_path.h"
9 #include "base/strings/string_util.h"
10 #include "chrome/browser/extensions/api/developer_private/developer_private_api.h"
11 #include "chrome/browser/platform_util.h"
12 #include "chrome/browser/ui/chrome_select_file_policy.h"
13 #include "content/public/browser/web_contents.h"
14 #include "ui/shell_dialogs/select_file_dialog.h"
18 bool g_skip_picker_for_test
= false;
19 base::FilePath
* g_path_to_be_picked_for_test
= NULL
;
23 namespace extensions
{
27 EntryPicker::EntryPicker(EntryPickerClient
* client
,
28 content::WebContents
* web_contents
,
29 ui::SelectFileDialog::Type picker_type
,
30 const base::FilePath
& last_directory
,
31 const base::string16
& select_title
,
32 const ui::SelectFileDialog::FileTypeInfo
& info
,
35 if (g_skip_picker_for_test
) {
36 if (g_path_to_be_picked_for_test
) {
37 content::BrowserThread::PostTask(content::BrowserThread::UI
, FROM_HERE
,
39 &EntryPicker::FileSelected
,
40 base::Unretained(this), *g_path_to_be_picked_for_test
, 1,
41 static_cast<void*>(nullptr)));
43 content::BrowserThread::PostTask(content::BrowserThread::UI
, FROM_HERE
,
45 &EntryPicker::FileSelectionCanceled
,
46 base::Unretained(this), static_cast<void*>(nullptr)));
51 select_file_dialog_
= ui::SelectFileDialog::Create(
52 this, new ChromeSelectFilePolicy(web_contents
));
54 gfx::NativeWindow owning_window
= web_contents
?
55 platform_util::GetTopLevel(web_contents
->GetNativeView()) :
58 select_file_dialog_
->SelectFile(picker_type
,
63 base::FilePath::StringType(),
68 EntryPicker::~EntryPicker() {}
70 void EntryPicker::FileSelected(const base::FilePath
& path
,
73 client_
->FileSelected(path
);
77 void EntryPicker::FileSelectionCanceled(void* params
) {
78 client_
->FileSelectionCanceled();
82 void EntryPicker::MultiFilesSelected(const std::vector
<base::FilePath
>& files
,
85 client_
->FileSelectionCanceled();
90 void EntryPicker::SkipPickerAndAlwaysSelectPathForTest(
91 base::FilePath
* path
) {
92 g_skip_picker_for_test
= true;
93 g_path_to_be_picked_for_test
= path
;
97 void EntryPicker::SkipPickerAndAlwaysCancelForTest() {
98 g_skip_picker_for_test
= true;
99 g_path_to_be_picked_for_test
= NULL
;
103 void EntryPicker::StopSkippingPickerForTest() {
104 g_skip_picker_for_test
= false;
109 } // namespace extensions