OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "core/dom/CrossThreadTask.h" | 34 #include "core/dom/CrossThreadTask.h" |
35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
36 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
37 #include "core/dom/ExecutionContext.h" | 37 #include "core/dom/ExecutionContext.h" |
38 #include "core/fileapi/FileError.h" | 38 #include "core/fileapi/FileError.h" |
39 #include "core/inspector/InspectorController.h" | 39 #include "core/inspector/InspectorController.h" |
40 #include "core/workers/WorkerGlobalScope.h" | 40 #include "core/workers/WorkerGlobalScope.h" |
41 #include "modules/filesystem/FileSystemClient.h" | 41 #include "modules/filesystem/FileSystemClient.h" |
42 #include "modules/filesystem/InspectorFileSystemAgent.h" | 42 #include "modules/filesystem/InspectorFileSystemAgent.h" |
43 #include "platform/AsyncFileSystemCallbacks.h" | 43 #include "platform/AsyncFileSystemCallbacks.h" |
44 #include "platform/PermissionCallbacks.h" | |
44 #include "public/platform/Platform.h" | 45 #include "public/platform/Platform.h" |
45 #include "public/platform/WebFileSystem.h" | 46 #include "public/platform/WebFileSystem.h" |
46 | 47 |
47 namespace WebCore { | 48 namespace WebCore { |
48 | 49 |
49 namespace { | 50 namespace { |
50 | 51 |
51 void fileSystemNotAllowed(ExecutionContext*, PassOwnPtr<AsyncFileSystemCallbacks > callbacks) | 52 void fileSystemNotAllowed(ExecutionContext*, PassOwnPtr<AsyncFileSystemCallbacks > callbacks) |
52 { | 53 { |
53 callbacks->didFail(FileError::ABORT_ERR); | 54 callbacks->didFail(FileError::ABORT_ERR); |
54 } | 55 } |
55 | 56 |
56 } // namespace | 57 } // namespace |
57 | 58 |
58 PassOwnPtrWillBeRawPtr<LocalFileSystem> LocalFileSystem::create(PassOwnPtr<FileS ystemClient> client) | 59 PassOwnPtrWillBeRawPtr<LocalFileSystem> LocalFileSystem::create(PassOwnPtr<FileS ystemClient> client) |
59 { | 60 { |
60 return adoptPtrWillBeNoop(new LocalFileSystem(client)); | 61 return adoptPtrWillBeNoop(new LocalFileSystem(client)); |
61 } | 62 } |
62 | 63 |
63 LocalFileSystem::~LocalFileSystem() | 64 LocalFileSystem::~LocalFileSystem() |
64 { | 65 { |
65 } | 66 } |
66 | 67 |
67 void LocalFileSystem::resolveURL(ExecutionContext* context, const KURL& fileSyst emURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 68 void LocalFileSystem::resolveURL(ExecutionContext* context, const KURL& fileSyst emURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) |
68 { | 69 { |
69 if (!client() || !client()->allowFileSystem(context)) { | 70 RefPtr<ExecutionContext> contextPtr(context); |
70 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); | 71 RefPtr<RefCountedFileSystemCallbacks> refCountedCallbacks = adoptRef(new Ref CountedFileSystemCallbacks(callbacks)); |
72 if (!client()) { | |
73 fileSystemNotAllowedInternal(contextPtr, refCountedCallbacks); | |
71 return; | 74 return; |
72 } | 75 } |
73 blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callback s); | 76 ASSERT(contextPtr); |
77 if (!contextPtr->isDocument()) { | |
78 if (!client()->requestFileSystemAccessSync(contextPtr.get())) { | |
79 fileSystemNotAllowedInternal(contextPtr, refCountedCallbacks); | |
80 return; | |
81 } | |
82 resolveURLInternal(fileSystemURL, refCountedCallbacks); | |
83 return; | |
84 } | |
85 requestFileSystemAccesssAsyncInternal( | |
86 contextPtr, | |
87 bind(&LocalFileSystem::resolveURLInternal, this, fileSystemURL, refCount edCallbacks), | |
88 bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, r efCountedCallbacks)); | |
74 } | 89 } |
75 | 90 |
76 void LocalFileSystem::requestFileSystem(ExecutionContext* context, FileSystemTyp e type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 91 void LocalFileSystem::requestFileSystem(ExecutionContext* context, FileSystemTyp e type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) |
77 { | 92 { |
78 if (!client() || !client()->allowFileSystem(context)) { | 93 RefPtr<ExecutionContext> contextPtr(context); |
79 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); | 94 RefPtr<RefCountedFileSystemCallbacks> refCountedCallbacks = adoptRef(new Ref CountedFileSystemCallbacks(callbacks)); |
95 if (!client()) { | |
96 fileSystemNotAllowedInternal(contextPtr, refCountedCallbacks); | |
80 return; | 97 return; |
81 } | 98 } |
82 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); | 99 ASSERT(contextPtr); |
83 blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, s tatic_cast<blink::WebFileSystemType>(type), callbacks); | 100 if (!contextPtr->isDocument()) { |
101 if (!client()->requestFileSystemAccessSync(contextPtr.get())) { | |
102 fileSystemNotAllowedInternal(contextPtr, refCountedCallbacks); | |
103 return; | |
104 } | |
105 fileSystemAllowedInternal(contextPtr, type, refCountedCallbacks); | |
106 return; | |
107 } | |
108 requestFileSystemAccesssAsyncInternal( | |
109 contextPtr, | |
110 bind(&LocalFileSystem::fileSystemAllowedInternal, this, contextPtr, type , refCountedCallbacks), | |
111 bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, r efCountedCallbacks)); | |
84 } | 112 } |
85 | 113 |
86 void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 114 void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) |
87 { | 115 { |
88 ASSERT(context); | 116 RefPtr<ExecutionContext> contextPtr(context); |
89 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument()); | 117 ASSERT(contextPtr); |
90 | 118 ASSERT_WITH_SECURITY_IMPLICATION(contextPtr->isDocument()); |
91 if (!client() || !client()->allowFileSystem(context)) { | 119 RefPtr<RefCountedFileSystemCallbacks> refCountedCallbacks = adoptRef(new Ref CountedFileSystemCallbacks(callbacks)); |
92 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); | 120 if (!client()) { |
121 fileSystemNotAllowedInternal(contextPtr, refCountedCallbacks); | |
93 return; | 122 return; |
94 } | 123 } |
124 requestFileSystemAccesssAsyncInternal( | |
125 contextPtr, | |
126 bind(&LocalFileSystem::deleteFileSystemInternal, this, contextPtr, type, refCountedCallbacks), | |
127 bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, r efCountedCallbacks)); | |
128 } | |
129 | |
130 void LocalFileSystem::fileSystemNotAllowedInternal( | |
131 PassRefPtr<ExecutionContext> context, | |
132 PassRefPtr<RefCountedFileSystemCallbacks> callbacks) { | |
133 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks->callb acks)); | |
134 } | |
135 | |
136 void LocalFileSystem::fileSystemAllowedInternal( | |
137 PassRefPtr<ExecutionContext> context, | |
138 FileSystemType type, | |
139 PassRefPtr<RefCountedFileSystemCallbacks> callbacks) { | |
95 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); | 140 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); |
96 blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks); | 141 blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, s tatic_cast<blink::WebFileSystemType>(type), callbacks->callbacks); |
142 } | |
143 | |
144 void LocalFileSystem::resolveURLInternal( | |
145 const KURL& fileSystemURL, | |
146 PassRefPtr<RefCountedFileSystemCallbacks> callbacks) { | |
kinuko
2014/05/22 10:37:42
Please break the line before '{' (here and below.
Xi Han
2014/05/22 14:21:41
Done.
| |
147 blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callback s->callbacks); | |
148 } | |
149 | |
150 void LocalFileSystem::deleteFileSystemInternal( | |
151 PassRefPtr<ExecutionContext> context, | |
152 FileSystemType type, | |
153 PassRefPtr<RefCountedFileSystemCallbacks> callbacks) { | |
154 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); | |
155 blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks->callbacks); | |
156 } | |
157 | |
158 void LocalFileSystem::requestFileSystemAccesssAsyncInternal( | |
159 PassRefPtr<ExecutionContext> context, | |
160 const Closure& allowedCallback, | |
161 const Closure& deniedCallback) { | |
162 client()->requestFileSystemAccessAsync(context.get(), PermissionCallbacks::c reate(allowedCallback, deniedCallback)); | |
97 } | 163 } |
98 | 164 |
99 LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client) | 165 LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client) |
100 : m_client(client) | 166 : m_client(client) |
101 { | 167 { |
102 } | 168 } |
103 | 169 |
104 const char* LocalFileSystem::supplementName() | 170 const char* LocalFileSystem::supplementName() |
105 { | 171 { |
106 return "LocalFileSystem"; | 172 return "LocalFileSystem"; |
(...skipping 13 matching lines...) Expand all Loading... | |
120 page.provideSupplement(LocalFileSystem::supplementName(), LocalFileSystem::c reate(client)); | 186 page.provideSupplement(LocalFileSystem::supplementName(), LocalFileSystem::c reate(client)); |
121 page.inspectorController().registerModuleAgent(InspectorFileSystemAgent::cre ate(&page)); | 187 page.inspectorController().registerModuleAgent(InspectorFileSystemAgent::cre ate(&page)); |
122 } | 188 } |
123 | 189 |
124 void provideLocalFileSystemToWorker(WorkerClients* clients, PassOwnPtr<FileSyste mClient> client) | 190 void provideLocalFileSystemToWorker(WorkerClients* clients, PassOwnPtr<FileSyste mClient> client) |
125 { | 191 { |
126 clients->provideSupplement(LocalFileSystem::supplementName(), LocalFileSyste m::create(client)); | 192 clients->provideSupplement(LocalFileSystem::supplementName(), LocalFileSyste m::create(client)); |
127 } | 193 } |
128 | 194 |
129 } // namespace WebCore | 195 } // namespace WebCore |
OLD | NEW |