Skip to content

Commit 910f174

Browse files
committed
Simplify APIs
1 parent 5e8147a commit 910f174

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
@@ -1350,7 +1350,7 @@ class BrowserWebViewClientTest {
13501350
}
13511351

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

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,12 +1200,8 @@ class BrowserTabFragment :
12001200
}
12011201

12021202
private fun postBreakageReportingEvent() {
1203-
appCoroutineScope.launch {
1204-
val eventData = createBreakageReportingEventData()
1205-
webViewClient.postMessage(eventData) {
1206-
contentScopeScripts.sendSubscriptionEvent(eventData)
1207-
}
1208-
}
1203+
val eventData = createBreakageReportingEventData()
1204+
webViewClient.postMessage(eventData)
12091205
}
12101206

12111207
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
@@ -763,14 +763,11 @@ class BrowserWebViewClient @Inject constructor(
763763
}
764764
}
765765

766-
suspend fun postMessage(
766+
fun postMessage(
767767
eventData: SubscriptionEventData,
768-
fallback: () -> Unit,
769768
) {
770769
webMessagingPlugins.getPlugins().forEach {
771-
if (!it.postMessage(eventData)) {
772-
fallback()
773-
}
770+
it.postMessage(eventData)
774771
}
775772
}
776773
}

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ContentScopeScriptsWebMessagingPlugin @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,
@@ -211,25 +212,26 @@ class ContentScopeScriptsWebMessagingPlugin @Inject constructor(
211212
}
212213

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

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

229-
withContext(dispatcherProvider.main()) {
230-
globalReplyProxy?.postMessage(subscriptionEvent)
231-
true
231+
withContext(dispatcherProvider.main()) {
232+
globalReplyProxy?.postMessage(subscriptionEvent)
233+
}
232234
}
233-
}.getOrElse { false }
235+
}
234236
}
235237
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class ContentScopeScriptsWebMessagingPluginTest {
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)