Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Ref #3071: Don't use FaviconMO in fetchIcon method. Move it outside. #3096

Merged
merged 1 commit into from
Dec 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions Client/Frontend/Browser/Favicons/FaviconFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,21 @@ class FaviconFetcher {
/// 4. Monogram (letter + background color)
func load(_ cachedOnly: Bool = false, _ completion: @escaping (URL, FaviconAttributes) -> Void) {
// Getting CoreData's properties before entering background thread to avoid threading conflicts.
let faviconType = domain.favicon?.type
let favicon = domain.favicon

// Fetch icon logic:
// 1. Check if current domain has a favicon.
var favicon = domain.favicon

// 2. Private mode uses their own in-memory only favicons.
// If no in-memory favicon is found we look if there's any persisted one(from normal browsing mode)
// and use that one until in-memory favicon is saved.
if favicon == nil,
PrivateBrowsingManager.shared.isPrivateBrowsing {
favicon = Domain.getPersistedDomain(for: url)?.favicon
}

let faviconType = favicon?.type
let faviconUrl = favicon?.url

loadTaskCancellable = DispatchWorkItem { [weak self] in
guard let self = self else { return }
Expand All @@ -115,7 +128,8 @@ class FaviconFetcher {
}
return
}
self.fetchIcon(favicon: favicon, cachedOnly: cachedOnly) { url, attributes in
self.fetchIcon(faviconUrl: faviconUrl, faviconType: faviconType,
cachedOnly: cachedOnly) { url, attributes in
DispatchQueue.main.async {
completion(url, attributes)
}
Expand Down Expand Up @@ -264,24 +278,12 @@ class FaviconFetcher {
}
}

private func fetchIcon(favicon: FaviconMO?, cachedOnly: Bool, _ completion: @escaping (URL, FaviconAttributes) -> Void) {
// Fetch icon logic:
// 1. Check if current domain has a favicon.
var domainFavicon = favicon

// 2. Private mode uses their own in-memory only favicons.
// If no in-memory favicon is found we look if there's any persisted one(from normal browsing mode)
// and use that one until in-memory favicon is saved.
if domainFavicon == nil,
PrivateBrowsingManager.shared.isPrivateBrowsing {
domainFavicon = Domain.getPersistedDomain(for: url)?.favicon
}

private func fetchIcon(faviconUrl: String?, faviconType: Int16?, cachedOnly: Bool, _ completion: @escaping (URL, FaviconAttributes) -> Void) {
// Attempt to find favicon cached for the given Domain
if let favicon = domainFavicon, let urlString = favicon.url, let url = URL(string: urlString) {
if let urlString = faviconUrl, let type = faviconType, let url = URL(string: urlString) {
// Verify that the favicon we have on file is what we want to pull
// If not, we will just default to monogram to avoid blurry images
if faviconOnFileMatchesFetchKind(favicon.type) {
if faviconOnFileMatchesFetchKind(type) {

// If loading from cache only is specified,
// Return monogram image if there is no cache.
Expand Down