Skip to content

Commit

Permalink
Omnibar Refactor: Use LegacyOmnibar (#5073)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1174433894299346/1208319036523674

### Description
This PR continues with the refactoring, moving logic from the BTF into
the Omnibar facade.

### Steps to test this PR
Smoke test of the app, chrome customtab, etc..
  • Loading branch information
malmstein authored Oct 7, 2024
1 parent 587ad2c commit 461af86
Show file tree
Hide file tree
Showing 11 changed files with 1,043 additions and 689 deletions.
910 changes: 328 additions & 582 deletions app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ class BrowserTabViewModel @Inject constructor(
AppPixelName.AUTOCOMPLETE_BOOKMARK_SELECTION
}
}

is AutoCompleteSearchSuggestion -> if (suggestion.isUrl) AUTOCOMPLETE_SEARCH_WEBSITE_SELECTION else AUTOCOMPLETE_SEARCH_PHRASE_SELECTION
is AutoCompleteHistorySuggestion -> AUTOCOMPLETE_HISTORY_SITE_SELECTION
is AutoCompleteHistorySearchSuggestion -> AUTOCOMPLETE_HISTORY_SEARCH_SELECTION
Expand Down Expand Up @@ -895,7 +896,10 @@ class BrowserTabViewModel @Inject constructor(
}
}

