WebFrameNetworkingContext.cpp [plain text]
#include "WebFrameNetworkingContext.h"
#include "WebView.h"
#include <WebCore/FrameLoader.h>
#include <WebCore/FrameLoaderClient.h>
#include <WebCore/NetworkStorageSession.h>
#include <WebCore/Page.h>
#include <WebCore/ResourceError.h>
#include <WebCore/Settings.h>
#include <wtf/NeverDestroyed.h>
#if USE(CFNETWORK)
#include <CFNetwork/CFHTTPCookiesPriv.h>
#include <WebKitSystemInterface/WebKitSystemInterface.h>
#endif
using namespace WebCore;
static std::unique_ptr<NetworkStorageSession>& privateSession()
{
static NeverDestroyed<std::unique_ptr<NetworkStorageSession>> session;
return session;
}
static String& identifierBase()
{
static NeverDestroyed<String> base;
return base;
}
#if USE(CFNETWORK)
void WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts(WebKitCookieStorageAcceptPolicy policy)
{
if (RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSession::defaultStorageSession().cookieStorage())
CFHTTPCookieStorageSetCookieAcceptPolicy(cookieStorage.get(), policy);
if (privateSession())
CFHTTPCookieStorageSetCookieAcceptPolicy(privateSession()->cookieStorage().get(), policy);
}
#endif
void WebFrameNetworkingContext::setPrivateBrowsingStorageSessionIdentifierBase(const String& base)
{
ASSERT(isMainThread());
identifierBase() = base;
}
void WebFrameNetworkingContext::ensurePrivateBrowsingSession()
{
#if USE(CFNETWORK)
ASSERT(isMainThread());
if (privateSession())
return;
String base;
if (identifierBase().isNull()) {
if (CFTypeRef bundleValue = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleIdentifierKey))
if (CFGetTypeID(bundleValue) == CFStringGetTypeID())
base = reinterpret_cast<CFStringRef>(bundleValue);
} else
base = identifierBase();
privateSession() = NetworkStorageSession::createPrivateBrowsingSession(base);
#endif
}
void WebFrameNetworkingContext::destroyPrivateBrowsingSession()
{
ASSERT(isMainThread());
privateSession() = nullptr;
}
ResourceError WebFrameNetworkingContext::blockedError(const ResourceRequest& request) const
{
return frame()->loader().client().blockedError(request);
}
#if USE(CFNETWORK)
NetworkStorageSession& WebFrameNetworkingContext::storageSession() const
{
ASSERT(isMainThread());
if (frame() && frame()->page()->usesEphemeralSession())
return *privateSession();
return NetworkStorageSession::defaultStorageSession();
}
#endif