Skip to content

Commit 8ac524e

Browse files
committed
Rename and document APIs
1 parent 41a19d6 commit 8ac524e

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package com.duckduckgo.contentscopescripts.api
1818

19-
import com.duckduckgo.js.messaging.api.AdsjsMessageHandler
19+
import com.duckduckgo.js.messaging.api.WebCompatMessageHandler
2020

2121
/**
2222
* Implement this interface and contribute it as a multibinding to manage JS Messages that are sent to C-S-S
2323
*/
24-
interface AdsjsContentScopeJsMessageHandlersPlugin {
24+
interface WebCompatContentScopeJsMessageHandlersPlugin {
2525
/**
26-
* @return a [AdsjsMessageHandler] that will be used to handle the JS messages
26+
* @return a [WebCompatMessageHandler] that will be used to handle the JS messages
2727
*/
28-
fun getJsMessageHandler(): AdsjsMessageHandler
28+
fun getJsMessageHandler(): WebCompatMessageHandler
2929
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
package com.duckduckgo.contentscopescripts.impl
1818

1919
import com.duckduckgo.anvil.annotations.ContributesPluginPoint
20-
import com.duckduckgo.contentscopescripts.api.AdsjsContentScopeJsMessageHandlersPlugin
20+
import com.duckduckgo.contentscopescripts.api.WebCompatContentScopeJsMessageHandlersPlugin
2121
import com.duckduckgo.di.scopes.AppScope
2222

2323
@ContributesPluginPoint(
2424
scope = AppScope::class,
25-
boundType = AdsjsContentScopeJsMessageHandlersPlugin::class,
25+
boundType = WebCompatContentScopeJsMessageHandlersPlugin::class,
2626
)
2727
@Suppress("unused")
28-
interface AdsjsContentScopeJsMessageHandlersPluginPoint
28+
interface WebCompatContentScopeJsMessageHandlersPluginPoint

content-scope-scripts/content-scope-scripts-impl/src/main/java/com/duckduckgo/contentscopescripts/impl/messaging/WebCompatMessagingPlugin.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ import androidx.annotation.VisibleForTesting
2121
import androidx.webkit.WebViewCompat.WebMessageListener
2222
import com.duckduckgo.common.utils.DispatcherProvider
2323
import com.duckduckgo.common.utils.plugins.PluginPoint
24-
import com.duckduckgo.contentscopescripts.api.AdsjsContentScopeJsMessageHandlersPlugin
2524
import com.duckduckgo.contentscopescripts.api.GlobalContentScopeJsMessageHandlersPlugin
25+
import com.duckduckgo.contentscopescripts.api.WebCompatContentScopeJsMessageHandlersPlugin
2626
import com.duckduckgo.contentscopescripts.api.WebMessagingPlugin
2727
import com.duckduckgo.contentscopescripts.impl.AdsJsContentScopeScripts
2828
import com.duckduckgo.di.scopes.ActivityScope
2929
import com.duckduckgo.js.messaging.api.JsMessage
3030
import com.duckduckgo.js.messaging.api.JsMessageCallback
3131
import com.squareup.anvil.annotations.ContributesBinding
3232
import com.squareup.moshi.Moshi
33+
import javax.inject.Inject
34+
import javax.inject.Named
3335
import kotlinx.coroutines.withContext
3436
import logcat.LogPriority.ERROR
3537
import logcat.asLog
3638
import logcat.logcat
37-
import javax.inject.Inject
38-
import javax.inject.Named
3939

4040
private const val JS_OBJECT_NAME = "contentScopeAdsjs"
4141

4242
@ContributesBinding(ActivityScope::class)
4343
@Named("AdsjsContentScopeScripts")
4444
class WebCompatMessagingPlugin @Inject constructor(
45-
private val handlers: PluginPoint<AdsjsContentScopeJsMessageHandlersPlugin>,
45+
private val handlers: PluginPoint<WebCompatContentScopeJsMessageHandlersPlugin>,
4646
private val globalHandlers: PluginPoint<GlobalContentScopeJsMessageHandlersPlugin>,
4747
private val adsJsContentScopeScripts: AdsJsContentScopeScripts,
4848
private val dispatcherProvider: DispatcherProvider,
@@ -83,19 +83,19 @@ class WebCompatMessagingPlugin @Inject constructor(
8383
}
8484
}
8585

86-
8786
override suspend fun register(
8887
webView: WebView,
8988
jsMessageCallback: JsMessageCallback?,
90-
registerer: suspend (objectName: String, allowedOriginRules: Set<String>, webMessageListener: WebMessageListener) -> Boolean)
91-
{
89+
registerer: suspend (objectName: String, allowedOriginRules: Set<String>, webMessageListener: WebMessageListener) -> Boolean,
90+
) {
9291
if (withContext(dispatcherProvider.io()) { !adsJsContentScopeScripts.isEnabled() }) return
9392
if (jsMessageCallback == null) throw Exception("Callback cannot be null")
9493

9594
runCatching {
96-
97-
return@runCatching registerer(JS_OBJECT_NAME, allowedDomains,
98-
WebMessageListener { _, message, _, _, _ -> process(message.data ?: "", jsMessageCallback) }
95+
return@runCatching registerer(
96+
JS_OBJECT_NAME,
97+
allowedDomains,
98+
WebMessageListener { _, message, _, _, _ -> process(message.data ?: "", jsMessageCallback) },
9999
)
100100
}.getOrElse { exception ->
101101
logcat(ERROR) { "Error adding WebMessageListener for contentScopeAdsjs: ${exception.asLog()}" }
@@ -104,7 +104,7 @@ class WebCompatMessagingPlugin @Inject constructor(
104104
}
105105

106106
override suspend fun unregister(
107-
unregisterer: suspend (objectName: String) -> Boolean
107+
unregisterer: suspend (objectName: String) -> Boolean,
108108
) {
109109
if (!adsJsContentScopeScripts.isEnabled()) return
110110
withContext(dispatcherProvider.main()) {

content-scope-scripts/content-scope-scripts-impl/src/test/java/com/duckduckgo/contentscopescripts/impl/messaging/AdsjsContentScopeScriptsJsMessagingTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
2020
import com.duckduckgo.app.browser.api.DuckDuckGoWebView
2121
import com.duckduckgo.common.test.CoroutineTestRule
2222
import com.duckduckgo.common.utils.plugins.PluginPoint
23-
import com.duckduckgo.contentscopescripts.api.AdsjsContentScopeJsMessageHandlersPlugin
2423
import com.duckduckgo.contentscopescripts.api.GlobalContentScopeJsMessageHandlersPlugin
2524
import com.duckduckgo.contentscopescripts.api.GlobalJsMessageHandler
25+
import com.duckduckgo.contentscopescripts.api.WebCompatContentScopeJsMessageHandlersPlugin
2626
import com.duckduckgo.contentscopescripts.impl.AdsJsContentScopeScripts
27-
import com.duckduckgo.js.messaging.api.AdsjsMessageHandler
2827
import com.duckduckgo.js.messaging.api.JsMessage
2928
import com.duckduckgo.js.messaging.api.JsMessageCallback
29+
import com.duckduckgo.js.messaging.api.WebCompatMessageHandler
3030
import junit.framework.TestCase.assertEquals
3131
import kotlinx.coroutines.test.runTest
3232
import org.json.JSONObject
@@ -46,18 +46,18 @@ class AdsjsContentScopeScriptsJsMessagingTest {
4646

4747
private val mockWebView: DuckDuckGoWebView = mock()
4848
private val adsJsContentScopeScripts: AdsJsContentScopeScripts = mock()
49-
private val handlers: PluginPoint<AdsjsContentScopeJsMessageHandlersPlugin> = FakePluginPoint()
49+
private val handlers: PluginPoint<WebCompatContentScopeJsMessageHandlersPlugin> = FakePluginPoint()
5050
private val globalHandlers: PluginPoint<GlobalContentScopeJsMessageHandlersPlugin> = FakeGlobalHandlersPluginPoint()
5151
private lateinit var contentScopeScriptsJsMessaging: AdsjsContentScopeMessaging
5252

53-
private class FakePluginPoint : PluginPoint<AdsjsContentScopeJsMessageHandlersPlugin> {
54-
override fun getPlugins(): Collection<AdsjsContentScopeJsMessageHandlersPlugin> {
53+
private class FakePluginPoint : PluginPoint<WebCompatContentScopeJsMessageHandlersPlugin> {
54+
override fun getPlugins(): Collection<WebCompatContentScopeJsMessageHandlersPlugin> {
5555
return listOf(FakePlugin())
5656
}
5757

58-
inner class FakePlugin : AdsjsContentScopeJsMessageHandlersPlugin {
59-
override fun getJsMessageHandler(): AdsjsMessageHandler {
60-
return object : AdsjsMessageHandler {
58+
inner class FakePlugin : WebCompatContentScopeJsMessageHandlersPlugin {
59+
override fun getJsMessageHandler(): WebCompatMessageHandler {
60+
return object : WebCompatMessageHandler {
6161
override fun process(
6262
jsMessage: JsMessage,
6363
jsMessageCallback: JsMessageCallback?,

js-messaging/js-messaging-api/src/main/java/com/duckduckgo/js/messaging/api/AdsjsMessaging.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package com.duckduckgo.js.messaging.api
1818

19-
interface AdsjsMessageHandler {
19+
interface WebCompatMessageHandler {
2020
/**
21-
* Processes a JavaScript message received by the WebView.
21+
* Processes a JavaScript message received by the WebView using WebCompat APIs
2222
*
2323
* This method is responsible for handling a [JsMessage] and optionally
2424
* invoking a callback so consumers can also process the message if needed.

0 commit comments

Comments
 (0)