109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)/* 209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Copyright (C) 2011 Google Inc. All rights reserved. 309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * modification, are permitted provided that the following conditions are 609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * met: 709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 1009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 1109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 1209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * in the documentation and/or other materials provided with the 1309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * distribution. 1409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 1509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 1609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * this software without specific prior written permission. 1709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 1809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) */ 3009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 3109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "config.h" 3209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/quota/DeprecatedStorageQuota.h" 3309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/dom/ExceptionCode.h" 3509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/dom/ExecutionContext.h" 3609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/quota/DeprecatedStorageQuotaCallbacksImpl.h" 3709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/quota/StorageErrorCallback.h" 3809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/quota/StorageQuotaClient.h" 3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/quota/StorageUsageCallback.h" 4009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "platform/StorageQuotaCallbacks.h" 4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "platform/weborigin/KURL.h" 4209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "platform/weborigin/SecurityOrigin.h" 4309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "public/platform/Platform.h" 4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "public/platform/WebStorageQuotaCallbacks.h" 4509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "public/platform/WebStorageQuotaType.h" 4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 47c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)DeprecatedStorageQuota::DeprecatedStorageQuota(Type type) 5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) : m_type(type) 5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 5209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 5309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 547242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccivoid DeprecatedStorageQuota::queryUsageAndQuota(ExecutionContext* executionContext, StorageUsageCallback* successCallback, StorageErrorCallback* errorCallback) 5509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT(executionContext); 5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 58e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) WebStorageQuotaType storageType = static_cast<WebStorageQuotaType>(m_type); 59e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) if (storageType != WebStorageQuotaTypeTemporary && storageType != WebStorageQuotaTypePersistent) { 6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // Unknown storage type is requested. 6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) executionContext->postTask(StorageErrorCallback::CallbackTask::create(errorCallback, NotSupportedError)); 6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return; 6309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 6409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 6509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) SecurityOrigin* securityOrigin = executionContext->securityOrigin(); 6609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (securityOrigin->isUnique()) { 6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) executionContext->postTask(StorageErrorCallback::CallbackTask::create(errorCallback, NotSupportedError)); 6809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return; 6909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 7009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 7109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) KURL storagePartition = KURL(KURL(), securityOrigin->toString()); 727242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci OwnPtrWillBeRawPtr<StorageQuotaCallbacks> callbacks = DeprecatedStorageQuotaCallbacksImpl::create(successCallback, errorCallback); 73e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) Platform::current()->queryStorageUsageAndQuota(storagePartition, storageType, callbacks.release()); 7409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 7509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 767242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccivoid DeprecatedStorageQuota::requestQuota(ExecutionContext* executionContext, unsigned long long newQuotaInBytes, StorageQuotaCallback* successCallback, StorageErrorCallback* errorCallback) 7709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 7809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT(executionContext); 7909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 80e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) WebStorageQuotaType storageType = static_cast<WebStorageQuotaType>(m_type); 81e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) if (storageType != WebStorageQuotaTypeTemporary && storageType != WebStorageQuotaTypePersistent) { 8209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // Unknown storage type is requested. 8309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) executionContext->postTask(StorageErrorCallback::CallbackTask::create(errorCallback, NotSupportedError)); 8409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return; 8509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 87aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch StorageQuotaClient* client = StorageQuotaClient::from(executionContext); 88aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch if (!client) { 89aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch executionContext->postTask(StorageErrorCallback::CallbackTask::create(errorCallback, NotSupportedError)); 90aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch return; 91aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch } 92aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch 93aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch client->requestQuota(executionContext, storageType, newQuotaInBytes, successCallback, errorCallback); 9409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 9509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 96c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 97