Skip to content

Commit

Permalink
Add EME permission to SitePermissionsRules.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Dec 4, 2020
1 parent 71b6249 commit 55ea2ce
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ data class SitePermissionsRules internal constructor(
val microphone: Action,
val autoplayAudible: Action,
val autoplayInaudible: Action,
val persistentStorage: Action
val persistentStorage: Action,
val mediaKeySystemAccess: Action
) {

constructor(
Expand All @@ -29,15 +30,17 @@ data class SitePermissionsRules internal constructor(
microphone: Action,
autoplayAudible: AutoplayAction,
autoplayInaudible: AutoplayAction,
persistentStorage: Action
persistentStorage: Action,
mediaKeySystemAccess: Action
) : this(
camera = camera,
location = location,
notification = notification,
microphone = microphone,
autoplayAudible = autoplayAudible.toAction(),
autoplayInaudible = autoplayInaudible.toAction(),
persistentStorage = persistentStorage
persistentStorage = persistentStorage,
mediaKeySystemAccess = mediaKeySystemAccess
)

enum class Action {
Expand Down Expand Up @@ -93,6 +96,9 @@ data class SitePermissionsRules internal constructor(
is Permission.ContentAutoPlayInaudible -> {
autoplayInaudible
}
is Permission.ContentMediaKeySystemAccess -> {
mediaKeySystemAccess
}
else -> ASK_TO_ALLOW
}
}
Expand All @@ -118,6 +124,7 @@ data class SitePermissionsRules internal constructor(
autoplayAudible = autoplayAudible.toStatus(),
autoplayInaudible = autoplayInaudible.toStatus(),
localStorage = persistentStorage.toStatus(),
mediaKeySystemAccess = mediaKeySystemAccess.toStatus(),
savedAt = savedAt
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,8 @@ class SitePermissionsFeatureTest {
microphone = SitePermissionsRules.Action.BLOCKED,
autoplayAudible = SitePermissionsRules.Action.BLOCKED,
autoplayInaudible = SitePermissionsRules.Action.ALLOWED,
persistentStorage = SitePermissionsRules.Action.BLOCKED
persistentStorage = SitePermissionsRules.Action.BLOCKED,
mediaKeySystemAccess = SitePermissionsRules.Action.ASK_TO_ALLOW
)

sitePermissionFeature.sitePermissionsRules = rules
Expand All @@ -787,6 +788,7 @@ class SitePermissionsFeatureTest {
assertEquals(BLOCKED, sitePermissions.autoplayAudible)
assertEquals(ALLOWED, sitePermissions.autoplayInaudible)
assertEquals(BLOCKED, sitePermissions.localStorage)
assertEquals(NO_DECISION, sitePermissions.mediaKeySystemAccess)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class SitePermissionsRulesTest {
microphone = BLOCKED,
autoplayAudible = ASK_TO_ALLOW,
autoplayInaudible = BLOCKED,
persistentStorage = BLOCKED
persistentStorage = BLOCKED,
mediaKeySystemAccess = ASK_TO_ALLOW
)

val mockRequest: PermissionRequest = mock()
Expand Down Expand Up @@ -101,6 +102,10 @@ class SitePermissionsRulesTest {
doReturn(listOf(Permission.ContentPersistentStorage())).`when`(mockRequest).permissions
action = rules.getActionFrom(mockRequest)
assertEquals(action, rules.persistentStorage)

doReturn(listOf(Permission.ContentMediaKeySystemAccess())).`when`(mockRequest).permissions
action = rules.getActionFrom(mockRequest)
assertEquals(action, rules.mediaKeySystemAccess)
}

@Test
Expand All @@ -112,7 +117,8 @@ class SitePermissionsRulesTest {
notification = ASK_TO_ALLOW,
microphone = BLOCKED,
autoplayInaudible = ASK_TO_ALLOW,
autoplayAudible = ASK_TO_ALLOW
autoplayAudible = ASK_TO_ALLOW,
mediaKeySystemAccess = ASK_TO_ALLOW
)

val mockRequest: PermissionRequest = mock()
Expand All @@ -128,7 +134,8 @@ class SitePermissionsRulesTest {
microphone = ASK_TO_ALLOW,
autoplayInaudible = BLOCKED,
autoplayAudible = BLOCKED,
persistentStorage = BLOCKED
persistentStorage = BLOCKED,
mediaKeySystemAccess = ASK_TO_ALLOW
)

action = rules.getActionFrom(mockRequest)
Expand All @@ -146,6 +153,7 @@ class SitePermissionsRulesTest {
microphone = Status.BLOCKED,
autoplayInaudible = Status.NO_DECISION,
autoplayAudible = Status.NO_DECISION,
mediaKeySystemAccess = Status.BLOCKED,
savedAt = 1L
)

Expand All @@ -156,7 +164,8 @@ class SitePermissionsRulesTest {
microphone = BLOCKED,
autoplayInaudible = ASK_TO_ALLOW,
autoplayAudible = ASK_TO_ALLOW,
persistentStorage = BLOCKED
persistentStorage = BLOCKED,
mediaKeySystemAccess = BLOCKED
)

val convertedSitePermissions = rules.toSitePermissions(origin = "origin", savedAt = 1L)
Expand All @@ -169,6 +178,7 @@ class SitePermissionsRulesTest {
assertEquals(expectedSitePermission.autoplayInaudible, convertedSitePermissions.autoplayInaudible)
assertEquals(expectedSitePermission.autoplayAudible, convertedSitePermissions.autoplayAudible)
assertEquals(expectedSitePermission.localStorage, convertedSitePermissions.localStorage)
assertEquals(expectedSitePermission.mediaKeySystemAccess, convertedSitePermissions.mediaKeySystemAccess)
assertEquals(expectedSitePermission.savedAt, convertedSitePermissions.savedAt)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SitePermissionEntityTest {
assertEquals(bluetooth, domainClass.bluetooth)
assertEquals(autoplayAudible, domainClass.autoplayAudible)
assertEquals(autoplayInaudible, domainClass.autoplayInaudible)
assertEquals(mediaKeySystemAccess, domainClass.mediaKeySystemAccess)
assertEquals(savedAt, domainClass.savedAt)
}
}
Expand All @@ -55,6 +56,9 @@ class SitePermissionEntityTest {
microphone = NO_DECISION,
camera = NO_DECISION,
bluetooth = ALLOWED,
autoplayInaudible = BLOCKED,
autoplayAudible = NO_DECISION,
mediaKeySystemAccess = NO_DECISION,
savedAt = 0
)

Expand All @@ -68,6 +72,9 @@ class SitePermissionEntityTest {
assertEquals(microphone, domainClass.microphone)
assertEquals(camera, domainClass.camera)
assertEquals(bluetooth, domainClass.bluetooth)
assertEquals(autoplayAudible, domainClass.autoplayAudible)
assertEquals(autoplayInaudible, domainClass.autoplayInaudible)
assertEquals(mediaKeySystemAccess, domainClass.mediaKeySystemAccess)
assertEquals(savedAt, domainClass.savedAt)
}
}
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ permalink: /changelog/
* **feature-search**
* ⚠️ **This is a breaking change**: Use cases in `SearchUseCases` now take the ID of s session/tab as parameter instead of a `Session` instance.

* **feature-sitepermissions**
* ⚠️ **This is a breaking change**: The `SitePermissionsRules` constructor, now requires a new parameter `mediaKeySystemAccess`.
* 🌟 Added support for EME permission prompts, see [#3153](https://github.com/mozilla-mobile/android-components/issues/7121).

# 68.0.0

* [Commits](https://github.com/mozilla-mobile/android-components/compare/v67.0.0...v68.0.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler {
location = SitePermissionsRules.Action.ASK_TO_ALLOW,
notification = SitePermissionsRules.Action.ASK_TO_ALLOW,
microphone = SitePermissionsRules.Action.ASK_TO_ALLOW,
persistentStorage = SitePermissionsRules.Action.ASK_TO_ALLOW
persistentStorage = SitePermissionsRules.Action.ASK_TO_ALLOW,
mediaKeySystemAccess = SitePermissionsRules.Action.ASK_TO_ALLOW
),
onNeedToRequestPermissions = { permissions ->
requestPermissions(permissions, REQUEST_CODE_APP_PERMISSIONS)
Expand Down

0 comments on commit 55ea2ce

Please sign in to comment.