Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from using the favicon service to obtaining favicons directly from the website #878

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.duckduckgo.app.global

import android.net.Uri
import androidx.core.net.toUri
import org.junit.Assert.*
import org.junit.Test

Expand Down Expand Up @@ -194,4 +195,33 @@ class UriExtensionTest {
val absoluteString = Uri.parse("https://example.com/test?q=example/#1/anotherrandomcode").absoluteString
assertEquals("https://example.com/test", absoluteString)
}

@Test
fun whenNullUrlThenNullFaviconUrl() {
assertNull("".toUri().faviconLocation())
}

@Test
fun whenHttpRequestThenFaviconLocationAlsoHttp() {
val favicon = "http://example.com".toUri().faviconLocation()
assertTrue(favicon!!.isHttp)
}

@Test
fun whenHttpsRequestThenFaviconLocationAlsoHttps() {
val favicon = "https://example.com".toUri().faviconLocation()
assertTrue(favicon!!.isHttps)
}

@Test
fun whenUrlContainsASubdomainThenSubdomainReturnedInFavicon() {
val favicon = "https://sub.example.com".toUri().faviconLocation()
assertEquals("https://sub.example.com/favicon.ico", favicon.toString())
}

@Test
fun whenUrlIsIpAddressThenIpReturnedInFaviconUrl() {
val favicon = "https://192.168.1.0".toUri().faviconLocation()
assertEquals("https://192.168.1.0/favicon.ico", favicon.toString())
}
}
9 changes: 6 additions & 3 deletions app/src/main/java/com/duckduckgo/app/global/UriExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ fun Uri.toDesktopUri(): Uri {
return parse(newUrl)
}

private const val faviconBaseUrlFormat = "https://proxy.duckduckgo.com/ip3/%s.ico"
// to obtain a favicon for a website, we go directly to the site and look for /favicon.ico
private const val faviconBaseUrlFormat = "%s://%s/favicon.ico"

fun Uri?.faviconLocation(): Uri? {
val host = this?.host
if (this == null) return null
val host = this.host
if (host.isNullOrBlank()) return null
return parse(String.format(faviconBaseUrlFormat, host))
val isHttps = this.isHttps
return parse(String.format(faviconBaseUrlFormat, if (isHttps) "https" else "http", host))
}
3 changes: 2 additions & 1 deletion app/version/release-notes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## What's new in this release?
Now the app can prompt you to Fireproof a site when you sign in. Enable this in Settings > Fireproof Websites.
Retrieve favicons directly from websites.
Bug fixes and other improvements.

## Have feedback?
We've adjusted the color contrast in both light and dark themes to improve visibility.
You can always reach us at https://duckduckgo.com/feedback.
2 changes: 1 addition & 1 deletion app/version/version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=5.58.0
VERSION=5.58.1