Merge pull request #1795 from Wevah/ios-candidate

Fix sites being added to the no-favicons cache if the homepage fails to load
This commit is contained in:
Brent Simmons 2020-02-17 17:59:37 -08:00 committed by GitHub
commit e22489ce40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 12 deletions

View File

@ -136,6 +136,7 @@ final class FaviconDownloader {
findFaviconURLs(with: url) { (faviconURLs) in
if let faviconURLs = faviconURLs {
// If the site explicitly specifies favicon.ico, it will appear twice.
self.currentHomePageHasOnlyFaviconICO = faviconURLs.count == 1
if let firstIconURL = faviconURLs.first {
@ -177,11 +178,9 @@ final class FaviconDownloader {
remainingFaviconURLs[homePageURL] = nil
if let url = singleFaviconDownloader.homePageURL {
if self.homePageToFaviconURLCache[url] == nil {
self.homePageToFaviconURLCache[url] = singleFaviconDownloader.faviconURL
self.homePageToFaviconURLCacheDirty = true
}
if self.homePageToFaviconURLCache[homePageURL] == nil {
self.homePageToFaviconURLCache[homePageURL] = singleFaviconDownloader.faviconURL
self.homePageToFaviconURLCacheDirty = true
}
postFaviconDidBecomeAvailableNotification(singleFaviconDownloader.faviconURL)
@ -212,21 +211,22 @@ private extension FaviconDownloader {
}
FaviconURLFinder.findFaviconURLs(with: homePageURL) { (faviconURLs) in
guard var faviconURLs = faviconURLs else {
completion(nil)
return
}
var defaultFaviconURL: String? = nil
if let scheme = url.scheme, let host = url.host {
defaultFaviconURL = "\(scheme)://\(host)/favicon.ico".lowercased(with: FaviconDownloader.localeForLowercasing)
}
if var faviconURLs = faviconURLs {
if let defaultFaviconURL = defaultFaviconURL {
faviconURLs.append(defaultFaviconURL)
}
completion(faviconURLs)
return
if let defaultFaviconURL = defaultFaviconURL {
faviconURLs.append(defaultFaviconURL)
}
completion(defaultFaviconURL != nil ? [defaultFaviconURL!] : nil)
completion(faviconURLs)
}
}