| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_CHILD_PROCESS_SECURITY_POLICY_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_CHILD_PROCESS_SECURITY_POLICY_IMPL_H_ |
| 6 #define CONTENT_BROWSER_CHILD_PROCESS_SECURITY_POLICY_IMPL_H_ | 6 #define CONTENT_BROWSER_CHILD_PROCESS_SECURITY_POLICY_IMPL_H_ |
| 7 | 7 |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 public: | 30 public: |
| 31 // Object can only be created through GetInstance() so the constructor is | 31 // Object can only be created through GetInstance() so the constructor is |
| 32 // private. | 32 // private. |
| 33 virtual ~ChildProcessSecurityPolicyImpl(); | 33 virtual ~ChildProcessSecurityPolicyImpl(); |
| 34 | 34 |
| 35 static ChildProcessSecurityPolicyImpl* GetInstance(); | 35 static ChildProcessSecurityPolicyImpl* GetInstance(); |
| 36 | 36 |
| 37 // ChildProcessSecurityPolicy implementation. | 37 // ChildProcessSecurityPolicy implementation. |
| 38 virtual void RegisterWebSafeScheme(const std::string& scheme) OVERRIDE; | 38 virtual void RegisterWebSafeScheme(const std::string& scheme) OVERRIDE; |
| 39 virtual bool IsWebSafeScheme(const std::string& scheme) OVERRIDE; | 39 virtual bool IsWebSafeScheme(const std::string& scheme) OVERRIDE; |
| 40 virtual void GrantPermissionsForFile(int child_id, | |
| 41 const base::FilePath& file, | |
| 42 int permissions) OVERRIDE; | |
| 43 virtual void GrantReadFile(int child_id, const base::FilePath& file) OVERRIDE; | 40 virtual void GrantReadFile(int child_id, const base::FilePath& file) OVERRIDE; |
| 41 virtual void GrantReadWriteFile(int child_id, |
| 42 const base::FilePath& file) OVERRIDE; |
| 43 virtual void GrantCreateWriteFile(int child_id, |
| 44 const base::FilePath& file) OVERRIDE; |
| 44 virtual void GrantReadFileSystem( | 45 virtual void GrantReadFileSystem( |
| 45 int child_id, | 46 int child_id, |
| 46 const std::string& filesystem_id) OVERRIDE; | 47 const std::string& filesystem_id) OVERRIDE; |
| 47 virtual void GrantWriteFileSystem( | 48 virtual void GrantWriteFileSystem( |
| 48 int child_id, | 49 int child_id, |
| 49 const std::string& filesystem_id) OVERRIDE; | 50 const std::string& filesystem_id) OVERRIDE; |
| 50 virtual void GrantCreateFileForFileSystem( | 51 virtual void GrantCreateFileForFileSystem( |
| 51 int child_id, | 52 int child_id, |
| 52 const std::string& filesystem_id) OVERRIDE; | 53 const std::string& filesystem_id) OVERRIDE; |
| 53 virtual void GrantScheme(int child_id, const std::string& scheme) OVERRIDE; | 54 virtual void GrantScheme(int child_id, const std::string& scheme) OVERRIDE; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // Only might return false if the very experimental | 150 // Only might return false if the very experimental |
| 150 // --enable-strict-site-isolation or --site-per-process flags are used. | 151 // --enable-strict-site-isolation or --site-per-process flags are used. |
| 151 bool CanSendCookiesForOrigin(int child_id, const GURL& gurl); | 152 bool CanSendCookiesForOrigin(int child_id, const GURL& gurl); |
| 152 | 153 |
| 153 // Sets the process as only permitted to use and see the cookies for the | 154 // Sets the process as only permitted to use and see the cookies for the |
| 154 // given origin. | 155 // given origin. |
| 155 // Only used if the very experimental --enable-strict-site-isolation or | 156 // Only used if the very experimental --enable-strict-site-isolation or |
| 156 // --site-per-process flags are used. | 157 // --site-per-process flags are used. |
| 157 void LockToOrigin(int child_id, const GURL& gurl); | 158 void LockToOrigin(int child_id, const GURL& gurl); |
| 158 | 159 |
| 159 // Grants access permission to the given isolated file system | |
| 160 // identified by |filesystem_id|. See comments for | |
| 161 // ChildProcessSecurityPolicy::GrantReadFileSystem() for more details. | |
| 162 void GrantPermissionsForFileSystem( | |
| 163 int child_id, | |
| 164 const std::string& filesystem_id, | |
| 165 int permission); | |
| 166 | |
| 167 // Determines if certain permissions were granted for a file fystem. | 160 // Determines if certain permissions were granted for a file fystem. |
| 168 // |permissions| must be a bit-set of base::PlatformFileFlags. | 161 // |permissions| must be a bit-set of base::PlatformFileFlags. |
| 169 bool HasPermissionsForFileSystem( | 162 bool HasPermissionsForFileSystem( |
| 170 int child_id, | 163 int child_id, |
| 171 const std::string& filesystem_id, | 164 const std::string& filesystem_id, |
| 172 int permission); | 165 int permission); |
| 173 | 166 |
| 174 private: | 167 private: |
| 175 friend class ChildProcessSecurityPolicyInProcessBrowserTest; | 168 friend class ChildProcessSecurityPolicyInProcessBrowserTest; |
| 169 friend class ChildProcessSecurityPolicyTest; |
| 176 FRIEND_TEST_ALL_PREFIXES(ChildProcessSecurityPolicyInProcessBrowserTest, | 170 FRIEND_TEST_ALL_PREFIXES(ChildProcessSecurityPolicyInProcessBrowserTest, |
| 177 NoLeak); | 171 NoLeak); |
| 178 | 172 |
| 179 class SecurityState; | 173 class SecurityState; |
| 180 | 174 |
| 181 typedef std::set<std::string> SchemeSet; | 175 typedef std::set<std::string> SchemeSet; |
| 182 typedef std::map<int, SecurityState*> SecurityStateMap; | 176 typedef std::map<int, SecurityState*> SecurityStateMap; |
| 183 typedef std::map<int, int> WorkerToMainProcessMap; | 177 typedef std::map<int, int> WorkerToMainProcessMap; |
| 184 | 178 |
| 185 // Obtain an instance of ChildProcessSecurityPolicyImpl via GetInstance(). | 179 // Obtain an instance of ChildProcessSecurityPolicyImpl via GetInstance(). |
| 186 ChildProcessSecurityPolicyImpl(); | 180 ChildProcessSecurityPolicyImpl(); |
| 187 friend struct DefaultSingletonTraits<ChildProcessSecurityPolicyImpl>; | 181 friend struct DefaultSingletonTraits<ChildProcessSecurityPolicyImpl>; |
| 188 | 182 |
| 189 // Adds child process during registration. | 183 // Adds child process during registration. |
| 190 void AddChild(int child_id); | 184 void AddChild(int child_id); |
| 191 | 185 |
| 192 // Determines if certain permissions were granted for a file to given child | 186 // Determines if certain permissions were granted for a file to given child |
| 193 // process. |permissions| must be a bit-set of base::PlatformFileFlags. | 187 // process. |permissions| must be a bit-set of base::PlatformFileFlags. |
| 194 bool ChildProcessHasPermissionsForFile(int child_id, | 188 bool ChildProcessHasPermissionsForFile(int child_id, |
| 195 const base::FilePath& file, | 189 const base::FilePath& file, |
| 196 int permissions); | 190 int permissions); |
| 197 | 191 |
| 192 // Grant a particular permission set for a file. |permissions| is a bit-set |
| 193 // of base::PlatformFileFlags. |
| 194 void GrantPermissionsForFile(int child_id, |
| 195 const base::FilePath& file, |
| 196 int permissions); |
| 197 |
| 198 // Grants access permission to the given isolated file system |
| 199 // identified by |filesystem_id|. See comments for |
| 200 // ChildProcessSecurityPolicy::GrantReadFileSystem() for more details. |
| 201 void GrantPermissionsForFileSystem( |
| 202 int child_id, |
| 203 const std::string& filesystem_id, |
| 204 int permission); |
| 205 |
| 198 // You must acquire this lock before reading or writing any members of this | 206 // You must acquire this lock before reading or writing any members of this |
| 199 // class. You must not block while holding this lock. | 207 // class. You must not block while holding this lock. |
| 200 base::Lock lock_; | 208 base::Lock lock_; |
| 201 | 209 |
| 202 // These schemes are white-listed for all child processes. This set is | 210 // These schemes are white-listed for all child processes. This set is |
| 203 // protected by |lock_|. | 211 // protected by |lock_|. |
| 204 SchemeSet web_safe_schemes_; | 212 SchemeSet web_safe_schemes_; |
| 205 | 213 |
| 206 // These schemes do not actually represent retrievable URLs. For example, | 214 // These schemes do not actually represent retrievable URLs. For example, |
| 207 // the the URLs in the "about" scheme are aliases to other URLs. This set is | 215 // the the URLs in the "about" scheme are aliases to other URLs. This set is |
| 208 // protected by |lock_|. | 216 // protected by |lock_|. |
| 209 SchemeSet pseudo_schemes_; | 217 SchemeSet pseudo_schemes_; |
| 210 | 218 |
| 211 // This map holds a SecurityState for each child process. The key for the | 219 // This map holds a SecurityState for each child process. The key for the |
| 212 // map is the ID of the ChildProcessHost. The SecurityState objects are | 220 // map is the ID of the ChildProcessHost. The SecurityState objects are |
| 213 // owned by this object and are protected by |lock_|. References to them must | 221 // owned by this object and are protected by |lock_|. References to them must |
| 214 // not escape this class. | 222 // not escape this class. |
| 215 SecurityStateMap security_state_; | 223 SecurityStateMap security_state_; |
| 216 | 224 |
| 217 // This maps keeps the record of which js worker thread child process | 225 // This maps keeps the record of which js worker thread child process |
| 218 // corresponds to which main js thread child process. | 226 // corresponds to which main js thread child process. |
| 219 WorkerToMainProcessMap worker_map_; | 227 WorkerToMainProcessMap worker_map_; |
| 220 | 228 |
| 221 DISALLOW_COPY_AND_ASSIGN(ChildProcessSecurityPolicyImpl); | 229 DISALLOW_COPY_AND_ASSIGN(ChildProcessSecurityPolicyImpl); |
| 222 }; | 230 }; |
| 223 | 231 |
| 224 } // namespace content | 232 } // namespace content |
| 225 | 233 |
| 226 #endif // CONTENT_BROWSER_CHILD_PROCESS_SECURITY_POLICY_IMPL_H_ | 234 #endif // CONTENT_BROWSER_CHILD_PROCESS_SECURITY_POLICY_IMPL_H_ |
| OLD | NEW |