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