Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: third_party/WebKit/Source/modules/filesystem/WorkerGlobalScopeFileSystem.cpp

Issue 2297043002: Web expose FileSystemFileEntry, FileSystemDirectoryEntry and friends (Closed)
Patch Set: Rebased Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. 3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 13 matching lines...) Expand all
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * 25 *
26 */ 26 */
27 27
28 #include "modules/filesystem/WorkerGlobalScopeFileSystem.h" 28 #include "modules/filesystem/WorkerGlobalScopeFileSystem.h"
29 29
30 #include "bindings/core/v8/ExceptionState.h" 30 #include "bindings/core/v8/ExceptionState.h"
31 #include "core/dom/ExceptionCode.h" 31 #include "core/dom/ExceptionCode.h"
32 #include "core/fileapi/FileError.h" 32 #include "core/fileapi/FileError.h"
33 #include "core/workers/WorkerGlobalScope.h" 33 #include "core/workers/WorkerGlobalScope.h"
34 #include "modules/filesystem/DOMFileSystemBase.h"
35 #include "modules/filesystem/DirectoryEntrySync.h"
36 #include "modules/filesystem/ErrorCallback.h" 34 #include "modules/filesystem/ErrorCallback.h"
37 #include "modules/filesystem/FileEntrySync.h" 35 #include "modules/filesystem/FileSystemBase.h"
38 #include "modules/filesystem/FileSystemCallback.h" 36 #include "modules/filesystem/FileSystemCallback.h"
39 #include "modules/filesystem/FileSystemCallbacks.h" 37 #include "modules/filesystem/FileSystemCallbacks.h"
38 #include "modules/filesystem/FileSystemDirectoryEntrySync.h"
39 #include "modules/filesystem/FileSystemFileEntrySync.h"
40 #include "modules/filesystem/LocalFileSystem.h" 40 #include "modules/filesystem/LocalFileSystem.h"
41 #include "modules/filesystem/SyncCallbackHelper.h" 41 #include "modules/filesystem/SyncCallbackHelper.h"
42 #include "platform/FileSystemType.h" 42 #include "platform/FileSystemType.h"
43 #include "platform/weborigin/SecurityOrigin.h" 43 #include "platform/weborigin/SecurityOrigin.h"
44 #include <memory> 44 #include <memory>
45 45
46 namespace blink { 46 namespace blink {
47 47
48 void WorkerGlobalScopeFileSystem::webkitRequestFileSystem( 48 void WorkerGlobalScopeFileSystem::webkitRequestFileSystem(
49 WorkerGlobalScope& worker, 49 WorkerGlobalScope& worker,
50 int type, 50 int type,
51 long long size, 51 long long size,
52 FileSystemCallback* successCallback, 52 FileSystemCallback* successCallback,
53 ErrorCallback* errorCallback) { 53 ErrorCallback* errorCallback) {
54 ExecutionContext* secureContext = worker.getExecutionContext(); 54 ExecutionContext* secureContext = worker.getExecutionContext();
55 if (!secureContext->getSecurityOrigin()->canAccessFileSystem()) { 55 if (!secureContext->getSecurityOrigin()->canAccessFileSystem()) {
56 DOMFileSystem::reportError(&worker, 56 FileSystem::reportError(&worker, ScriptErrorCallback::wrap(errorCallback),
57 ScriptErrorCallback::wrap(errorCallback), 57 FileError::kSecurityErr);
58 FileError::kSecurityErr);
59 return; 58 return;
60 } 59 }
61 60
62 FileSystemType fileSystemType = static_cast<FileSystemType>(type); 61 FileSystemType fileSystemType = static_cast<FileSystemType>(type);
63 if (!DOMFileSystemBase::isValidType(fileSystemType)) { 62 if (!FileSystemBase::isValidType(fileSystemType)) {
64 DOMFileSystem::reportError(&worker, 63 FileSystem::reportError(&worker, ScriptErrorCallback::wrap(errorCallback),
65 ScriptErrorCallback::wrap(errorCallback), 64 FileError::kInvalidModificationErr);
66 FileError::kInvalidModificationErr);
67 return; 65 return;
68 } 66 }
69 67
70 LocalFileSystem::from(worker)->requestFileSystem( 68 LocalFileSystem::from(worker)->requestFileSystem(
71 &worker, fileSystemType, size, 69 &worker, fileSystemType, size,
72 FileSystemCallbacks::create(successCallback, 70 FileSystemCallbacks::create(successCallback,
73 ScriptErrorCallback::wrap(errorCallback), 71 ScriptErrorCallback::wrap(errorCallback),
74 &worker, fileSystemType)); 72 &worker, fileSystemType));
75 } 73 }
76 74
77 DOMFileSystemSync* WorkerGlobalScopeFileSystem::webkitRequestFileSystemSync( 75 FileSystemSync* WorkerGlobalScopeFileSystem::webkitRequestFileSystemSync(
78 WorkerGlobalScope& worker, 76 WorkerGlobalScope& worker,
79 int type, 77 int type,
80 long long size, 78 long long size,
81 ExceptionState& exceptionState) { 79 ExceptionState& exceptionState) {
82 ExecutionContext* secureContext = worker.getExecutionContext(); 80 ExecutionContext* secureContext = worker.getExecutionContext();
83 if (!secureContext->getSecurityOrigin()->canAccessFileSystem()) { 81 if (!secureContext->getSecurityOrigin()->canAccessFileSystem()) {
84 exceptionState.throwSecurityError(FileError::securityErrorMessage); 82 exceptionState.throwSecurityError(FileError::securityErrorMessage);
85 return 0; 83 return 0;
86 } 84 }
87 85
88 FileSystemType fileSystemType = static_cast<FileSystemType>(type); 86 FileSystemType fileSystemType = static_cast<FileSystemType>(type);
89 if (!DOMFileSystemBase::isValidType(fileSystemType)) { 87 if (!FileSystemBase::isValidType(fileSystemType)) {
90 exceptionState.throwDOMException( 88 exceptionState.throwDOMException(
91 InvalidModificationError, 89 InvalidModificationError,
92 "the type must be kTemporary or kPersistent."); 90 "the type must be kTemporary or kPersistent.");
93 return 0; 91 return 0;
94 } 92 }
95 93
96 FileSystemSyncCallbackHelper* helper = FileSystemSyncCallbackHelper::create(); 94 FileSystemSyncCallbackHelper* helper = FileSystemSyncCallbackHelper::create();
97 std::unique_ptr<AsyncFileSystemCallbacks> callbacks = 95 std::unique_ptr<AsyncFileSystemCallbacks> callbacks =
98 FileSystemCallbacks::create(helper->getSuccessCallback(), 96 FileSystemCallbacks::create(helper->getSuccessCallback(),
99 helper->getErrorCallback(), &worker, 97 helper->getErrorCallback(), &worker,
100 fileSystemType); 98 fileSystemType);
101 callbacks->setShouldBlockUntilCompletion(true); 99 callbacks->setShouldBlockUntilCompletion(true);
102 100
103 LocalFileSystem::from(worker)->requestFileSystem(&worker, fileSystemType, 101 LocalFileSystem::from(worker)->requestFileSystem(&worker, fileSystemType,
104 size, std::move(callbacks)); 102 size, std::move(callbacks));
105 return helper->getResult(exceptionState); 103 return helper->getResult(exceptionState);
106 } 104 }
107 105
108 void WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemURL( 106 void WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemURL(
109 WorkerGlobalScope& worker, 107 WorkerGlobalScope& worker,
110 const String& url, 108 const String& url,
111 EntryCallback* successCallback, 109 FileSystemEntryCallback* successCallback,
112 ErrorCallback* errorCallback) { 110 ErrorCallback* errorCallback) {
113 KURL completedURL = worker.completeURL(url); 111 KURL completedURL = worker.completeURL(url);
114 ExecutionContext* secureContext = worker.getExecutionContext(); 112 ExecutionContext* secureContext = worker.getExecutionContext();
115 if (!secureContext->getSecurityOrigin()->canAccessFileSystem() || 113 if (!secureContext->getSecurityOrigin()->canAccessFileSystem() ||
116 !secureContext->getSecurityOrigin()->canRequest(completedURL)) { 114 !secureContext->getSecurityOrigin()->canRequest(completedURL)) {
117 DOMFileSystem::reportError(&worker, 115 FileSystem::reportError(&worker, ScriptErrorCallback::wrap(errorCallback),
118 ScriptErrorCallback::wrap(errorCallback), 116 FileError::kSecurityErr);
119 FileError::kSecurityErr);
120 return; 117 return;
121 } 118 }
122 119
123 if (!completedURL.isValid()) { 120 if (!completedURL.isValid()) {
124 DOMFileSystem::reportError(&worker, 121 FileSystem::reportError(&worker, ScriptErrorCallback::wrap(errorCallback),
125 ScriptErrorCallback::wrap(errorCallback), 122 FileError::kEncodingErr);
126 FileError::kEncodingErr);
127 return; 123 return;
128 } 124 }
129 125
130 LocalFileSystem::from(worker)->resolveURL( 126 LocalFileSystem::from(worker)->resolveURL(
131 &worker, completedURL, 127 &worker, completedURL,
132 ResolveURICallbacks::create( 128 ResolveURICallbacks::create(
133 successCallback, ScriptErrorCallback::wrap(errorCallback), &worker)); 129 successCallback, ScriptErrorCallback::wrap(errorCallback), &worker));
134 } 130 }
135 131
136 EntrySync* WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemSyncURL( 132 FileSystemEntrySync*
133 WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemSyncURL(
137 WorkerGlobalScope& worker, 134 WorkerGlobalScope& worker,
138 const String& url, 135 const String& url,
139 ExceptionState& exceptionState) { 136 ExceptionState& exceptionState) {
140 KURL completedURL = worker.completeURL(url); 137 KURL completedURL = worker.completeURL(url);
141 ExecutionContext* secureContext = worker.getExecutionContext(); 138 ExecutionContext* secureContext = worker.getExecutionContext();
142 if (!secureContext->getSecurityOrigin()->canAccessFileSystem() || 139 if (!secureContext->getSecurityOrigin()->canAccessFileSystem() ||
143 !secureContext->getSecurityOrigin()->canRequest(completedURL)) { 140 !secureContext->getSecurityOrigin()->canRequest(completedURL)) {
144 exceptionState.throwSecurityError(FileError::securityErrorMessage); 141 exceptionState.throwSecurityError(FileError::securityErrorMessage);
145 return 0; 142 return 0;
146 } 143 }
(...skipping 20 matching lines...) Expand all
167 static_assert(static_cast<int>(WorkerGlobalScopeFileSystem::kTemporary) == 164 static_assert(static_cast<int>(WorkerGlobalScopeFileSystem::kTemporary) ==
168 static_cast<int>(FileSystemTypeTemporary), 165 static_cast<int>(FileSystemTypeTemporary),
169 "WorkerGlobalScopeFileSystem::kTemporary should match " 166 "WorkerGlobalScopeFileSystem::kTemporary should match "
170 "FileSystemTypeTemporary"); 167 "FileSystemTypeTemporary");
171 static_assert(static_cast<int>(WorkerGlobalScopeFileSystem::kPersistent) == 168 static_assert(static_cast<int>(WorkerGlobalScopeFileSystem::kPersistent) ==
172 static_cast<int>(FileSystemTypePersistent), 169 static_cast<int>(FileSystemTypePersistent),
173 "WorkerGlobalScopeFileSystem::kPersistent should match " 170 "WorkerGlobalScopeFileSystem::kPersistent should match "
174 "FileSystemTypePersistent"); 171 "FileSystemTypePersistent");
175 172
176 } // namespace blink 173 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698