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" |
47 #include "wtf/Functional.h" | |
46 | 48 |
47 namespace WebCore { | 49 namespace WebCore { |
48 | 50 |
49 namespace { | 51 namespace { |
50 | 52 |
51 void fileSystemNotAllowed(ExecutionContext*, PassOwnPtr<AsyncFileSystemCallbacks > callbacks) | 53 void fileSystemNotAllowed(ExecutionContext*, PassOwnPtr<AsyncFileSystemCallbacks > callbacks) |
52 { | 54 { |
53 callbacks->didFail(FileError::ABORT_ERR); | 55 callbacks->didFail(FileError::ABORT_ERR); |
54 } | 56 } |
55 | 57 |
56 } // namespace | 58 } // namespace |
57 | 59 |
58 PassOwnPtrWillBeRawPtr<LocalFileSystem> LocalFileSystem::create(PassOwnPtr<FileS ystemClient> client) | 60 PassOwnPtrWillBeRawPtr<LocalFileSystem> LocalFileSystem::create(PassOwnPtr<FileS ystemClient> client) |
59 { | 61 { |
60 return adoptPtrWillBeNoop(new LocalFileSystem(client)); | 62 return adoptPtrWillBeNoop(new LocalFileSystem(client)); |
61 } | 63 } |
62 | 64 |
63 LocalFileSystem::~LocalFileSystem() | 65 LocalFileSystem::~LocalFileSystem() |
64 { | 66 { |
65 } | 67 } |
66 | 68 |
67 void LocalFileSystem::resolveURL(ExecutionContext* context, const KURL& fileSyst emURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 69 void LocalFileSystem::resolveURL(PassRefPtr<ExecutionContext> context, const KUR L& fileSystemURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) |
68 { | 70 { |
69 if (!client() || !client()->allowFileSystem(context)) { | 71 RefPtr<ExecutionContext> contextPtr = context; |
70 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); | 72 if (!client()) { |
73 fileSystemNotAllowedInternal(contextPtr, callbacks); | |
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, callbacks); | |
80 return; | |
81 } | |
82 resolveURLInternal(fileSystemURL, callbacks); | |
83 return; | |
84 } | |
85 client()->requestFileSystemAccessAsync(contextPtr.get(), PermissionCallbacks ::create( | |
86 bind(&LocalFileSystem::resolveURLInternal, this, fileSystemURL, callback s), | |
87 bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, c allbacks))); | |
kinuko
2014/05/19 09:02:46
I think these patterns can be probably implemented
Xi Han
2014/05/20 16:13:32
Done.
| |
74 } | 88 } |
75 | 89 |
76 void LocalFileSystem::requestFileSystem(ExecutionContext* context, FileSystemTyp e type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 90 void LocalFileSystem::requestFileSystem(PassRefPtr<ExecutionContext> context, Fi leSystemType type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callback s) |
77 { | 91 { |
78 if (!client() || !client()->allowFileSystem(context)) { | 92 RefPtr<ExecutionContext> contextPtr = context; |
79 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); | 93 if (!client()) { |
94 fileSystemNotAllowedInternal(contextPtr, callbacks); | |
80 return; | 95 return; |
81 } | 96 } |
97 ASSERT(contextPtr); | |
98 if (!contextPtr->isDocument()) { | |
99 if (!client()->requestFileSystemAccessSync(contextPtr.get())) { | |
100 fileSystemNotAllowedInternal(contextPtr, callbacks); | |
101 return; | |
102 } | |
103 fileSystemAllowedInternal(contextPtr, type, callbacks); | |
104 return; | |
105 } | |
106 client()->requestFileSystemAccessAsync(contextPtr.get(), PermissionCallbacks ::create( | |
107 bind(&LocalFileSystem::fileSystemAllowedInternal, this, contextPtr, type , callbacks), | |
108 bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, c allbacks))); | |
109 } | |
110 | |
111 void LocalFileSystem::deleteFileSystem(PassRefPtr<ExecutionContext> context, Fil eSystemType type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | |
112 { | |
113 RefPtr<ExecutionContext> contextPtr = context; | |
114 ASSERT(contextPtr); | |
115 ASSERT_WITH_SECURITY_IMPLICATION(contextPtr->isDocument()); | |
116 if (!client()) { | |
117 fileSystemNotAllowedInternal(contextPtr, callbacks); | |
118 return; | |
119 } | |
120 client()->requestFileSystemAccessAsync(contextPtr.get(), PermissionCallbacks ::create( | |
121 bind(&LocalFileSystem::deleteFileSystemInternal, this, contextPtr, type, callbacks), | |
122 bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, c allbacks))); | |
123 } | |
124 | |
125 void LocalFileSystem::fileSystemNotAllowedInternal( | |
126 PassRefPtr<ExecutionContext> context, | |
127 PassOwnPtr<AsyncFileSystemCallbacks> callbacks) { | |
128 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); | |
129 } | |
130 | |
131 void LocalFileSystem::fileSystemAllowedInternal( | |
132 PassRefPtr<ExecutionContext> context, | |
133 FileSystemType type, | |
134 PassOwnPtr<AsyncFileSystemCallbacks> callbacks) { | |
82 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); | 135 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); |
83 blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, s tatic_cast<blink::WebFileSystemType>(type), callbacks); | 136 blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, s tatic_cast<blink::WebFileSystemType>(type), callbacks); |
84 } | 137 } |
85 | 138 |
86 void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 139 void LocalFileSystem::resolveURLInternal( |
87 { | 140 const KURL& fileSystemURL, |
88 ASSERT(context); | 141 PassOwnPtr<AsyncFileSystemCallbacks> callbacks) { |
89 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument()); | 142 blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callback s); |
143 } | |
90 | 144 |
91 if (!client() || !client()->allowFileSystem(context)) { | 145 void LocalFileSystem::deleteFileSystemInternal( |
92 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); | 146 PassRefPtr<ExecutionContext> context, |
93 return; | 147 FileSystemType type, |
94 } | 148 PassOwnPtr<AsyncFileSystemCallbacks> callbacks) { |
95 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); | 149 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); |
96 blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks); | 150 blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks); |
97 } | 151 } |
98 | 152 |
99 LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client) | 153 LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client) |
100 : m_client(client) | 154 : m_client(client) |
101 { | 155 { |
102 } | 156 } |
103 | 157 |
104 const char* LocalFileSystem::supplementName() | 158 const char* LocalFileSystem::supplementName() |
(...skipping 15 matching lines...) Expand all Loading... | |
120 page.provideSupplement(LocalFileSystem::supplementName(), LocalFileSystem::c reate(client)); | 174 page.provideSupplement(LocalFileSystem::supplementName(), LocalFileSystem::c reate(client)); |
121 page.inspectorController().registerModuleAgent(InspectorFileSystemAgent::cre ate(&page)); | 175 page.inspectorController().registerModuleAgent(InspectorFileSystemAgent::cre ate(&page)); |
122 } | 176 } |
123 | 177 |
124 void provideLocalFileSystemToWorker(WorkerClients* clients, PassOwnPtr<FileSyste mClient> client) | 178 void provideLocalFileSystemToWorker(WorkerClients* clients, PassOwnPtr<FileSyste mClient> client) |
125 { | 179 { |
126 clients->provideSupplement(LocalFileSystem::supplementName(), LocalFileSyste m::create(client)); | 180 clients->provideSupplement(LocalFileSystem::supplementName(), LocalFileSyste m::create(client)); |
127 } | 181 } |
128 | 182 |
129 } // namespace WebCore | 183 } // namespace WebCore |
OLD | NEW |