Skip to content

Commit

Permalink
Show DRM first time dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Apr 7, 2020
1 parent ef823f0 commit 78e7c4d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WindowWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.PermissionWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.PromptDialogWidget;
import org.mozilla.vrbrowser.utils.SystemUtils;
import org.mozilla.vrbrowser.utils.UrlUtils;

Expand Down Expand Up @@ -178,10 +179,29 @@ public void onContentPermissionRequest(GeckoSession aSession, String aUri, int a
} else if (aType == PERMISSION_GEOLOCATION) {
type = PermissionWidget.PermissionType.Location;
} else if (aType == PERMISSION_MEDIA_KEY_SYSTEM_ACCESS) {
if (SettingsStore.getInstance(mContext).isDrmContentPlaybackEnabled()) {
callback.grant();
Runnable enableDrm = () -> {
if (SettingsStore.getInstance(mContext).isDrmContentPlaybackEnabled()) {
callback.grant();
} else {
callback.reject();
}
};
if (SettingsStore.getInstance(mContext).isDrmContentPlaybackSet()) {
enableDrm.run();

} else {
callback.reject();
mWidgetManager.getFocusedWindow().showConfirmPrompt(
mContext.getString(R.string.drm_first_use_title),
mContext.getString(R.string.drm_first_use_body),
new String[]{
mContext.getString(R.string.drm_first_use_do_not_enable),
mContext.getString(R.string.drm_first_use_enable),
},
index -> {
SettingsStore.getInstance(mContext).setDrmContentPlaybackEnabled(index == PromptDialogWidget.POSITIVE);
enableDrm.run();
}
);
}
mWidgetManager.getFocusedWindow().setDrmUsed(true);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ public boolean isDrmContentPlaybackEnabled() {
mContext.getString(R.string.settings_key_drm_playback), DRM_PLAYBACK_DEFAULT);
}

public boolean isDrmContentPlaybackSet() {
return mPrefs.contains(mContext.getString(R.string.settings_key_drm_playback));
}

public void setDrmContentPlaybackEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_drm_playback), isEnabled);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/navigation_url.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
app:visibleGone="@{settingsViewmodel.isDrmEnabled && viewmodel.isDrmUsed}">
app:visibleGone="@{viewmodel.isDrmUsed}">
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1510,4 +1510,20 @@ the Select` button. When clicked it closes all the previously selected tabs -->

<!-- This string is displayed in the switch button of the quick DRM dialog when it's in disabled state. It's accessed from the DRM icon in the URL bar. -->
<string name="drm_dialog_button_not_allow">Don\'t Allow</string>

<!-- This string is displayed as the title of a dialog that is displayed the first time a user access DRM content if they haven't
explicitly enable/Disable the DRM setting yet. -->
<string name="drm_first_use_title">DRM</string>

<!-- This string is displayed as the body of a dialog that is displayed the first time a user access DRM content if they haven't
explicitly enable/Disable the DRM setting yet. -->
<string name="drm_first_use_body">You need to enable DRM to play some audio or video on this page</string>

<!-- This string is displayed in the do not enable button that is displayed inside the dialog that is displayed the first time a user access
access DRM content if they haven't explicitly enable/Disable the DRM setting yet. -->
<string name="drm_first_use_do_not_enable">Don\'t enable</string>

<!-- This string is displayed in the enable button that is displayed inside the dialog that is displayed the first time a user access
access DRM content if they haven't explicitly enable/Disable the DRM setting yet. -->
<string name="drm_first_use_enable">Enable</string>
</resources>

0 comments on commit 78e7c4d

Please sign in to comment.