Move NetworkStorageSession ownership to NetworkProcess
[WebKit-https.git] / Source / WebKit / NetworkProcess / NetworkSession.cpp
1 /*
2  * Copyright (C) 2015-2019 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 "NetworkSession.h"
28
29 #include "NetworkProcess.h"
30 #include "NetworkProcessProxyMessages.h"
31 #include "WebProcessProxy.h"
32 #include "WebResourceLoadStatisticsStore.h"
33 #include <WebCore/NetworkStorageSession.h>
34
35 #if PLATFORM(COCOA)
36 #include "NetworkSessionCocoa.h"
37 #endif
38 #if USE(SOUP)
39 #include "NetworkSessionSoup.h"
40 #endif
41 #if USE(CURL)
42 #include "NetworkSessionCurl.h"
43 #endif
44
45 namespace WebKit {
46 using namespace WebCore;
47
48 Ref<NetworkSession> NetworkSession::create(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
49 {
50 #if PLATFORM(COCOA)
51     return NetworkSessionCocoa::create(networkProcess, WTFMove(parameters));
52 #endif
53 #if USE(SOUP)
54     return NetworkSessionSoup::create(networkProcess, WTFMove(parameters));
55 #endif
56 #if USE(CURL)
57     return NetworkSessionCurl::create(networkProcess, WTFMove(parameters));
58 #endif
59 }
60
61 NetworkStorageSession& NetworkSession::networkStorageSession() const
62 {
63     auto* storageSession = m_networkProcess->storageSession(m_sessionID);
64     RELEASE_ASSERT(storageSession);
65     return *storageSession;
66 }
67
68 NetworkSession::NetworkSession(NetworkProcess& networkProcess, PAL::SessionID sessionID)
69     : m_sessionID(sessionID)
70     , m_networkProcess(networkProcess)
71 {
72 }
73
74 NetworkSession::~NetworkSession()
75 {
76 }
77
78 void NetworkSession::invalidateAndCancel()
79 {
80     for (auto* task : m_dataTaskSet)
81         task->invalidateAndCancel();
82 }
83
84 #if ENABLE(RESOURCE_LOAD_STATISTICS)
85 void NetworkSession::setResourceLoadStatisticsEnabled(bool enable)
86 {
87     if (!enable) {
88         m_resourceLoadStatistics = nullptr;
89         return;
90     }
91
92     if (m_resourceLoadStatistics)
93         return;
94
95     m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(*this, m_resourceLoadStatisticsDirectory);
96 }
97
98 void NetworkSession::notifyResourceLoadStatisticsProcessed()
99 {
100     m_networkProcess->parentProcessConnection()->send(Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsProcessed(), 0);
101 }
102
103 void NetworkSession::logDiagnosticMessageWithValue(const String& message, const String& description, unsigned value, unsigned significantFigures, WebCore::ShouldSample shouldSample)
104 {
105     m_networkProcess->parentProcessConnection()->send(Messages::WebPageProxy::LogDiagnosticMessageWithValue(message, description, value, significantFigures, shouldSample), 0);
106 }
107
108 void NetworkSession::notifyPageStatisticsTelemetryFinished(unsigned totalPrevalentResources, unsigned totalPrevalentResourcesWithUserInteraction, unsigned top3SubframeUnderTopFrameOrigins)
109 {
110     m_networkProcess->parentProcessConnection()->send(Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsTelemetryFinished(totalPrevalentResources, totalPrevalentResourcesWithUserInteraction, top3SubframeUnderTopFrameOrigins), 0);
111 }
112
113 void NetworkSession::deleteWebsiteDataForTopPrivatelyControlledDomainsInAllPersistentDataStores(OptionSet<WebsiteDataType> dataTypes, Vector<String>&& topPrivatelyControlledDomains, bool shouldNotifyPage, CompletionHandler<void(const HashSet<String>&)>&& completionHandler)
114 {
115     m_networkProcess->deleteWebsiteDataForTopPrivatelyControlledDomainsInAllPersistentDataStores(m_sessionID, dataTypes, WTFMove(topPrivatelyControlledDomains), shouldNotifyPage, WTFMove(completionHandler));
116 }
117
118 void NetworkSession::topPrivatelyControlledDomainsWithWebsiteData(OptionSet<WebsiteDataType> dataTypes, bool shouldNotifyPage, CompletionHandler<void(HashSet<String>&&)>&& completionHandler)
119 {
120     m_networkProcess->topPrivatelyControlledDomainsWithWebsiteData(m_sessionID, dataTypes, shouldNotifyPage, WTFMove(completionHandler));
121 }
122 #endif
123
124 } // namespace WebKit