1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_LOCAL_FILE_SYSTEM_H_
32 #define THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_LOCAL_FILE_SYSTEM_H_
33 
34 #include <memory>
35 
36 #include "base/callback.h"
37 #include "base/macros.h"
38 #include "third_party/blink/public/mojom/filesystem/file_system.mojom-blink-forward.h"
39 #include "third_party/blink/renderer/core/execution_context/execution_context.h"
40 #include "third_party/blink/renderer/platform/bindings/name_client.h"
41 #include "third_party/blink/renderer/platform/heap/handle.h"
42 #include "third_party/blink/renderer/platform/supplementable.h"
43 #include "third_party/blink/renderer/platform/wtf/forward.h"
44 #include "third_party/blink/renderer/platform/wtf/functional.h"
45 
46 namespace blink {
47 
48 class ExecutionContext;
49 class FileSystemCallbacks;
50 class KURL;
51 class ResolveURICallbacks;
52 
53 class LocalFileSystem final : public GarbageCollected<LocalFileSystem>,
54                               public Supplement<ExecutionContext>,
55                               public NameClient {
56  public:
57   enum SynchronousType { kAsynchronous, kSynchronous };
58 
59   static const char kSupplementName[];
60 
61   explicit LocalFileSystem(ExecutionContext&);
62 
63   void ResolveURL(const KURL&,
64                   std::unique_ptr<ResolveURICallbacks>,
65                   SynchronousType sync_type);
66   void RequestFileSystem(mojom::blink::FileSystemType,
67                          int64_t size,
68                          std::unique_ptr<FileSystemCallbacks>,
69                          SynchronousType sync_type);
70 
71   static LocalFileSystem* From(ExecutionContext&);
72 
NameInHeapSnapshot()73   const char* NameInHeapSnapshot() const override { return "LocalFileSystem"; }
74 
75  private:
76   void ResolveURLCallback(const KURL& file_system_url,
77                           std::unique_ptr<ResolveURICallbacks> callbacks,
78                           SynchronousType sync_type,
79                           bool allowed);
80   void RequestFileSystemCallback(mojom::blink::FileSystemType type,
81                                  std::unique_ptr<FileSystemCallbacks> callbacks,
82                                  SynchronousType sync_type,
83                                  bool allowed);
84   void RequestFileSystemAccessInternal(base::OnceCallback<void(bool)> callback);
85   void FileSystemNotAllowedInternal(std::unique_ptr<FileSystemCallbacks>);
86   void FileSystemNotAllowedInternal(std::unique_ptr<ResolveURICallbacks>);
87   void FileSystemAllowedInternal(mojom::blink::FileSystemType,
88                                  std::unique_ptr<FileSystemCallbacks> callbacks,
89                                  SynchronousType sync_type);
90   void ResolveURLInternal(const KURL&,
91                           std::unique_ptr<ResolveURICallbacks>,
92                           SynchronousType sync_type);
93 
94   DISALLOW_COPY_AND_ASSIGN(LocalFileSystem);
95 };
96 
97 }  // namespace blink
98 
99 #endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_LOCAL_FILE_SYSTEM_H_
100