1926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)/* 209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Copyright (C) 2014 Google Inc. All rights reserved. 3926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 4926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without 5926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * modification, are permitted provided that the following conditions are 6926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * met: 7926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 8926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * * Redistributions of source code must retain the above copyright 9926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 10926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * * Redistributions in binary form must reproduce the above 11926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 12926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * in the documentation and/or other materials provided with the 13926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * distribution. 14926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 15926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * contributors may be used to endorse or promote products derived from 16926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * this software without specific prior written permission. 17926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 18926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) */ 30926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 31926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#include "config.h" 32f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "web/StorageQuotaClientImpl.h" 33926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 34197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "bindings/core/v8/ScriptPromise.h" 35197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "bindings/core/v8/ScriptPromiseResolver.h" 36197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "bindings/core/v8/ScriptState.h" 3709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/dom/DOMError.h" 3853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/Document.h" 3953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/ExceptionCode.h" 401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "core/dom/ExecutionContext.h" 4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/quota/DeprecatedStorageQuotaCallbacksImpl.h" 4253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/quota/StorageErrorCallback.h" 4353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/quota/StorageQuotaCallback.h" 4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/quota/StorageQuotaCallbacksImpl.h" 4553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/quota/StorageUsageCallback.h" 4651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "public/platform/WebStorageQuotaType.h" 47f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebFrameClient.h" 48f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "web/WebLocalFrameImpl.h" 49591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/Threading.h" 50926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)namespace blink { 52926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 53f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo LiuPassOwnPtrWillBeRawPtr<StorageQuotaClientImpl> StorageQuotaClientImpl::create() 5409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 55f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu return adoptPtrWillBeNoop(new StorageQuotaClientImpl()); 5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 5809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)StorageQuotaClientImpl::~StorageQuotaClientImpl() 5909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 627242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccivoid StorageQuotaClientImpl::requestQuota(ExecutionContext* executionContext, WebStorageQuotaType storageType, unsigned long long newQuotaInBytes, StorageQuotaCallback* successCallback, StorageErrorCallback* errorCallback) 63926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) ASSERT(executionContext); 6509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 6609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (executionContext->isDocument()) { 6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) Document* document = toDocument(executionContext); 6810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch WebLocalFrameImpl* webFrame = WebLocalFrameImpl::fromFrame(document->frame()); 697242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci OwnPtrWillBeRawPtr<StorageQuotaCallbacks> callbacks = DeprecatedStorageQuotaCallbacksImpl::create(successCallback, errorCallback); 7009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) webFrame->client()->requestStorageQuota(webFrame, storageType, newQuotaInBytes, callbacks.release()); 7109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } else { 7209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // Requesting quota in Worker is not supported. 731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) executionContext->postTask(StorageErrorCallback::CallbackTask::create(errorCallback, NotSupportedError)); 74926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) } 7509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 7609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 77d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)ScriptPromise StorageQuotaClientImpl::requestPersistentQuota(ScriptState* scriptState, unsigned long long newQuotaInBytes) 7809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 79197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); 80d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) ScriptPromise promise = resolver->promise(); 8109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 82d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) if (scriptState->executionContext()->isDocument()) { 83d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) Document* document = toDocument(scriptState->executionContext()); 8410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch WebLocalFrameImpl* webFrame = WebLocalFrameImpl::fromFrame(document->frame()); 857242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci OwnPtrWillBeRawPtr<StorageQuotaCallbacks> callbacks = StorageQuotaCallbacksImpl::create(resolver); 8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) webFrame->client()->requestStorageQuota(webFrame, WebStorageQuotaTypePersistent, newQuotaInBytes, callbacks.release()); 87926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) } else { 88926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) // Requesting quota in Worker is not supported. 8909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) resolver->reject(DOMError::create(NotSupportedError)); 90926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) } 9109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 9209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return promise; 9309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 9409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 9509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)StorageQuotaClientImpl::StorageQuotaClientImpl() 9609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 97926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 98926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 9909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} // namespace blink 100