Skip to content

Commit f0f6493

Browse files
muodovnalcalag
andauthored
Bundle CPM rules (#4751)
Task/Issue URL: https://app.asana.com/0/0/1207739322230535/f ### Description Bundle autoconsent JSON rules in the userscript ### Steps to test this PR - enable CPM - verify that it handles pop-ups on https://etsy.com and https://doodle.com ### UI changes | Before | After | | ------ | ----- | !(Upload before screenshot)|(Upload after screenshot)| --------- Co-authored-by: Noelia Alcala <[email protected]>
1 parent 083f75a commit f0f6493

File tree

8 files changed

+6
-10405
lines changed

8 files changed

+6
-10405
lines changed

autoconsent/autoconsent-impl/libs/autoconsent-bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

autoconsent/autoconsent-impl/libs/rules.json

Lines changed: 0 additions & 9906 deletions
This file was deleted.

autoconsent/autoconsent-impl/libs/userscript.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import AutoConsent from '@duckduckgo/autoconsent';
2+
import * as rules from '@duckduckgo/autoconsent/rules/rules.json';
23

34
const autoconsent = new AutoConsent(
45
(message) => {
56
AutoconsentAndroid.process(JSON.stringify(message));
67
},
8+
null,
9+
rules,
710
);
811
window.autoconsentMessageCallback = (msg) => {
912
autoconsent.receiveMessageCallback(msg);

autoconsent/autoconsent-impl/src/main/java/com/duckduckgo/autoconsent/impl/handlers/InitMessageHandlerPlugin.kt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import android.webkit.WebView
2020
import androidx.core.net.toUri
2121
import com.duckduckgo.app.di.AppCoroutineScope
2222
import com.duckduckgo.autoconsent.api.AutoconsentCallback
23-
import com.duckduckgo.autoconsent.impl.JsReader
2423
import com.duckduckgo.autoconsent.impl.MessageHandlerPlugin
2524
import com.duckduckgo.autoconsent.impl.adapters.JSONObjectAdapter
2625
import com.duckduckgo.autoconsent.impl.remoteconfig.AutoconsentFeatureSettingsRepository
@@ -35,7 +34,6 @@ import com.squareup.moshi.Moshi
3534
import javax.inject.Inject
3635
import kotlinx.coroutines.CoroutineScope
3736
import kotlinx.coroutines.launch
38-
import org.json.JSONObject
3937
import timber.log.Timber
4038

4139
@ContributesMultibinding(AppScope::class)
@@ -47,7 +45,6 @@ class InitMessageHandlerPlugin @Inject constructor(
4745
) : MessageHandlerPlugin {
4846

4947
private val moshi = Moshi.Builder().add(JSONObjectAdapter()).build()
50-
private lateinit var rules: String
5148

5249
override fun process(messageType: String, jsonString: String, webView: WebView, autoconsentCallback: AutoconsentCallback) {
5350
if (supportedTypes.contains(messageType)) {
@@ -77,7 +74,7 @@ class InitMessageHandlerPlugin @Inject constructor(
7774
val detectRetries = 20
7875

7976
val config = Config(enabled = true, autoAction, disabledCmps, enablePreHide, detectRetries, enableCosmeticRules = true)
80-
val initResp = InitResp(rules = getRules(), config = config)
77+
val initResp = InitResp(config = config)
8178

8279
val response = ReplyHandler.constructReply(getMessage(initResp))
8380

@@ -107,13 +104,6 @@ class InitMessageHandlerPlugin @Inject constructor(
107104
return jsonAdapter.toJson(initResp).toString()
108105
}
109106

110-
private fun getRules(): JSONObject {
111-
if (!this::rules.isInitialized) {
112-
rules = JsReader.loadJs("rules.json")
113-
}
114-
return JSONObject(rules)
115-
}
116-
117107
data class InitMessage(val type: String, val url: String)
118108

119109
data class Config(
@@ -125,6 +115,5 @@ class InitMessageHandlerPlugin @Inject constructor(
125115
val enableCosmeticRules: Boolean,
126116
)
127117

128-
// rules can actually be null, but we will always pass them through
129-
data class InitResp(val type: String = "initResp", val config: Config, val rules: JSONObject)
118+
data class InitResp(val type: String = "initResp", val config: Config)
130119
}

autoconsent/autoconsent-impl/src/test/java/com/duckduckgo/autoconsent/impl/handlers/InitMessageHandlerPluginTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ class InitMessageHandlerPluginTest {
128128
val result = shadow.lastEvaluatedJavascript
129129
val initResp = jsonToInitResp(result)
130130
assertEquals("optOut", initResp!!.config.autoAction)
131-
assertNotNull(initResp.rules)
132131
assertTrue(initResp.config.enablePrehide)
133132
assertTrue(initResp.config.enabled)
134133
assertEquals(20, initResp.config.detectRetries)

0 commit comments

Comments
 (0)