File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
browser-api/src/main/java/com/duckduckgo/browser/api
js-messaging/js-messaging-api/src/main/java/com/duckduckgo/js/messaging/api Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 16
16
17
17
package com.duckduckgo.browser.api
18
18
19
+ import com.duckduckgo.common.utils.plugins.PluginPoint
19
20
import com.duckduckgo.js.messaging.api.WebMessaging
20
21
22
+ /* *
23
+ * Interface to provide implementations of [WebMessaging] to the browser, through
24
+ * [PluginPoint]<[WebMessaging]>
25
+ */
21
26
interface WebMessagingBrowserPlugin {
27
+ /* *
28
+ * Provides an implementation of [WebMessaging] to be used by the browser.
29
+ * @return an instance of [WebMessaging]
30
+ */
22
31
fun webMessaging (): WebMessaging
23
32
}
Original file line number Diff line number Diff line change @@ -19,18 +19,43 @@ package com.duckduckgo.js.messaging.api
19
19
import android.webkit.WebView
20
20
21
21
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
+ */
22
29
suspend fun register (
23
30
jsMessageCallback : WebViewCompatMessageCallback ,
24
31
webView : WebView ,
25
32
)
26
33
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
+ */
27
42
suspend fun unregister (webView : WebView )
28
43
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
+ */
29
49
suspend fun postMessage (
30
50
webView : WebView ,
31
51
subscriptionEventData : SubscriptionEventData ,
32
52
)
33
53
54
+ /* *
55
+ * The context for this instance.
56
+ * This can be used to differentiate between different messaging implementations.
57
+ * @return context string
58
+ */
34
59
val context: String
35
60
}
36
61
You can’t perform that action at this time.
0 commit comments