Skip to content

Commit 6f99b38

Browse files
committed
Update documentation
1 parent 2be80bc commit 6f99b38

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

browser-api/src/main/java/com/duckduckgo/browser/api/WebMessagingBrowserPlugin.kt

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

1717
package com.duckduckgo.browser.api
1818

19+
import com.duckduckgo.common.utils.plugins.PluginPoint
1920
import com.duckduckgo.js.messaging.api.WebMessaging
2021

22+
/**
23+
* Interface to provide implementations of [WebMessaging] to the browser, through
24+
* [PluginPoint]<[WebMessaging]>
25+
*/
2126
interface WebMessagingBrowserPlugin {
27+
/**
28+
* Provides an implementation of [WebMessaging] to be used by the browser.
29+
* @return an instance of [WebMessaging]
30+
*/
2231
fun webMessaging(): WebMessaging
2332
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,43 @@ package com.duckduckgo.js.messaging.api
1919
import android.webkit.WebView
2020

2121
interface WebMessaging {
22+
/**
23+
* Registers the given [jsMessageCallback] to handle messages from the provided [webView].
24+
* @param jsMessageCallback the callback to handle incoming messages
25+
* @param webView the WebView to register the callback with
26+
* Notes:
27+
* - It's not recommended to unregister and then register again on the same WebView instance.
28+
*/
2229
suspend fun register(
2330
jsMessageCallback: WebViewCompatMessageCallback,
2431
webView: WebView,
2532
)
2633

34+
/**
35+
* Unregisters any previously registered message handlers from the given [webView].
36+
* Notes:
37+
* - This does not remove the JavaScript interface from the WebView, just the handlers.
38+
* - It's not required to call this when the WebView is being destroyed.
39+
* - It's not recommended to unregister and then register again on the same WebView instance.
40+
* @param webView the WebView to unregister the handlers from
41+
*/
2742
suspend fun unregister(webView: WebView)
2843

44+
/**
45+
* Posts a message to the given [webView] using the provided [subscriptionEventData].
46+
* @param webView the WebView to which the message should be posted
47+
* @param subscriptionEventData the data to be sent in the message
48+
*/
2949
suspend fun postMessage(
3050
webView: WebView,
3151
subscriptionEventData: SubscriptionEventData,
3252
)
3353

54+
/**
55+
* The context for this instance.
56+
* This can be used to differentiate between different messaging implementations.
57+
* @return context string
58+
*/
3459
val context: String
3560
}
3661

0 commit comments

Comments
 (0)