Skip to content

Commit

Permalink
Scope exemptions to tab
Browse files Browse the repository at this point in the history
  • Loading branch information
CrisBarreiro committed Feb 3, 2025
1 parent a2affdd commit 1e7059b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1432,8 +1432,9 @@ class BrowserTabFragment :
viewModel.closeCurrentTab()
}

private fun onBypassMaliciousWarning(url: Uri) {
private fun onBypassMaliciousWarning(url: Uri, feed: Feed) {
showBrowser()
webViewClient.addExemptedMaliciousSite(url, feed)
webView?.loadUrl(url.toString())
}

Expand Down Expand Up @@ -1809,7 +1810,7 @@ class BrowserTabFragment :
is Command.ShowWarningMaliciousSite -> showMaliciousWarning(it.url, it.feed)
is Command.HideWarningMaliciousSite -> hideMaliciousWarning()
is Command.EscapeMaliciousSite -> onEscapeMaliciousSite()
is Command.BypassMaliciousSiteWarning -> onBypassMaliciousWarning(it.url)
is Command.BypassMaliciousSiteWarning -> onBypassMaliciousWarning(it.url, it.feed)
is OpenBrokenSiteLearnMore -> openBrokenSiteLearnMore(it.url)
is ReportBrokenSiteError -> openBrokenSiteReportError(it.url)
is Command.SendResponseToJs -> contentScopeScripts.onResponse(it.data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ import com.duckduckgo.app.browser.webview.MaliciousSiteBlockedWarningLayout.Acti
import com.duckduckgo.app.browser.webview.MaliciousSiteBlockedWarningLayout.Action.LeaveSite
import com.duckduckgo.app.browser.webview.MaliciousSiteBlockedWarningLayout.Action.ReportError
import com.duckduckgo.app.browser.webview.MaliciousSiteBlockedWarningLayout.Action.VisitSite
import com.duckduckgo.app.browser.webview.MaliciousSiteBlockerWebViewIntegration
import com.duckduckgo.app.browser.webview.SslWarningLayout.Action
import com.duckduckgo.app.cta.ui.BrokenSitePromptDialogCta
import com.duckduckgo.app.cta.ui.Cta
Expand Down Expand Up @@ -462,7 +461,6 @@ class BrowserTabViewModel @Inject constructor(
private val toggleReports: ToggleReports,
private val brokenSitePrompt: BrokenSitePrompt,
private val tabStatsBucketing: TabStatsBucketing,
private val maliciousSiteBlockerWebViewIntegration: MaliciousSiteBlockerWebViewIntegration,
private val defaultBrowserPromptsExperiment: DefaultBrowserPromptsExperiment,
private val swipingTabsFeature: SwipingTabsFeatureProvider,
) : WebViewClientListener,
Expand Down Expand Up @@ -1891,12 +1889,11 @@ class BrowserTabViewModel @Inject constructor(
}

VisitSite -> {
command.postValue(BypassMaliciousSiteWarning(url))
command.postValue(BypassMaliciousSiteWarning(url, feed))
browserViewState.value = currentBrowserViewState().copy(
browserShowing = true,
showPrivacyShield = HighlightableButton.Visible(enabled = true),
)
addExemptedMaliciousUrlToMemory(url, feed)
}
LearnMore -> command.postValue(OpenBrokenSiteLearnMore(MALICIOUS_SITE_LEARN_MORE_URL))
ReportError -> command.postValue(ReportBrokenSiteError("$MALICIOUS_SITE_REPORT_ERROR_URL$url"))
Expand Down Expand Up @@ -3803,10 +3800,6 @@ class BrowserTabViewModel @Inject constructor(
command.value = SetOnboardingDialogBackground(getBackgroundResource(lightModeEnabled))
}

fun addExemptedMaliciousUrlToMemory(url: Uri, feed: Feed) {
maliciousSiteBlockerWebViewIntegration.onSiteExempted(url, feed)
}

private fun getBackgroundResource(lightModeEnabled: Boolean): Int {
return when {
lightModeEnabled && highlightsOnboardingExperimentManager.isHighlightsEnabled() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import com.duckduckgo.duckplayer.api.DuckPlayer.DuckPlayerState.ENABLED
import com.duckduckgo.duckplayer.api.DuckPlayer.OpenDuckPlayerInNewTab.On
import com.duckduckgo.duckplayer.impl.DUCK_PLAYER_OPEN_IN_YOUTUBE_PATH
import com.duckduckgo.history.api.NavigationHistory
import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection.Feed
import com.duckduckgo.privacy.config.api.AmpLinks
import com.duckduckgo.subscriptions.api.Subscriptions
import com.duckduckgo.user.agent.api.ClientBrandHintProvider
Expand Down Expand Up @@ -710,6 +711,10 @@ class BrowserWebViewClient @Inject constructor(
else -> "ERROR_OTHER"
}
}

fun addExemptedMaliciousSite(url: Uri, feed: Feed) {
requestInterceptor.addExemptedMaliciousSite(url, feed)
}
}

enum class WebViewPixelName(override val pixelName: String) : Pixel.PixelName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ interface RequestInterceptor {
url: Uri,
isForMainFrame: Boolean,
): Boolean

fun addExemptedMaliciousSite(url: Uri, feed: Feed)
}

class WebViewRequestInterceptor(
Expand Down Expand Up @@ -223,6 +225,10 @@ class WebViewRequestInterceptor(
url?.let { webViewClientListener?.onReceivedMaliciousSiteWarning(it, feed, exempted) }
}

override fun addExemptedMaliciousSite(url: Uri, feed: Feed) {
maliciousSiteBlockerWebViewIntegration.onSiteExempted(url, feed)
}

private fun getWebResourceResponse(
request: WebResourceRequest,
documentUrl: Uri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ sealed class Command {

data class BypassMaliciousSiteWarning(
val url: Uri,
val feed: Feed,
) : Command()

data class OpenBrokenSiteLearnMore(val url: String) : Command()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection.Malici
import com.duckduckgo.privacy.config.api.PrivacyConfigCallbackPlugin
import com.squareup.anvil.annotations.ContributesBinding
import com.squareup.anvil.annotations.ContributesMultibinding
import dagger.SingleInstanceIn
import java.net.URLDecoder
import java.util.concurrent.atomic.AtomicInteger
import javax.inject.Inject
Expand Down Expand Up @@ -70,9 +69,14 @@ interface MaliciousSiteBlockerWebViewIntegration {

data class ExemptedUrl(val url: Uri, val feed: Feed)

@SingleInstanceIn(AppScope::class)
class ExemptedUrlsHolder @Inject constructor() {
val exemptedMaliciousUrls = mutableSetOf<ExemptedUrl>()
val exemptedMaliciousUrls: Set<ExemptedUrl>
get() = _exemptedMaliciousUrls
private val _exemptedMaliciousUrls = mutableSetOf<ExemptedUrl>()

fun addExemptedMaliciousUrl(url: ExemptedUrl) {
_exemptedMaliciousUrls.add(url)
}
}

@ContributesMultibinding(AppScope::class, PrivacyConfigCallbackPlugin::class)
Expand Down Expand Up @@ -247,7 +251,7 @@ class RealMaliciousSiteBlockerWebViewIntegration @Inject constructor(
feed: Feed,
) {
val convertedUrl = URLDecoder.decode(url.toString(), "UTF-8").lowercase()
exemptedUrlsHolder.exemptedMaliciousUrls.add(ExemptedUrl(convertedUrl.toUri(), feed))
exemptedUrlsHolder.addExemptedMaliciousUrl(ExemptedUrl(convertedUrl.toUri(), feed))
Timber.tag("MaliciousSiteDetector").d(
"Added $url to exemptedUrls, contents: ${exemptedUrlsHolder.exemptedMaliciousUrls}",
)
Expand Down

0 comments on commit 1e7059b

Please sign in to comment.