| 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 15 matching lines...) Expand all  Loading... | 
|   26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |   26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|   27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |   27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
|   28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |   28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|   29  */ |   29  */ | 
|   30  |   30  | 
|   31 #include "config.h" |   31 #include "config.h" | 
|   32 #include "modules/quota/StorageQuota.h" |   32 #include "modules/quota/StorageQuota.h" | 
|   33  |   33  | 
|   34 #include "WebFrameClient.h" |   34 #include "WebFrameClient.h" | 
|   35 #include "WebFrameImpl.h" |   35 #include "WebFrameImpl.h" | 
|   36 #include "WebStorageQuotaCallbacksImpl.h" |  | 
|   37 #include "WebStorageQuotaType.h" |   36 #include "WebStorageQuotaType.h" | 
|   38 #include "WebWorkerBase.h" |   37 #include "WebWorkerBase.h" | 
|   39 #include "WorkerStorageQuotaCallbacksBridge.h" |  | 
|   40 #include "core/dom/Document.h" |   38 #include "core/dom/Document.h" | 
|   41 #include "core/dom/ExceptionCode.h" |   39 #include "core/dom/ExceptionCode.h" | 
|   42 #include "core/dom/ScriptExecutionContext.h" |   40 #include "core/dom/ScriptExecutionContext.h" | 
|   43 #include "core/workers/WorkerGlobalScope.h" |   41 #include "core/workers/WorkerGlobalScope.h" | 
|   44 #include "core/workers/WorkerThread.h" |   42 #include "core/workers/WorkerThread.h" | 
|   45 #include "modules/quota/StorageErrorCallback.h" |   43 #include "modules/quota/StorageErrorCallback.h" | 
|   46 #include "modules/quota/StorageQuotaCallback.h" |   44 #include "modules/quota/StorageQuotaCallback.h" | 
|   47 #include "modules/quota/StorageUsageCallback.h" |   45 #include "modules/quota/StorageUsageCallback.h" | 
 |   46 #include "modules/quota/WebStorageQuotaCallbacksImpl.h" | 
|   48 #include "wtf/Threading.h" |   47 #include "wtf/Threading.h" | 
|   49  |   48  | 
|   50 using namespace WebKit; |   49 using namespace WebKit; | 
|   51  |   50  | 
|   52 namespace WebCore { |   51 namespace WebCore { | 
|   53  |   52  | 
|   54 static void queryUsageAndQuotaFromWorker(WebCommonWorkerClient* commonClient, We
     bStorageQuotaType storageType, WebStorageQuotaCallbacksImpl* callbacks) |   53 // FIXME: Implement this as StorageQuotaClient. | 
|   55 { |  | 
|   56     WorkerGlobalScope* workerGlobalScope = WorkerScriptController::controllerFor
     Context()->workerGlobalScope(); |  | 
|   57     WebCore::WorkerThread* workerThread = workerGlobalScope->thread(); |  | 
|   58     WebCore::WorkerLoaderProxy* workerLoaderProxy = &workerThread->workerLoaderP
     roxy(); |  | 
|   59  |  | 
|   60     String mode = "queryUsageAndQuotaMode" + String::number(workerThread->runLoo
     p().createUniqueId()); |  | 
|   61  |  | 
|   62     RefPtr<WorkerStorageQuotaCallbacksBridge> bridge = WorkerStorageQuotaCallbac
     ksBridge::create(workerLoaderProxy, workerGlobalScope, callbacks); |  | 
|   63  |  | 
|   64     // The bridge is held by the task that is created in posted to the main thre
     ad by this method. |  | 
|   65     bridge->postQueryUsageAndQuotaToMainThread(commonClient, storageType, mode); |  | 
|   66 } |  | 
|   67  |  | 
|   68 void StorageQuota::queryUsageAndQuota(ScriptExecutionContext* scriptExecutionCon
     text, PassRefPtr<StorageUsageCallback> successCallback, PassRefPtr<StorageErrorC
     allback> errorCallback) |  | 
|   69 { |  | 
|   70     ASSERT(scriptExecutionContext); |  | 
|   71     WebStorageQuotaType storageType = static_cast<WebStorageQuotaType>(m_type); |  | 
|   72     if (storageType != WebStorageQuotaTypeTemporary && storageType != WebStorage
     QuotaTypePersistent) { |  | 
|   73         // Unknown storage type is requested. |  | 
|   74         scriptExecutionContext->postTask(StorageErrorCallback::CallbackTask::cre
     ate(errorCallback, NotSupportedError)); |  | 
|   75         return; |  | 
|   76     } |  | 
|   77     if (scriptExecutionContext->isDocument()) { |  | 
|   78         Document* document = toDocument(scriptExecutionContext); |  | 
|   79         WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame()); |  | 
|   80         webFrame->client()->queryStorageUsageAndQuota(webFrame, storageType, new
      WebStorageQuotaCallbacksImpl(successCallback, errorCallback)); |  | 
|   81     } else { |  | 
|   82         WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(scriptExecuti
     onContext); |  | 
|   83         WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerGlobalScope
     ->thread()->workerLoaderProxy().toWebWorkerBase()); |  | 
|   84         queryUsageAndQuotaFromWorker(webWorker->commonClient(), storageType, new
      WebStorageQuotaCallbacksImpl(successCallback, errorCallback)); |  | 
|   85     } |  | 
|   86 } |  | 
|   87  |  | 
|   88 void StorageQuota::requestQuota(ScriptExecutionContext* scriptExecutionContext, 
     unsigned long long newQuotaInBytes, PassRefPtr<StorageQuotaCallback> successCall
     back, PassRefPtr<StorageErrorCallback> errorCallback) |   54 void StorageQuota::requestQuota(ScriptExecutionContext* scriptExecutionContext, 
     unsigned long long newQuotaInBytes, PassRefPtr<StorageQuotaCallback> successCall
     back, PassRefPtr<StorageErrorCallback> errorCallback) | 
