Skip to content

Commit 436abfe

Browse files
authored
Remove calls to adsjs for C-S-S (#7017)
Task/Issue URL: https://app.asana.com/1/137249556945/project/488551667048375/task/1211767917352312?focus=true ### Description Don't rely on RC flags, and just remove calls to the new APIs from the codebase ### Steps to test this PR _Feature 1_ - [ ] Smoke test app ### UI changes n/a
1 parent f8a8c1b commit 436abfe

File tree

4 files changed

+3
-271
lines changed

4 files changed

+3
-271
lines changed

app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import androidx.lifecycle.LiveData
4141
import androidx.lifecycle.MutableLiveData
4242
import androidx.lifecycle.Observer
4343
import androidx.room.Room
44-
import androidx.test.annotation.UiThreadTest
4544
import androidx.test.filters.SdkSuppress
4645
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
4746
import com.duckduckgo.adclick.api.AdClickManager
@@ -617,10 +616,6 @@ class BrowserTabViewModelTest {
617616

618617
private val mockWebView: WebView = mock()
619618

620-
private val fakeAddDocumentStartJavaScriptPlugins = FakeAddDocumentStartJavaScriptPluginPoint()
621-
private val fakeMessagingPlugins = FakeWebMessagingPluginPoint()
622-
private val fakePostMessageWrapperPlugins = FakePostMessageWrapperPluginPoint()
623-
624619
private val mockDeviceAppLookup: DeviceAppLookup = mock()
625620

626621
@Before
@@ -850,9 +845,6 @@ class BrowserTabViewModelTest {
850845
externalIntentProcessingState = mockExternalIntentProcessingState,
851846
vpnMenuStateProvider = mockVpnMenuStateProvider,
852847
webViewCompatWrapper = mockWebViewCompatWrapper,
853-
addDocumentStartJavascriptPlugins = fakeAddDocumentStartJavaScriptPlugins,
854-
webMessagingPlugins = fakeMessagingPlugins,
855-
postMessageWrapperPlugins = fakePostMessageWrapperPlugins,
856848
addressBarTrackersAnimationFeatureToggle = mockAddressBarTrackersAnimationFeatureToggle,
857849
autoconsentPixelManager = mockAutoconsentPixelManager,
858850
)
@@ -7091,102 +7083,6 @@ class BrowserTabViewModelTest {
70917083
verify(mockOnboardingDesignExperimentManager).onWebPageFinishedLoading(url)
70927084
}
70937085

7094-
@Test
7095-
fun whenPageFinishedAndUpdateScriptOnPageFinishedEnabledThenAddDocumentStartJavaScript() =
7096-
runTest {
7097-
val url = "https://example.com"
7098-
val webViewNavState = WebViewNavigationState(mockStack, 100)
7099-
fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State(true))
7100-
7101-
testee.pageFinished(mockWebView, webViewNavState, url)
7102-
7103-
assertEquals(1, fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7104-
assertEquals(1, fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7105-
}
7106-
7107-
@Test
7108-
fun whenPageFinishedAndUpdateScriptOnPageFinishedDisabledThenDoNotCallAddDocumentStartJavaScript() =
7109-
runTest {
7110-
val url = "https://example.com"
7111-
val webViewNavState = WebViewNavigationState(mockStack, 100)
7112-
fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State(false))
7113-
7114-
testee.pageFinished(mockWebView, webViewNavState, url)
7115-
7116-
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7117-
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7118-
}
7119-
7120-
@Test
7121-
fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedEnabledAndUpdateScriptOnProtectionsChangedEnabledThenAddDocumentStartJavaScript() =
7122-
runTest {
7123-
fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State(true))
7124-
fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State(true))
7125-
7126-
testee.privacyProtectionsUpdated(mockWebView)
7127-
7128-
assertEquals(1, fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7129-
assertEquals(1, fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7130-
}
7131-
7132-
@Test
7133-
fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnProtectionsChangedEnabledAndStopLoadingBeforeUpdatingScriptEnabledThenStopLoading() =
7134-
runTest {
7135-
fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State(true))
7136-
fakeAndroidConfigBrowserFeature.stopLoadingBeforeUpdatingScript().setRawStoredState(State(true))
7137-
7138-
testee.privacyProtectionsUpdated(mockWebView)
7139-
7140-
verify(mockWebView).stopLoading()
7141-
}
7142-
7143-
@Test
7144-
fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnProtectionsChangedEnabledAndStopLoadingBeforeUpdatingScriptDisabledThenDoNotStopLoading() =
7145-
runTest {
7146-
fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State(true))
7147-
fakeAndroidConfigBrowserFeature.stopLoadingBeforeUpdatingScript().setRawStoredState(State(false))
7148-
7149-
testee.privacyProtectionsUpdated(mockWebView)
7150-
7151-
verify(mockWebView, never()).stopLoading()
7152-
}
7153-
7154-
@Test
7155-
fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedTrueAndUpdateScriptOnProtectionsChangedFalseThenNotAddDocumentStartJavaScript() =
7156-
runTest {
7157-
fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State(true))
7158-
fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State(false))
7159-
7160-
testee.privacyProtectionsUpdated(mockWebView)
7161-
7162-
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7163-
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7164-
}
7165-
7166-
@Test
7167-
fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedDisabledThenAddDocumentStartJavaScriptOnlyOnCSS() =
7168-
runTest {
7169-
fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State(false))
7170-
fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State(true))
7171-
7172-
testee.privacyProtectionsUpdated(mockWebView)
7173-
7174-
assertEquals(1, fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7175-
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7176-
}
7177-
7178-
@Test
7179-
fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedFalseAndUpdateScriptOnProtectionsChangedFalseThenNotAddDocumentStartJavaScript() =
7180-
runTest {
7181-
fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State(false))
7182-
fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State(false))
7183-
7184-
testee.privacyProtectionsUpdated(mockWebView)
7185-
7186-
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7187-
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7188-
}
7189-
71907086
@Test
71917087
fun whenCtaShownThenFireInContextDialogShownPixel() =
71927088
runTest {
@@ -7689,46 +7585,6 @@ class BrowserTabViewModelTest {
76897585
assertNull("SERP logo should be cleared when navigating to non-DuckDuckGo URL", omnibarViewState().serpLogo)
76907586
}
76917587

7692-
@UiThreadTest
7693-
@Test
7694-
fun whenConfigureWebViewThenCallAddDocumentStartJavaScript() =
7695-
runTest {
7696-
val mockCallback = mock<WebViewCompatMessageCallback>()
7697-
val webView = DuckDuckGoWebView(context)
7698-
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7699-
7700-
testee.configureWebView(webView, mockCallback)
7701-
7702-
assertEquals(1, fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7703-
}
7704-
7705-
@UiThreadTest
7706-
@Test
7707-
fun whenConfigureWebViewThenCallAddMessageListener() =
7708-
runTest {
7709-
val mockCallback = mock<WebViewCompatMessageCallback>()
7710-
val webView = DuckDuckGoWebView(context)
7711-
assertFalse(fakeMessagingPlugins.plugin.registered)
7712-
7713-
testee.configureWebView(webView, mockCallback)
7714-
7715-
assertTrue(fakeMessagingPlugins.plugin.registered)
7716-
}
7717-
7718-
@UiThreadTest
7719-
@Test
7720-
fun whenPostMessageThenCallPostContentScopeMessage() =
7721-
runTest {
7722-
val data = SubscriptionEventData("feature", "method", JSONObject())
7723-
val webView = DuckDuckGoWebView(context)
7724-
7725-
assertFalse(fakePostMessageWrapperPlugins.plugin.postMessageCalled)
7726-
7727-
testee.postContentScopeMessage(data, webView)
7728-
7729-
assertTrue(fakePostMessageWrapperPlugins.plugin.postMessageCalled)
7730-
}
7731-
77327588
private fun aCredential(): LoginCredentials = LoginCredentials(domain = null, username = null, password = null)
77337589

77347590
private fun assertShowHistoryCommandSent(expectedStackSize: Int) {

app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ import com.duckduckgo.js.messaging.api.JsCallbackData
307307
import com.duckduckgo.js.messaging.api.JsMessageCallback
308308
import com.duckduckgo.js.messaging.api.JsMessaging
309309
import com.duckduckgo.js.messaging.api.SubscriptionEventData
310-
import com.duckduckgo.js.messaging.api.WebViewCompatMessageCallback
311310
import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection.Feed
312311
import com.duckduckgo.mobile.android.app.tracking.ui.AppTrackingProtectionScreens.AppTrackerOnboardingActivityWithEmptyParamsParams
313312
import com.duckduckgo.navigation.api.GlobalActivityStarter
@@ -1226,31 +1225,24 @@ class BrowserTabFragment :
12261225
private fun onOmnibarCustomTabPrivacyDashboardPressed() {
12271226
val params = PrivacyDashboardPrimaryScreen(tabId)
12281227
val intent = globalActivityStarter.startIntent(requireContext(), params)
1229-
postBreakageReportingEvent()
1228+
contentScopeScripts.sendSubscriptionEvent(createBreakageReportingEventData())
12301229
intent?.let { activityResultPrivacyDashboard.launch(intent) }
12311230
pixel.fire(CustomTabPixelNames.CUSTOM_TABS_PRIVACY_DASHBOARD_OPENED)
12321231
}
12331232

1234-
private fun postBreakageReportingEvent() {
1235-
val eventData = createBreakageReportingEventData()
1236-
webView?.let {
1237-
viewModel.postContentScopeMessage(eventData, it)
1238-
}
1239-
}
1240-
12411233
private fun onFireButtonPressed() {
12421234
val isFocusedNtp = omnibar.viewMode == ViewMode.NewTab && omnibar.getText().isEmpty() && omnibar.omnibarTextInput.hasFocus()
12431235
browserActivity?.launchFire(launchedFromFocusedNtp = isFocusedNtp)
12441236
viewModel.onFireMenuSelected()
12451237
}
12461238

12471239
private fun onBrowserMenuButtonPressed() {
1248-
postBreakageReportingEvent()
1240+
contentScopeScripts.sendSubscriptionEvent(createBreakageReportingEventData())
12491241
viewModel.onBrowserMenuClicked(isCustomTab = isActiveCustomTab())
12501242
}
12511243

12521244
private fun onOmnibarPrivacyShieldButtonPressed() {
1253-
postBreakageReportingEvent()
1245+
contentScopeScripts.sendSubscriptionEvent(createBreakageReportingEventData())
12541246
launchPrivacyDashboard(toggle = false)
12551247
}
12561248

@@ -2014,7 +2006,6 @@ class BrowserTabFragment :
20142006
is Command.RefreshAndShowPrivacyProtectionEnabledConfirmation -> {
20152007
webView?.let { safeWebView ->
20162008
lifecycleScope.launch {
2017-
viewModel.privacyProtectionsUpdated(safeWebView)
20182009
refresh()
20192010
privacyProtectionEnabledConfirmation(it.domain)
20202011
}
@@ -2024,7 +2015,6 @@ class BrowserTabFragment :
20242015
is Command.RefreshAndShowPrivacyProtectionDisabledConfirmation -> {
20252016
webView?.let { safeWebView ->
20262017
lifecycleScope.launch {
2027-
viewModel.privacyProtectionsUpdated(safeWebView)
20282018
refresh()
20292019
privacyProtectionDisabledConfirmation(it.domain)
20302020
}
@@ -3242,29 +3232,6 @@ class BrowserTabFragment :
32423232
}
32433233
},
32443234
)
3245-
viewModel.configureWebView(
3246-
it,
3247-
object : WebViewCompatMessageCallback {
3248-
override fun process(
3249-
context: String,
3250-
featureName: String,
3251-
method: String,
3252-
id: String?,
3253-
data: JSONObject?,
3254-
onResponse: suspend (JSONObject) -> Unit,
3255-
) {
3256-
viewModel.webViewCompatProcessJsCallbackMessage(
3257-
context = context,
3258-
featureName = featureName,
3259-
method = method,
3260-
id = id,
3261-
data = data,
3262-
onResponse = onResponse,
3263-
)
3264-
}
3265-
},
3266-
)
3267-
32683235
duckPlayerScripts.register(
32693236
it,
32703237
object : JsMessageCallback() {

app/src/main/java/com/duckduckgo/app/browser/BrowserTabViewModel.kt

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,7 @@ import com.duckduckgo.duckplayer.api.DuckPlayer
322322
import com.duckduckgo.duckplayer.api.DuckPlayer.DuckPlayerState.ENABLED
323323
import com.duckduckgo.feature.toggles.api.Toggle
324324
import com.duckduckgo.history.api.NavigationHistory
325-
import com.duckduckgo.js.messaging.api.AddDocumentStartJavaScriptPlugin
326325
import com.duckduckgo.js.messaging.api.JsCallbackData
327-
import com.duckduckgo.js.messaging.api.PostMessageWrapperPlugin
328-
import com.duckduckgo.js.messaging.api.SubscriptionEventData
329-
import com.duckduckgo.js.messaging.api.WebMessagingPlugin
330-
import com.duckduckgo.js.messaging.api.WebViewCompatMessageCallback
331326
import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection.Feed
332327
import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection.Feed.MALWARE
333328
import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection.Feed.PHISHING
@@ -492,9 +487,6 @@ class BrowserTabViewModel @Inject constructor(
492487
private val externalIntentProcessingState: ExternalIntentProcessingState,
493488
private val vpnMenuStateProvider: VpnMenuStateProvider,
494489
private val webViewCompatWrapper: WebViewCompatWrapper,
495-
private val addDocumentStartJavascriptPlugins: PluginPoint<AddDocumentStartJavaScriptPlugin>,
496-
private val webMessagingPlugins: PluginPoint<WebMessagingPlugin>,
497-
private val postMessageWrapperPlugins: PluginPoint<PostMessageWrapperPlugin>,
498490
private val addressBarTrackersAnimationFeatureToggle: AddressBarTrackersAnimationFeatureToggle,
499491
private val autoconsentPixelManager: AutoconsentPixelManager,
500492
) : ViewModel(),
@@ -1941,11 +1933,6 @@ class BrowserTabViewModel @Inject constructor(
19411933

19421934
evaluateSerpLogoState(url)
19431935
}
1944-
viewModelScope.launch(dispatchers.io()) {
1945-
if (androidBrowserConfig.updateScriptOnPageFinished().isEnabled()) {
1946-
addDocumentStartJavaScript(webView)
1947-
}
1948-
}
19491936
}
19501937

19511938
private fun evaluateSerpLogoState(url: String?) {
@@ -4254,75 +4241,6 @@ class BrowserTabViewModel @Inject constructor(
42544241
}
42554242
}
42564243

4257-
fun configureWebView(
4258-
webView: DuckDuckGoWebView,
4259-
callback: WebViewCompatMessageCallback?,
4260-
) {
4261-
viewModelScope.launch {
4262-
addDocumentStartJavaScript(webView)
4263-
4264-
callback?.let {
4265-
webMessagingPlugins.getPlugins().forEach { plugin ->
4266-
plugin.register(callback, webView)
4267-
}
4268-
}
4269-
}
4270-
}
4271-
4272-
fun postContentScopeMessage(
4273-
eventData: SubscriptionEventData,
4274-
webView: WebView,
4275-
) {
4276-
viewModelScope.launch {
4277-
postMessageWrapperPlugins
4278-
.getPlugins()
4279-
.firstOrNull { it.context == "contentScopeScripts" }
4280-
?.postMessage(eventData, webView)
4281-
}
4282-
}
4283-
4284-
private suspend fun addDocumentStartJavaScript(webView: WebView) {
4285-
addDocumentStartJavascriptPlugins.getPlugins().forEach {
4286-
it.addDocumentStartJavaScript(
4287-
webView,
4288-
)
4289-
}
4290-
}
4291-
4292-
suspend fun privacyProtectionsUpdated(webView: WebView) {
4293-
val updateScriptOnProtectionsChanged: Boolean
4294-
val stopLoadingBeforeUpdatingScript: Boolean
4295-
val updateScriptOnPageFinished: Boolean
4296-
4297-
withContext(dispatchers.io()) {
4298-
updateScriptOnProtectionsChanged = androidBrowserConfig.updateScriptOnProtectionsChanged().isEnabled()
4299-
stopLoadingBeforeUpdatingScript = androidBrowserConfig.stopLoadingBeforeUpdatingScript().isEnabled()
4300-
updateScriptOnPageFinished = androidBrowserConfig.updateScriptOnPageFinished().isEnabled()
4301-
}
4302-
4303-
if (!updateScriptOnProtectionsChanged) {
4304-
return
4305-
}
4306-
4307-
if (stopLoadingBeforeUpdatingScript) {
4308-
withContext(dispatchers.main()) {
4309-
webView.stopLoading()
4310-
}
4311-
}
4312-
4313-
if (!updateScriptOnPageFinished) {
4314-
addDocumentStartJavascriptPlugins
4315-
.getPlugins()
4316-
.filter { plugin ->
4317-
(plugin.context == "contentScopeScripts")
4318-
}.forEach {
4319-
it.addDocumentStartJavaScript(webView)
4320-
}
4321-
} else {
4322-
addDocumentStartJavaScript(webView)
4323-
}
4324-
}
4325-
43264244
fun onUserDismissedAutoCompleteInAppMessage() {
43274245
viewModelScope.launch(dispatchers.io()) {
43284246
autoComplete.userDismissedHistoryInAutoCompleteIAM()

app/src/main/java/com/duckduckgo/app/pixels/remoteconfig/AndroidBrowserConfigFeature.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,6 @@ interface AndroidBrowserConfigFeature {
181181
@Toggle.DefaultValue(DefaultFeatureValue.FALSE)
182182
fun vpnMenuItem(): Toggle
183183

184-
@Toggle.DefaultValue(TRUE)
185-
fun updateScriptOnPageFinished(): Toggle
186-
187-
@Toggle.DefaultValue(TRUE)
188-
fun updateScriptOnProtectionsChanged(): Toggle
189-
190-
@Toggle.DefaultValue(FALSE)
191-
fun stopLoadingBeforeUpdatingScript(): Toggle
192-
193184
@Toggle.DefaultValue(TRUE)
194185
fun useUnifiedOmnibarLayout(): Toggle
195186
}

0 commit comments

Comments
 (0)