1/* 2 * Copyright (C) 2012 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#import "config.h" 27#import "RemoteNetworkingContext.h" 28 29#import "NetworkProcess.h" 30#import "SessionTracker.h" 31#import "WebErrors.h" 32#import <WebCore/ResourceError.h> 33#import <WebKitSystemInterface.h> 34#import <wtf/MainThread.h> 35#import <wtf/NeverDestroyed.h> 36 37using namespace WebCore; 38 39namespace WebKit { 40 41 42RemoteNetworkingContext::~RemoteNetworkingContext() 43{ 44} 45 46bool RemoteNetworkingContext::isValid() const 47{ 48 return true; 49} 50 51bool RemoteNetworkingContext::needsSiteSpecificQuirks() const 52{ 53 return m_needsSiteSpecificQuirks; 54} 55 56bool RemoteNetworkingContext::localFileContentSniffingEnabled() const 57{ 58 return m_localFileContentSniffingEnabled; 59} 60 61NetworkStorageSession& RemoteNetworkingContext::storageSession() const 62{ 63 NetworkStorageSession* session = SessionTracker::session(m_sessionID); 64 if (session) 65 return *session; 66 // Some requests may still be coming shortly after NetworkProcess was told to destroy its session. 67 LOG_ERROR("Invalid session ID. Please file a bug unless you just disabled private browsing, in which case it's an expected race."); 68 return NetworkStorageSession::defaultStorageSession(); 69} 70 71RetainPtr<CFDataRef> RemoteNetworkingContext::sourceApplicationAuditData() const 72{ 73#if PLATFORM(IOS) 74 audit_token_t auditToken; 75 if (!NetworkProcess::shared().parentProcessConnection()->getAuditToken(auditToken)) 76 return nullptr; 77 return adoptCF(CFDataCreate(0, (const UInt8*)&auditToken, sizeof(auditToken))); 78#else 79 return nullptr; 80#endif 81} 82 83String RemoteNetworkingContext::sourceApplicationIdentifier() const 84{ 85 return SessionTracker::getIdentifierBase(); 86} 87 88ResourceError RemoteNetworkingContext::blockedError(const ResourceRequest& request) const 89{ 90 return WebKit::blockedError(request); 91} 92 93void RemoteNetworkingContext::ensurePrivateBrowsingSession(SessionID sessionID) 94{ 95 ASSERT(sessionID.isEphemeral()); 96 97 if (SessionTracker::session(sessionID)) 98 return; 99 100 ASSERT(!SessionTracker::getIdentifierBase().isNull()); 101 SessionTracker::setSession(sessionID, NetworkStorageSession::createPrivateBrowsingSession(SessionTracker::getIdentifierBase() + '.' + String::number(sessionID.sessionID()))); 102} 103 104} 105