Skip to content

Commit 17690e9

Browse files
committed
Add UpdateNativeSettingsHandler to process updateNativeSettings messages from SERP
1 parent bc4160d commit 17690e9

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.settings.impl.serpsettings.messaging
18+
19+
import com.duckduckgo.common.utils.AppUrl
20+
import com.duckduckgo.contentscopescripts.api.ContentScopeJsMessageHandlersPlugin
21+
import com.duckduckgo.di.scopes.AppScope
22+
import com.duckduckgo.js.messaging.api.JsMessage
23+
import com.duckduckgo.js.messaging.api.JsMessageCallback
24+
import com.duckduckgo.js.messaging.api.JsMessageHandler
25+
import com.duckduckgo.js.messaging.api.JsMessaging
26+
import com.squareup.anvil.annotations.ContributesMultibinding
27+
import logcat.logcat
28+
import javax.inject.Inject
29+
30+
/**
31+
* Handles the updateNativeSettings message from SERP to persist setting changes.
32+
*/
33+
@ContributesMultibinding(AppScope::class)
34+
class UpdateNativeSettingsHandler @Inject constructor(
35+
// TODO: Inject SerpSettingsRepository when implemented
36+
) : ContentScopeJsMessageHandlersPlugin {
37+
38+
override fun getJsMessageHandler(): JsMessageHandler =
39+
object : JsMessageHandler {
40+
override fun process(
41+
jsMessage: JsMessage,
42+
jsMessaging: JsMessaging,
43+
jsMessageCallback: JsMessageCallback?,
44+
) {
45+
logcat { "SERP-SETTINGS: UpdateNativeSettingsHandler processing message" }
46+
47+
// TODO Use a data store to store the settings from SERP
48+
}
49+
50+
override val allowedDomains: List<String> = listOf(AppUrl.Url.HOST)
51+
override val featureName: String = "serpSettings"
52+
override val methods: List<String> = listOf("updateNativeSettings")
53+
}
54+
}

0 commit comments

Comments
 (0)