|
5 | 5 | #include "atom/browser/api/atom_api_web_contents.h"
|
6 | 6 |
|
7 | 7 | #include "atom/browser/atom_browser_context.h"
|
| 8 | +#include "atom/browser/native_window.h" |
| 9 | +#include "atom/browser/web_dialog_helper.h" |
| 10 | +#include "atom/browser/web_view/web_view_renderer_state.h" |
8 | 11 | #include "atom/common/api/api_messages.h"
|
9 | 12 | #include "atom/common/native_mate_converters/gfx_converter.h"
|
10 | 13 | #include "atom/common/native_mate_converters/gurl_converter.h"
|
@@ -34,6 +37,17 @@ namespace {
|
34 | 37 |
|
35 | 38 | v8::Persistent<v8::ObjectTemplate> template_;
|
36 | 39 |
|
| 40 | +// Get the window that has the |guest| embedded. |
| 41 | +NativeWindow* GetWindowFromGuest(const content::WebContents* guest) { |
| 42 | + int guest_process_id = guest->GetRenderProcessHost()->GetID(); |
| 43 | + WebViewRendererState::WebViewInfo info; |
| 44 | + if (!WebViewRendererState::GetInstance()->GetInfo(guest_process_id, &info)) |
| 45 | + return nullptr; |
| 46 | + return NativeWindow::FromRenderView( |
| 47 | + info.embedder->GetRenderProcessHost()->GetID(), |
| 48 | + info.embedder->GetRoutingID()); |
| 49 | +} |
| 50 | + |
37 | 51 | } // namespace
|
38 | 52 |
|
39 | 53 | WebContents::WebContents(content::WebContents* web_contents)
|
@@ -135,6 +149,21 @@ content::WebContents* WebContents::OpenURLFromTab(
|
135 | 149 | return web_contents();
|
136 | 150 | }
|
137 | 151 |
|
| 152 | +void WebContents::RunFileChooser(content::WebContents* guest, |
| 153 | + const content::FileChooserParams& params) { |
| 154 | + if (!web_dialog_helper_) |
| 155 | + web_dialog_helper_.reset(new WebDialogHelper(GetWindowFromGuest(guest))); |
| 156 | + web_dialog_helper_->RunFileChooser(guest, params); |
| 157 | +} |
| 158 | + |
| 159 | +void WebContents::EnumerateDirectory(content::WebContents* guest, |
| 160 | + int request_id, |
| 161 | + const base::FilePath& path) { |
| 162 | + if (!web_dialog_helper_) |
| 163 | + web_dialog_helper_.reset(new WebDialogHelper(GetWindowFromGuest(guest))); |
| 164 | + web_dialog_helper_->EnumerateDirectory(guest, request_id, path); |
| 165 | +} |
| 166 | + |
138 | 167 | void WebContents::RequestMediaAccessPermission(
|
139 | 168 | content::WebContents*,
|
140 | 169 | const content::MediaStreamRequest& request,
|
|
0 commit comments