| 1 | /* |
| 2 | * Copyright (C) 2013-2017 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "StorageNamespaceImpl.h" |
| 28 | |
| 29 | #include "StorageAreaImpl.h" |
| 30 | #include "StorageAreaMap.h" |
| 31 | #include "WebPage.h" |
| 32 | #include "WebPageGroupProxy.h" |
| 33 | #include "WebProcess.h" |
| 34 | #include <WebCore/Frame.h> |
| 35 | #include <WebCore/PageGroup.h> |
| 36 | #include <WebCore/SecurityOrigin.h> |
| 37 | #include <WebCore/Settings.h> |
| 38 | #include <WebCore/StorageType.h> |
| 39 | |
| 40 | namespace WebKit { |
| 41 | using namespace WebCore; |
| 42 | |
| 43 | Ref<StorageNamespaceImpl> StorageNamespaceImpl::createSessionStorageNamespace(uint64_t identifier, unsigned quotaInBytes) |
| 44 | { |
| 45 | return adoptRef(*new StorageNamespaceImpl(StorageType::Session, identifier, nullptr, quotaInBytes)); |
| 46 | } |
| 47 | |
| 48 | Ref<StorageNamespaceImpl> StorageNamespaceImpl::createEphemeralLocalStorageNamespace(uint64_t identifier, unsigned quotaInBytes) |
| 49 | { |
| 50 | return createSessionStorageNamespace(identifier, quotaInBytes); |
| 51 | } |
| 52 | |
| 53 | Ref<StorageNamespaceImpl> StorageNamespaceImpl::createLocalStorageNamespace(uint64_t identifier, unsigned quotaInBytes) |
| 54 | { |
| 55 | return adoptRef(*new StorageNamespaceImpl(StorageType::Local, identifier, nullptr, quotaInBytes)); |
| 56 | } |
| 57 | |
| 58 | Ref<StorageNamespaceImpl> StorageNamespaceImpl::createTransientLocalStorageNamespace(uint64_t identifier, WebCore::SecurityOrigin& topLevelOrigin, uint64_t quotaInBytes) |
| 59 | { |
| 60 | return adoptRef(*new StorageNamespaceImpl(StorageType::TransientLocal, identifier, &topLevelOrigin, quotaInBytes)); |
| 61 | } |
| 62 | |
| 63 | StorageNamespaceImpl::StorageNamespaceImpl(WebCore::StorageType storageType, uint64_t storageNamespaceID, WebCore::SecurityOrigin* topLevelOrigin, unsigned quotaInBytes) |
| 64 | : m_storageType(storageType) |
| 65 | , m_storageNamespaceID(storageNamespaceID) |
| 66 | , m_topLevelOrigin(topLevelOrigin) |
| 67 | , m_quotaInBytes(quotaInBytes) |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | StorageNamespaceImpl::~StorageNamespaceImpl() |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | void StorageNamespaceImpl::didDestroyStorageAreaMap(StorageAreaMap& map) |
| 76 | { |
| 77 | m_storageAreaMaps.remove(map.securityOrigin().data()); |
| 78 | } |
| 79 | |
| 80 | Ref<StorageArea> StorageNamespaceImpl::storageArea(const SecurityOriginData& securityOrigin) |
| 81 | { |
| 82 | RefPtr<StorageAreaMap> map; |
| 83 | |
| 84 | auto& slot = m_storageAreaMaps.add(securityOrigin, nullptr).iterator->value; |
| 85 | if (!slot) { |
| 86 | map = StorageAreaMap::create(this, securityOrigin.securityOrigin()); |
| 87 | slot = map.get(); |
| 88 | } else |
| 89 | map = slot; |
| 90 | |
| 91 | return StorageAreaImpl::create(map.releaseNonNull()); |
| 92 | } |
| 93 | |
| 94 | Ref<StorageNamespace> StorageNamespaceImpl::copy(Page* newPage) |
| 95 | { |
| 96 | ASSERT(m_storageNamespaceID); |
| 97 | |
| 98 | if (m_storageType == StorageType::Session) |
| 99 | return createSessionStorageNamespace(WebPage::fromCorePage(newPage)->pageID(), m_quotaInBytes); |
| 100 | |
| 101 | ASSERT(m_storageType == StorageType::EphemeralLocal); |
| 102 | auto newNamespace = adoptRef(*new StorageNamespaceImpl(m_storageType, m_storageNamespaceID, m_topLevelOrigin.get(), m_quotaInBytes)); |
| 103 | |
| 104 | return newNamespace; |
| 105 | } |
| 106 | |
| 107 | } // namespace WebKit |
| 108 | |