Commit 2a0b0bdb authored by mrefaat's avatar mrefaat Committed by Commit Bot

Fix NTP Omnibox suggestions not working with WKHTTPSystemCookieStore

Create a work around to force getAllCookies: completion handler to be executed
as soon as possible.
Workaround description and reasoning on the document:
https://docs.google.com/document/d/1aPNO5p44T-LMQT1Mocdll-SG7xq_9DIjb4N0oOTHZUs

Bug: 894540, 885218
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I94090ed1b6b6aa1dce3f764bfa46bc1d700ddf4d
Reviewed-on: https://chromium-review.googlesource.com/c/1281685
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600078}
parent 5524af60
...@@ -48,6 +48,22 @@ bool ShouldIncludeForRequestUrl(NSHTTPCookie* cookie, const GURL& url) { ...@@ -48,6 +48,22 @@ bool ShouldIncludeForRequestUrl(NSHTTPCookie* cookie, const GURL& url) {
return canonical_cookie.IncludeForRequestURL(url, options); return canonical_cookie.IncludeForRequestURL(url, options);
} }
// Prioritizes queued WKHTTPCookieStore completion handlers to run as soon as
// possible. This function is needed because some of WKHTTPCookieStore methods
// completion handlers are not called until there is a WKWebView on the view
// hierarchy.
void PrioritizeWKHTTPCookieStoreCallbacks() {
// TODO(crbug.com/885218): Currently this hack is needed to fix
// crbug.com/885218. Remove when the behavior of
// [WKHTTPCookieStore getAllCookies:] changes.
NSSet* data_types = [NSSet setWithObject:WKWebsiteDataTypeCookies];
[[WKWebsiteDataStore defaultDataStore]
removeDataOfTypes:data_types
modifiedSince:[NSDate distantFuture]
completionHandler:^{
}];
}
} // namespace } // namespace
WKHTTPSystemCookieStore::WKHTTPSystemCookieStore( WKHTTPSystemCookieStore::WKHTTPSystemCookieStore(
...@@ -89,6 +105,7 @@ void WKHTTPSystemCookieStore::GetCookiesForURLAsync( ...@@ -89,6 +105,7 @@ void WKHTTPSystemCookieStore::GetCookiesForURLAsync(
RunSystemCookieCallbackForCookies(std::move(shared_callback), RunSystemCookieCallbackForCookies(std::move(shared_callback),
weak_time_manager, result); weak_time_manager, result);
}]; }];
PrioritizeWKHTTPCookieStoreCallbacks();
} else { } else {
net::ReportGetCookiesForURLResult( net::ReportGetCookiesForURLResult(
net::SystemCookieStoreType::kWKHTTPSystemCookieStore, false); net::SystemCookieStoreType::kWKHTTPSystemCookieStore, false);
...@@ -115,6 +132,7 @@ void WKHTTPSystemCookieStore::GetAllCookiesAsync( ...@@ -115,6 +132,7 @@ void WKHTTPSystemCookieStore::GetAllCookiesAsync(
RunSystemCookieCallbackForCookies(std::move(shared_callback), RunSystemCookieCallbackForCookies(std::move(shared_callback),
weak_time_manager, cookies); weak_time_manager, cookies);
}]; }];
PrioritizeWKHTTPCookieStoreCallbacks();
} else { } else {
RunSystemCookieCallbackForCookies(std::move(shared_callback), RunSystemCookieCallbackForCookies(std::move(shared_callback),
weak_time_manager, @[]); weak_time_manager, @[]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment