| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2010, 2012 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 "WebFileSystemCallbacksImpl.h" | 34 #include "WebFileSystemCallbacksImpl.h" |
| 35 #include "WebFrameClient.h" | 35 #include "WebFrameClient.h" |
| 36 #include "WebFrameImpl.h" | 36 #include "WebFrameImpl.h" |
| 37 #include "WebPermissionClient.h" | 37 #include "WebPermissionClient.h" |
| 38 #include "WebViewImpl.h" | 38 #include "WebViewImpl.h" |
| 39 #include "WebWorkerBase.h" | 39 #include "WebWorkerBase.h" |
| 40 #include "WorkerAllowMainThreadBridgeBase.h" | 40 #include "WorkerAllowMainThreadBridgeBase.h" |
| 41 #include "WorkerFileSystemCallbacksBridge.h" | 41 #include "WorkerFileSystemCallbacksBridge.h" |
| 42 #include "core/dom/CrossThreadTask.h" | 42 #include "core/dom/CrossThreadTask.h" |
| 43 #include "core/dom/Document.h" | 43 #include "core/dom/Document.h" |
| 44 #include "core/workers/WorkerContext.h" | 44 #include "core/workers/WorkerGlobalScope.h" |
| 45 #include "core/workers/WorkerThread.h" | 45 #include "core/workers/WorkerThread.h" |
| 46 #include "modules/filesystem/ErrorCallback.h" | 46 #include "modules/filesystem/ErrorCallback.h" |
| 47 #include "modules/filesystem/FileSystemCallback.h" | 47 #include "modules/filesystem/FileSystemCallback.h" |
| 48 #include "modules/filesystem/FileSystemCallbacks.h" | 48 #include "modules/filesystem/FileSystemCallbacks.h" |
| 49 #include "modules/filesystem/FileSystemType.h" | 49 #include "modules/filesystem/FileSystemType.h" |
| 50 #include "public/platform/WebFileError.h" | 50 #include "public/platform/WebFileError.h" |
| 51 #include "public/platform/WebFileSystem.h" | 51 #include "public/platform/WebFileSystem.h" |
| 52 #include "public/platform/WebFileSystemType.h" | 52 #include "public/platform/WebFileSystemType.h" |
| 53 #include <wtf/text/WTFString.h> | 53 #include <wtf/text/WTFString.h> |
| 54 #include <wtf/Threading.h> | 54 #include <wtf/Threading.h> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 70 CreateIfNotPresent | 70 CreateIfNotPresent |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 static const char allowFileSystemMode[] = "allowFileSystemMode"; | 73 static const char allowFileSystemMode[] = "allowFileSystemMode"; |
| 74 static const char openFileSystemMode[] = "openFileSystemMode"; | 74 static const char openFileSystemMode[] = "openFileSystemMode"; |
| 75 | 75 |
| 76 // This class is used to route the result of the WebWorkerBase::allowFileSystem | 76 // This class is used to route the result of the WebWorkerBase::allowFileSystem |
| 77 // call back to the worker context. | 77 // call back to the worker context. |
| 78 class AllowFileSystemMainThreadBridge : public WorkerAllowMainThreadBridgeBase { | 78 class AllowFileSystemMainThreadBridge : public WorkerAllowMainThreadBridgeBase { |
| 79 public: | 79 public: |
| 80 static PassRefPtr<AllowFileSystemMainThreadBridge> create(WebCore::WorkerCon
text* workerContext, WebWorkerBase* webWorkerBase, const String& mode) | 80 static PassRefPtr<AllowFileSystemMainThreadBridge> create(WebCore::WorkerGlo
balScope* workerGlobalScope, WebWorkerBase* webWorkerBase, const String& mode) |
| 81 { | 81 { |
| 82 return adoptRef(new AllowFileSystemMainThreadBridge(workerContext, webWo
rkerBase, mode)); | 82 return adoptRef(new AllowFileSystemMainThreadBridge(workerGlobalScope, w
ebWorkerBase, mode)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 AllowFileSystemMainThreadBridge(WebCore::WorkerContext* workerContext, WebWo
rkerBase* webWorkerBase, const String& mode) | 86 AllowFileSystemMainThreadBridge(WebCore::WorkerGlobalScope* workerGlobalScop
e, WebWorkerBase* webWorkerBase, const String& mode) |
| 87 : WorkerAllowMainThreadBridgeBase(workerContext, webWorkerBase) | 87 : WorkerAllowMainThreadBridgeBase(workerGlobalScope, webWorkerBase) |
| 88 { | 88 { |
| 89 postTaskToMainThread(adoptPtr(new AllowParams(mode))); | 89 postTaskToMainThread(adoptPtr(new AllowParams(mode))); |
| 90 } | 90 } |
| 91 | 91 |
| 92 virtual bool allowOnMainThread(WebCommonWorkerClient* commonClient, AllowPar
ams*) | 92 virtual bool allowOnMainThread(WebCommonWorkerClient* commonClient, AllowPar
ams*) |
| 93 { | 93 { |
| 94 ASSERT(isMainThread()); | 94 ASSERT(isMainThread()); |
| 95 return commonClient->allowFileSystem(); | 95 return commonClient->allowFileSystem(); |
| 96 } | 96 } |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 bool allowFileSystemForWorker() | 99 bool allowFileSystemForWorker() |
| 100 { | 100 { |
| 101 WorkerScriptController* controller = WorkerScriptController::controllerForCo
ntext(); | 101 WorkerScriptController* controller = WorkerScriptController::controllerForCo
ntext(); |
| 102 WorkerContext* workerContext = controller->workerContext(); | 102 WorkerGlobalScope* workerGlobalScope = controller->workerGlobalScope(); |
| 103 WebCore::WorkerThread* workerThread = workerContext->thread(); | 103 WebCore::WorkerThread* workerThread = workerGlobalScope->thread(); |
| 104 WorkerRunLoop& runLoop = workerThread->runLoop(); | 104 WorkerRunLoop& runLoop = workerThread->runLoop(); |
| 105 WebCore::WorkerLoaderProxy* workerLoaderProxy = &workerThread->workerLoaderP
roxy(); | 105 WebCore::WorkerLoaderProxy* workerLoaderProxy = &workerThread->workerLoaderP
roxy(); |
| 106 | 106 |
| 107 // Create a unique mode just for this synchronous call. | 107 // Create a unique mode just for this synchronous call. |
| 108 String mode = allowFileSystemMode; | 108 String mode = allowFileSystemMode; |
| 109 mode.append(String::number(runLoop.createUniqueId())); | 109 mode.append(String::number(runLoop.createUniqueId())); |
| 110 | 110 |
| 111 RefPtr<AllowFileSystemMainThreadBridge> bridge = AllowFileSystemMainThreadBr
idge::create(workerContext, workerLoaderProxy->toWebWorkerBase(), mode); | 111 RefPtr<AllowFileSystemMainThreadBridge> bridge = AllowFileSystemMainThreadBr
idge::create(workerGlobalScope, workerLoaderProxy->toWebWorkerBase(), mode); |
| 112 | 112 |
| 113 // Either the bridge returns, or the queue gets terminated. | 113 // Either the bridge returns, or the queue gets terminated. |
| 114 if (runLoop.runInMode(workerContext, mode) == MessageQueueTerminated) { | 114 if (runLoop.runInMode(workerGlobalScope, mode) == MessageQueueTerminated) { |
| 115 bridge->cancel(); | 115 bridge->cancel(); |
| 116 return false; | 116 return false; |
| 117 } | 117 } |
| 118 | 118 |
| 119 return bridge->result(); | 119 return bridge->result(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void openFileSystemForWorker(WebCommonWorkerClient* commonClient, WebFileSystemT
ype type, long long size, bool create, WebFileSystemCallbacksImpl* callbacks, Fi
leSystemSynchronousType synchronousType) | 122 void openFileSystemForWorker(WebCommonWorkerClient* commonClient, WebFileSystemT
ype type, long long size, bool create, WebFileSystemCallbacksImpl* callbacks, Fi
leSystemSynchronousType synchronousType) |
| 123 { | 123 { |
| 124 WorkerScriptController* controller = WorkerScriptController::controllerForCo
ntext(); | 124 WorkerScriptController* controller = WorkerScriptController::controllerForCo
ntext(); |
| 125 WorkerContext* workerContext = controller->workerContext(); | 125 WorkerGlobalScope* workerGlobalScope = controller->workerGlobalScope(); |
| 126 WebCore::WorkerThread* workerThread = workerContext->thread(); | 126 WebCore::WorkerThread* workerThread = workerGlobalScope->thread(); |
| 127 WorkerRunLoop& runLoop = workerThread->runLoop(); | 127 WorkerRunLoop& runLoop = workerThread->runLoop(); |
| 128 WebCore::WorkerLoaderProxy* workerLoaderProxy = &workerThread->workerLoader
Proxy(); | 128 WebCore::WorkerLoaderProxy* workerLoaderProxy = &workerThread->workerLoader
Proxy(); |
| 129 | 129 |
| 130 // Create a unique mode for this openFileSystem call. | 130 // Create a unique mode for this openFileSystem call. |
| 131 String mode = openFileSystemMode; | 131 String mode = openFileSystemMode; |
| 132 mode.append(String::number(runLoop.createUniqueId())); | 132 mode.append(String::number(runLoop.createUniqueId())); |
| 133 | 133 |
| 134 RefPtr<WorkerFileSystemCallbacksBridge> bridge = WorkerFileSystemCallbacksBr
idge::create(workerLoaderProxy, workerContext, callbacks); | 134 RefPtr<WorkerFileSystemCallbacksBridge> bridge = WorkerFileSystemCallbacksBr
idge::create(workerLoaderProxy, workerGlobalScope, callbacks); |
| 135 bridge->postOpenFileSystemToMainThread(commonClient, type, size, create, mod
e); | 135 bridge->postOpenFileSystemToMainThread(commonClient, type, size, create, mod
e); |
| 136 | 136 |
| 137 if (synchronousType == SynchronousFileSystem) { | 137 if (synchronousType == SynchronousFileSystem) { |
| 138 if (runLoop.runInMode(workerContext, mode) == MessageQueueTerminated) | 138 if (runLoop.runInMode(workerGlobalScope, mode) == MessageQueueTerminated
) |
| 139 bridge->stop(); | 139 bridge->stop(); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 | 142 |
| 143 } // namespace | 143 } // namespace |
| 144 | 144 |
| 145 static void openFileSystemNotAllowed(ScriptExecutionContext*, PassOwnPtr<AsyncFi
leSystemCallbacks> callbacks) | 145 static void openFileSystemNotAllowed(ScriptExecutionContext*, PassOwnPtr<AsyncFi
leSystemCallbacks> callbacks) |
| 146 { | 146 { |
| 147 callbacks->didFail(WebKit::WebFileErrorAbort); | 147 callbacks->didFail(WebKit::WebFileErrorAbort); |
| 148 } | 148 } |
| 149 | 149 |
| 150 static void deleteFileSystemNotAllowed(ScriptExecutionContext*, PassOwnPtr<Async
FileSystemCallbacks> callbacks) | 150 static void deleteFileSystemNotAllowed(ScriptExecutionContext*, PassOwnPtr<Async
FileSystemCallbacks> callbacks) |
| 151 { | 151 { |
| 152 callbacks->didFail(WebKit::WebFileErrorAbort); | 152 callbacks->didFail(WebKit::WebFileErrorAbort); |
| 153 } | 153 } |
| 154 | 154 |
| 155 static void openFileSystemHelper(ScriptExecutionContext* context, FileSystemType
type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks, FileSystemSynchronousType
synchronousType, long long size, CreationFlag create) | 155 static void openFileSystemHelper(ScriptExecutionContext* context, FileSystemType
type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks, FileSystemSynchronousType
synchronousType, long long size, CreationFlag create) |
| 156 { | 156 { |
| 157 bool allowed = true; | 157 bool allowed = true; |
| 158 ASSERT(context); | 158 ASSERT(context); |
| 159 if (context->isDocument()) { | 159 if (context->isDocument()) { |
| 160 Document* document = static_cast<Document*>(context); | 160 Document* document = static_cast<Document*>(context); |
| 161 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame()); | 161 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame()); |
| 162 WebKit::WebViewImpl* webView = webFrame->viewImpl(); | 162 WebKit::WebViewImpl* webView = webFrame->viewImpl(); |
| 163 if (webView->permissionClient() && !webView->permissionClient()->allowFi
leSystem(webFrame)) | 163 if (webView->permissionClient() && !webView->permissionClient()->allowFi
leSystem(webFrame)) |
| 164 allowed = false; | 164 allowed = false; |
| 165 else | 165 else |
| 166 webFrame->client()->openFileSystem(webFrame, static_cast<WebFileSyst
emType>(type), size, create == CreateIfNotPresent, new WebFileSystemCallbacksImp
l(callbacks)); | 166 webFrame->client()->openFileSystem(webFrame, static_cast<WebFileSyst
emType>(type), size, create == CreateIfNotPresent, new WebFileSystemCallbacksImp
l(callbacks)); |
| 167 } else { | 167 } else { |
| 168 WorkerContext* workerContext = static_cast<WorkerContext*>(context); | 168 WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(c
ontext); |
| 169 WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerContext->th
read()->workerLoaderProxy().toWebWorkerBase()); | 169 WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerGlobalScope
->thread()->workerLoaderProxy().toWebWorkerBase()); |
| 170 if (!allowFileSystemForWorker()) | 170 if (!allowFileSystemForWorker()) |
| 171 allowed = false; | 171 allowed = false; |
| 172 else | 172 else |
| 173 openFileSystemForWorker(webWorker->commonClient(), static_cast<WebFi
leSystemType>(type), size, create == CreateIfNotPresent, new WebFileSystemCallba
cksImpl(callbacks, context, synchronousType), synchronousType); | 173 openFileSystemForWorker(webWorker->commonClient(), static_cast<WebFi
leSystemType>(type), size, create == CreateIfNotPresent, new WebFileSystemCallba
cksImpl(callbacks, context, synchronousType), synchronousType); |
| 174 } | 174 } |
| 175 | 175 |
| 176 if (!allowed) { | 176 if (!allowed) { |
| 177 // The tasks are expected to be called asynchronously. | 177 // The tasks are expected to be called asynchronously. |
| 178 context->postTask(createCallbackTask(&openFileSystemNotAllowed, callback
s)); | 178 context->postTask(createCallbackTask(&openFileSystemNotAllowed, callback
s)); |
| 179 } | 179 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 199 WebKit::WebViewImpl* webView = webFrame->viewImpl(); | 199 WebKit::WebViewImpl* webView = webFrame->viewImpl(); |
| 200 if (webView->permissionClient() && !webView->permissionClient()->allowFileSy
stem(webFrame)) { | 200 if (webView->permissionClient() && !webView->permissionClient()->allowFileSy
stem(webFrame)) { |
| 201 context->postTask(createCallbackTask(&deleteFileSystemNotAllowed, callba
cks)); | 201 context->postTask(createCallbackTask(&deleteFileSystemNotAllowed, callba
cks)); |
| 202 return; | 202 return; |
| 203 } | 203 } |
| 204 | 204 |
| 205 webFrame->client()->deleteFileSystem(webFrame, static_cast<WebFileSystemType
>(type), new WebFileSystemCallbacksImpl(callbacks)); | 205 webFrame->client()->deleteFileSystem(webFrame, static_cast<WebFileSystemType
>(type), new WebFileSystemCallbacksImpl(callbacks)); |
| 206 } | 206 } |
| 207 | 207 |
| 208 } // namespace WebCore | 208 } // namespace WebCore |
| OLD | NEW |