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 select_file_dialog_ = ui::SelectFileDialog::Create(
36 this, new ChromeSelectFilePolicy(web_contents));
38 gfx::NativeWindow owning_window = web_contents ?
39 platform_util::GetTopLevel(web_contents->GetNativeView()) :
42 if (g_skip_picker_for_test) {
43 if (g_path_to_be_picked_for_test) {
44 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
46 &EntryPicker::FileSelected,
47 base::Unretained(this), *g_path_to_be_picked_for_test, 1,
48 static_cast<void*>(NULL)));
50 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
52 &EntryPicker::FileSelectionCanceled,
53 base::Unretained(this), static_cast<void*>(NULL)));
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();
83 void EntryPicker::SkipPickerAndAlwaysSelectPathForTest(
84 base::FilePath* path) {
85 g_skip_picker_for_test = true;
86 g_path_to_be_picked_for_test = path;
90 void EntryPicker::SkipPickerAndAlwaysCancelForTest() {
91 g_skip_picker_for_test = true;
92 g_path_to_be_picked_for_test = NULL;
96 void EntryPicker::StopSkippingPickerForTest() {
97 g_skip_picker_for_test = false;
102 } // namespace extensions