OLD | NEW |
---|---|
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 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 bool pp_truncate = !!(pp_open_flags & PP_FILEOPENFLAG_TRUNCATE); | 21 bool pp_truncate = !!(pp_open_flags & PP_FILEOPENFLAG_TRUNCATE); |
22 bool pp_exclusive = !!(pp_open_flags & PP_FILEOPENFLAG_EXCLUSIVE); | 22 bool pp_exclusive = !!(pp_open_flags & PP_FILEOPENFLAG_EXCLUSIVE); |
23 bool pp_append = !!(pp_open_flags & PP_FILEOPENFLAG_APPEND); | 23 bool pp_append = !!(pp_open_flags & PP_FILEOPENFLAG_APPEND); |
24 | 24 |
25 if (pp_read && !policy->CanReadFile(child_id, file)) | 25 if (pp_read && !policy->CanReadFile(child_id, file)) |
26 return false; | 26 return false; |
27 | 27 |
28 if (pp_write && !policy->CanWriteFile(child_id, file)) | 28 if (pp_write && !policy->CanWriteFile(child_id, file)) |
29 return false; | 29 return false; |
30 | 30 |
31 if (pp_append) { | 31 // TODO(tommycli): Maybe tighten up required permission. crbug.com/284792 |
32 // Given ChildSecurityPolicyImpl's current definition of permissions, | 32 if (pp_append && !policy->CanCreateWriteFile(child_id, file)) |
33 // APPEND is never supported. | |
34 return false; | 33 return false; |
35 } | |
36 | 34 |
37 if (pp_truncate && !pp_write) | 35 if (pp_truncate && !pp_write) |
38 return false; | 36 return false; |
39 | 37 |
40 if (pp_create) { | 38 if (pp_create) { |
41 if (pp_exclusive) { | 39 if (pp_exclusive) { |
42 return policy->CanCreateFile(child_id, file); | 40 return policy->CanCreateFile(child_id, file); |
43 } else { | 41 } else { |
44 // Asks for too much, but this is the only grant that allows overwrite. | 42 // Asks for too much, but this is the only grant that allows overwrite. |
45 return policy->CanCreateWriteFile(child_id, file); | 43 return policy->CanCreateWriteFile(child_id, file); |
46 } | 44 } |
47 } else if (pp_truncate) { | 45 } else if (pp_truncate) { |
48 return policy->CanCreateWriteFile(child_id, file); | 46 return policy->CanCreateWriteFile(child_id, file); |
49 } | 47 } |
50 | 48 |
51 return true; | 49 return true; |
52 } | 50 } |
53 | 51 |
52 bool CanOpenFileSystemURLWithPepperFlags(int pp_open_flags, int child_id, | |
53 const fileapi::FileSystemURL& url) { | |
54 ChildProcessSecurityPolicyImpl* policy = | |
55 ChildProcessSecurityPolicyImpl::GetInstance(); | |
56 | |
57 bool pp_read = !!(pp_open_flags & PP_FILEOPENFLAG_READ); | |
Tom Sepez
2013/09/04 22:22:45
Seems a shame to have this same logic here and abo
tommycli
2013/09/04 23:21:27
I agree it's a shame. The only obvious way I saw t
kinuko
2013/09/05 03:49:43
Could we make the common logic a template? I thin
tommycli
2013/09/06 01:41:43
Done. I had no idea you could do this with templat
| |
58 bool pp_write = !!(pp_open_flags & PP_FILEOPENFLAG_WRITE); | |
59 bool pp_create = !!(pp_open_flags & PP_FILEOPENFLAG_CREATE); | |
60 bool pp_truncate = !!(pp_open_flags & PP_FILEOPENFLAG_TRUNCATE); | |
61 bool pp_exclusive = !!(pp_open_flags & PP_FILEOPENFLAG_EXCLUSIVE); | |
62 bool pp_append = !!(pp_open_flags & PP_FILEOPENFLAG_APPEND); | |
63 | |
64 if (pp_read && !policy->CanReadFileSystemFile(child_id, url)) | |
65 return false; | |
66 | |
67 if (pp_write && !policy->CanWriteFileSystemFile(child_id, url)) | |
68 return false; | |
69 | |
70 // TODO(tommycli): Maybe tighten up required permission. crbug.com/284792 | |
71 if (pp_append && !policy->CanCreateWriteFileSystemFile(child_id, url)) | |
72 return false; | |
73 | |
74 if (pp_truncate && !pp_write) | |
75 return false; | |
76 | |
77 if (pp_create) { | |
78 if (pp_exclusive) { | |
79 return policy->CanCreateFileSystemFile(child_id, url); | |
80 } else { | |
81 // Asks for too much, but this is the only grant that allows overwrite. | |
82 return policy->CanCreateWriteFileSystemFile(child_id, url); | |
83 } | |
84 } else if (pp_truncate) { | |
85 return policy->CanCreateWriteFileSystemFile(child_id, url); | |
86 } | |
87 | |
88 return true; | |
89 } | |
90 | |
54 } // namespace content | 91 } // namespace content |
OLD | NEW |