2626import android .view .inputmethod .EditorInfo ;
2727import android .view .inputmethod .InputConnection ;
2828
29+ import androidx .annotation .DrawableRes ;
2930import androidx .annotation .IntDef ;
3031import androidx .annotation .NonNull ;
3132import androidx .annotation .Nullable ;
@@ -86,7 +87,7 @@ public class WindowWidget extends UIWidget implements SessionChangeListener,
8687 GeckoSession .ContentDelegate , GeckoSession .NavigationDelegate , VideoAvailabilityListener ,
8788 GeckoSession .HistoryDelegate , GeckoSession .ProgressDelegate , GeckoSession .SelectionActionDelegate ,
8889 Session .WebXRStateChangedListener , Session .PopUpStateChangedListener ,
89- SharedPreferences .OnSharedPreferenceChangeListener {
90+ Session . DrmStateChangedListener , SharedPreferences .OnSharedPreferenceChangeListener {
9091
9192 @ IntDef (value = { SESSION_RELEASE_DISPLAY , SESSION_DO_NOT_RELEASE_DISPLAY })
9293 public @interface OldSessionDisplayAction {}
@@ -256,6 +257,7 @@ void setupListeners(Session aSession) {
256257 aSession .addSelectionActionListener (this );
257258 aSession .addWebXRStateChangedListener (this );
258259 aSession .addPopUpStateChangedListener (this );
260+ aSession .addDrmStateChangedListener (this );
259261 }
260262
261263 void cleanListeners (Session aSession ) {
@@ -268,6 +270,7 @@ void cleanListeners(Session aSession) {
268270 aSession .removeSelectionActionListener (this );
269271 aSession .removeWebXRStateChangedListener (this );
270272 aSession .removePopUpStateChangedListener (this );
273+ aSession .removeDrmStateChangedListener (this );
271274 }
272275
273276 @ Override
@@ -1266,46 +1269,73 @@ public void showAlert(String title, @NonNull String msg, @Nullable PromptDialogW
12661269 mAlertDialog .releaseWidget ();
12671270 mAlertDialog = null ;
12681271 });
1272+ mAlertDialog .setLinkDelegate ((widget , url ) -> {
1273+ mWidgetManager .openNewTabForeground (url );
1274+ mAlertDialog .hide (REMOVE_WIDGET );
1275+ mAlertDialog .releaseWidget ();
1276+ mAlertDialog = null ;
1277+ });
12691278 mAlertDialog .show (REQUEST_FOCUS );
12701279 }
12711280
1272- public void showConfirmPrompt (String title , @ NonNull String msg , @ NonNull String [] btnMsg , @ Nullable PromptDialogWidget .Delegate callback ) {
1273- if (mConfirmDialog == null ) {
1274- mConfirmDialog = new PromptDialogWidget (getContext ());
1275- mConfirmDialog .setButtons (new int [] {
1276- R .string .cancel_button ,
1277- R .string .ok_button
1278- });
1279- mConfirmDialog .setCheckboxVisible (false );
1280- mConfirmDialog .setDescriptionVisible (false );
1281- }
1282- mConfirmDialog .setTitle (title );
1283- mConfirmDialog .setBody (msg );
1284- mConfirmDialog .setButtons (btnMsg );
1285- mConfirmDialog .setButtonsDelegate (index -> {
1286- mConfirmDialog .hide (REMOVE_WIDGET );
1287- if (callback != null ) {
1288- callback .onButtonClicked (index );
1289- }
1290- mConfirmDialog .releaseWidget ();
1291- mConfirmDialog = null ;
1292- });
1293- mConfirmDialog .show (REQUEST_FOCUS );
1281+ public void showConfirmPrompt (@ NonNull String title ,
1282+ @ NonNull String msg ,
1283+ @ NonNull String [] btnMsg ,
1284+ @ Nullable PromptDialogWidget .Delegate callback ) {
1285+ showConfirmPrompt (-1 ,
1286+ title ,
1287+ msg ,
1288+ btnMsg ,
1289+ null ,
1290+ callback );
1291+ }
1292+
1293+ public void showConfirmPrompt (@ DrawableRes int icon ,
1294+ @ NonNull String title ,
1295+ @ NonNull String msg ,
1296+ @ NonNull String [] btnMsg ,
1297+ @ Nullable PromptDialogWidget .Delegate callback ) {
1298+ showConfirmPrompt (icon ,
1299+ title ,
1300+ msg ,
1301+ btnMsg ,
1302+ null ,
1303+ callback );
12941304 }
12951305
12961306 public void showConfirmPrompt (@ NonNull String title ,
12971307 @ NonNull String msg ,
12981308 @ NonNull String [] btnMsg ,
12991309 @ NonNull String checkBoxText ,
13001310 @ Nullable PromptDialogWidget .Delegate callback ) {
1311+ showConfirmPrompt (-1 ,
1312+ title ,
1313+ msg ,
1314+ btnMsg ,
1315+ checkBoxText ,
1316+ callback );
1317+ }
1318+
1319+ public void showConfirmPrompt (@ DrawableRes int icon ,
1320+ @ NonNull String title ,
1321+ @ NonNull String msg ,
1322+ @ NonNull String [] btnMsg ,
1323+ @ Nullable String checkBoxText ,
1324+ @ Nullable PromptDialogWidget .Delegate callback ) {
13011325 if (mConfirmDialog == null ) {
13021326 mConfirmDialog = new PromptDialogWidget (getContext ());
13031327 mConfirmDialog .setButtons (new int [] {
13041328 R .string .cancel_button ,
13051329 R .string .ok_button
13061330 });
1307- mConfirmDialog .setCheckboxVisible (true );
1308- mConfirmDialog .setCheckboxText (checkBoxText );
1331+ mConfirmDialog .setCheckboxVisible (false );
1332+ if (checkBoxText != null ) {
1333+ mConfirmDialog .setCheckboxVisible (true );
1334+ mConfirmDialog .setCheckboxText (checkBoxText );
1335+ }
1336+ if (icon != -1 ) {
1337+ mConfirmDialog .setIcon (icon );
1338+ }
13091339 mConfirmDialog .setDescriptionVisible (false );
13101340 }
13111341 mConfirmDialog .setTitle (title );
@@ -1319,10 +1349,16 @@ public void showConfirmPrompt(@NonNull String title,
13191349 mConfirmDialog .releaseWidget ();
13201350 mConfirmDialog = null ;
13211351 });
1352+ mConfirmDialog .setLinkDelegate ((widget , url ) -> {
1353+ mWidgetManager .openNewTabForeground (url );
1354+ mConfirmDialog .hide (REMOVE_WIDGET );
1355+ mConfirmDialog .releaseWidget ();
1356+ mConfirmDialog = null ;
1357+ });
13221358 mConfirmDialog .show (REQUEST_FOCUS );
13231359 }
13241360
1325- public void showDialog (@ NonNull String title , @ NonNull @ StringRes int description , @ NonNull @ StringRes int [] btnMsg ,
1361+ public void showDialog (@ NonNull String title , @ StringRes int description , @ NonNull @ StringRes int [] btnMsg ,
13261362 @ Nullable PromptDialogWidget .Delegate buttonsCallback , @ Nullable Runnable linkCallback ) {
13271363 mAppDialog = new PromptDialogWidget (getContext ());
13281364 mAppDialog .setIconVisible (false );
@@ -1338,7 +1374,8 @@ public void showDialog(@NonNull String title, @NonNull @StringRes int descripti
13381374 }
13391375 mAppDialog .releaseWidget ();
13401376 });
1341- mAppDialog .setLinkDelegate (() -> {
1377+ mConfirmDialog .setLinkDelegate ((widget , url ) -> {
1378+ mWidgetManager .openNewTabForeground (url );
13421379 mAppDialog .hide (REMOVE_WIDGET );
13431380 if (linkCallback != null ) {
13441381 linkCallback .run ();
@@ -1351,11 +1388,12 @@ public void showDialog(@NonNull String title, @NonNull @StringRes int descripti
13511388
13521389 public void showFirstTimeDrmDialog (@ NonNull Runnable callback ) {
13531390 showConfirmPrompt (
1354- getContext ().getString (R .string .drm_first_use_title ),
1355- getContext ().getString (R .string .drm_first_use_body ),
1391+ R .drawable .ic_icon_drm_allowed ,
1392+ getContext ().getString (R .string .drm_first_use_title_v1 ),
1393+ getContext ().getString (R .string .drm_first_use_body_v1 , getResources ().getString (R .string .sumo_drm_url )),
13561394 new String []{
1357- getContext ().getString (R .string .drm_first_use_do_not_enable ),
1358- getContext ().getString (R .string .drm_first_use_enable ),
1395+ getContext ().getString (R .string .drm_first_use_do_not_allow ),
1396+ getContext ().getString (R .string .drm_first_use_allow ),
13591397 },
13601398 index -> {
13611399 // We remove the prefs listener before the first DRM update to avoid reloading the session
@@ -1493,6 +1531,7 @@ public void startDownload(@NonNull DownloadJob downloadJob, boolean showConfirmD
14931531 Runnable download = () -> {
14941532 if (showConfirmDialog ) {
14951533 mWidgetManager .getFocusedWindow ().showConfirmPrompt (
1534+ R .drawable .ic_icon_downloads ,
14961535 getResources ().getString (R .string .download_confirm_title ),
14971536 downloadJob .getFilename (),
14981537 new String []{
@@ -1988,4 +2027,12 @@ public void onPopUpStateChanged(Session aSession, @SessionState.PopupState int a
19882027 mViewModel .setIsPopUpBlocked (aPopUpState == SessionState .POPUP_BLOCKED );
19892028 mViewModel .setIsPopUpAvailable (aPopUpState != SessionState .POPUP_UNUSED );
19902029 }
2030+
2031+ // DrmStateChangedListener
2032+
2033+ @ Override
2034+ public void onDrmStateChanged (Session aSession , @ SessionState .DrmState int aDrmState ) {
2035+ mViewModel .setIsDrmUsed (aDrmState == SessionState .DRM_BLOCKED ||
2036+ aDrmState == SessionState .DRM_ALLOWED );
2037+ }
19912038}
0 commit comments