Changeset 216977 in webkit
- Timestamp:
- May 17, 2017 9:51:46 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r216967 r216977 2412 2412 platform/network/BlobResourceHandle.cpp 2413 2413 platform/network/CacheValidation.cpp 2414 platform/network/Cookie.cpp 2414 2415 platform/network/CredentialBase.cpp 2415 2416 platform/network/CredentialStorage.cpp -
trunk/Source/WebCore/ChangeLog
r216974 r216977 1 2017-05-17 Alex Christensen <achristensen@webkit.org> 2 3 Interacting with WKHTTPCookieStores before creating WKWebViews and WKProcessPools should affect cookies used 4 https://bugs.webkit.org/show_bug.cgi?id=171987 5 6 Reviewed by Brady Eidson. 7 8 Covered by new API tests. 9 10 * CMakeLists.txt: 11 * platform/Cookie.h: 12 (WebCore::Cookie::Cookie): 13 (WebCore::Cookie::isNull): 14 (WebCore::CookieHash::hash): 15 (WebCore::CookieHash::equal): 16 (WTF::HashTraits<WebCore::Cookie>::emptyValue): 17 (WTF::HashTraits<WebCore::Cookie>::constructDeletedValue): 18 (WTF::HashTraits<WebCore::Cookie>::isDeletedValue): 19 * platform/network/Cookie.cpp: Added. 20 (WebCore::Cookie::operator==): 21 (WebCore::Cookie::hash): 22 * platform/network/cocoa/CookieCocoa.mm: 23 (WebCore::Cookie::operator NSHTTPCookie *): 24 (WebCore::Cookie::operator==): 25 (WebCore::Cookie::hash): 26 * platform/network/cocoa/NetworkStorageSessionCocoa.mm: 27 (WebCore::NetworkStorageSession::setCookies): 28 Use NSHTTPCookie's hash and equality comparison to more closely match the NSHTTPCookie behavior. 29 1 30 2017-05-17 Emilio Cobos Álvarez <ecobos@igalia.com> 2 31 -
trunk/Source/WebCore/platform/Cookie.h
r213877 r216977 1 1 /* 2 2 * Copyright (C) 2009 Joseph Pecoraro. All rights reserved. 3 * Copyright (C) 2017 Apple Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 38 39 struct Cookie { 39 40 Cookie() { } 41 42 Cookie(WTF::HashTableDeletedValueType) 43 : name(WTF::HashTableDeletedValue) 44 { } 40 45 41 46 Cookie(const String& name, const String& value, const String& domain, const String& path, double expires, bool httpOnly, bool secure, bool session, const String& comment, const URL& commentURL, const Vector<uint16_t> ports) … … 57 62 template<class Decoder> static bool decode(Decoder&, Cookie&); 58 63 64 WEBCORE_EXPORT bool operator==(const Cookie&) const; 65 WEBCORE_EXPORT unsigned hash() const; 66 59 67 #ifdef __OBJC__ 60 68 WEBCORE_EXPORT Cookie(NSHTTPCookie *); … … 62 70 #endif 63 71 72 bool isNull() const 73 { 74 return name.isNull() 75 && value.isNull() 76 && domain.isNull() 77 && path.isNull() 78 && expires == 0 79 && !httpOnly 80 && !secure 81 && !session 82 && comment.isNull() 83 && commentURL.isNull(); 84 } 85 64 86 String name; 65 87 String value; … … 67 89 String path; 68 90 // Expiration date, expressed as milliseconds since the UNIX epoch. 69 double expires ;70 bool httpOnly ;71 bool secure ;72 bool session ;91 double expires { 0 }; 92 bool httpOnly { false }; 93 bool secure { false }; 94 bool session { false }; 73 95 String comment; 74 96 URL commentURL; 75 97 Vector<uint16_t> ports; 76 77 98 }; 78 99 79 100 struct CookieHash { 80 101 static unsigned hash(const Cookie& key) 81 { 82 return StringHash::hash(key.name) + StringHash::hash(key.domain) + StringHash::hash(key.path) + key.secure;102 { 103 return key.hash(); 83 104 } 84 105 85 106 static bool equal(const Cookie& a, const Cookie& b) 86 107 { 87 return a .name == b.name && a.domain == b.domain && a.path == b.path && a.secure == b.secure;108 return a == b; 88 109 } 110 static const bool safeToCompareToEmptyOrDeleted = false; 89 111 }; 90 112 … … 131 153 typedef WebCore::CookieHash Hash; 132 154 }; 155 template<> struct HashTraits<WebCore::Cookie> : GenericHashTraits<WebCore::Cookie> { 156 static WebCore::Cookie emptyValue() { return { }; } 157 static void constructDeletedValue(WebCore::Cookie& slot) { slot = WebCore::Cookie(WTF::HashTableDeletedValue); } 158 static bool isDeletedValue(const WebCore::Cookie& slot) { return slot.name.isHashTableDeletedValue(); } 159 }; 133 160 } -
trunk/Source/WebCore/platform/network/cocoa/CookieCocoa.mm
r216292 r216977 65 65 Cookie::operator NSHTTPCookie *() const 66 66 { 67 if (isNull()) 68 return nil; 69 67 70 // FIXME: existing APIs do not provide a way to set httpOnly without parsing headers from scratch. 68 71 … … 106 109 return [NSHTTPCookie cookieWithProperties:properties]; 107 110 } 111 112 bool Cookie::operator==(const Cookie& other) const 113 { 114 ASSERT(!name.isHashTableDeletedValue()); 115 bool thisNull = isNull(); 116 bool otherNull = other.isNull(); 117 if (thisNull || otherNull) 118 return thisNull == otherNull; 119 120 NSHTTPCookie *nsCookie(*this); 121 return [nsCookie isEqual:other]; 122 } 123 124 unsigned Cookie::hash() const 125 { 126 ASSERT(!name.isHashTableDeletedValue()); 127 ASSERT(!isNull()); 128 NSHTTPCookie *nsCookie(*this); 129 return nsCookie.hash; 130 } 108 131 109 132 } // namespace WebCore -
trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm
r214127 r216977 44 44 { 45 45 RetainPtr<NSMutableArray> nsCookies = adoptNS([[NSMutableArray alloc] initWithCapacity:cookies.size()]); 46 for ( autocookie : cookies)46 for (const auto& cookie : cookies) 47 47 [nsCookies addObject:(NSHTTPCookie *)cookie]; 48 48 -
trunk/Source/WebKit2/ChangeLog
r216974 r216977 1 2017-05-17 Alex Christensen <achristensen@webkit.org> 2 3 Interacting with WKHTTPCookieStores before creating WKWebViews and WKProcessPools should affect cookies used 4 https://bugs.webkit.org/show_bug.cgi?id=171987 5 6 Reviewed by Brady Eidson. 7 8 When putting cookies in a WKHTTPCookieStore that hasn't been associated with a WKProcessPool yet, there is no 9 NetworkProcess into which to put the cookies. In such a case, we should store these cookies in the WebsiteDataStore 10 until there is a NetworkProcess. 11 12 * NetworkProcess/NetworkConnectionToWebProcess.cpp: 13 (WebKit::NetworkConnectionToWebProcess::ensureLegacyPrivateBrowsingSession): 14 * NetworkProcess/NetworkProcess.cpp: 15 (WebKit::NetworkProcess::initializeNetworkProcess): 16 (WebKit::NetworkProcess::ensurePrivateBrowsingSession): 17 * NetworkProcess/NetworkProcess.h: 18 * NetworkProcess/NetworkProcess.messages.in: 19 * NetworkProcess/RemoteNetworkingContext.h: 20 * NetworkProcess/mac/RemoteNetworkingContext.mm: 21 (WebKit::RemoteNetworkingContext::ensurePrivateBrowsingSession): 22 (WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession): 23 * Shared/WebsiteDataStoreParameters.cpp: 24 (WebKit::WebsiteDataStoreParameters::~WebsiteDataStoreParameters): 25 (WebKit::WebsiteDataStoreParameters::encode): 26 (WebKit::WebsiteDataStoreParameters::decode): 27 (WebKit::WebsiteDataStoreParameters::WebsiteDataStoreParameters): Deleted. 28 * Shared/WebsiteDataStoreParameters.h: 29 * UIProcess/API/APIHTTPCookieStore.cpp: 30 (API::HTTPCookieStore::cookies): 31 (API::HTTPCookieStore::setCookie): 32 (API::HTTPCookieStore::deleteCookie): 33 * UIProcess/API/APIHTTPCookieStore.h: 34 * UIProcess/WebProcessPool.cpp: 35 (WebKit::WebProcessPool::setAnyPageGroupMightHavePrivateBrowsingEnabled): 36 (WebKit::WebProcessPool::pageAddedToProcess): 37 * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm: 38 (WebKit::WebsiteDataStore::parameters): 39 * UIProcess/WebsiteData/WebsiteDataStore.cpp: 40 (WebKit::WebsiteDataStore::pendingCookies): 41 (WebKit::WebsiteDataStore::addPendingCookie): 42 (WebKit::WebsiteDataStore::removePendingCookie): 43 * UIProcess/WebsiteData/WebsiteDataStore.h: 44 1 45 2017-05-17 Emilio Cobos Álvarez <ecobos@igalia.com> 2 46 -
trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp
r215941 r216977 46 46 #include "SessionTracker.h" 47 47 #include "WebCoreArgumentCoders.h" 48 #include "WebsiteDataStoreParameters.h" 48 49 #include <WebCore/NetworkStorageSession.h> 49 50 #include <WebCore/PingHandle.h> … … 400 401 void NetworkConnectionToWebProcess::ensureLegacyPrivateBrowsingSession() 401 402 { 402 NetworkProcess::singleton().ensurePrivateBrowsingSession( SessionID::legacyPrivateSessionID());403 NetworkProcess::singleton().ensurePrivateBrowsingSession({SessionID::legacyPrivateSessionID(), { }, { }, { }}); 403 404 } 404 405 -
trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp
r216903 r216977 50 50 #include "WebsiteData.h" 51 51 #include "WebsiteDataFetchOption.h" 52 #include "WebsiteDataStoreParameters.h" 52 53 #include "WebsiteDataType.h" 53 54 #include <WebCore/DNS.h> … … 237 238 // FIXME: instead of handling this here, a message should be sent later (scales to multiple sessions) 238 239 if (parameters.privateBrowsingEnabled) 239 RemoteNetworkingContext::ensurePrivateBrowsingSession( SessionID::legacyPrivateSessionID());240 RemoteNetworkingContext::ensurePrivateBrowsingSession({SessionID::legacyPrivateSessionID(), { }, { }, { }}); 240 241 241 242 if (parameters.shouldUseTestingNetworkSession) … … 288 289 } 289 290 290 void NetworkProcess::ensurePrivateBrowsingSession( SessionID sessionID)291 { 292 RemoteNetworkingContext::ensurePrivateBrowsingSession( sessionID);291 void NetworkProcess::ensurePrivateBrowsingSession(WebsiteDataStoreParameters&& parameters) 292 { 293 RemoteNetworkingContext::ensurePrivateBrowsingSession(WTFMove(parameters)); 293 294 } 294 295 -
trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h
r215991 r216977 114 114 void prefetchDNS(const String&); 115 115 116 void ensurePrivateBrowsingSession(Web Core::SessionID);116 void ensurePrivateBrowsingSession(WebsiteDataStoreParameters&&); 117 117 118 118 void grantSandboxExtensionsToDatabaseProcessForBlobs(const Vector<String>& filenames, Function<void ()>&& completionHandler); -
trunk/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in
r215991 r216977 36 36 ClearCachedCredentials() 37 37 38 EnsurePrivateBrowsingSession( WebCore::SessionID sessionID)38 EnsurePrivateBrowsingSession(struct WebKit::WebsiteDataStoreParameters websiteDataStoreParameters) 39 39 AddWebsiteDataStore(struct WebKit::WebsiteDataStoreParameters websiteDataStoreParameters); 40 40 DestroySession(WebCore::SessionID sessionID) -
trunk/Source/WebKit2/NetworkProcess/RemoteNetworkingContext.h
r215941 r216977 44 44 45 45 // FIXME: Remove platform-specific code and use SessionTracker. 46 static void ensurePrivateBrowsingSession(Web Core::SessionID);46 static void ensurePrivateBrowsingSession(WebsiteDataStoreParameters&&); 47 47 static void ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&&); 48 48 -
trunk/Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.mm
r215991 r216977 81 81 } 82 82 83 void RemoteNetworkingContext::ensurePrivateBrowsingSession( SessionID sessionID)83 void RemoteNetworkingContext::ensurePrivateBrowsingSession(WebsiteDataStoreParameters&& parameters) 84 84 { 85 ASSERT( sessionID.isEphemeral());85 ASSERT(parameters.sessionID.isEphemeral()); 86 86 87 if (NetworkStorageSession::storageSession( sessionID))87 if (NetworkStorageSession::storageSession(parameters.sessionID)) 88 88 return; 89 89 … … 94 94 base = SessionTracker::getIdentifierBase(); 95 95 96 NetworkStorageSession::ensurePrivateBrowsingSession(sessionID, base + '.' + String::number(sessionID.sessionID())); 96 NetworkStorageSession::ensurePrivateBrowsingSession(parameters.sessionID, base + '.' + String::number(parameters.sessionID.sessionID())); 97 98 auto* session = NetworkStorageSession::storageSession(parameters.sessionID); 99 for (const auto& cookie : parameters.pendingCookies) 100 session->setCookie(cookie); 97 101 98 102 #if USE(NETWORK_SESSION) 99 auto networkSession = NetworkSession::create( sessionID, NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>());100 SessionTracker::setSession( sessionID, WTFMove(networkSession));103 auto networkSession = NetworkSession::create(parameters.sessionID, NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>()); 104 SessionTracker::setSession(parameters.sessionID, WTFMove(networkSession)); 101 105 #endif 102 106 } … … 123 127 NetworkStorageSession::ensureSession(parameters.sessionID, base + '.' + String::number(parameters.sessionID.sessionID()), WTFMove(uiProcessCookieStorage)); 124 128 129 auto* session = NetworkStorageSession::storageSession(parameters.sessionID); 130 for (const auto& cookie : parameters.pendingCookies) 131 session->setCookie(cookie); 132 125 133 #if USE(NETWORK_SESSION) 126 134 auto networkSession = NetworkSession::create(parameters.sessionID, NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>()); -
trunk/Source/WebKit2/NetworkProcess/soup/RemoteNetworkingContextSoup.cpp
r215941 r216977 49 49 } 50 50 51 void RemoteNetworkingContext::ensurePrivateBrowsingSession( SessionID sessionID)51 void RemoteNetworkingContext::ensurePrivateBrowsingSession(WebsiteDataStoreParameters&& parameters) 52 52 { 53 ASSERT( sessionID.isEphemeral());53 ASSERT(parameters.sessionID.isEphemeral()); 54 54 55 if (NetworkStorageSession::storageSession( sessionID))55 if (NetworkStorageSession::storageSession(parameters.sessionID)) 56 56 return; 57 57 58 NetworkStorageSession::ensurePrivateBrowsingSession( sessionID, String::number(sessionID.sessionID()));59 SessionTracker::setSession( sessionID, NetworkSession::create(sessionID));58 NetworkStorageSession::ensurePrivateBrowsingSession(parameters.sessionID, String::number(parameters.sessionID.sessionID())); 59 SessionTracker::setSession(parameters.sessionID, NetworkSession::create(parameters.sessionID)); 60 60 } 61 61 -
trunk/Source/WebKit2/Shared/WebsiteDataStoreParameters.cpp
r215991 r216977 31 31 namespace WebKit { 32 32 33 34 WebsiteDataStoreParameters::WebsiteDataStoreParameters() 33 WebsiteDataStoreParameters::~WebsiteDataStoreParameters() 35 34 { 36 35 } … … 41 40 encoder << uiProcessCookieStorageIdentifier; 42 41 encoder << cookieStoragePathExtensionHandle; 42 encoder << pendingCookies; 43 43 } 44 44 … … 54 54 return false; 55 55 56 if (!decoder.decode(parameters.pendingCookies)) 57 return false; 58 56 59 return true; 57 60 } -
trunk/Source/WebKit2/Shared/WebsiteDataStoreParameters.h
r215991 r216977 27 27 28 28 #include "SandboxExtension.h" 29 #include <WebCore/Cookie.h> 29 30 #include <WebCore/SessionID.h> 30 31 #include <wtf/Vector.h> … … 39 40 40 41 struct WebsiteDataStoreParameters { 41 WebsiteDataStoreParameters(); 42 42 WebsiteDataStoreParameters() = default; 43 WebsiteDataStoreParameters(WebsiteDataStoreParameters&&) = default; 44 ~WebsiteDataStoreParameters(); 45 43 46 void encode(IPC::Encoder&) const; 44 47 static bool decode(IPC::Decoder&, WebsiteDataStoreParameters&); … … 47 50 Vector<uint8_t> uiProcessCookieStorageIdentifier; 48 51 SandboxExtension::Handle cookieStoragePathExtensionHandle; 52 Vector<WebCore::Cookie> pendingCookies; 49 53 }; 50 54 -
trunk/Source/WebKit2/UIProcess/API/APIHTTPCookieStore.cpp
r214127 r216977 58 58 auto* pool = dataStore.processPoolForCookieStorageOperations(); 59 59 if (!pool) { 60 // FIXME: This is not necessarily the right storage session, but it's currently 61 // the best we can do in the absence of a process pool. 62 auto allCookies = WebCore::NetworkStorageSession::defaultStorageSession().getAllCookies(); 63 callOnMainThread([completionHandler = WTFMove(completionHandler), allCookies = WTFMove(allCookies)]() { 60 callOnMainThread([completionHandler = WTFMove(completionHandler), allCookies = dataStore.pendingCookies()]() { 64 61 completionHandler(allCookies); 65 62 }); 66 67 63 return; 68 64 } … … 79 75 auto* pool = dataStore.processPoolForCookieStorageOperations(); 80 76 if (!pool) { 81 // FIXME: This is not necessarily the right storage session, but it's currently 82 // the best we can do in the absence of a process pool. 83 WebCore::NetworkStorageSession::defaultStorageSession().setCookie(cookie); 77 dataStore.addPendingCookie(cookie); 84 78 callOnMainThread([completionHandler = WTFMove(completionHandler)]() { 85 79 completionHandler(); 86 80 }); 87 88 81 return; 89 82 } … … 100 93 auto* pool = dataStore.processPoolForCookieStorageOperations(); 101 94 if (!pool) { 102 // FIXME: This is not necessarily the right storage session, but it's currently 103 // the best we can do in the absence of a process pool. 104 WebCore::NetworkStorageSession::defaultStorageSession().deleteCookie(cookie); 95 dataStore.removePendingCookie(cookie); 105 96 callOnMainThread([completionHandler = WTFMove(completionHandler)]() { 106 97 completionHandler(); 107 98 }); 108 109 99 return; 110 100 } -
trunk/Source/WebKit2/UIProcess/API/APIHTTPCookieStore.h
r214127 r216977 28 28 #include "APIObject.h" 29 29 #include "HTTPCookieAcceptPolicy.h" 30 #include <WebCore/Cookie.h> 30 31 #include <wtf/Function.h> 31 32 #include <wtf/HashSet.h> -
trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp
r216903 r216977 579 579 if (networkProcess()) { 580 580 if (privateBrowsingEnabled) 581 networkProcess()->send(Messages::NetworkProcess::EnsurePrivateBrowsingSession( SessionID::legacyPrivateSessionID()), 0);581 networkProcess()->send(Messages::NetworkProcess::EnsurePrivateBrowsingSession({SessionID::legacyPrivateSessionID(), { }, { }, { }}), 0); 582 582 else 583 583 networkProcess()->send(Messages::NetworkProcess::DestroySession(SessionID::legacyPrivateSessionID()), 0); … … 946 946 auto sessionID = page.sessionID(); 947 947 if (sessionID.isEphemeral()) { 948 sendToNetworkingProcess(Messages::NetworkProcess::EnsurePrivateBrowsingSession(sessionID)); 948 // FIXME: Merge NetworkProcess::EnsurePrivateBrowsingSession and NetworkProcess::AddWebsiteDataStore into one message type. 949 // They do basically the same thing. 950 sendToNetworkingProcess(Messages::NetworkProcess::EnsurePrivateBrowsingSession(page.websiteDataStore().parameters())); 949 951 page.process().send(Messages::WebProcess::EnsurePrivateBrowsingSession(sessionID), 0); 950 952 } else if (sessionID != SessionID::defaultSessionID()) { -
trunk/Source/WebKit2/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm
r215991 r216977 71 71 #endif 72 72 73 copyToVector(m_pendingCookies, parameters.pendingCookies); 74 73 75 if (!cookieFile.isEmpty()) 74 76 SandboxExtension::createHandleForReadWriteDirectory(WebCore::directoryName(cookieFile), parameters.cookieStoragePathExtensionHandle); -
trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp
r216841 r216977 1266 1266 } 1267 1267 1268 Vector<WebCore::Cookie> WebsiteDataStore::pendingCookies() const 1269 { 1270 Vector<WebCore::Cookie> cookies; 1271 copyToVector(m_pendingCookies, cookies); 1272 return cookies; 1273 } 1274 1275 void WebsiteDataStore::addPendingCookie(const WebCore::Cookie& cookie) 1276 { 1277 m_pendingCookies.add(cookie); 1278 } 1279 1280 void WebsiteDataStore::removePendingCookie(const WebCore::Cookie& cookie) 1281 { 1282 m_pendingCookies.remove(cookie); 1283 } 1284 1268 1285 #if !PLATFORM(COCOA) 1269 1286 WebsiteDataStoreParameters WebsiteDataStore::parameters() -
trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h
r215991 r216977 27 27 28 28 #include "WebProcessLifetimeObserver.h" 29 #include <WebCore/Cookie.h> 29 30 #include <WebCore/SecurityOriginData.h> 30 31 #include <WebCore/SecurityOriginHash.h> … … 119 120 DatabaseProcessCreationParameters databaseProcessParameters(); 120 121 122 Vector<WebCore::Cookie> pendingCookies() const; 123 void addPendingCookie(const WebCore::Cookie&); 124 void removePendingCookie(const WebCore::Cookie&); 125 121 126 private: 122 127 explicit WebsiteDataStore(WebCore::SessionID); … … 161 166 RetainPtr<CFHTTPCookieStorageRef> m_cfCookieStorage; 162 167 #endif 168 HashSet<WebCore::Cookie> m_pendingCookies; 163 169 }; 164 170 -
trunk/Tools/ChangeLog
r216974 r216977 1 2017-05-17 Alex Christensen <achristensen@webkit.org> 2 3 Interacting with WKHTTPCookieStores before creating WKWebViews and WKProcessPools should affect cookies used 4 https://bugs.webkit.org/show_bug.cgi?id=171987 5 6 Reviewed by Brady Eidson. 7 8 * TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStore.mm: 9 (-[CookieUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]): 10 (TEST): 11 1 12 2017-05-17 Emilio Cobos Álvarez <ecobos@igalia.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKHTTPCookieStore.mm
r216292 r216977 168 168 } 169 169 170 static bool finished; 171 172 @interface CookieUIDelegate : NSObject <WKUIDelegate> 173 @end 174 175 @implementation CookieUIDelegate 176 - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler 177 { 178 EXPECT_STREQ("cookie:cookiename=cookievalue", message.UTF8String); 179 finished = true; 180 completionHandler(); 181 } 182 @end 183 184 TEST(WebKit2, WKHTTPCookieStoreWithoutProcessPool) 185 { 186 NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:@"127.0.0.1", NSHTTPCookieDomain, @"/", NSHTTPCookiePath, @"cookiename", NSHTTPCookieName, @"cookievalue", NSHTTPCookieValue, [NSDate distantFuture], NSHTTPCookieExpires, nil]]; 187 NSString *alertCookieHTML = @"<script>alert('cookie:'+document.cookie);</script>"; 188 189 finished = false; 190 WKWebsiteDataStore *ephemeralStoreWithCookies = [WKWebsiteDataStore nonPersistentDataStore]; 191 [ephemeralStoreWithCookies.httpCookieStore setCookie:cookie completionHandler:^ { 192 WKWebsiteDataStore *ephemeralStoreWithIndependentCookieStorage = [WKWebsiteDataStore nonPersistentDataStore]; 193 [ephemeralStoreWithIndependentCookieStorage.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) { 194 ASSERT_EQ(cookies.count, 0u); 195 196 WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; 197 configuration.websiteDataStore = ephemeralStoreWithCookies; 198 WKWebView *view = [[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration]; 199 view.UIDelegate = [[CookieUIDelegate alloc] init]; 200 201 [view loadHTMLString:alertCookieHTML baseURL:[NSURL URLWithString:@"http://127.0.0.1/"]]; 202 }]; 203 }]; 204 TestWebKitAPI::Util::run(&finished); 205 206 finished = false; 207 WKWebsiteDataStore *defaultStore = [WKWebsiteDataStore defaultDataStore]; 208 [defaultStore.httpCookieStore setCookie:cookie completionHandler:^ { 209 [defaultStore.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) { 210 ASSERT_EQ(cookies.count, 1u); 211 212 WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; 213 configuration.websiteDataStore = defaultStore; 214 WKWebView *view = [[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration]; 215 view.UIDelegate = [[CookieUIDelegate alloc] init]; 216 217 [view loadHTMLString:alertCookieHTML baseURL:[NSURL URLWithString:@"http://127.0.0.1/"]]; 218 }]; 219 }]; 220 TestWebKitAPI::Util::run(&finished); 221 222 [defaultStore.httpCookieStore deleteCookie:cookie completionHandler:^ { 223 [defaultStore.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) { 224 ASSERT_EQ(cookies.count, 0u); 225 finished = true; 226 }]; 227 }]; 228 TestWebKitAPI::Util::run(&finished); 229 } 170 230 #endif
Note: See TracChangeset
for help on using the changeset viewer.