Skip to content

Commit

Permalink
sitepermissions: Handle EME permission.
Browse files Browse the repository at this point in the history
This allows Fenix to play EME content without having to toggle manually
`media.eme.require-app-approval=false` in `about:config`.

Fixes mozilla-mobile#7121
  • Loading branch information
emilio committed Dec 3, 2020
1 parent bacdfa9 commit 2ec6361
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_AUTOPLAY
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_AUTOPLAY_INAUDIBLE
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_GEOLOCATION
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_MEDIA_KEY_SYSTEM_ACCESS
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_PERSISTENT_STORAGE
import java.util.UUID

Expand Down Expand Up @@ -59,7 +60,8 @@ sealed class GeckoPermissionRequest constructor(
PERMISSION_GEOLOCATION to Permission.ContentGeoLocation(),
PERMISSION_AUTOPLAY_AUDIBLE to Permission.ContentAutoPlayAudible(),
PERMISSION_AUTOPLAY_INAUDIBLE to Permission.ContentAutoPlayInaudible(),
PERMISSION_PERSISTENT_STORAGE to Permission.ContentPersistentStorage()
PERMISSION_PERSISTENT_STORAGE to Permission.ContentPersistentStorage(),
PERMISSION_MEDIA_KEY_SYSTEM_ACCESS to Permission.ContentMediaKeySystemAccess()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_AUTOPLAY
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_AUTOPLAY_INAUDIBLE
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_GEOLOCATION
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_MEDIA_KEY_SYSTEM_ACCESS
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_PERSISTENT_STORAGE
import java.util.UUID

Expand Down Expand Up @@ -59,7 +60,8 @@ sealed class GeckoPermissionRequest constructor(
PERMISSION_GEOLOCATION to Permission.ContentGeoLocation(),
PERMISSION_AUTOPLAY_AUDIBLE to Permission.ContentAutoPlayAudible(),
PERMISSION_AUTOPLAY_INAUDIBLE to Permission.ContentAutoPlayInaudible(),
PERMISSION_PERSISTENT_STORAGE to Permission.ContentPersistentStorage()
PERMISSION_PERSISTENT_STORAGE to Permission.ContentPersistentStorage(),
PERMISSION_MEDIA_KEY_SYSTEM_ACCESS to Permission.ContentMediaKeySystemAccess()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_AUTOPLAY
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_AUTOPLAY_INAUDIBLE
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_GEOLOCATION
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_MEDIA_KEY_SYSTEM_ACCESS
import org.mozilla.geckoview.GeckoSession.PermissionDelegate.PERMISSION_PERSISTENT_STORAGE
import java.util.UUID

Expand Down Expand Up @@ -59,7 +60,8 @@ sealed class GeckoPermissionRequest constructor(
PERMISSION_GEOLOCATION to Permission.ContentGeoLocation(),
PERMISSION_AUTOPLAY_AUDIBLE to Permission.ContentAutoPlayAudible(),
PERMISSION_AUTOPLAY_INAUDIBLE to Permission.ContentAutoPlayInaudible(),
PERMISSION_PERSISTENT_STORAGE to Permission.ContentPersistentStorage()
PERMISSION_PERSISTENT_STORAGE to Permission.ContentPersistentStorage(),
PERMISSION_MEDIA_KEY_SYSTEM_ACCESS to Permission.ContentMediaKeySystemAccess()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ sealed class Permission {
data class ContentAutoPlayAudible(override val id: String? = "", override val desc: String? = "") : Permission()
data class ContentAutoPlayInaudible(override val id: String? = "", override val desc: String? = "") : Permission()
data class ContentPersistentStorage(override val id: String? = "", override val desc: String? = "") : Permission()
data class ContentMediaKeySystemAccess(override val id: String? = "", override val desc: String? = "") : Permission()

data class AppCamera(override val id: String? = "", override val desc: String? = "") : Permission()
data class AppAudio(override val id: String? = "", override val desc: String? = "") : Permission()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "f5350dbda12da0f415e9d09d00c36f49",
"identityHash": "f5379c8eb4f1519eb5994e508626ca10",
"entities": [
{
"tableName": "site_permissions",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`origin` TEXT NOT NULL, `location` INTEGER NOT NULL, `notification` INTEGER NOT NULL, `microphone` INTEGER NOT NULL, `camera` INTEGER NOT NULL, `bluetooth` INTEGER NOT NULL, `local_storage` INTEGER NOT NULL, `autoplay_audible` INTEGER NOT NULL, `autoplay_inaudible` INTEGER NOT NULL, `saved_at` INTEGER NOT NULL, PRIMARY KEY(`origin`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`origin` TEXT NOT NULL, `location` INTEGER NOT NULL, `notification` INTEGER NOT NULL, `microphone` INTEGER NOT NULL, `camera` INTEGER NOT NULL, `bluetooth` INTEGER NOT NULL, `local_storage` INTEGER NOT NULL, `autoplay_audible` INTEGER NOT NULL, `autoplay_inaudible` INTEGER NOT NULL, `media_key_system_access` INTEGER NOT NULL, `saved_at` INTEGER NOT NULL, PRIMARY KEY(`origin`))",
"fields": [
{
"fieldPath": "origin",
Expand Down Expand Up @@ -62,6 +62,12 @@
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mediaKeySystemAccess",
"columnName": "media_key_system_access",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "savedAt",
"columnName": "saved_at",
Expand All @@ -82,7 +88,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f5350dbda12da0f415e9d09d00c36f49')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f5379c8eb4f1519eb5994e508626ca10')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data class SitePermissions(
val localStorage: Status = NO_DECISION,
val autoplayAudible: Status = NO_DECISION,
val autoplayInaudible: Status = NO_DECISION,
val mediaKeySystemAccess: Status = NO_DECISION,
val savedAt: Long
) : Parcelable {
enum class Status(
Expand Down Expand Up @@ -53,6 +54,7 @@ data class SitePermissions(
Permission.LOCATION -> location
Permission.AUTOPLAY_AUDIBLE -> autoplayAudible
Permission.AUTOPLAY_INAUDIBLE -> autoplayInaudible
Permission.MEDIA_KEY_SYSTEM_ACCESS -> mediaKeySystemAccess
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import mozilla.components.concept.engine.permission.Permission.ContentNotificati
import mozilla.components.concept.engine.permission.Permission.ContentVideoCamera
import mozilla.components.concept.engine.permission.Permission.ContentVideoCapture
import mozilla.components.concept.engine.permission.Permission.ContentPersistentStorage
import mozilla.components.concept.engine.permission.Permission.ContentMediaKeySystemAccess
import mozilla.components.concept.engine.permission.Permission.AppLocationCoarse
import mozilla.components.concept.engine.permission.Permission.AppLocationFine
import mozilla.components.concept.engine.permission.Permission.AppAudio
Expand Down Expand Up @@ -442,6 +443,9 @@ class SitePermissionsFeature(
is ContentPersistentStorage -> {
permissionFromStore.localStorage.doNotAskAgain()
}
is ContentMediaKeySystemAccess -> {
permissionFromStore.mediaKeySystemAccess.doNotAskAgain()
}
else -> false
}
}
Expand Down Expand Up @@ -503,6 +507,9 @@ class SitePermissionsFeature(
is ContentPersistentStorage -> {
sitePermissions.copy(localStorage = status)
}
is ContentMediaKeySystemAccess -> {
sitePermissions.copy(mediaKeySystemAccess = status)
}
else ->
throw InvalidParameterException("$permission is not a valid permission.")
}
Expand Down Expand Up @@ -596,6 +603,18 @@ class SitePermissionsFeature(
shouldSelectRememberChoice = true
)
}
is ContentMediaKeySystemAccess -> {
createSinglePermissionPrompt(
context,
host,
permissionRequest,
R.string.mozac_feature_sitepermissions_media_key_system_access_title,
// TODO: Do we want a different icon? Video seems close enough.
R.drawable.mozac_ic_video,
showDoNotAskAgainCheckBox = false,
shouldSelectRememberChoice = true
)
}
else ->
throw InvalidParameterException("$permission is not a valid permission.")
}
Expand Down Expand Up @@ -731,6 +750,9 @@ internal fun isPermissionGranted(
is ContentPersistentStorage -> {
permissionFromStorage.localStorage.isAllowed()
}
is ContentMediaKeySystemAccess -> {
permissionFromStorage.mediaKeySystemAccess.isAllowed()
}
else ->
throw InvalidParameterException("$permission is not a valid permission.")
}
Expand All @@ -743,7 +765,8 @@ private fun Permission.isSupported(): Boolean {
is ContentPersistentStorage,
is ContentAudioCapture, is ContentAudioMicrophone,
is ContentVideoCamera, is ContentVideoCapture,
is ContentAutoPlayAudible, is ContentAutoPlayInaudible -> true
is ContentAutoPlayAudible, is ContentAutoPlayInaudible,
is ContentMediaKeySystemAccess -> true
else -> false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import mozilla.components.feature.sitepermissions.SitePermissionsStorage.Permiss
import mozilla.components.feature.sitepermissions.SitePermissionsStorage.Permission.NOTIFICATION
import mozilla.components.feature.sitepermissions.SitePermissionsStorage.Permission.AUTOPLAY_AUDIBLE
import mozilla.components.feature.sitepermissions.SitePermissionsStorage.Permission.AUTOPLAY_INAUDIBLE
import mozilla.components.feature.sitepermissions.SitePermissionsStorage.Permission.MEDIA_KEY_SYSTEM_ACCESS
import mozilla.components.feature.sitepermissions.db.SitePermissionsDatabase
import mozilla.components.feature.sitepermissions.db.toSitePermissionsEntity

Expand Down Expand Up @@ -116,6 +117,7 @@ class SitePermissionsStorage(
map.putIfAllowed(LOCATION, location, permission)
map.putIfAllowed(AUTOPLAY_AUDIBLE, autoplayAudible, permission)
map.putIfAllowed(AUTOPLAY_INAUDIBLE, autoplayInaudible, permission)
map.putIfAllowed(MEDIA_KEY_SYSTEM_ACCESS, mediaKeySystemAccess, permission)
}
}
return map
Expand Down Expand Up @@ -173,6 +175,6 @@ class SitePermissionsStorage(

enum class Permission {
MICROPHONE, BLUETOOTH, CAMERA, LOCAL_STORAGE, NOTIFICATION, LOCATION, AUTOPLAY_AUDIBLE,
AUTOPLAY_INAUDIBLE
AUTOPLAY_INAUDIBLE, MEDIA_KEY_SYSTEM_ACCESS
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ internal data class SitePermissionsEntity(
@ColumnInfo(name = "autoplay_inaudible")
var autoplayInaudible: SitePermissions.Status,

@ColumnInfo(name = "media_key_system_access")
var mediaKeySystemAccess: SitePermissions.Status,

@ColumnInfo(name = "saved_at")
var savedAt: Long
) {
Expand All @@ -58,6 +61,7 @@ internal data class SitePermissionsEntity(
localStorage,
autoplayAudible,
autoplayInaudible,
mediaKeySystemAccess,
savedAt
)
}
Expand All @@ -74,6 +78,7 @@ internal fun SitePermissions.toSitePermissionsEntity(): SitePermissionsEntity {
localStorage,
autoplayAudible,
autoplayInaudible,
mediaKeySystemAccess,
savedAt
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@
<string name="mozac_feature_sitepermissions_never_allow">Never</string>
<!-- Title of a dialog to require to save data in persistent storage. %1$s will be replaced with the URL of the current page -->
<string name="mozac_feature_sitepermissions_persistent_storage_title">Allow %1$s to store data in persistent storage?</string>
</resources>
<!-- Title of a dialog to use EME. %1$s will be replaced with the URL of the current page -->
<string name="mozac_feature_sitepermissions_media_key_system_access_title">Allow %1$s to use EME?</string>
</resources>

0 comments on commit 2ec6361

Please sign in to comment.