Skip to content

Commit 6bed82c

Browse files
committed
Simplify APIs
1 parent 5fb3922 commit 6bed82c

File tree

6 files changed

+26
-30
lines changed

6 files changed

+26
-30
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ class BrowserWebViewClientTest {
13511351
}
13521352

13531353
// TODO (cbarreiro) Test message posting
1354-
override suspend fun postMessage(subscriptionEventData: SubscriptionEventData): Boolean {
1354+
override fun postMessage(subscriptionEventData: SubscriptionEventData) {
13551355
TODO("Not yet implemented")
13561356
}
13571357
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,12 +1214,8 @@ class BrowserTabFragment :
12141214
}
12151215

12161216
private fun postBreakageReportingEvent() {
1217-
appCoroutineScope.launch {
1218-
val eventData = createBreakageReportingEventData()
1219-
webViewClient.postMessage(eventData) {
1220-
contentScopeScripts.sendSubscriptionEvent(eventData)
1221-
}
1222-
}
1217+
val eventData = createBreakageReportingEventData()
1218+
webViewClient.postMessage(eventData)
12231219
}
12241220

12251221
private fun onFireButtonPressed() {

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,14 +772,11 @@ class BrowserWebViewClient @Inject constructor(
772772
}
773773
}
774774

775-
suspend fun postMessage(
775+
fun postMessage(
776776
eventData: SubscriptionEventData,
777-
fallback: () -> Unit,
778777
) {
779778
webMessagingPlugins.getPlugins().forEach {
780-
if (!it.postMessage(eventData)) {
781-
fallback()
782-
}
779+
it.postMessage(eventData)
783780
}
784781
}
785782
}

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class WebViewCompatWebCompatMessagingPlugin @Inject constructor(
5353
private val handlers: PluginPoint<WebViewCompatContentScopeJsMessageHandlersPlugin>,
5454
private val globalHandlers: PluginPoint<GlobalContentScopeJsMessageHandlersPlugin>,
5555
private val webViewCompatContentScopeScripts: WebViewCompatContentScopeScripts,
56+
private val contentScopeScriptsJsMessaging: ContentScopeScriptsJsMessaging,
5657
private val webViewCompatWrapper: WebViewCompatWrapper,
5758
private val dispatcherProvider: DispatcherProvider,
5859
@AppCoroutineScope private val appCoroutineScope: CoroutineScope,
@@ -212,25 +213,26 @@ class WebViewCompatWebCompatMessagingPlugin @Inject constructor(
212213
}
213214

214215
@SuppressLint("RequiresFeature")
215-
override suspend fun postMessage(subscriptionEventData: SubscriptionEventData): Boolean {
216-
return runCatching {
217-
if (!webViewCompatContentScopeScripts.isEnabled()) {
218-
return false
219-
}
216+
override fun postMessage(subscriptionEventData: SubscriptionEventData) {
217+
runCatching {
218+
appCoroutineScope.launch {
219+
if (!webViewCompatContentScopeScripts.isEnabled()) {
220+
contentScopeScriptsJsMessaging.sendSubscriptionEvent(subscriptionEventData)
221+
}
220222

221-
val subscriptionEvent = SubscriptionEvent(
222-
context = context,
223-
featureName = subscriptionEventData.featureName,
224-
subscriptionName = subscriptionEventData.subscriptionName,
225-
params = subscriptionEventData.params,
226-
).let {
227-
moshi.adapter(SubscriptionEvent::class.java).toJson(it)
228-
}
223+
val subscriptionEvent = SubscriptionEvent(
224+
context = context,
225+
featureName = subscriptionEventData.featureName,
226+
subscriptionName = subscriptionEventData.subscriptionName,
227+
params = subscriptionEventData.params,
228+
).let {
229+
moshi.adapter(SubscriptionEvent::class.java).toJson(it)
230+
}
229231

230-
withContext(dispatcherProvider.main()) {
231-
globalReplyProxy?.postMessage(subscriptionEvent)
232-
true
232+
withContext(dispatcherProvider.main()) {
233+
globalReplyProxy?.postMessage(subscriptionEvent)
234+
}
233235
}
234-
}.getOrElse { false }
236+
}
235237
}
236238
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class WebViewCompatWebCompatMessagingPluginTest {
110110
webViewCompatWrapper = mockWebViewCompatWrapper,
111111
dispatcherProvider = coroutineRule.testDispatcherProvider,
112112
appCoroutineScope = coroutineRule.testScope,
113+
contentScopeScriptsJsMessaging = mock(),
113114
)
114115
}
115116

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ interface WebMessagingPlugin {
2828
webView: WebView,
2929
)
3030

31-
suspend fun postMessage(subscriptionEventData: SubscriptionEventData): Boolean
31+
fun postMessage(subscriptionEventData: SubscriptionEventData)
3232
}

0 commit comments

Comments
 (0)