| 1 | /* |
| 2 | * Copyright (C) 2015 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 "WebsiteData.h" |
| 28 | |
| 29 | #include "ArgumentCoders.h" |
| 30 | #include "WebsiteDataType.h" |
| 31 | #include <WebCore/SecurityOriginData.h> |
| 32 | #include <wtf/text/StringHash.h> |
| 33 | |
| 34 | namespace WebKit { |
| 35 | |
| 36 | void WebsiteData::Entry::encode(IPC::Encoder& encoder) const |
| 37 | { |
| 38 | encoder << origin; |
| 39 | encoder.encodeEnum(type); |
| 40 | encoder << size; |
| 41 | } |
| 42 | |
| 43 | auto WebsiteData::Entry::decode(IPC::Decoder& decoder) -> Optional<Entry> |
| 44 | { |
| 45 | Entry result; |
| 46 | |
| 47 | Optional<WebCore::SecurityOriginData> securityOriginData; |
| 48 | decoder >> securityOriginData; |
| 49 | if (!securityOriginData) |
| 50 | return WTF::nullopt; |
| 51 | result.origin = WTFMove(*securityOriginData); |
| 52 | |
| 53 | if (!decoder.decodeEnum(result.type)) |
| 54 | return WTF::nullopt; |
| 55 | |
| 56 | if (!decoder.decode(result.size)) |
| 57 | return WTF::nullopt; |
| 58 | |
| 59 | return result; |
| 60 | } |
| 61 | |
| 62 | void WebsiteData::encode(IPC::Encoder& encoder) const |
| 63 | { |
| 64 | encoder << entries; |
| 65 | encoder << hostNamesWithCookies; |
| 66 | #if ENABLE(NETSCAPE_PLUGIN_API) |
| 67 | encoder << hostNamesWithPluginData; |
| 68 | #endif |
| 69 | encoder << originsWithCredentials; |
| 70 | encoder << hostNamesWithHSTSCache; |
| 71 | } |
| 72 | |
| 73 | bool WebsiteData::decode(IPC::Decoder& decoder, WebsiteData& result) |
| 74 | { |
| 75 | if (!decoder.decode(result.entries)) |
| 76 | return false; |
| 77 | if (!decoder.decode(result.hostNamesWithCookies)) |
| 78 | return false; |
| 79 | #if ENABLE(NETSCAPE_PLUGIN_API) |
| 80 | if (!decoder.decode(result.hostNamesWithPluginData)) |
| 81 | return false; |
| 82 | #endif |
| 83 | if (!decoder.decode(result.originsWithCredentials)) |
| 84 | return false; |
| 85 | if (!decoder.decode(result.hostNamesWithHSTSCache)) |
| 86 | return false; |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | WebsiteDataProcessType WebsiteData::ownerProcess(WebsiteDataType dataType) |
| 91 | { |
| 92 | switch (dataType) { |
| 93 | case WebsiteDataType::Cookies: |
| 94 | return WebsiteDataProcessType::Network; |
| 95 | case WebsiteDataType::DiskCache: |
| 96 | return WebsiteDataProcessType::Network; |
| 97 | case WebsiteDataType::MemoryCache: |
| 98 | return WebsiteDataProcessType::Web; |
| 99 | case WebsiteDataType::OfflineWebApplicationCache: |
| 100 | return WebsiteDataProcessType::UI; |
| 101 | case WebsiteDataType::SessionStorage: |
| 102 | return WebsiteDataProcessType::UI; |
| 103 | case WebsiteDataType::LocalStorage: |
| 104 | return WebsiteDataProcessType::UI; |
| 105 | case WebsiteDataType::WebSQLDatabases: |
| 106 | return WebsiteDataProcessType::UI; |
| 107 | case WebsiteDataType::IndexedDBDatabases: |
| 108 | return WebsiteDataProcessType::Network; |
| 109 | case WebsiteDataType::MediaKeys: |
| 110 | return WebsiteDataProcessType::UI; |
| 111 | case WebsiteDataType::HSTSCache: |
| 112 | return WebsiteDataProcessType::Network; |
| 113 | case WebsiteDataType::SearchFieldRecentSearches: |
| 114 | return WebsiteDataProcessType::UI; |
| 115 | #if ENABLE(NETSCAPE_PLUGIN_API) |
| 116 | case WebsiteDataType::PlugInData: |
| 117 | return WebsiteDataProcessType::UI; |
| 118 | #endif |
| 119 | case WebsiteDataType::ResourceLoadStatistics: |
| 120 | return WebsiteDataProcessType::Network; |
| 121 | case WebsiteDataType::Credentials: |
| 122 | return WebsiteDataProcessType::Network; |
| 123 | #if ENABLE(SERVICE_WORKER) |
| 124 | case WebsiteDataType::ServiceWorkerRegistrations: |
| 125 | return WebsiteDataProcessType::Network; |
| 126 | #endif |
| 127 | case WebsiteDataType::DOMCache: |
| 128 | return WebsiteDataProcessType::Network; |
| 129 | case WebsiteDataType::DeviceIdHashSalt: |
| 130 | return WebsiteDataProcessType::UI; |
| 131 | case WebsiteDataType::AdClickAttributions: |
| 132 | return WebsiteDataProcessType::Network; |
| 133 | } |
| 134 | |
| 135 | RELEASE_ASSERT_NOT_REACHED(); |
| 136 | } |
| 137 | |
| 138 | OptionSet<WebsiteDataType> WebsiteData::filter(OptionSet<WebsiteDataType> unfilteredWebsiteDataTypes, WebsiteDataProcessType WebsiteDataProcessType) |
| 139 | { |
| 140 | OptionSet<WebsiteDataType> filtered; |
| 141 | for (auto dataType : unfilteredWebsiteDataTypes) { |
| 142 | if (ownerProcess(dataType) == WebsiteDataProcessType) |
| 143 | filtered.add(dataType); |
| 144 | } |
| 145 | |
| 146 | return filtered; |
| 147 | } |
| 148 | |
| 149 | } |
| 150 | |