@@ -65,14 +65,14 @@ public class SessionStack implements ContentBlocking.Delegate, GeckoSession.Navi
6565 private transient LinkedList <GeckoSession .ContentDelegate > mContentListeners ;
6666 private transient LinkedList <SessionChangeListener > mSessionChangeListeners ;
6767 private transient LinkedList <GeckoSession .TextInputDelegate > mTextInputListeners ;
68- private transient LinkedList <GeckoSession .PromptDelegate > mPromptListeners ;
6968 private transient LinkedList <VideoAvailabilityListener > mVideoAvailabilityListeners ;
7069 private transient UserAgentOverride mUserAgentOverride ;
7170
7271 private transient GeckoSession mCurrentSession ;
7372 private HashMap <Integer , SessionState > mSessions ;
7473 private Deque <Integer > mSessionsStack ;
7574 private transient GeckoSession .PermissionDelegate mPermissionDelegate ;
75+ private transient GeckoSession .PromptDelegate mPromptDelegate ;
7676 private int mPreviousGeckoSessionId = NO_SESSION ;
7777 private String mRegion ;
7878 private transient Context mContext ;
@@ -91,7 +91,6 @@ protected SessionStack(Context context, GeckoRuntime runtime, boolean usePrivate
9191 mContentListeners = new LinkedList <>();
9292 mSessionChangeListeners = new LinkedList <>();
9393 mTextInputListeners = new LinkedList <>();
94- mPromptListeners = new LinkedList <>();
9594 mVideoAvailabilityListeners = new LinkedList <>();
9695
9796 if (mPrefs != null ) {
@@ -201,6 +200,13 @@ public void setPermissionDelegate(GeckoSession.PermissionDelegate aDelegate) {
201200 }
202201 }
203202
203+ public void setPromptDelegate (GeckoSession .PromptDelegate aDelegate ) {
204+ mPromptDelegate = aDelegate ;
205+ for (HashMap .Entry <Integer , SessionState > entry : mSessions .entrySet ()) {
206+ entry .getValue ().mSession .setPromptDelegate (aDelegate );
207+ }
208+ }
209+
204210 public void addNavigationListener (GeckoSession .NavigationDelegate aListener ) {
205211 mNavigationListeners .add (aListener );
206212 dumpState (mCurrentSession , aListener );
@@ -244,14 +250,6 @@ public void removeTextInputListener(GeckoSession.TextInputDelegate aListener) {
244250 mTextInputListeners .remove (aListener );
245251 }
246252
247- public void addPromptListener (GeckoSession .PromptDelegate aListener ) {
248- mPromptListeners .add (aListener );
249- }
250-
251- public void removePromptListener (GeckoSession .PromptDelegate aListener ) {
252- mPromptListeners .remove (aListener );
253- }
254-
255253 public void addVideoAvailabilityListener (VideoAvailabilityListener aListener ) {
256254 mVideoAvailabilityListeners .add (aListener );
257255 }
@@ -300,10 +298,10 @@ public void restore(SessionStack store, int currentSessionId) {
300298
301299 state .mSession .setNavigationDelegate (this );
302300 state .mSession .setProgressDelegate (this );
303- state .mSession .setPromptDelegate (this );
304301 state .mSession .setContentDelegate (this );
305302 state .mSession .getTextInput ().setDelegate (this );
306303 state .mSession .setPermissionDelegate (mPermissionDelegate );
304+ state .mSession .setPromptDelegate (mPromptDelegate );
307305 state .mSession .setContentBlockingDelegate (this );
308306 state .mSession .setMediaDelegate (this );
309307 for (SessionChangeListener listener : mSessionChangeListeners ) {
@@ -360,10 +358,10 @@ private int createSession(@NonNull SessionSettings aSettings) {
360358 state .mSession .getSettings ().setUserAgentMode (aSettings .getUserAgentMode ());
361359 state .mSession .setNavigationDelegate (this );
362360 state .mSession .setProgressDelegate (this );
363- state .mSession .setPromptDelegate (this );
364361 state .mSession .setContentDelegate (this );
365362 state .mSession .getTextInput ().setDelegate (this );
366363 state .mSession .setPermissionDelegate (mPermissionDelegate );
364+ state .mSession .setPromptDelegate (mPromptDelegate );
367365 state .mSession .setContentBlockingDelegate (this );
368366 state .mSession .setMediaDelegate (this );
369367 for (SessionChangeListener listener : mSessionChangeListeners ) {
@@ -1149,100 +1147,95 @@ public void updateCursorAnchorInfo(@NonNull GeckoSession aSession, @NonNull Curs
11491147
11501148 @ Override
11511149 public void onContentBlocked (@ NonNull final GeckoSession session , @ NonNull final ContentBlocking .BlockEvent event ) {
1152- if ((event .categories & ContentBlocking .AT_AD ) != 0 ) {
1150+ if ((event .getAntiTrackingCategory () & ContentBlocking .AntiTracking . AD ) != 0 ) {
11531151 Log .i (LOGTAG , "Blocking Ad: " + event .uri );
11541152 }
11551153
1156- if ((event .categories & ContentBlocking .AT_ANALYTIC ) != 0 ) {
1154+ if ((event .getAntiTrackingCategory () & ContentBlocking .AntiTracking . ANALYTIC ) != 0 ) {
11571155 Log .i (LOGTAG , "Blocking Analytic: " + event .uri );
11581156 }
11591157
1160- if ((event .categories & ContentBlocking .AT_CONTENT ) != 0 ) {
1158+ if ((event .getAntiTrackingCategory () & ContentBlocking .AntiTracking . CONTENT ) != 0 ) {
11611159 Log .i (LOGTAG , "Blocking Content: " + event .uri );
11621160 }
11631161
1164- if ((event .categories & ContentBlocking .AT_SOCIAL ) != 0 ) {
1162+ if ((event .getAntiTrackingCategory () & ContentBlocking .AntiTracking . SOCIAL ) != 0 ) {
11651163 Log .i (LOGTAG , "Blocking Social: " + event .uri );
11661164 }
11671165 }
11681166
11691167 // PromptDelegate
11701168
1169+ @ Nullable
11711170 @ Override
1172- public void onAlert (@ NonNull GeckoSession session , String title , String msg , @ NonNull AlertCallback callback ) {
1173- if (session == mCurrentSession ) {
1174- for (GeckoSession .PromptDelegate listener : mPromptListeners ) {
1175- listener .onAlert (session , title , msg , callback );
1176- }
1177- }
1178- }
1171+ public GeckoResult <PromptResponse > onAlertPrompt (@ NonNull GeckoSession geckoSession , @ NonNull AlertPrompt alertPrompt ) {
1172+ if (mPromptDelegate != null )
1173+ return mPromptDelegate .onAlertPrompt (geckoSession , alertPrompt );
11791174
1180- @ Override
1181- public void onButtonPrompt (@ NonNull GeckoSession session , String title , String msg , String [] btnMsg , @ NonNull ButtonCallback callback ) {
1182- if (session == mCurrentSession ) {
1183- for (GeckoSession .PromptDelegate listener : mPromptListeners ) {
1184- listener .onButtonPrompt (session , title , msg , btnMsg , callback );
1185- }
1186- }
1175+ return GeckoResult .fromValue (alertPrompt .dismiss ());
11871176 }
11881177
1178+ @ Nullable
11891179 @ Override
1190- public void onTextPrompt (@ NonNull GeckoSession session , String title , String msg , String value , @ NonNull TextCallback callback ) {
1191- if (session == mCurrentSession ) {
1192- for (GeckoSession .PromptDelegate listener : mPromptListeners ) {
1193- listener .onTextPrompt (session , title , msg , value , callback );
1194- }
1195- }
1180+ public GeckoResult <PromptResponse > onButtonPrompt (@ NonNull GeckoSession geckoSession , @ NonNull ButtonPrompt buttonPrompt ) {
1181+ if (mPromptDelegate != null )
1182+ return mPromptDelegate .onButtonPrompt (geckoSession , buttonPrompt );
1183+
1184+ return GeckoResult .fromValue (buttonPrompt .dismiss ());
11961185 }
11971186
1187+ @ Nullable
11981188 @ Override
1199- public void onAuthPrompt (@ NonNull GeckoSession session , String title , String msg , @ NonNull AuthOptions options , @ NonNull AuthCallback callback ) {
1200- if (session == mCurrentSession ) {
1201- for (GeckoSession .PromptDelegate listener : mPromptListeners ) {
1202- listener .onAuthPrompt (session , title , msg , options , callback );
1203- }
1204- }
1189+ public GeckoResult <PromptResponse > onTextPrompt (@ NonNull GeckoSession geckoSession , @ NonNull TextPrompt textPrompt ) {
1190+ if (mPromptDelegate != null )
1191+ return mPromptDelegate .onTextPrompt (geckoSession , textPrompt );
1192+
1193+ return GeckoResult .fromValue (textPrompt .dismiss ());
12051194 }
12061195
1196+ @ Nullable
12071197 @ Override
1208- public void onChoicePrompt (@ NonNull GeckoSession session , String title , String msg , int type , @ NonNull Choice [] choices , @ NonNull ChoiceCallback callback ) {
1209- if (session == mCurrentSession ) {
1210- for (GeckoSession .PromptDelegate listener : mPromptListeners ) {
1211- listener .onChoicePrompt (session , title , msg , type , choices , callback );
1212- }
1213- }
1198+ public GeckoResult <PromptResponse > onAuthPrompt (@ NonNull GeckoSession geckoSession , @ NonNull AuthPrompt authPrompt ) {
1199+ if (mPromptDelegate != null )
1200+ return mPromptDelegate .onAuthPrompt (geckoSession , authPrompt );
1201+
1202+ return GeckoResult .fromValue (authPrompt .dismiss ());
12141203 }
12151204
1205+ @ Nullable
12161206 @ Override
1217- public void onColorPrompt (@ NonNull GeckoSession session , String title , String value , @ NonNull TextCallback callback ) {
1218- if (session == mCurrentSession ) {
1219- for (GeckoSession .PromptDelegate listener : mPromptListeners ) {
1220- listener .onColorPrompt (session , title , value , callback );
1221- }
1222- }
1207+ public GeckoResult <PromptResponse > onChoicePrompt (@ NonNull GeckoSession geckoSession , @ NonNull ChoicePrompt choicePrompt ) {
1208+ if (mPromptDelegate != null )
1209+ return mPromptDelegate .onChoicePrompt (geckoSession , choicePrompt );
1210+
1211+ return GeckoResult .fromValue (choicePrompt .dismiss ());
12231212 }
12241213
1214+ @ Nullable
12251215 @ Override
1226- public void onDateTimePrompt (@ NonNull GeckoSession session , String title , int type , String value , String min , String max , @ NonNull TextCallback callback ) {
1227- if (session == mCurrentSession ) {
1228- for (GeckoSession .PromptDelegate listener : mPromptListeners ) {
1229- listener .onDateTimePrompt (session , title , type , value , min , max , callback );
1230- }
1231- }
1216+ public GeckoResult <PromptResponse > onColorPrompt (@ NonNull GeckoSession geckoSession , @ NonNull ColorPrompt colorPrompt ) {
1217+ if (mPromptDelegate != null )
1218+ return mPromptDelegate .onColorPrompt (geckoSession , colorPrompt );
1219+
1220+ return GeckoResult .fromValue (colorPrompt .dismiss ());
12321221 }
12331222
1223+ @ Nullable
12341224 @ Override
1235- public void onFilePrompt (@ NonNull GeckoSession session , String title , int type , String [] mimeTypes , int capture , @ NonNull FileCallback callback ) {
1236- if (session == mCurrentSession ) {
1237- for (GeckoSession .PromptDelegate listener : mPromptListeners ) {
1238- listener .onFilePrompt (session , title , type , mimeTypes , capture , callback );
1239- }
1240- }
1225+ public GeckoResult <PromptResponse > onDateTimePrompt (@ NonNull GeckoSession geckoSession , @ NonNull DateTimePrompt dateTimePrompt ) {
1226+ if (mPromptDelegate != null )
1227+ return mPromptDelegate .onDateTimePrompt (geckoSession , dateTimePrompt );
1228+
1229+ return GeckoResult .fromValue (dateTimePrompt .dismiss ());
12411230 }
12421231
1232+ @ Nullable
12431233 @ Override
1244- public GeckoResult <AllowOrDeny > onPopupRequest (@ NonNull final GeckoSession session , final String targetUri ) {
1245- return GeckoResult .fromValue (AllowOrDeny .DENY );
1234+ public GeckoResult <PromptResponse > onFilePrompt (@ NonNull GeckoSession geckoSession , @ NonNull FilePrompt filePrompt ) {
1235+ if (mPromptDelegate != null )
1236+ return mPromptDelegate .onFilePrompt (geckoSession , filePrompt );
1237+
1238+ return GeckoResult .fromValue (filePrompt .dismiss ());
12461239 }
12471240
12481241 // MediaDelegate
0 commit comments