Make file dialogs work in <webview>, fixes #930
This commit is contained in:
parent
a1ae399d10
commit
47d7a355f2
4 changed files with 44 additions and 0 deletions
|
@ -5,6 +5,9 @@
|
||||||
#include "atom/browser/api/atom_api_web_contents.h"
|
#include "atom/browser/api/atom_api_web_contents.h"
|
||||||
|
|
||||||
#include "atom/browser/atom_browser_context.h"
|
#include "atom/browser/atom_browser_context.h"
|
||||||
|
#include "atom/browser/native_window.h"
|
||||||
|
#include "atom/browser/web_dialog_helper.h"
|
||||||
|
#include "atom/browser/web_view/web_view_renderer_state.h"
|
||||||
#include "atom/common/api/api_messages.h"
|
#include "atom/common/api/api_messages.h"
|
||||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||||
|
@ -34,6 +37,17 @@ namespace {
|
||||||
|
|
||||||
v8::Persistent<v8::ObjectTemplate> template_;
|
v8::Persistent<v8::ObjectTemplate> template_;
|
||||||
|
|
||||||
|
// Get the window that has the |guest| embedded.
|
||||||
|
NativeWindow* GetWindowFromGuest(const content::WebContents* guest) {
|
||||||
|
int guest_process_id = guest->GetRenderProcessHost()->GetID();
|
||||||
|
WebViewRendererState::WebViewInfo info;
|
||||||
|
if (!WebViewRendererState::GetInstance()->GetInfo(guest_process_id, &info))
|
||||||
|
return nullptr;
|
||||||
|
return NativeWindow::FromRenderView(
|
||||||
|
info.embedder->GetRenderProcessHost()->GetID(),
|
||||||
|
info.embedder->GetRoutingID());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
WebContents::WebContents(content::WebContents* web_contents)
|
WebContents::WebContents(content::WebContents* web_contents)
|
||||||
|
@ -135,6 +149,21 @@ content::WebContents* WebContents::OpenURLFromTab(
|
||||||
return web_contents();
|
return web_contents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::RunFileChooser(content::WebContents* guest,
|
||||||
|
const content::FileChooserParams& params) {
|
||||||
|
if (!web_dialog_helper_)
|
||||||
|
web_dialog_helper_.reset(new WebDialogHelper(GetWindowFromGuest(guest)));
|
||||||
|
web_dialog_helper_->RunFileChooser(guest, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebContents::EnumerateDirectory(content::WebContents* guest,
|
||||||
|
int request_id,
|
||||||
|
const base::FilePath& path) {
|
||||||
|
if (!web_dialog_helper_)
|
||||||
|
web_dialog_helper_.reset(new WebDialogHelper(GetWindowFromGuest(guest)));
|
||||||
|
web_dialog_helper_->EnumerateDirectory(guest, request_id, path);
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::RequestMediaAccessPermission(
|
void WebContents::RequestMediaAccessPermission(
|
||||||
content::WebContents*,
|
content::WebContents*,
|
||||||
const content::MediaStreamRequest& request,
|
const content::MediaStreamRequest& request,
|
||||||
|
|
|
@ -24,6 +24,8 @@ class Dictionary;
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
class WebDialogHelper;
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
class WebContents : public mate::EventEmitter,
|
class WebContents : public mate::EventEmitter,
|
||||||
|
@ -113,6 +115,11 @@ class WebContents : public mate::EventEmitter,
|
||||||
content::WebContents* OpenURLFromTab(
|
content::WebContents* OpenURLFromTab(
|
||||||
content::WebContents* source,
|
content::WebContents* source,
|
||||||
const content::OpenURLParams& params) override;
|
const content::OpenURLParams& params) 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 RequestMediaAccessPermission(
|
void RequestMediaAccessPermission(
|
||||||
content::WebContents*,
|
content::WebContents*,
|
||||||
const content::MediaStreamRequest&,
|
const content::MediaStreamRequest&,
|
||||||
|
@ -165,6 +172,8 @@ class WebContents : public mate::EventEmitter,
|
||||||
void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
|
void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
|
||||||
const gfx::Size& new_size);
|
const gfx::Size& new_size);
|
||||||
|
|
||||||
|
scoped_ptr<WebDialogHelper> web_dialog_helper_;
|
||||||
|
|
||||||
// Unique ID for a guest WebContents.
|
// Unique ID for a guest WebContents.
|
||||||
int guest_instance_id_;
|
int guest_instance_id_;
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ void WebViewManager::AddGuest(int guest_instance_id,
|
||||||
|
|
||||||
WebViewRendererState::WebViewInfo web_view_info = {
|
WebViewRendererState::WebViewInfo web_view_info = {
|
||||||
guest_instance_id,
|
guest_instance_id,
|
||||||
|
embedder,
|
||||||
options.node_integration,
|
options.node_integration,
|
||||||
options.plugins,
|
options.plugins,
|
||||||
options.disable_web_security,
|
options.disable_web_security,
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#include "base/memory/singleton.h"
|
#include "base/memory/singleton.h"
|
||||||
|
|
||||||
|
namespace content {
|
||||||
|
class WebContents;
|
||||||
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class WebViewManager;
|
class WebViewManager;
|
||||||
|
@ -22,6 +26,7 @@ class WebViewRendererState {
|
||||||
public:
|
public:
|
||||||
struct WebViewInfo {
|
struct WebViewInfo {
|
||||||
int guest_instance_id;
|
int guest_instance_id;
|
||||||
|
content::WebContents* embedder;
|
||||||
bool node_integration;
|
bool node_integration;
|
||||||
bool plugins;
|
bool plugins;
|
||||||
bool disable_web_security;
|
bool disable_web_security;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue