Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: content/browser/renderer_host/pepper/pepper_security_helper.cc

Issue 23760004: ChildProcessSecurityPolicy: Port FileAPIMessageFilter to use new checks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/pepper/pepper_security_helper.h" 5 #include "content/browser/renderer_host/pepper/pepper_security_helper.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/child_process_security_policy_impl.h" 8 #include "content/browser/child_process_security_policy_impl.h"
9 #include "ppapi/c/ppb_file_io.h" 9 #include "ppapi/c/ppb_file_io.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 bool CanOpenWithPepperFlags(int pp_open_flags, int child_id, 13 namespace {
14 const base::FilePath& file) { 14
15 template <typename CanRead, typename CanWrite,
16 typename CanCreate, typename CanCreateWrite,
17 typename FileID>
18 bool CanOpenFileWithPepperFlags(CanRead can_read,
19 CanWrite can_write,
20 CanCreate can_create,
21 CanCreateWrite can_create_write,
22 int pp_open_flags,
23 int child_id,
24 const FileID& file) {
15 ChildProcessSecurityPolicyImpl* policy = 25 ChildProcessSecurityPolicyImpl* policy =
16 ChildProcessSecurityPolicyImpl::GetInstance(); 26 ChildProcessSecurityPolicyImpl::GetInstance();
17 27
18 bool pp_read = !!(pp_open_flags & PP_FILEOPENFLAG_READ); 28 bool pp_read = !!(pp_open_flags & PP_FILEOPENFLAG_READ);
19 bool pp_write = !!(pp_open_flags & PP_FILEOPENFLAG_WRITE); 29 bool pp_write = !!(pp_open_flags & PP_FILEOPENFLAG_WRITE);
20 bool pp_create = !!(pp_open_flags & PP_FILEOPENFLAG_CREATE); 30 bool pp_create = !!(pp_open_flags & PP_FILEOPENFLAG_CREATE);
21 bool pp_truncate = !!(pp_open_flags & PP_FILEOPENFLAG_TRUNCATE); 31 bool pp_truncate = !!(pp_open_flags & PP_FILEOPENFLAG_TRUNCATE);
22 bool pp_exclusive = !!(pp_open_flags & PP_FILEOPENFLAG_EXCLUSIVE); 32 bool pp_exclusive = !!(pp_open_flags & PP_FILEOPENFLAG_EXCLUSIVE);
23 bool pp_append = !!(pp_open_flags & PP_FILEOPENFLAG_APPEND); 33 bool pp_append = !!(pp_open_flags & PP_FILEOPENFLAG_APPEND);
24 34
25 if (pp_read && !policy->CanReadFile(child_id, file)) 35 if (pp_read && !(policy->*can_read)(child_id, file))
26 return false; 36 return false;
27 37
28 if (pp_write && !policy->CanWriteFile(child_id, file)) 38 if (pp_write && !(policy->*can_write)(child_id, file))
29 return false; 39 return false;
30 40
31 if (pp_append) { 41 // TODO(tommycli): Maybe tighten up required permission. crbug.com/284792
32 // Given ChildSecurityPolicyImpl's current definition of permissions, 42 if (pp_append && !(policy->*can_create_write)(child_id, file))
33 // APPEND is never supported.
34 return false; 43 return false;
35 }
36 44
37 if (pp_truncate && !pp_write) 45 if (pp_truncate && !pp_write)
38 return false; 46 return false;
39 47
40 if (pp_create) { 48 if (pp_create) {
41 if (pp_exclusive) { 49 if (pp_exclusive) {
42 return policy->CanCreateFile(child_id, file); 50 return (policy->*can_create)(child_id, file);
43 } else { 51 } else {
44 // Asks for too much, but this is the only grant that allows overwrite. 52 // Asks for too much, but this is the only grant that allows overwrite.
45 return policy->CanCreateWriteFile(child_id, file); 53 return (policy->*can_create_write)(child_id, file);
46 } 54 }
47 } else if (pp_truncate) { 55 } else if (pp_truncate) {
48 return policy->CanCreateWriteFile(child_id, file); 56 return (policy->*can_create_write)(child_id, file);
49 } 57 }
50 58
51 return true; 59 return true;
52 } 60 }
53 61
62 }
63
64 bool CanOpenWithPepperFlags(int pp_open_flags, int child_id,
65 const base::FilePath& file) {
66 return CanOpenFileWithPepperFlags(
67 &ChildProcessSecurityPolicyImpl::CanReadFile,
68 &ChildProcessSecurityPolicyImpl::CanWriteFile,
69 &ChildProcessSecurityPolicyImpl::CanCreateFile,
70 &ChildProcessSecurityPolicyImpl::CanCreateWriteFile,
71 pp_open_flags, child_id, file);
72 }
73
74 bool CanOpenFileSystemURLWithPepperFlags(int pp_open_flags, int child_id,
75 const fileapi::FileSystemURL& url) {
76 return CanOpenFileWithPepperFlags(
77 &ChildProcessSecurityPolicyImpl::CanReadFileSystemFile,
78 &ChildProcessSecurityPolicyImpl::CanWriteFileSystemFile,
79 &ChildProcessSecurityPolicyImpl::CanCreateFileSystemFile,
80 &ChildProcessSecurityPolicyImpl::CanCreateWriteFileSystemFile,
81 pp_open_flags, child_id, url);
82 }
83
54 } // namespace content 84 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/pepper/pepper_security_helper.h ('k') | content/child/fileapi/file_system_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698