| Index: webkit/fileapi/isolated_context.h
|
| diff --git a/webkit/fileapi/isolated_context.h b/webkit/fileapi/isolated_context.h
|
| index b4eaadd3fc1ef2292f6878ccb1bf0ae017d5ccd8..edb7aa93e588bc81c502480274bf2f6015a043fc 100644
|
| --- a/webkit/fileapi/isolated_context.h
|
| +++ b/webkit/fileapi/isolated_context.h
|
| @@ -26,23 +26,57 @@ namespace fileapi {
|
| // Some methods of this class are virtual just for mocking.
|
| class FILEAPI_EXPORT IsolatedContext {
|
| public:
|
| + struct FILEAPI_EXPORT FileInfo {
|
| + FileInfo();
|
| + FileInfo(const std::string& name, const FilePath& path);
|
| +
|
| + // The name to be used to register the file. The registered file can
|
| + // be referred by a virtual path /<filesystem_id>/<name>.
|
| + // The name should NOT contain a path separator '/'.
|
| + std::string name;
|
| +
|
| + // The path of the file.
|
| + FilePath path;
|
| +
|
| + // For STL operation.
|
| + bool operator<(const FileInfo& that) const { return name < that.name; }
|
| + };
|
| +
|
| + class FILEAPI_EXPORT FileInfoSet {
|
| + public:
|
| + FileInfoSet();
|
| + ~FileInfoSet();
|
| +
|
| + // Add the given |path| to the set and returns the registered name
|
| + // assigned for the path.
|
| + std::string AddPath(const FilePath& path);
|
| +
|
| + // Add the given |path| with the |name|.
|
| + // Returns false if the |name| is already registered in the set.
|
| + bool AddPathWithName(const FilePath& path, const std::string& name);
|
| +
|
| + const std::set<FileInfo>& fileset() const { return fileset_; }
|
| +
|
| + private:
|
| + std::set<FileInfo> fileset_;
|
| + };
|
| +
|
| // The instance is lazily created per browser process.
|
| static IsolatedContext* GetInstance();
|
|
|
| - // Registers a new file isolated filesystem with the given set of files
|
| + // Registers a new isolated filesystem with the given FileInfoSet |files|
|
| // and returns the new filesystem_id. The files are registered with their
|
| - // basenames as their keys so that later we can resolve the full paths
|
| - // for the given file name in the isolated filesystem. We only expose the
|
| - // key and the ID for the newly created filesystem to the renderer for
|
| - // the sake of security.
|
| + // register_name as their keys so that later we can resolve the full paths
|
| + // for the given name. We only expose the name and the ID for the
|
| + // newly created filesystem to the renderer for the sake of security.
|
| //
|
| // The renderer will be sending filesystem requests with a virtual path like
|
| - // '/<filesystem_id>/<relative_path_from_the_basename_of_dropped_path>'
|
| - // for which we could crack in the browser by calling CrackIsolatedPath to
|
| - // get the full path.
|
| + // '/<filesystem_id>/<registered_name>/<relative_path_from_the_dropped_path>'
|
| + // for which we could crack in the browser process by calling
|
| + // CrackIsolatedPath to get the full path.
|
| //
|
| - // For example: if a dropped file has a path like '/a/b/foo' we register
|
| - // the path with the key 'foo' in the newly created filesystem.
|
| + // For example: if a dropped file has a path like '/a/b/foo' and we register
|
| + // the path with the name 'foo' in the newly created filesystem.
|
| // Later if the context is asked to crack a virtual path like '/<fsid>/foo'
|
| // it can properly return the original path '/a/b/foo' by looking up the
|
| // internal mapping. Similarly if a dropped entry is a directory and its
|
| @@ -51,13 +85,20 @@ class FILEAPI_EXPORT IsolatedContext {
|
| //
|
| // Note that the path in |fileset| that contains '..' or is not an
|
| // absolute path is skipped and is not registerred.
|
| - std::string RegisterIsolatedFileSystem(const std::set<FilePath>& fileset);
|
| + std::string RegisterFileSystem(const FileInfoSet& files);
|
| +
|
| + // Registers a new isolated filesystem for a given |path|.
|
| + // If |register_name| is non-null and has non-empty string the path is
|
| + // registered as the given |register_name|, otherwise it is populated
|
| + // with the name internally assigned to the path.
|
| + std::string RegisterFileSystemForFile(const FilePath& path,
|
| + std::string* register_name);
|
|
|
| // Revokes filesystem specified by the given filesystem_id.
|
| // Note that this revokes the filesystem no matter how many references it has.
|
| // It is ok to call this on the filesystem that has been already deleted
|
| // (if its reference count had reached 0).
|
| - void RevokeIsolatedFileSystem(const std::string& filesystem_id);
|
| + void RevokeFileSystem(const std::string& filesystem_id);
|
|
|
| // Adds a reference to a filesystem specified by the given filesystem_id.
|
| void AddReference(const std::string& filesystem_id);
|
| @@ -65,43 +106,40 @@ class FILEAPI_EXPORT IsolatedContext {
|
| // Removes a reference to a filesystem specified by the given filesystem_id.
|
| // If the reference count reaches 0 the isolated context gets destroyed.
|
| // It is ok to call this on the filesystem that has been already deleted
|
| - // (e.g. by RevokeIsolatedFileSystem).
|
| + // (e.g. by RevokeFileSystem).
|
| void RemoveReference(const std::string& filesystem_id);
|
|
|
| // Cracks the given |virtual_path| (which should look like
|
| - // "/<filesystem_id>/<relative_path>") and populates the |filesystem_id|
|
| - // and |platform_path| if the embedded <filesystem_id> is registerred
|
| - // to this context. |root_path| is also populated to have the platform
|
| - // root (toplevel) path for the |virtual_path|
|
| - // (i.e. |platform_path| = |root_path| + <relative_path>).
|
| + // "/<filesystem_id>/<registered_name>/<relative_path>") and populates
|
| + // the |filesystem_id| and |platform_path| if the embedded <filesystem_id>
|
| + // is registerred to this context. |root_path| is also populated to have
|
| + // the registered root (toplevel) file info for the |virtual_path|.
|
| //
|
| // Returns false if the given virtual_path or the cracked filesystem_id
|
| // is not valid.
|
| //
|
| - // Note that |root_path| and |platform_path| are set to empty paths if
|
| + // Note that |root_info| and |platform_path| are set to empty paths if
|
| // |virtual_path| has no <relative_path> part (i.e. pointing to
|
| // the virtual root).
|
| bool CrackIsolatedPath(const FilePath& virtual_path,
|
| std::string* filesystem_id,
|
| - FilePath* root_path,
|
| + FileInfo* root_info,
|
| FilePath* platform_path) const;
|
|
|
| - // Returns a vector of the full paths of the top-level entry paths
|
| - // registered for the |filesystem_id|. Returns false if the
|
| - // |filesystem_is| is not valid.
|
| - bool GetTopLevelPaths(const std::string& filesystem_id,
|
| - std::vector<FilePath>* paths) const;
|
| + // Returns a set of FileInfo registered for the |filesystem_id|.
|
| + // Returns false if the |filesystem_id| is not valid.
|
| + bool GetRegisteredFileInfo(const std::string& filesystem_id,
|
| + std::vector<FileInfo>* files) const;
|
|
|
| - // Returns the virtual path that looks like /<filesystem_id>/<relative_path>.
|
| - FilePath CreateVirtualPath(const std::string& filesystem_id,
|
| - const FilePath& relative_path) const;
|
| + // Returns the virtual root path that looks like /<filesystem_id>.
|
| + FilePath CreateVirtualRootPath(const std::string& filesystem_id) const;
|
|
|
| private:
|
| friend struct base::DefaultLazyInstanceTraits<IsolatedContext>;
|
|
|
| // Maps from filesystem id to a path conversion map for top-level entries.
|
| - typedef std::map<FilePath, FilePath> PathMap;
|
| - typedef std::map<std::string, PathMap> IDToPathMap;
|
| + typedef std::set<FileInfo> FileSet;
|
| + typedef std::map<std::string, FileSet> IDToFileSet;
|
|
|
| // Obtain an instance of this class via GetInstance().
|
| IsolatedContext();
|
| @@ -118,7 +156,7 @@ class FILEAPI_EXPORT IsolatedContext {
|
| mutable base::Lock lock_;
|
|
|
| // Maps the toplevel entries to the filesystem id.
|
| - IDToPathMap toplevel_map_;
|
| + IDToFileSet toplevel_map_;
|
|
|
| // Reference counts. Note that an isolated filesystem is created with ref==0.
|
| // and will get deleted when the ref count reaches <=0.
|
|
|