Resource Load Statistics: Grandfather domains for existing data records
[WebKit-https.git] / Source / WebKit2 / UIProcess / WebResourceLoadStatisticsManager.cpp
1 /*
2  * Copyright (C) 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 "WebResourceLoadStatisticsManager.h"
28
29 #include "Logging.h"
30 #include "WebResourceLoadStatisticsStore.h"
31 #include <WebCore/ResourceLoadObserver.h>
32 #include <WebCore/URL.h>
33
34 using namespace WebCore;
35
36 namespace WebKit {
37
38 void WebResourceLoadStatisticsManager::setPrevalentResource(const String& hostName, bool value)
39 {
40     if (value)
41         WebCore::ResourceLoadObserver::sharedObserver().setPrevalentResource(URL(URL(), hostName));
42     else
43         WebCore::ResourceLoadObserver::sharedObserver().clearPrevalentResource(URL(URL(), hostName));
44 }
45
46 bool WebResourceLoadStatisticsManager::isPrevalentResource(const String& hostName)
47 {
48     return WebCore::ResourceLoadObserver::sharedObserver().isPrevalentResource(URL(URL(), hostName));
49 }
50     
51 void WebResourceLoadStatisticsManager::setHasHadUserInteraction(const String& hostName, bool value)
52 {
53     if (value)
54         WebCore::ResourceLoadObserver::sharedObserver().logUserInteraction(URL(URL(), hostName));
55     else
56         WebCore::ResourceLoadObserver::sharedObserver().clearUserInteraction(URL(URL(), hostName));
57 }
58
59 bool WebResourceLoadStatisticsManager::hasHadUserInteraction(const String& hostName)
60 {
61     return WebCore::ResourceLoadObserver::sharedObserver().hasHadUserInteraction(URL(URL(), hostName));
62 }
63
64 void WebResourceLoadStatisticsManager::setGrandfathered(const String& hostName, bool value)
65 {
66     WebCore::ResourceLoadObserver::sharedObserver().setGrandfathered(URL(URL(), hostName), value);
67 }
68
69 bool WebResourceLoadStatisticsManager::isGrandfathered(const String& hostName)
70 {
71     return WebCore::ResourceLoadObserver::sharedObserver().isGrandfathered(URL(URL(), hostName));
72 }
73
74 void WebResourceLoadStatisticsManager::setSubframeUnderTopFrameOrigin(const String& hostName, const String& topFrameHostName)
75 {
76     WebCore::ResourceLoadObserver::sharedObserver().setSubframeUnderTopFrameOrigin(URL(URL(), hostName), URL(URL(), topFrameHostName));
77 }
78
79 void WebResourceLoadStatisticsManager::setSubresourceUnderTopFrameOrigin(const String& hostName, const String& topFrameHostName)
80 {
81     WebCore::ResourceLoadObserver::sharedObserver().setSubresourceUnderTopFrameOrigin(URL(URL(), hostName), URL(URL(), topFrameHostName));
82 }
83
84 void WebResourceLoadStatisticsManager::setSubresourceUniqueRedirectTo(const String& hostName, const String& hostNameRedirectedTo)
85 {
86     WebCore::ResourceLoadObserver::sharedObserver().setSubresourceUniqueRedirectTo(URL(URL(), hostName), URL(URL(), hostNameRedirectedTo));
87 }
88
89 void WebResourceLoadStatisticsManager::setTimeToLiveUserInteraction(double seconds)
90 {
91     WebCore::ResourceLoadObserver::sharedObserver().setTimeToLiveUserInteraction(seconds);
92 }
93
94 void WebResourceLoadStatisticsManager::setTimeToLiveCookiePartitionFree(double seconds)
95 {
96     WebCore::ResourceLoadObserver::sharedObserver().setTimeToLiveCookiePartitionFree(seconds);
97 }
98
99 void WebResourceLoadStatisticsManager::setMinimumTimeBetweeenDataRecordsRemoval(double seconds)
100 {
101     WebCore::ResourceLoadObserver::sharedObserver().setMinimumTimeBetweeenDataRecordsRemoval(seconds);
102 }
103
104 void WebResourceLoadStatisticsManager::setGrandfatheringTime(double seconds)
105 {
106     WebCore::ResourceLoadObserver::sharedObserver().setGrandfatheringTime(seconds);
107 }
108
109 void WebResourceLoadStatisticsManager::fireDataModificationHandler()
110 {
111     WebCore::ResourceLoadObserver::sharedObserver().fireDataModificationHandler();
112 }
113
114 void WebResourceLoadStatisticsManager::fireShouldPartitionCookiesHandler()
115 {
116     WebCore::ResourceLoadObserver::sharedObserver().fireShouldPartitionCookiesHandler();
117 }
118
119 void WebResourceLoadStatisticsManager::fireShouldPartitionCookiesHandlerForOneDomain(const String& hostName, bool value)
120 {
121     if (value)
122         WebCore::ResourceLoadObserver::sharedObserver().fireShouldPartitionCookiesHandler({ }, {hostName}, false);
123     else
124         WebCore::ResourceLoadObserver::sharedObserver().fireShouldPartitionCookiesHandler({hostName}, { }, false);
125 }
126
127 void WebResourceLoadStatisticsManager::setNotifyPagesWhenDataRecordsWereScanned(bool value)
128 {
129     WebResourceLoadStatisticsStore::setNotifyPagesWhenDataRecordsWereScanned(value);
130 }
131
132 void WebResourceLoadStatisticsManager::setShouldClassifyResourcesBeforeDataRecordsRemoval(bool value)
133 {
134     WebResourceLoadStatisticsStore::setShouldClassifyResourcesBeforeDataRecordsRemoval(value);
135 }
136
137 void WebResourceLoadStatisticsManager::clearInMemoryAndPersistentStore()
138 {
139     WebCore::ResourceLoadObserver::sharedObserver().clearInMemoryAndPersistentStore();
140 }
141
142 void WebResourceLoadStatisticsManager::clearInMemoryAndPersistentStoreModifiedSinceHours(unsigned hours)
143 {
144     WebCore::ResourceLoadObserver::sharedObserver().clearInMemoryAndPersistentStore(std::chrono::system_clock::now() - std::chrono::hours(hours));
145 }
146     
147 void WebResourceLoadStatisticsManager::resetToConsistentState()
148 {
149     WebCore::ResourceLoadObserver::sharedObserver().setTimeToLiveUserInteraction(2592000);
150     WebCore::ResourceLoadObserver::sharedObserver().setTimeToLiveCookiePartitionFree(86400);
151     WebCore::ResourceLoadObserver::sharedObserver().setMinimumTimeBetweeenDataRecordsRemoval(60);
152     WebResourceLoadStatisticsStore::setNotifyPagesWhenDataRecordsWereScanned(false);
153     WebResourceLoadStatisticsStore::setShouldClassifyResourcesBeforeDataRecordsRemoval(true);
154     WebCore::ResourceLoadObserver::sharedObserver().clearInMemoryStore();
155 }
156     
157 } // namespace WebKit