| // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef CONTENT_PUBLIC_BROWSER_FILE_SYSTEM_ACCESS_ENTRY_FACTORY_H_ |
| #define CONTENT_PUBLIC_BROWSER_FILE_SYSTEM_ACCESS_ENTRY_FACTORY_H_ |
| |
| #include "base/files/file_path.h" |
| #include "base/memory/ref_counted.h" |
| #include "content/common/content_export.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/file_system_access_permission_context.h" |
| #include "content/public/browser/global_routing_id.h" |
| #include "ipc/ipc_message.h" |
| #include "third_party/blink/public/common/storage_key/storage_key.h" |
| #include "third_party/blink/public/mojom/file_system_access/file_system_access_directory_handle.mojom-forward.h" |
| #include "url/gurl.h" |
| |
| namespace content { |
| |
| // Exposes methods for creating FileSystemAccessEntries. All these methods need |
| // to be called on the UI thread. |
| class CONTENT_EXPORT FileSystemAccessEntryFactory |
| : public base::RefCountedThreadSafe<FileSystemAccessEntryFactory, |
| BrowserThread::DeleteOnUIThread> { |
| public: |
| using UserAction = FileSystemAccessPermissionContext::UserAction; |
| using PathType = FileSystemAccessPermissionContext::PathType; |
| |
| // Context from which a created handle is going to be used. This is used for |
| // security and permission checks. Pass in the URL most relevant as the url |
| // parameter. This url will be used for verifications later for SafeBrowsing |
| // and Quarantine Service if used for writes. |
| struct CONTENT_EXPORT BindingContext { |
| BindingContext(const blink::StorageKey& storage_key, |
| const GURL& url, |
| GlobalRenderFrameHostId frame_id) |
| : storage_key(storage_key), url(url), frame_id(frame_id) {} |
| BindingContext(const blink::StorageKey& storage_key, |
| const GURL& url, |
| int worker_process_id) |
| : storage_key(storage_key), |
| url(url), |
| frame_id(worker_process_id, MSG_ROUTING_NONE) {} |
| blink::StorageKey storage_key; |
| GURL url; |
| GlobalRenderFrameHostId frame_id; |
| bool is_worker() const { return !frame_id; } |
| int process_id() const { return frame_id.child_id; } |
| }; |
| |
| // Creates a new FileSystemAccessEntryPtr from the path to a file. Assumes the |
| // passed in path is valid and represents a file. |
| virtual blink::mojom::FileSystemAccessEntryPtr CreateFileEntryFromPath( |
| const BindingContext& binding_context, |
| PathType path_type, |
| const base::FilePath& file_path, |
| UserAction user_action) = 0; |
| |
| // Creates a new FileSystemAccessEntryPtr from the path to a directory. |
| // Assumes the passed in path is valid and represents a directory. |
| virtual blink::mojom::FileSystemAccessEntryPtr CreateDirectoryEntryFromPath( |
| const BindingContext& binding_context, |
| PathType path_type, |
| const base::FilePath& directory_path, |
| UserAction user_action) = 0; |
| |
| protected: |
| friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| friend class base::DeleteHelper<FileSystemAccessEntryFactory>; |
| virtual ~FileSystemAccessEntryFactory() {} |
| }; |
| |
| } // namespace content |
| |
| #endif // CONTENT_PUBLIC_BROWSER_FILE_SYSTEM_ACCESS_ENTRY_FACTORY_H_ |