fun onRemoveSearchSuggestionConfirmed(suggestion: AutoCompleteSuggestion, omnibarText: String) {
fun onRemoveSearchSuggestionConfirmed(
suggestion: AutoCompleteSuggestion,
omnibarText: String,
) {
appCoroutineScope.launch(dispatchers.io()) {
pixel.fire(AUTOCOMPLETE_RESULT_DELETED)
pixel.fire(AUTOCOMPLETE_RESULT_DELETED_DAILY, type = Daily())
Expand All @@ -904,9 +908,11 @@ class BrowserTabViewModel @Inject constructor(
is AutoCompleteHistorySuggestion -> {
history.removeHistoryEntryByUrl(suggestion.url)
}

is AutoCompleteHistorySearchSuggestion -> {
history.removeHistoryEntryByQuery(suggestion.phrase)
}

else -> {}
}
withContext(dispatchers.main()) {
Expand Down Expand Up @@ -1190,7 +1196,10 @@ class BrowserTabViewModel @Inject constructor(
}
}

fun urlUnchangedForExternalLaunchPurposes(oldUrl: String?, newUrl: String): Boolean {
fun urlUnchangedForExternalLaunchPurposes(
oldUrl: String?,
newUrl: String,
): Boolean {
if (oldUrl == null) return false
fun normalizeUrl(url: String): String {
val regex = Regex("^(https?://)?(www\\.)?")
Expand All @@ -1202,6 +1211,7 @@ class BrowserTabViewModel @Inject constructor(

return normalizedUrl
}

val normalizedOldUrl = normalizeUrl(oldUrl)
val normalizedNewUrl = normalizeUrl(newUrl)
return normalizedOldUrl == normalizedNewUrl
Expand Down Expand Up @@ -1322,6 +1332,7 @@ class BrowserTabViewModel @Inject constructor(
}
}
}

is WebNavigationStateChange.PageCleared -> pageCleared()
is WebNavigationStateChange.UrlUpdated -> {
val uri = stateChange.url.toUri()
Expand All @@ -1339,6 +1350,7 @@ class BrowserTabViewModel @Inject constructor(
}
}
}

is WebNavigationStateChange.PageNavigationCleared -> disableUserNavigation()
else -> {}
}
Expand Down Expand Up @@ -2413,7 +2425,10 @@ class BrowserTabViewModel @Inject constructor(
}
}

private suspend fun addToAllowList(domain: String, clickedFromCustomTab: Boolean) {
private suspend fun addToAllowList(
domain: String,
clickedFromCustomTab: Boolean,
) {
val pixelParams = privacyProtectionsPopupExperimentExternalPixels.getPixelParams()
if (clickedFromCustomTab) {
pixel.fire(CustomTabPixelNames.CUSTOM_TABS_MENU_DISABLE_PROTECTIONS_ALLOW_LIST_ADD)
Expand All @@ -2428,7 +2443,10 @@ class BrowserTabViewModel @Inject constructor(
}
}

private suspend fun removeFromAllowList(domain: String, clickedFromCustomTab: Boolean) {
private suspend fun removeFromAllowList(
domain: String,
clickedFromCustomTab: Boolean,
) {
val pixelParams = privacyProtectionsPopupExperimentExternalPixels.getPixelParams()
if (clickedFromCustomTab) {
pixel.fire(CustomTabPixelNames.CUSTOM_TABS_MENU_DISABLE_PROTECTIONS_ALLOW_LIST_REMOVE)
Expand Down Expand Up @@ -2515,6 +2533,10 @@ class BrowserTabViewModel @Inject constructor(

fun userFindingInPage(searchTerm: String) {
val currentViewState = currentFindInPageViewState()
if (!currentViewState.visible && searchTerm.isEmpty()) {
return
}

var findInPage = currentViewState.copy(visible = true, searchTerm = searchTerm)
if (searchTerm.isEmpty()) {
findInPage = findInPage.copy(showNumberMatches = false)
Expand Down Expand Up @@ -3012,7 +3034,10 @@ class BrowserTabViewModel @Inject constructor(
}
}

private fun sameOrigin(firstUrl: String, secondUrl: String): Boolean {
private fun sameOrigin(
firstUrl: String,
secondUrl: String,
): Boolean {
return kotlin.runCatching {
val firstUri = Uri.parse(firstUrl)
val secondUri = Uri.parse(secondUrl)
Expand Down Expand Up @@ -3359,6 +3384,7 @@ class BrowserTabViewModel @Inject constructor(
}
}
}

else -> {}
}
}
Expand Down Expand Up @@ -3450,7 +3476,10 @@ class BrowserTabViewModel @Inject constructor(
}
}

fun onSSLCertificateWarningAction(action: Action, url: String) {
fun onSSLCertificateWarningAction(
action: Action,
url: String,
) {
when (action) {
is Action.Shown -> {
when (action.errorType) {
Expand Down Expand Up @@ -3547,6 +3576,7 @@ class BrowserTabViewModel @Inject constructor(
}
null
}

else -> null
}
}
Expand Down Expand Up @@ -3642,7 +3672,11 @@ class BrowserTabViewModel @Inject constructor(
}
}

fun saveReplyProxyForBlobDownload(originUrl: String, replyProxy: JavaScriptReplyProxy, locationHref: String? = null) {
fun saveReplyProxyForBlobDownload(
originUrl: String,
replyProxy: JavaScriptReplyProxy,
locationHref: String? = null,
) {
appCoroutineScope.launch(dispatchers.io()) { // FF check has disk IO
if (androidBrowserConfig.fixBlobDownloadWithIframes().isEnabled()) {
val frameProxies = fixedReplyProxyMap[originUrl]?.toMutableMap() ?: mutableMapOf()
Expand Down Expand Up @@ -3706,7 +3740,11 @@ class BrowserTabViewModel @Inject constructor(

fun hasOmnibarPositionChanged(currentPosition: OmnibarPosition): Boolean = settingsDataStore.omnibarPosition != currentPosition

private fun firePixelBasedOnCurrentUrl(emptyUrlPixel: AppPixelName, duckDuckGoQueryUrlPixel: AppPixelName, websiteUrlPixel: AppPixelName) {
private fun firePixelBasedOnCurrentUrl(
emptyUrlPixel: AppPixelName,
duckDuckGoQueryUrlPixel: AppPixelName,
websiteUrlPixel: AppPixelName,
) {
val text = url.orEmpty()
if (text.isEmpty()) {
pixel.fire(emptyUrlPixel)
Expand Down
Loading

0 comments on commit 461af86

Please sign in to comment.