Skip to content

Commit 37a86a6

Browse files
committed
Reply to initialPing
1 parent a66981d commit 37a86a6

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3672,6 +3672,16 @@ class BrowserTabViewModel @Inject constructor(
36723672
"breakageReportResult" -> if (data != null) {
36733673
breakageReportResult(data)
36743674
}
3675+
"initialPing" -> {
3676+
// TODO: Eventually, we might want plugins here
3677+
val response = JSONObject(
3678+
mapOf(
3679+
"desktopModeEnabled" to (getSite()?.isDesktopMode ?: false),
3680+
"forcedZoomEnabled" to (accessibilityViewState.value?.forceZoom ?: false),
3681+
),
3682+
)
3683+
onResponse(response)
3684+
}
36753685
}
36763686
}
36773687

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

Comments
 (0)