Implement EnumerateDirectory
This commit is contained in:
parent
b710cc3063
commit
9b1bcf51c6
4 changed files with 54 additions and 14 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include "atom/browser/atom_javascript_dialog_manager.h"
|
#include "atom/browser/atom_javascript_dialog_manager.h"
|
||||||
#include "atom/browser/browser.h"
|
#include "atom/browser/browser.h"
|
||||||
#include "atom/browser/ui/file_dialog.h"
|
#include "atom/browser/ui/file_dialog.h"
|
||||||
|
#include "atom/browser/web_dialog_helper.h"
|
||||||
#include "atom/browser/window_list.h"
|
#include "atom/browser/window_list.h"
|
||||||
#include "atom/common/api/api_messages.h"
|
#include "atom/common/api/api_messages.h"
|
||||||
#include "atom/common/atom_version.h"
|
#include "atom/common/atom_version.h"
|
||||||
|
@ -483,6 +484,21 @@ void NativeWindow::BeforeUnloadFired(content::WebContents* tab,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
void NativeWindow::RequestToLockMouse(content::WebContents* web_contents,
|
||||||
bool user_gesture,
|
bool user_gesture,
|
||||||
bool last_unlocked_by_target) {
|
bool last_unlocked_by_target) {
|
||||||
|
|
|
@ -51,6 +51,7 @@ namespace atom {
|
||||||
|
|
||||||
class AtomJavaScriptDialogManager;
|
class AtomJavaScriptDialogManager;
|
||||||
struct DraggableRegion;
|
struct DraggableRegion;
|
||||||
|
class WebDialogHelper;
|
||||||
|
|
||||||
class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
public brightray::InspectableWebContentsDelegate,
|
public brightray::InspectableWebContentsDelegate,
|
||||||
|
@ -229,6 +230,11 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
void BeforeUnloadFired(content::WebContents* tab,
|
void BeforeUnloadFired(content::WebContents* tab,
|
||||||
bool proceed,
|
bool proceed,
|
||||||
bool* proceed_to_fire_unload) override;
|
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,
|
void RequestToLockMouse(content::WebContents* web_contents,
|
||||||
bool user_gesture,
|
bool user_gesture,
|
||||||
bool last_unlocked_by_target) override;
|
bool last_unlocked_by_target) override;
|
||||||
|
@ -313,6 +319,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
|
|
||||||
base::WeakPtrFactory<NativeWindow> weak_factory_;
|
base::WeakPtrFactory<NativeWindow> weak_factory_;
|
||||||
|
|
||||||
|
scoped_ptr<WebDialogHelper> web_dialog_helper_;
|
||||||
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
||||||
|
|
||||||
// Notice that inspectable_web_contents_ must be placed after dialog_manager_,
|
// Notice that inspectable_web_contents_ must be placed after dialog_manager_,
|
||||||
|
|
|
@ -4,26 +4,43 @@
|
||||||
|
|
||||||
#include "atom/browser/web_dialog_helper.h"
|
#include "atom/browser/web_dialog_helper.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "atom/browser/ui/file_dialog.h"
|
#include "atom/browser/ui/file_dialog.h"
|
||||||
#include "base/bind.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 {
|
namespace atom {
|
||||||
|
|
||||||
WebDialogHelper::WebDialogHelper(content::WebContents* web_contents,
|
WebDialogHelper::WebDialogHelper(NativeWindow* window)
|
||||||
NativeWindow* window)
|
: window_(window),
|
||||||
: web_contents_(web_contents),
|
|
||||||
window_(window),
|
|
||||||
weak_factory_(this) {
|
weak_factory_(this) {
|
||||||
}
|
}
|
||||||
|
|
||||||
WebDialogHelper::~WebDialogHelper() {
|
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,
|
void WebDialogHelper::EnumerateDirectory(content::WebContents* web_contents,
|
||||||
const base::FilePath& path) {
|
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
|
} // namespace atom
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
#ifndef ATOM_BROWSER_WEB_DIALOG_HELPER_H_
|
#ifndef ATOM_BROWSER_WEB_DIALOG_HELPER_H_
|
||||||
#define ATOM_BROWSER_WEB_DIALOG_HELPER_H_
|
#define ATOM_BROWSER_WEB_DIALOG_HELPER_H_
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "base/memory/weak_ptr.h"
|
#include "base/memory/weak_ptr.h"
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
|
@ -14,8 +12,8 @@ class FilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
|
struct FileChooserParams;
|
||||||
class WebContents;
|
class WebContents;
|
||||||
class FileChooserParams;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -24,14 +22,16 @@ class NativeWindow;
|
||||||
|
|
||||||
class WebDialogHelper {
|
class WebDialogHelper {
|
||||||
public:
|
public:
|
||||||
WebDialogHelper(content::WebContents* web_contents, NativeWindow* window);
|
explicit WebDialogHelper(NativeWindow* window);
|
||||||
~WebDialogHelper();
|
~WebDialogHelper();
|
||||||
|
|
||||||
void RunFileChooser(const content::FileChooserParams& params);
|
void RunFileChooser(content::WebContents* web_contents,
|
||||||
void EnumerateDirectory(int request_id, const base::FilePath& path);
|
const content::FileChooserParams& params);
|
||||||
|
void EnumerateDirectory(content::WebContents* web_contents,
|
||||||
|
int request_id,
|
||||||
|
const base::FilePath& path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
content::WebContents* web_contents_;
|
|
||||||
NativeWindow* window_;
|
NativeWindow* window_;
|
||||||
|
|
||||||
base::WeakPtrFactory<WebDialogHelper> weak_factory_;
|
base::WeakPtrFactory<WebDialogHelper> weak_factory_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue