child_process_security_policy.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 3// found in the LICENSE file. 4 5#ifndef CONTENT_PUBLIC_BROWSER_CHILD_PROCESS_SECURITY_POLICY_H_ 6#define CONTENT_PUBLIC_BROWSER_CHILD_PROCESS_SECURITY_POLICY_H_ 7 8#include <set> 9#include <string> 10 11#include "base/basictypes.h" 12#include "content/common/content_export.h" 13 14class FilePath; 15 16namespace content { 17 18// The ChildProcessSecurityPolicy class is used to grant and revoke security 19// capabilities for child processes. For example, it restricts whether a child 20// process is permitted to load file:// URLs based on whether the process 21// has ever been commanded to load file:// URLs by the browser. 22// 23// ChildProcessSecurityPolicy is a singleton that may be used on any thread. 24// 25class ChildProcessSecurityPolicy { 26 public: 27 virtual ~ChildProcessSecurityPolicy() {} 28 29 // There is one global ChildProcessSecurityPolicy object for the entire 30 // browser process. The object returned by this method may be accessed on 31 // any thread. 32 static CONTENT_EXPORT ChildProcessSecurityPolicy* GetInstance(); 33 34 // Web-safe schemes can be requested by any child process. Once a web-safe 35 // scheme has been registered, any child process can request URLs with 36 // that scheme. There is no mechanism for revoking web-safe schemes. 37 virtual void RegisterWebSafeScheme(const std::string& scheme) = 0; 38 39 // Returns true iff |scheme| has been registered as a web-safe scheme. 40 virtual bool IsWebSafeScheme(const std::string& scheme) = 0; 41 42 // Sets the list of disabled schemes. 43 // URLs using these schemes won't be loaded at all. The previous list of 44 // schemes is overwritten. An empty |schemes| disables this feature. 45 // Schemes listed as disabled take precedence over Web-safe schemes. 46 virtual void RegisterDisabledSchemes( 47 const std::set<std::string>& schemes) = 0; 48 49 // Grants certain permissions to a file. |permissions| must be a bit-set of 50 // base::PlatformFileFlags. 51 virtual void GrantPermissionsForFile(int child_id, 52 const FilePath& file, 53 int permissions) = 0; 54 55 // Before servicing a child process's request to upload a file to the web, the 56 // browser should call this method to determine whether the process has the 57 // capability to upload the requested file. 58 virtual bool CanReadFile(int child_id, const FilePath& file) = 0; 59 60 // Whenever the user picks a file from a <input type="file"> element, the 61 // browser should call this function to grant the child process the capability 62 // to upload the file to the web. 63 virtual void GrantReadFile(int child_id, const FilePath& file) = 0; 64 65 // Grants read access permission to the given isolated file system 66 // identified by |filesystem_id|. An isolated file system can be 67 // created for a set of native files/directories (like dropped files) 68 // using fileapi::IsolatedContext. A child process needs to be granted 69 // permission to the file system to access the files in it using 70 // file system URL. 71 // 72 // Note: to grant read access to the content of files you also need 73 // to give permission directly to the file paths using GrantReadFile. 74 // TODO(kinuko): We should unify this file-level and file-system-level 75 // permission when a file is accessed via a file system. 76 // 77 // Note: files/directories in the same file system share the same 78 // permission as far as they are accessed via the file system, i.e. 79 // using the file system URL (tip: you can create a new file system 80 // to give different permission to part of files). 81 virtual void GrantReadFileSystem(int child_id, 82 const std::string& filesystem_id) = 0; 83 84 // Grants write access permission to the given isolated file system 85 // identified by |filesystem_id|. See comments for GrantReadFileSystem 86 // for more details. For writing you do NOT need to give direct permission 87 // to individual file paths. 88 // 89 // This must be called with a great care as this gives write permission 90 // to all files/directories included in the file system. Especially this 91 // should NOT be called if the file system contains directories. 92 virtual void GrantReadWriteFileSystem(int child_id, 93 const std::string& filesystem_id) = 0; 94 95 // Grants the child process the capability to access URLs of the provided 96 // scheme. 97 virtual void GrantScheme(int child_id, const std::string& scheme) = 0; 98 99 // Returns true iff read access has been granted to the file system with 100 // |filesystem_id|. 101 virtual bool CanReadFileSystem(int child_id, 102 const std::string& filesystem_id) = 0; 103 104 // Returns true iff read and write access has been granted to the filesystem 105 // with |filesystem_id|. 106 virtual bool CanReadWriteFileSystem(int child_id, 107 const std::string& filesystem_id) = 0; 108}; 109 110}; // namespace content 111 112#endif // CONTENT_PUBLIC_BROWSER_CHILD_PROCESS_SECURITY_POLICY_H_ 113