Skip to content

Commit 90a773b

Browse files
committed
Rename isEnabled to canHandleMessaging
1 parent d22d4aa commit 90a773b

File tree

3 files changed

+8
-28
lines changed

3 files changed

+8
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ContentScopeScriptsWebMessagingPlugin @Inject constructor(
4747
override val objectName: String
4848
get() = "contentScopeAdsjs"
4949

50-
override suspend fun isEnabled(): Boolean {
50+
override suspend fun canHandleMessaging(): Boolean {
5151
return webViewCompatContentScopeScripts.isEnabled()
5252
}
5353

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ interface WebMessagingPluginStrategy {
5454
val objectName: String
5555

5656
/**
57-
* Determines whether messaging actions should proceed (i.e. by checking feature flags).
58-
* @return true if messaging is allowed, false otherwise
57+
* Determines whether messaging can be handled (i.e. by checking feature flags).
58+
* @return true if messaging can be handled for this plugin, false otherwise
5959
*/
60-
suspend fun isEnabled(): Boolean
60+
suspend fun canHandleMessaging(): Boolean
6161

6262
/**
6363
* Provides the list of message handlers to process incoming messages.

js-messaging/js-messaging-impl/src/main/java/com/duckduckgo/js/messaging/impl/RealWebMessagingDelegate.kt

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,6 @@ import logcat.asLog
4646
import logcat.logcat
4747
import org.json.JSONObject
4848

49-
50-
/*
51-
52-
53-
54-
55-
56-
override suspend fun unregister(webView: WebView) {
57-
if (!webViewCompatContentScopeScripts.isEnabled()) return
58-
runCatching {
59-
return@runCatching webViewCompatWrapper.removeWebMessageListener(webView, JS_OBJECT_NAME)
60-
}.getOrElse { exception ->
61-
logcat(ERROR) {
62-
"Error removing WebMessageListener for contentScopeAdsjs: ${exception.asLog()}"
63-
}
64-
}
65-
}
66-
67-
*/
68-
6949
@ContributesBinding(FragmentScope::class)
7050
class RealWebMessagingDelegate @Inject constructor(
7151
private val webViewCompatWrapper: WebViewCompatWrapper,
@@ -178,7 +158,8 @@ class RealWebMessagingDelegate @Inject constructor(
178158
override suspend fun register(
179159
jsMessageCallback: WebViewCompatMessageCallback,
180160
webView: WebView,
181-
) {if (!strategy.isEnabled()) {
161+
) {
162+
if (!strategy.canHandleMessaging()) {
182163
return
183164
}
184165

@@ -204,7 +185,7 @@ class RealWebMessagingDelegate @Inject constructor(
204185
override suspend fun unregister(
205186
webView: WebView,
206187
) {
207-
if (!strategy.isEnabled()) return
188+
if (!strategy.canHandleMessaging()) return
208189
runCatching {
209190
return@runCatching webViewCompatWrapper.removeWebMessageListener(webView, strategy.objectName)
210191
}.getOrElse { exception ->
@@ -231,11 +212,10 @@ class RealWebMessagingDelegate @Inject constructor(
231212
}
232213
}
233214

234-
235215
@SuppressLint("RequiresFeature")
236216
override suspend fun postMessage(webView: WebView, subscriptionEventData: SubscriptionEventData) {
237217
runCatching {
238-
if (!strategy.isEnabled()) {
218+
if (!strategy.canHandleMessaging()) {
239219
return
240220
}
241221

0 commit comments

Comments
 (0)