Skip to content

Commit 8f03612

Browse files
committed
support setting the value of a file input
Fix nwjs#927 . Users can do this to set the input: var f = new File('/path/to/file', 'name'); var files = new FileList(); files.append(f); document.getElementById('input0').files = files;
1 parent c7b81f2 commit 8f03612

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

src/api/api_messages.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ IPC_MESSAGE_CONTROL1(ShellViewMsg_Open,
9494

9595
// clear cache on the renderer side
9696
IPC_MESSAGE_CONTROL0(ShellViewMsg_ClearCache)
97+
98+
// grant the policy permissions
99+
IPC_SYNC_MESSAGE_ROUTED0_1(ShellViewHostMsg_GrantUniversalPermissions, int)
100+

src/api/dispatcher_host.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "base/logging.h"
2424
#include "base/values.h"
25+
#include "content/browser/child_process_security_policy_impl.h"
2526
#include "content/browser/web_contents/web_contents_impl.h"
2627
#include "content/nw/src/api/api_messages.h"
2728
#include "content/nw/src/api/app/app.h"
@@ -79,6 +80,7 @@ bool DispatcherHost::OnMessageReceived(const IPC::Message& message) {
7980
OnUncaughtException);
8081
IPC_MESSAGE_HANDLER(ShellViewHostMsg_GetShellId, OnGetShellId);
8182
IPC_MESSAGE_HANDLER(ShellViewHostMsg_CreateShell, OnCreateShell);
83+
IPC_MESSAGE_HANDLER(ShellViewHostMsg_GrantUniversalPermissions, OnGrantUniversalPermissions);
8284
IPC_MESSAGE_UNHANDLED(handled = false)
8385
IPC_END_MESSAGE_MAP()
8486

@@ -228,4 +230,14 @@ void DispatcherHost::OnCreateShell(const std::string& url,
228230
*routing_id = web_contents->GetRoutingID();
229231
}
230232

233+
void DispatcherHost::OnGrantUniversalPermissions(int *ret) {
234+
content::Shell* shell =
235+
content::Shell::FromRenderViewHost(render_view_host());
236+
if (shell->nodejs()) {
237+
content::ChildProcessSecurityPolicy::GetInstance()->GrantUniversalAccess(shell->web_contents()->GetRenderProcessHost()->GetID());
238+
*ret = 1;
239+
}else
240+
*ret = 0;
241+
}
242+
231243
} // namespace api

src/api/dispatcher_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class DispatcherHost : public content::RenderViewHostObserver {
9595
void OnCreateShell(const std::string& url,
9696
const base::DictionaryValue& manifest,
9797
int* routing_id);
98-
98+
void OnGrantUniversalPermissions(int* ret);
9999
DISALLOW_COPY_AND_ASSIGN(DispatcherHost);
100100
};
101101

src/renderer/shell_content_renderer_client.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ bool ShellContentRendererClient::WillSetSecurityToken(
212212
// Override context's security token
213213
context->SetSecurityToken(node::g_context->GetSecurityToken());
214214
frame->document().securityOrigin().grantUniversalAccess();
215+
216+
int ret;
217+
RenderViewImpl* rv = RenderViewImpl::FromWebView(frame->view());
218+
rv->Send(new ShellViewHostMsg_GrantUniversalPermissions(rv->GetRoutingID(), &ret));
219+
215220
return true;
216221
}
217222

0 commit comments

Comments
 (0)