|   89 { |   55 { | 
|   90     ASSERT(scriptExecutionContext); |   56     ASSERT(scriptExecutionContext); | 
|   91     WebStorageQuotaType storageType = static_cast<WebStorageQuotaType>(m_type); |   57     WebStorageQuotaType storageType = static_cast<WebStorageQuotaType>(m_type); | 
|   92     if (storageType != WebStorageQuotaTypeTemporary && storageType != WebStorage
     QuotaTypePersistent) { |   58     if (storageType != WebStorageQuotaTypeTemporary && storageType != WebStorage
     QuotaTypePersistent) { | 
|   93         // Unknown storage type is requested. |   59         // Unknown storage type is requested. | 
|   94         scriptExecutionContext->postTask(StorageErrorCallback::CallbackTask::cre
     ate(errorCallback, NotSupportedError)); |   60         scriptExecutionContext->postTask(StorageErrorCallback::CallbackTask::cre
     ate(errorCallback, NotSupportedError)); | 
|   95         return; |   61         return; | 
|   96     } |   62     } | 
|   97     if (scriptExecutionContext->isDocument()) { |   63     if (scriptExecutionContext->isDocument()) { | 
|   98         Document* document = toDocument(scriptExecutionContext); |   64         Document* document = toDocument(scriptExecutionContext); | 
|   99         WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame()); |   65         WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame()); | 
|  100         webFrame->client()->requestStorageQuota(webFrame, storageType, newQuotaI
     nBytes, new WebStorageQuotaCallbacksImpl(successCallback, errorCallback)); |   66         webFrame->client()->requestStorageQuota(webFrame, storageType, newQuotaI
     nBytes, WebStorageQuotaCallbacksImpl::createLeakedPtr(successCallback, errorCall
     back)); | 
|  101     } else { |   67     } else { | 
|  102         // Requesting quota in Worker is not supported. |   68         // Requesting quota in Worker is not supported. | 
|  103         scriptExecutionContext->postTask(StorageErrorCallback::CallbackTask::cre
     ate(errorCallback, NotSupportedError)); |   69         scriptExecutionContext->postTask(StorageErrorCallback::CallbackTask::cre
     ate(errorCallback, NotSupportedError)); | 
|  104     } |   70     } | 
|  105 } |   71 } | 
|  106  |   72  | 
|  107 } // namespace WebCore |   73 } // namespace WebCore | 
| OLD | NEW |