| 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 #include "content/browser/child_process_security_policy.h" | 5 #include "content/browser/child_process_security_policy_impl.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "content/browser/site_instance_impl.h" | 13 #include "content/browser/site_instance_impl.h" |
| 14 #include "content/public/browser/content_browser_client.h" | 14 #include "content/public/browser/content_browser_client.h" |
| 15 #include "content/public/common/bindings_policy.h" | 15 #include "content/public/common/bindings_policy.h" |
| 16 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 19 #include "webkit/fileapi/isolated_context.h" | 19 #include "webkit/fileapi/isolated_context.h" |
| 20 | 20 |
| 21 using content::ChildProcessSecurityPolicy; |
| 21 using content::SiteInstance; | 22 using content::SiteInstance; |
| 22 | 23 |
| 23 static const int kReadFilePermissions = | 24 static const int kReadFilePermissions = |
| 24 base::PLATFORM_FILE_OPEN | | 25 base::PLATFORM_FILE_OPEN | |
| 25 base::PLATFORM_FILE_READ | | 26 base::PLATFORM_FILE_READ | |
| 26 base::PLATFORM_FILE_EXCLUSIVE_READ | | 27 base::PLATFORM_FILE_EXCLUSIVE_READ | |
| 27 base::PLATFORM_FILE_ASYNC; | 28 base::PLATFORM_FILE_ASYNC; |
| 28 | 29 |
| 29 static const int kEnumerateDirectoryPermissions = | 30 static const int kEnumerateDirectoryPermissions = |
| 30 kReadFilePermissions | | 31 kReadFilePermissions | |
| 31 base::PLATFORM_FILE_ENUMERATE; | 32 base::PLATFORM_FILE_ENUMERATE; |
| 32 | 33 |
| 33 // The SecurityState class is used to maintain per-child process security state | 34 // The SecurityState class is used to maintain per-child process security state |
| 34 // information. | 35 // information. |
| 35 class ChildProcessSecurityPolicy::SecurityState { | 36 class ChildProcessSecurityPolicyImpl::SecurityState { |
| 36 public: | 37 public: |
| 37 SecurityState() | 38 SecurityState() |
| 38 : enabled_bindings_(0), | 39 : enabled_bindings_(0), |
| 39 can_read_raw_cookies_(false) { } | 40 can_read_raw_cookies_(false) { } |
| 40 | 41 |
| 41 ~SecurityState() { | 42 ~SecurityState() { |
| 42 scheme_policy_.clear(); | 43 scheme_policy_.clear(); |
| 43 fileapi::IsolatedContext* isolated_context = | 44 fileapi::IsolatedContext* isolated_context = |
| 44 fileapi::IsolatedContext::GetInstance(); | 45 fileapi::IsolatedContext::GetInstance(); |
| 45 for (FileSystemSet::iterator iter = access_granted_filesystems_.begin(); | 46 for (FileSystemSet::iterator iter = access_granted_filesystems_.begin(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 bool can_read_raw_cookies_; | 156 bool can_read_raw_cookies_; |
| 156 | 157 |
| 157 GURL origin_lock_; | 158 GURL origin_lock_; |
| 158 | 159 |
| 159 // The set of isolated filesystems the child process is permitted to access. | 160 // The set of isolated filesystems the child process is permitted to access. |
| 160 FileSystemSet access_granted_filesystems_; | 161 FileSystemSet access_granted_filesystems_; |
| 161 | 162 |
| 162 DISALLOW_COPY_AND_ASSIGN(SecurityState); | 163 DISALLOW_COPY_AND_ASSIGN(SecurityState); |
| 163 }; | 164 }; |
| 164 | 165 |
| 165 ChildProcessSecurityPolicy::ChildProcessSecurityPolicy() { | 166 ChildProcessSecurityPolicyImpl::ChildProcessSecurityPolicyImpl() { |
| 166 // We know about these schemes and believe them to be safe. | 167 // We know about these schemes and believe them to be safe. |
| 167 RegisterWebSafeScheme(chrome::kHttpScheme); | 168 RegisterWebSafeScheme(chrome::kHttpScheme); |
| 168 RegisterWebSafeScheme(chrome::kHttpsScheme); | 169 RegisterWebSafeScheme(chrome::kHttpsScheme); |
| 169 RegisterWebSafeScheme(chrome::kFtpScheme); | 170 RegisterWebSafeScheme(chrome::kFtpScheme); |
| 170 RegisterWebSafeScheme(chrome::kDataScheme); | 171 RegisterWebSafeScheme(chrome::kDataScheme); |
| 171 RegisterWebSafeScheme("feed"); | 172 RegisterWebSafeScheme("feed"); |
| 172 RegisterWebSafeScheme(chrome::kBlobScheme); | 173 RegisterWebSafeScheme(chrome::kBlobScheme); |
| 173 RegisterWebSafeScheme(chrome::kFileSystemScheme); | 174 RegisterWebSafeScheme(chrome::kFileSystemScheme); |
| 174 | 175 |
| 175 // We know about the following pseudo schemes and treat them specially. | 176 // We know about the following pseudo schemes and treat them specially. |
| 176 RegisterPseudoScheme(chrome::kAboutScheme); | 177 RegisterPseudoScheme(chrome::kAboutScheme); |
| 177 RegisterPseudoScheme(chrome::kJavaScriptScheme); | 178 RegisterPseudoScheme(chrome::kJavaScriptScheme); |
| 178 RegisterPseudoScheme(chrome::kViewSourceScheme); | 179 RegisterPseudoScheme(chrome::kViewSourceScheme); |
| 179 } | 180 } |
| 180 | 181 |
| 181 ChildProcessSecurityPolicy::~ChildProcessSecurityPolicy() { | 182 ChildProcessSecurityPolicyImpl::~ChildProcessSecurityPolicyImpl() { |
| 182 web_safe_schemes_.clear(); | 183 web_safe_schemes_.clear(); |
| 183 pseudo_schemes_.clear(); | 184 pseudo_schemes_.clear(); |
| 184 STLDeleteContainerPairSecondPointers(security_state_.begin(), | 185 STLDeleteContainerPairSecondPointers(security_state_.begin(), |
| 185 security_state_.end()); | 186 security_state_.end()); |
| 186 security_state_.clear(); | 187 security_state_.clear(); |
| 187 } | 188 } |
| 188 | 189 |
| 189 // static | 190 // static |
| 190 ChildProcessSecurityPolicy* ChildProcessSecurityPolicy::GetInstance() { | 191 ChildProcessSecurityPolicy* ChildProcessSecurityPolicy::GetInstance() { |
| 191 return Singleton<ChildProcessSecurityPolicy>::get(); | 192 return ChildProcessSecurityPolicyImpl::GetInstance(); |
| 192 } | 193 } |
| 193 | 194 |
| 194 void ChildProcessSecurityPolicy::Add(int child_id) { | 195 ChildProcessSecurityPolicyImpl* ChildProcessSecurityPolicyImpl::GetInstance() { |
| 196 return Singleton<ChildProcessSecurityPolicyImpl>::get(); |
| 197 } |
| 198 |
| 199 void ChildProcessSecurityPolicyImpl::Add(int child_id) { |
| 195 base::AutoLock lock(lock_); | 200 base::AutoLock lock(lock_); |
| 196 AddChild(child_id); | 201 AddChild(child_id); |
| 197 } | 202 } |
| 198 | 203 |
| 199 void ChildProcessSecurityPolicy::AddWorker(int child_id, | 204 void ChildProcessSecurityPolicyImpl::AddWorker(int child_id, |
| 200 int main_render_process_id) { | 205 int main_render_process_id) { |
| 201 base::AutoLock lock(lock_); | 206 base::AutoLock lock(lock_); |
| 202 AddChild(child_id); | 207 AddChild(child_id); |
| 203 worker_map_[child_id] = main_render_process_id; | 208 worker_map_[child_id] = main_render_process_id; |
| 204 } | 209 } |
| 205 | 210 |
| 206 void ChildProcessSecurityPolicy::Remove(int child_id) { | 211 void ChildProcessSecurityPolicyImpl::Remove(int child_id) { |
| 207 base::AutoLock lock(lock_); | 212 base::AutoLock lock(lock_); |
| 208 if (!security_state_.count(child_id)) | 213 if (!security_state_.count(child_id)) |
| 209 return; // May be called multiple times. | 214 return; // May be called multiple times. |
| 210 | 215 |
| 211 delete security_state_[child_id]; | 216 delete security_state_[child_id]; |
| 212 security_state_.erase(child_id); | 217 security_state_.erase(child_id); |
| 213 worker_map_.erase(child_id); | 218 worker_map_.erase(child_id); |
| 214 } | 219 } |
| 215 | 220 |
| 216 void ChildProcessSecurityPolicy::RegisterWebSafeScheme( | 221 void ChildProcessSecurityPolicyImpl::RegisterWebSafeScheme( |
| 217 const std::string& scheme) { | 222 const std::string& scheme) { |
| 218 base::AutoLock lock(lock_); | 223 base::AutoLock lock(lock_); |
| 219 DCHECK(web_safe_schemes_.count(scheme) == 0) << "Add schemes at most once."; | 224 DCHECK(web_safe_schemes_.count(scheme) == 0) << "Add schemes at most once."; |
| 220 DCHECK(pseudo_schemes_.count(scheme) == 0) << "Web-safe implies not pseudo."; | 225 DCHECK(pseudo_schemes_.count(scheme) == 0) << "Web-safe implies not pseudo."; |
| 221 | 226 |
| 222 web_safe_schemes_.insert(scheme); | 227 web_safe_schemes_.insert(scheme); |
| 223 } | 228 } |
| 224 | 229 |
| 225 bool ChildProcessSecurityPolicy::IsWebSafeScheme(const std::string& scheme) { | 230 bool ChildProcessSecurityPolicyImpl::IsWebSafeScheme( |
| 231 const std::string& scheme) { |
| 226 base::AutoLock lock(lock_); | 232 base::AutoLock lock(lock_); |
| 227 | 233 |
| 228 return (web_safe_schemes_.find(scheme) != web_safe_schemes_.end()); | 234 return (web_safe_schemes_.find(scheme) != web_safe_schemes_.end()); |
| 229 } | 235 } |
| 230 | 236 |
| 231 void ChildProcessSecurityPolicy::RegisterPseudoScheme( | 237 void ChildProcessSecurityPolicyImpl::RegisterPseudoScheme( |
| 232 const std::string& scheme) { | 238 const std::string& scheme) { |
| 233 base::AutoLock lock(lock_); | 239 base::AutoLock lock(lock_); |
| 234 DCHECK(pseudo_schemes_.count(scheme) == 0) << "Add schemes at most once."; | 240 DCHECK(pseudo_schemes_.count(scheme) == 0) << "Add schemes at most once."; |
| 235 DCHECK(web_safe_schemes_.count(scheme) == 0) << | 241 DCHECK(web_safe_schemes_.count(scheme) == 0) << |
| 236 "Pseudo implies not web-safe."; | 242 "Pseudo implies not web-safe."; |
| 237 | 243 |
| 238 pseudo_schemes_.insert(scheme); | 244 pseudo_schemes_.insert(scheme); |
| 239 } | 245 } |
| 240 | 246 |
| 241 bool ChildProcessSecurityPolicy::IsPseudoScheme(const std::string& scheme) { | 247 bool ChildProcessSecurityPolicyImpl::IsPseudoScheme( |
| 248 const std::string& scheme) { |
| 242 base::AutoLock lock(lock_); | 249 base::AutoLock lock(lock_); |
| 243 | 250 |
| 244 return (pseudo_schemes_.find(scheme) != pseudo_schemes_.end()); | 251 return (pseudo_schemes_.find(scheme) != pseudo_schemes_.end()); |
| 245 } | 252 } |
| 246 | 253 |
| 247 void ChildProcessSecurityPolicy::RegisterDisabledSchemes( | 254 void ChildProcessSecurityPolicyImpl::RegisterDisabledSchemes( |
| 248 const std::set<std::string>& schemes) { | 255 const std::set<std::string>& schemes) { |
| 249 base::AutoLock lock(lock_); | 256 base::AutoLock lock(lock_); |
| 250 disabled_schemes_ = schemes; | 257 disabled_schemes_ = schemes; |
| 251 } | 258 } |
| 252 | 259 |
| 253 bool ChildProcessSecurityPolicy::IsDisabledScheme(const std::string& scheme) { | 260 bool ChildProcessSecurityPolicyImpl::IsDisabledScheme( |
| 261 const std::string& scheme) { |
| 254 base::AutoLock lock(lock_); | 262 base::AutoLock lock(lock_); |
| 255 return disabled_schemes_.find(scheme) != disabled_schemes_.end(); | 263 return disabled_schemes_.find(scheme) != disabled_schemes_.end(); |
| 256 } | 264 } |
| 257 | 265 |
| 258 void ChildProcessSecurityPolicy::GrantRequestURL( | 266 void ChildProcessSecurityPolicyImpl::GrantRequestURL( |
| 259 int child_id, const GURL& url) { | 267 int child_id, const GURL& url) { |
| 260 | 268 |
| 261 if (!url.is_valid()) | 269 if (!url.is_valid()) |
| 262 return; // Can't grant the capability to request invalid URLs. | 270 return; // Can't grant the capability to request invalid URLs. |
| 263 | 271 |
| 264 if (IsWebSafeScheme(url.scheme())) | 272 if (IsWebSafeScheme(url.scheme())) |
| 265 return; // The scheme has already been whitelisted for every child process. | 273 return; // The scheme has already been whitelisted for every child process. |
| 266 | 274 |
| 267 if (IsPseudoScheme(url.scheme())) { | 275 if (IsPseudoScheme(url.scheme())) { |
| 268 // The view-source scheme is a special case of a pseudo-URL that eventually | 276 // The view-source scheme is a special case of a pseudo-URL that eventually |
| (...skipping 14 matching lines...) Expand all Loading... |
| 283 SecurityStateMap::iterator state = security_state_.find(child_id); | 291 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 284 if (state == security_state_.end()) | 292 if (state == security_state_.end()) |
| 285 return; | 293 return; |
| 286 | 294 |
| 287 // If the child process has been commanded to request a scheme, then we | 295 // If the child process has been commanded to request a scheme, then we |
| 288 // grant it the capability to request URLs of that scheme. | 296 // grant it the capability to request URLs of that scheme. |
| 289 state->second->GrantScheme(url.scheme()); | 297 state->second->GrantScheme(url.scheme()); |
| 290 } | 298 } |
| 291 } | 299 } |
| 292 | 300 |
| 293 void ChildProcessSecurityPolicy::GrantReadFile(int child_id, | 301 void ChildProcessSecurityPolicyImpl::GrantReadFile(int child_id, |
| 294 const FilePath& file) { | 302 const FilePath& file) { |
| 295 GrantPermissionsForFile(child_id, file, kReadFilePermissions); | 303 GrantPermissionsForFile(child_id, file, kReadFilePermissions); |
| 296 } | 304 } |
| 297 | 305 |
| 298 void ChildProcessSecurityPolicy::GrantReadDirectory(int child_id, | 306 void ChildProcessSecurityPolicyImpl::GrantReadDirectory( |
| 299 const FilePath& directory) { | 307 int child_id, const FilePath& directory) { |
| 300 GrantPermissionsForFile(child_id, directory, kEnumerateDirectoryPermissions); | 308 GrantPermissionsForFile(child_id, directory, kEnumerateDirectoryPermissions); |
| 301 } | 309 } |
| 302 | 310 |
| 303 void ChildProcessSecurityPolicy::GrantPermissionsForFile( | 311 void ChildProcessSecurityPolicyImpl::GrantPermissionsForFile( |
| 304 int child_id, const FilePath& file, int permissions) { | 312 int child_id, const FilePath& file, int permissions) { |
| 305 base::AutoLock lock(lock_); | 313 base::AutoLock lock(lock_); |
| 306 | 314 |
| 307 SecurityStateMap::iterator state = security_state_.find(child_id); | 315 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 308 if (state == security_state_.end()) | 316 if (state == security_state_.end()) |
| 309 return; | 317 return; |
| 310 | 318 |
| 311 state->second->GrantPermissionsForFile(file, permissions); | 319 state->second->GrantPermissionsForFile(file, permissions); |
| 312 } | 320 } |
| 313 | 321 |
| 314 void ChildProcessSecurityPolicy::RevokeAllPermissionsForFile( | 322 void ChildProcessSecurityPolicyImpl::RevokeAllPermissionsForFile( |
| 315 int child_id, const FilePath& file) { | 323 int child_id, const FilePath& file) { |
| 316 base::AutoLock lock(lock_); | 324 base::AutoLock lock(lock_); |
| 317 | 325 |
| 318 SecurityStateMap::iterator state = security_state_.find(child_id); | 326 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 319 if (state == security_state_.end()) | 327 if (state == security_state_.end()) |
| 320 return; | 328 return; |
| 321 | 329 |
| 322 state->second->RevokeAllPermissionsForFile(file); | 330 state->second->RevokeAllPermissionsForFile(file); |
| 323 } | 331 } |
| 324 | 332 |
| 325 void ChildProcessSecurityPolicy::GrantAccessFileSystem( | 333 void ChildProcessSecurityPolicyImpl::GrantAccessFileSystem( |
| 326 int child_id, const std::string& filesystem_id) { | 334 int child_id, const std::string& filesystem_id) { |
| 327 base::AutoLock lock(lock_); | 335 base::AutoLock lock(lock_); |
| 328 | 336 |
| 329 SecurityStateMap::iterator state = security_state_.find(child_id); | 337 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 330 if (state == security_state_.end()) | 338 if (state == security_state_.end()) |
| 331 return; | 339 return; |
| 332 | 340 |
| 333 state->second->GrantAccessFileSystem(filesystem_id); | 341 state->second->GrantAccessFileSystem(filesystem_id); |
| 334 } | 342 } |
| 335 | 343 |
| 336 void ChildProcessSecurityPolicy::GrantScheme(int child_id, | 344 void ChildProcessSecurityPolicyImpl::GrantScheme(int child_id, |
| 337 const std::string& scheme) { | 345 const std::string& scheme) { |
| 338 base::AutoLock lock(lock_); | 346 base::AutoLock lock(lock_); |
| 339 | 347 |
| 340 SecurityStateMap::iterator state = security_state_.find(child_id); | 348 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 341 if (state == security_state_.end()) | 349 if (state == security_state_.end()) |
| 342 return; | 350 return; |
| 343 | 351 |
| 344 state->second->GrantScheme(scheme); | 352 state->second->GrantScheme(scheme); |
| 345 } | 353 } |
| 346 | 354 |
| 347 void ChildProcessSecurityPolicy::GrantWebUIBindings(int child_id) { | 355 void ChildProcessSecurityPolicyImpl::GrantWebUIBindings(int child_id) { |
| 348 base::AutoLock lock(lock_); | 356 base::AutoLock lock(lock_); |
| 349 | 357 |
| 350 SecurityStateMap::iterator state = security_state_.find(child_id); | 358 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 351 if (state == security_state_.end()) | 359 if (state == security_state_.end()) |
| 352 return; | 360 return; |
| 353 | 361 |
| 354 state->second->GrantBindings(content::BINDINGS_POLICY_WEB_UI); | 362 state->second->GrantBindings(content::BINDINGS_POLICY_WEB_UI); |
| 355 | 363 |
| 356 // Web UI bindings need the ability to request chrome: URLs. | 364 // Web UI bindings need the ability to request chrome: URLs. |
| 357 state->second->GrantScheme(chrome::kChromeUIScheme); | 365 state->second->GrantScheme(chrome::kChromeUIScheme); |
| 358 | 366 |
| 359 // Web UI pages can contain links to file:// URLs. | 367 // Web UI pages can contain links to file:// URLs. |
| 360 state->second->GrantScheme(chrome::kFileScheme); | 368 state->second->GrantScheme(chrome::kFileScheme); |
| 361 } | 369 } |
| 362 | 370 |
| 363 void ChildProcessSecurityPolicy::GrantReadRawCookies(int child_id) { | 371 void ChildProcessSecurityPolicyImpl::GrantReadRawCookies(int child_id) { |
| 364 base::AutoLock lock(lock_); | 372 base::AutoLock lock(lock_); |
| 365 | 373 |
| 366 SecurityStateMap::iterator state = security_state_.find(child_id); | 374 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 367 if (state == security_state_.end()) | 375 if (state == security_state_.end()) |
| 368 return; | 376 return; |
| 369 | 377 |
| 370 state->second->GrantReadRawCookies(); | 378 state->second->GrantReadRawCookies(); |
| 371 } | 379 } |
| 372 | 380 |
| 373 void ChildProcessSecurityPolicy::RevokeReadRawCookies(int child_id) { | 381 void ChildProcessSecurityPolicyImpl::RevokeReadRawCookies(int child_id) { |
| 374 base::AutoLock lock(lock_); | 382 base::AutoLock lock(lock_); |
| 375 | 383 |
| 376 SecurityStateMap::iterator state = security_state_.find(child_id); | 384 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 377 if (state == security_state_.end()) | 385 if (state == security_state_.end()) |
| 378 return; | 386 return; |
| 379 | 387 |
| 380 state->second->RevokeReadRawCookies(); | 388 state->second->RevokeReadRawCookies(); |
| 381 } | 389 } |
| 382 | 390 |
| 383 bool ChildProcessSecurityPolicy::CanRequestURL( | 391 bool ChildProcessSecurityPolicyImpl::CanRequestURL( |
| 384 int child_id, const GURL& url) { | 392 int child_id, const GURL& url) { |
| 385 if (!url.is_valid()) | 393 if (!url.is_valid()) |
| 386 return false; // Can't request invalid URLs. | 394 return false; // Can't request invalid URLs. |
| 387 | 395 |
| 388 if (IsDisabledScheme(url.scheme())) | 396 if (IsDisabledScheme(url.scheme())) |
| 389 return false; // The scheme is disabled by policy. | 397 return false; // The scheme is disabled by policy. |
| 390 | 398 |
| 391 if (IsWebSafeScheme(url.scheme())) | 399 if (IsWebSafeScheme(url.scheme())) |
| 392 return true; // The scheme has been white-listed for every child process. | 400 return true; // The scheme has been white-listed for every child process. |
| 393 | 401 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 SecurityStateMap::iterator state = security_state_.find(child_id); | 433 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 426 if (state == security_state_.end()) | 434 if (state == security_state_.end()) |
| 427 return false; | 435 return false; |
| 428 | 436 |
| 429 // Otherwise, we consult the child process's security state to see if it is | 437 // Otherwise, we consult the child process's security state to see if it is |
| 430 // allowed to request the URL. | 438 // allowed to request the URL. |
| 431 return state->second->CanRequestURL(url); | 439 return state->second->CanRequestURL(url); |
| 432 } | 440 } |
| 433 } | 441 } |
| 434 | 442 |
| 435 bool ChildProcessSecurityPolicy::CanReadFile(int child_id, | 443 bool ChildProcessSecurityPolicyImpl::CanReadFile(int child_id, |
| 436 const FilePath& file) { | 444 const FilePath& file) { |
| 437 return HasPermissionsForFile(child_id, file, kReadFilePermissions); | 445 return HasPermissionsForFile(child_id, file, kReadFilePermissions); |
| 438 } | 446 } |
| 439 | 447 |
| 440 bool ChildProcessSecurityPolicy::CanReadDirectory(int child_id, | 448 bool ChildProcessSecurityPolicyImpl::CanReadDirectory( |
| 441 const FilePath& directory) { | 449 int child_id, const FilePath& directory) { |
| 442 return HasPermissionsForFile(child_id, | 450 return HasPermissionsForFile(child_id, |
| 443 directory, | 451 directory, |
| 444 kEnumerateDirectoryPermissions); | 452 kEnumerateDirectoryPermissions); |
| 445 } | 453 } |
| 446 | 454 |
| 447 bool ChildProcessSecurityPolicy::HasPermissionsForFile( | 455 bool ChildProcessSecurityPolicyImpl::HasPermissionsForFile( |
| 448 int child_id, const FilePath& file, int permissions) { | 456 int child_id, const FilePath& file, int permissions) { |
| 449 base::AutoLock lock(lock_); | 457 base::AutoLock lock(lock_); |
| 450 bool result = ChildProcessHasPermissionsForFile(child_id, file, permissions); | 458 bool result = ChildProcessHasPermissionsForFile(child_id, file, permissions); |
| 451 if (!result) { | 459 if (!result) { |
| 452 // If this is a worker thread that has no access to a given file, | 460 // If this is a worker thread that has no access to a given file, |
| 453 // let's check that its renderer process has access to that file instead. | 461 // let's check that its renderer process has access to that file instead. |
| 454 WorkerToMainProcessMap::iterator iter = worker_map_.find(child_id); | 462 WorkerToMainProcessMap::iterator iter = worker_map_.find(child_id); |
| 455 if (iter != worker_map_.end() && iter->second != 0) { | 463 if (iter != worker_map_.end() && iter->second != 0) { |
| 456 result = ChildProcessHasPermissionsForFile(iter->second, | 464 result = ChildProcessHasPermissionsForFile(iter->second, |
| 457 file, | 465 file, |
| 458 permissions); | 466 permissions); |
| 459 } | 467 } |
| 460 } | 468 } |
| 461 return result; | 469 return result; |
| 462 } | 470 } |
| 463 | 471 |
| 464 bool ChildProcessSecurityPolicy::HasWebUIBindings(int child_id) { | 472 bool ChildProcessSecurityPolicyImpl::HasWebUIBindings(int child_id) { |
| 465 base::AutoLock lock(lock_); | 473 base::AutoLock lock(lock_); |
| 466 | 474 |
| 467 SecurityStateMap::iterator state = security_state_.find(child_id); | 475 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 468 if (state == security_state_.end()) | 476 if (state == security_state_.end()) |
| 469 return false; | 477 return false; |
| 470 | 478 |
| 471 return state->second->has_web_ui_bindings(); | 479 return state->second->has_web_ui_bindings(); |
| 472 } | 480 } |
| 473 | 481 |
| 474 bool ChildProcessSecurityPolicy::CanReadRawCookies(int child_id) { | 482 bool ChildProcessSecurityPolicyImpl::CanReadRawCookies(int child_id) { |
| 475 base::AutoLock lock(lock_); | 483 base::AutoLock lock(lock_); |
| 476 | 484 |
| 477 SecurityStateMap::iterator state = security_state_.find(child_id); | 485 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 478 if (state == security_state_.end()) | 486 if (state == security_state_.end()) |
| 479 return false; | 487 return false; |
| 480 | 488 |
| 481 return state->second->can_read_raw_cookies(); | 489 return state->second->can_read_raw_cookies(); |
| 482 } | 490 } |
| 483 | 491 |
| 484 void ChildProcessSecurityPolicy::AddChild(int child_id) { | 492 void ChildProcessSecurityPolicyImpl::AddChild(int child_id) { |
| 485 if (security_state_.count(child_id) != 0) { | 493 if (security_state_.count(child_id) != 0) { |
| 486 NOTREACHED() << "Add child process at most once."; | 494 NOTREACHED() << "Add child process at most once."; |
| 487 return; | 495 return; |
| 488 } | 496 } |
| 489 | 497 |
| 490 security_state_[child_id] = new SecurityState(); | 498 security_state_[child_id] = new SecurityState(); |
| 491 } | 499 } |
| 492 | 500 |
| 493 bool ChildProcessSecurityPolicy::ChildProcessHasPermissionsForFile( | 501 bool ChildProcessSecurityPolicyImpl::ChildProcessHasPermissionsForFile( |
| 494 int child_id, const FilePath& file, int permissions) { | 502 int child_id, const FilePath& file, int permissions) { |
| 495 SecurityStateMap::iterator state = security_state_.find(child_id); | 503 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 496 if (state == security_state_.end()) | 504 if (state == security_state_.end()) |
| 497 return false; | 505 return false; |
| 498 return state->second->HasPermissionsForFile(file, permissions); | 506 return state->second->HasPermissionsForFile(file, permissions); |
| 499 } | 507 } |
| 500 | 508 |
| 501 bool ChildProcessSecurityPolicy::CanUseCookiesForOrigin(int child_id, | 509 bool ChildProcessSecurityPolicyImpl::CanUseCookiesForOrigin(int child_id, |
| 502 const GURL& gurl) { | 510 const GURL& gurl) { |
| 503 base::AutoLock lock(lock_); | 511 base::AutoLock lock(lock_); |
| 504 SecurityStateMap::iterator state = security_state_.find(child_id); | 512 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 505 if (state == security_state_.end()) | 513 if (state == security_state_.end()) |
| 506 return false; | 514 return false; |
| 507 return state->second->CanUseCookiesForOrigin(gurl); | 515 return state->second->CanUseCookiesForOrigin(gurl); |
| 508 } | 516 } |
| 509 | 517 |
| 510 void ChildProcessSecurityPolicy::LockToOrigin(int child_id, const GURL& gurl) { | 518 void ChildProcessSecurityPolicyImpl::LockToOrigin(int child_id, |
| 519 const GURL& gurl) { |
| 511 // "gurl" can be currently empty in some cases, such as file://blah. | 520 // "gurl" can be currently empty in some cases, such as file://blah. |
| 512 DCHECK(SiteInstanceImpl::GetSiteForURL(NULL, gurl) == gurl); | 521 DCHECK(SiteInstanceImpl::GetSiteForURL(NULL, gurl) == gurl); |
| 513 base::AutoLock lock(lock_); | 522 base::AutoLock lock(lock_); |
| 514 SecurityStateMap::iterator state = security_state_.find(child_id); | 523 SecurityStateMap::iterator state = security_state_.find(child_id); |
| 515 DCHECK(state != security_state_.end()); | 524 DCHECK(state != security_state_.end()); |
| 516 state->second->LockToOrigin(gurl); | 525 state->second->LockToOrigin(gurl); |
| 517 } | 526 } |
| OLD | NEW |