-
Notifications
You must be signed in to change notification settings - Fork 949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duck Player custom error #5698
base: develop
Are you sure you want to change the base?
Duck Player custom error #5698
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ import com.duckduckgo.app.pixels.AppPixelName.DUCK_PLAYER_SETTING_ALWAYS_SERP | |
import com.duckduckgo.app.pixels.AppPixelName.DUCK_PLAYER_SETTING_NEVER_OVERLAY_YOUTUBE | ||
import com.duckduckgo.app.pixels.AppPixelName.DUCK_PLAYER_SETTING_NEVER_SERP | ||
import com.duckduckgo.app.statistics.pixels.Pixel | ||
import com.duckduckgo.app.statistics.pixels.Pixel.PixelType.Daily | ||
import com.duckduckgo.appbuildconfig.api.AppBuildConfig | ||
import com.duckduckgo.duckplayer.api.DuckPlayer | ||
import com.duckduckgo.duckplayer.api.DuckPlayer.DuckPlayerOrigin.AUTO | ||
|
@@ -41,6 +42,15 @@ import com.duckduckgo.duckplayer.api.DuckPlayer.OpenDuckPlayerInNewTab.On | |
import com.duckduckgo.duckplayer.api.DuckPlayer.UserPreferences | ||
import com.duckduckgo.duckplayer.api.PrivatePlayerMode | ||
import com.duckduckgo.duckplayer.api.PrivatePlayerMode.Enabled | ||
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName | ||
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_YOUTUBE_ERROR_AGE_RESTRICTED_DAILY_UNIQUE | ||
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_YOUTUBE_ERROR_AGE_RESTRICTED_IMPRESSION | ||
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_YOUTUBE_ERROR_NO_EMBED_DAILY_UNIQUE | ||
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_YOUTUBE_ERROR_NO_EMBED_IMPRESSION | ||
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_YOUTUBE_ERROR_SIGN_IN_REQUIRED_DAILY_UNIQUE | ||
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_YOUTUBE_ERROR_SIGN_IN_REQUIRED_IMPRESSION | ||
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_YOUTUBE_ERROR_UNKNOWN_DAILY_UNIQUE | ||
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_YOUTUBE_ERROR_UNKNOWN_IMPRESSION | ||
import com.duckduckgo.js.messaging.api.JsCallbackData | ||
import com.duckduckgo.js.messaging.api.SubscriptionEventData | ||
import javax.inject.Inject | ||
|
@@ -127,6 +137,9 @@ class DuckPlayerJSHelper @Inject constructor( | |
jsonObject.put("platform", JSONObject("""{ name: "android" }""")) | ||
jsonObject.put("locale", java.util.Locale.getDefault().language) | ||
jsonObject.put("env", if (appBuildConfig.isDebug) "development" else "production") | ||
|
||
// Custom Error Settings | ||
jsonObject.getJSONObject("settings").put("customError", getCustomErrorSettings()) | ||
} | ||
DUCK_PLAYER_FEATURE_NAME -> { | ||
jsonObject.put("platform", JSONObject("""{ name: "android" }""")) | ||
|
@@ -142,6 +155,17 @@ class DuckPlayerJSHelper @Inject constructor( | |
) | ||
} | ||
|
||
private fun getCustomErrorSettings(): JSONObject { | ||
val customErrorObject = JSONObject() | ||
customErrorObject.put("state", if (duckPlayer.shouldShowCustomError()) "enabled" else "disabled") | ||
|
||
duckPlayer.customErrorSettings()?.let { settings -> | ||
customErrorObject.put("signInRequiredSelector", settings.signInRequiredSelector.takeIf { it.isNotEmpty() } ?: "") | ||
} | ||
|
||
return customErrorObject | ||
} | ||
|
||
private suspend fun setUserPreferences(data: JSONObject) { | ||
val overlayInteracted = data.getBoolean(OVERLAY_INTERACTED) | ||
val privatePlayerModeObject = data.getJSONObject(PRIVATE_PLAYER_MODE) | ||
|
@@ -247,6 +271,24 @@ class DuckPlayerJSHelper @Inject constructor( | |
else -> null | ||
} | ||
} | ||
"reportYouTubeError" -> { | ||
val impressionPixelName: DuckPlayerPixelName = when (data?.getString("error")) { | ||
"age-restricted" -> DUCK_PLAYER_YOUTUBE_ERROR_AGE_RESTRICTED_IMPRESSION | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Extract to constants |
||
"no-embed" -> DUCK_PLAYER_YOUTUBE_ERROR_NO_EMBED_IMPRESSION | ||
"sign-in-restricted" -> DUCK_PLAYER_YOUTUBE_ERROR_SIGN_IN_REQUIRED_IMPRESSION | ||
else -> DUCK_PLAYER_YOUTUBE_ERROR_UNKNOWN_IMPRESSION | ||
} | ||
|
||
val dailyPixelName: DuckPlayerPixelName = when (data?.getString("error")) { | ||
"age-restricted" -> DUCK_PLAYER_YOUTUBE_ERROR_AGE_RESTRICTED_DAILY_UNIQUE | ||
"no-embed" -> DUCK_PLAYER_YOUTUBE_ERROR_NO_EMBED_DAILY_UNIQUE | ||
"sign-in-restricted" -> DUCK_PLAYER_YOUTUBE_ERROR_SIGN_IN_REQUIRED_DAILY_UNIQUE | ||
else -> DUCK_PLAYER_YOUTUBE_ERROR_UNKNOWN_DAILY_UNIQUE | ||
} | ||
|
||
pixel.fire(impressionPixelName) | ||
pixel.fire(dailyPixelName, emptyMap(), emptyMap(), Daily()) | ||
} | ||
else -> { | ||
return null | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,6 +184,20 @@ interface DuckPlayer { | |
*/ | ||
fun shouldOpenDuckPlayerInNewTab(): OpenDuckPlayerInNewTab | ||
|
||
/** | ||
* Checks whether Duck Player should show a custom error view based on RC flag | ||
* | ||
* @return True if should show a custom error view, false otherwise. | ||
*/ | ||
fun shouldShowCustomError(): Boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to what I said above, we shouldn't expose this on the public API, but rather rely on CSS to get this values internally from the RC JSON |
||
|
||
/** | ||
* Retrieves settings for the Custom Error feature from RC | ||
* | ||
* @return A CustomErrorSettings Object with the settings or null if not settings are available | ||
*/ | ||
fun customErrorSettings(): CustomErrorSettings? | ||
|
||
/** | ||
* Observes whether a duck Player will be opened in a new tab based on RC flag and user settings | ||
* | ||
|
@@ -209,6 +223,15 @@ interface DuckPlayer { | |
val privatePlayerMode: PrivatePlayerMode, | ||
) | ||
|
||
/** | ||
* Data class representing custom error settings for Duck Player. | ||
* | ||
* @property signInRequiredSelector A a CSS selector used in detecting a client-side sign-in error | ||
*/ | ||
data class CustomErrorSettings( | ||
val signInRequiredSelector: String, | ||
) | ||
|
||
enum class DuckPlayerState { | ||
ENABLED, | ||
DISABLED, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,12 @@ enum class DuckPlayerPixelName(override val pixelName: String) : Pixel.PixelName | |
DUCK_PLAYER_SETTINGS_PRESSED("duckplayer_setting_pressed"), | ||
DUCK_PLAYER_NEWTAB_SETTING_ON("duckplayer_newtab_setting-on"), | ||
DUCK_PLAYER_NEWTAB_SETTING_OFF("duckplayer_newtab_setting-off"), | ||
DUCK_PLAYER_YOUTUBE_ERROR_SIGN_IN_REQUIRED_IMPRESSION("duckplayer_youtube-signin-error_impression"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since these pixels are fired from the app module, they should be moved to AppPixelName. Other modules should never access the impl directly |
||
DUCK_PLAYER_YOUTUBE_ERROR_AGE_RESTRICTED_IMPRESSION("duckplayer_youtube-age-restricted-error_impression"), | ||
DUCK_PLAYER_YOUTUBE_ERROR_NO_EMBED_IMPRESSION("duckplayer_youtube-no-embed-error_impression"), | ||
DUCK_PLAYER_YOUTUBE_ERROR_UNKNOWN_IMPRESSION("duckplayer_youtube-unknown-error_impression"), | ||
DUCK_PLAYER_YOUTUBE_ERROR_SIGN_IN_REQUIRED_DAILY_UNIQUE("duckplayer_youtube-signin-error_daily-unique"), | ||
DUCK_PLAYER_YOUTUBE_ERROR_AGE_RESTRICTED_DAILY_UNIQUE("duckplayer_youtube-age-restricted-error_daily-unique"), | ||
DUCK_PLAYER_YOUTUBE_ERROR_NO_EMBED_DAILY_UNIQUE("duckplayer_youtube-no-embed-error_daily-unique"), | ||
DUCK_PLAYER_YOUTUBE_ERROR_UNKNOWN_DAILY_UNIQUE("duckplayer_youtube-unknown-error_daily-unique"), | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't pass this from native when CSS already has access to the RC JSON. See
DuckPlayerContentScopeConfigPlugin