#include "atom/browser/atom_javascript_dialog_manager.h"
#include "atom/browser/browser.h"
#include "atom/browser/ui/file_dialog.h"
+#include "atom/browser/web_dialog_helper.h"
#include "atom/browser/window_list.h"
#include "atom/common/api/api_messages.h"
#include "atom/common/atom_version.h"
}
}
+void NativeWindow::RunFileChooser(content::WebContents* web_contents,
+ const content::FileChooserParams& params) {
+ if (!web_dialog_helper_)
+ web_dialog_helper_.reset(new WebDialogHelper(this));
+ web_dialog_helper_->RunFileChooser(web_contents, params);
+}
+
+void NativeWindow::EnumerateDirectory(content::WebContents* web_contents,
+ int request_id,
+ const base::FilePath& path) {
+ if (!web_dialog_helper_)
+ web_dialog_helper_.reset(new WebDialogHelper(this));
+ web_dialog_helper_->EnumerateDirectory(web_contents, request_id, path);
+}
+
void NativeWindow::RequestToLockMouse(content::WebContents* web_contents,
bool user_gesture,
bool last_unlocked_by_target) {
class AtomJavaScriptDialogManager;
struct DraggableRegion;
+class WebDialogHelper;
class NativeWindow : public brightray::DefaultWebContentsDelegate,
public brightray::InspectableWebContentsDelegate,
void BeforeUnloadFired(content::WebContents* tab,
bool proceed,
bool* proceed_to_fire_unload) override;
+ void RunFileChooser(content::WebContents* web_contents,
+ const content::FileChooserParams& params) override;
+ void EnumerateDirectory(content::WebContents* web_contents,
+ int request_id,
+ const base::FilePath& path) override;
void RequestToLockMouse(content::WebContents* web_contents,
bool user_gesture,
bool last_unlocked_by_target) override;
base::WeakPtrFactory<NativeWindow> weak_factory_;
+ scoped_ptr<WebDialogHelper> web_dialog_helper_;
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
// Notice that inspectable_web_contents_ must be placed after dialog_manager_,
#include "atom/browser/web_dialog_helper.h"
+#include <vector>
+
#include "atom/browser/ui/file_dialog.h"
#include "base/bind.h"
+#include "base/files/file_enumerator.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
namespace atom {
-WebDialogHelper::WebDialogHelper(content::WebContents* web_contents,
- NativeWindow* window)
- : web_contents_(web_contents),
- window_(window),
+WebDialogHelper::WebDialogHelper(NativeWindow* window)
+ : window_(window),
weak_factory_(this) {
}
WebDialogHelper::~WebDialogHelper() {
}
-void WebDialogHelper::RunFileChooser(const content::FileChooserParams& params) {
+void WebDialogHelper::RunFileChooser(content::WebContents* web_contents,
+ const content::FileChooserParams& params) {
}
-void WebDialogHelper::EnumerateDirectory(int request_id,
- const base::FilePath& path) {
+void WebDialogHelper::EnumerateDirectory(content::WebContents* web_contents,
+ int request_id,
+ const base::FilePath& dir) {
+ int types = base::FileEnumerator::FILES |
+ base::FileEnumerator::DIRECTORIES |
+ base::FileEnumerator::INCLUDE_DOT_DOT;
+ base::FileEnumerator file_enum(dir, false, types);
+
+ base::FilePath path;
+ std::vector<base::FilePath> paths;
+ while (!(path = file_enum.Next()).empty())
+ paths.push_back(path);
+
+ web_contents->GetRenderViewHost()->DirectoryEnumerationFinished(
+ request_id, paths);
}
} // namespace atom
#ifndef ATOM_BROWSER_WEB_DIALOG_HELPER_H_
#define ATOM_BROWSER_WEB_DIALOG_HELPER_H_
-#include <vector>
-
#include "base/memory/weak_ptr.h"
namespace base {
}
namespace content {
+struct FileChooserParams;
class WebContents;
-class FileChooserParams;
}
namespace atom {
class WebDialogHelper {
public:
- WebDialogHelper(content::WebContents* web_contents, NativeWindow* window);
+ explicit WebDialogHelper(NativeWindow* window);
~WebDialogHelper();
- void RunFileChooser(const content::FileChooserParams& params);
- void EnumerateDirectory(int request_id, const base::FilePath& path);
+ void RunFileChooser(content::WebContents* web_contents,
+ const content::FileChooserParams& params);
+ void EnumerateDirectory(content::WebContents* web_contents,
+ int request_id,
+ const base::FilePath& path);
private:
- content::WebContents* web_contents_;
NativeWindow* window_;
base::WeakPtrFactory<WebDialogHelper> weak_factory_;