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

Side by Side Diff: Source/modules/filesystem/WorkerContextFileSystem.cpp

Issue 17648006: Rename WorkerContext to WorkerGlobalScope (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 5 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
27
28 #include "config.h"
29 #include "modules/filesystem/WorkerContextFileSystem.h"
30
31 #include "core/fileapi/FileError.h"
32 #include "core/fileapi/FileException.h"
33 #include "core/platform/AsyncFileSystem.h"
34 #include "core/workers/WorkerContext.h"
35 #include "modules/filesystem/DOMFileSystemBase.h"
36 #include "modules/filesystem/DOMFileSystemSync.h"
37 #include "modules/filesystem/DirectoryEntrySync.h"
38 #include "modules/filesystem/ErrorCallback.h"
39 #include "modules/filesystem/FileEntrySync.h"
40 #include "modules/filesystem/FileSystemCallback.h"
41 #include "modules/filesystem/FileSystemCallbacks.h"
42 #include "modules/filesystem/FileSystemType.h"
43 #include "modules/filesystem/LocalFileSystem.h"
44 #include "modules/filesystem/SyncCallbackHelper.h"
45 #include "weborigin/SecurityOrigin.h"
46
47 namespace WebCore {
48
49 void WorkerContextFileSystem::webkitRequestFileSystem(WorkerContext* worker, int type, long long size, PassRefPtr<FileSystemCallback> successCallback, PassRefPt r<ErrorCallback> errorCallback)
50 {
51 ScriptExecutionContext* secureContext = worker->scriptExecutionContext();
52 if (!secureContext->securityOrigin()->canAccessFileSystem()) {
53 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create (FileError::SECURITY_ERR));
54 return;
55 }
56
57 FileSystemType fileSystemType = static_cast<FileSystemType>(type);
58 if (!DOMFileSystemBase::isValidType(fileSystemType)) {
59 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create (FileError::INVALID_MODIFICATION_ERR));
60 return;
61 }
62
63 LocalFileSystem::localFileSystem().requestFileSystem(worker, fileSystemType, size, FileSystemCallbacks::create(successCallback, errorCallback, worker, fileS ystemType), AsynchronousFileSystem);
64 }
65
66 PassRefPtr<DOMFileSystemSync> WorkerContextFileSystem::webkitRequestFileSystemSy nc(WorkerContext* worker, int type, long long size, ExceptionCode& ec)
67 {
68 ec = 0;
69 ScriptExecutionContext* secureContext = worker->scriptExecutionContext();
70 if (!secureContext->securityOrigin()->canAccessFileSystem()) {
71 ec = FileException::SECURITY_ERR;
72 return 0;
73 }
74
75 FileSystemType fileSystemType = static_cast<FileSystemType>(type);
76 if (!DOMFileSystemBase::isValidType(fileSystemType)) {
77 ec = FileException::INVALID_MODIFICATION_ERR;
78 return 0;
79 }
80
81 FileSystemSyncCallbackHelper helper;
82 LocalFileSystem::localFileSystem().requestFileSystem(worker, fileSystemType, size, FileSystemCallbacks::create(helper.successCallback(), helper.errorCallbac k(), worker, fileSystemType), SynchronousFileSystem);
83 return helper.getResult(ec);
84 }
85
86 void WorkerContextFileSystem::webkitResolveLocalFileSystemURL(WorkerContext* wor ker, const String& url, PassRefPtr<EntryCallback> successCallback, PassRefPtr<Er rorCallback> errorCallback)
87 {
88 KURL completedURL = worker->completeURL(url);
89 ScriptExecutionContext* secureContext = worker->scriptExecutionContext();
90 if (!secureContext->securityOrigin()->canAccessFileSystem() || !secureContex t->securityOrigin()->canRequest(completedURL)) {
91 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create (FileError::SECURITY_ERR));
92 return;
93 }
94
95 FileSystemType type;
96 String filePath;
97 if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(comple tedURL, type, filePath)) {
98 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create (FileError::ENCODING_ERR));
99 return;
100 }
101
102 LocalFileSystem::localFileSystem().readFileSystem(worker, type, ResolveURICa llbacks::create(successCallback, errorCallback, worker, type, filePath));
103 }
104
105 PassRefPtr<EntrySync> WorkerContextFileSystem::webkitResolveLocalFileSystemSyncU RL(WorkerContext* worker, const String& url, ExceptionCode& ec)
106 {
107 ec = 0;
108 KURL completedURL = worker->completeURL(url);
109 ScriptExecutionContext* secureContext = worker->scriptExecutionContext();
110 if (!secureContext->securityOrigin()->canAccessFileSystem() || !secureContex t->securityOrigin()->canRequest(completedURL)) {
111 ec = FileException::SECURITY_ERR;
112 return 0;
113 }
114
115 FileSystemType type;
116 String filePath;
117 if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(comple tedURL, type, filePath)) {
118 ec = FileException::ENCODING_ERR;
119 return 0;
120 }
121
122 FileSystemSyncCallbackHelper readFileSystemHelper;
123 LocalFileSystem::localFileSystem().readFileSystem(worker, type, FileSystemCa llbacks::create(readFileSystemHelper.successCallback(), readFileSystemHelper.err orCallback(), worker, type), SynchronousFileSystem);
124 RefPtr<DOMFileSystemSync> fileSystem = readFileSystemHelper.getResult(ec);
125 if (!fileSystem)
126 return 0;
127
128 RefPtr<EntrySync> entry = fileSystem->root()->getDirectory(filePath, Diction ary(), ec);
129 if (ec == FileException::TYPE_MISMATCH_ERR)
130 return fileSystem->root()->getFile(filePath, Dictionary(), ec);
131
132 return entry.release();
133 }
134
135 COMPILE_ASSERT(static_cast<int>(WorkerContextFileSystem::TEMPORARY) == static_ca st<int>(FileSystemTypeTemporary), enum_mismatch);
136 COMPILE_ASSERT(static_cast<int>(WorkerContextFileSystem::PERSISTENT) == static_c ast<int>(FileSystemTypePersistent), enum_mismatch);
137
138 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/filesystem/WorkerContextFileSystem.h ('k') | Source/modules/filesystem/WorkerContextFileSystem.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698