|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 DuckDuckGo |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.duckduckgo.contentscopescripts.impl |
| 18 | + |
| 19 | +import com.duckduckgo.contentscopescripts.api.AdsjsContentScopeJsMessageHandlersPlugin |
| 20 | +import com.duckduckgo.di.scopes.ActivityScope |
| 21 | +import com.duckduckgo.js.messaging.api.AdsjsJsMessageCallback |
| 22 | +import com.duckduckgo.js.messaging.api.AdsjsMessageHandler |
| 23 | +import com.duckduckgo.js.messaging.api.JsMessage |
| 24 | +import com.squareup.anvil.annotations.ContributesMultibinding |
| 25 | +import javax.inject.Inject |
| 26 | +import org.json.JSONObject |
| 27 | + |
| 28 | +@ContributesMultibinding(ActivityScope::class) |
| 29 | +class AdsjsMessagingContentScopeJsMessageHandler @Inject constructor() : AdsjsContentScopeJsMessageHandlersPlugin { |
| 30 | + |
| 31 | + override fun getJsMessageHandler(): AdsjsMessageHandler = object : AdsjsMessageHandler { |
| 32 | + |
| 33 | + override fun process( |
| 34 | + jsMessage: JsMessage, |
| 35 | + jsMessageCallback: AdsjsJsMessageCallback?, |
| 36 | + onResponse: (JSONObject) -> Unit, |
| 37 | + ) { |
| 38 | + jsMessageCallback?.process(featureName, jsMessage.method, jsMessage.id, jsMessage.params, onResponse) |
| 39 | + } |
| 40 | + |
| 41 | + override val featureName: String = "messaging" |
| 42 | + override val methods: List<String> = listOf("initialPing") |
| 43 | + } |
| 44 | +} |
0 commit comments