Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

New Prompt API #1560

Merged
merged 1 commit into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import org.mozilla.vrbrowser.crashreporting.CrashReporterService;
import org.mozilla.vrbrowser.crashreporting.GlobalExceptionHandler;
import org.mozilla.vrbrowser.geolocation.GeolocationWrapper;
import org.mozilla.vrbrowser.ui.widgets.prompts.AlertPromptWidget;
import org.mozilla.vrbrowser.ui.widgets.prompts.ConfirmPromptWidget;
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.input.MotionEventGenerator;
import org.mozilla.vrbrowser.search.SearchEngineWrapper;
Expand Down Expand Up @@ -900,12 +902,10 @@ private void setDeviceType(int aType) {
private void haltActivity(final int aReason) {
runOnUiThread(() -> {
if (mConnectionAvailable && mWindows.getFocusedWindow() != null) {
mWindows.getFocusedWindow().showAlert(getString(R.string.not_entitled_title), getString(R.string.not_entitled_message, getString(R.string.app_name)), new GeckoSession.PromptDelegate.AlertCallback() {
@Override
public void dismiss() {
VRBrowserActivity.this.finish();
}
});
mWindows.getFocusedWindow().showAlert(
getString(R.string.not_entitled_title),
getString(R.string.not_entitled_message, getString(R.string.app_name)),
() -> VRBrowserActivity.this.finish());
}
});
}
Expand All @@ -930,15 +930,20 @@ private void handlePoorPerformance() {
return;
}
window.getSessionStack().loadUri("about:blank");
final String[] buttons = {getString(R.string.ok_button), null, getString(R.string.performance_unblock_page)};
window.showButtonPrompt(getString(R.string.performance_title), getString(R.string.performance_message), buttons, new GeckoSession.PromptDelegate.ButtonCallback() {
final String[] buttons = {getString(R.string.ok_button), getString(R.string.performance_unblock_page)};
window.showButtonPrompt(getString(R.string.performance_title), getString(R.string.performance_message), buttons, new ConfirmPromptWidget.ConfirmPromptDelegate() {
@Override
public void confirm(int button) {
if (button == GeckoSession.PromptDelegate.BUTTON_TYPE_NEGATIVE) {
public void confirm(int index) {
if (index == GeckoSession.PromptDelegate.ButtonPrompt.Type.NEGATIVE) {
mPoorPerformanceWhiteList.add(originalUrl);
window.getSessionStack().loadUri(originalUrl);
}
}

@Override
public void dismiss() {

}
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ public class SessionStack implements ContentBlocking.Delegate, GeckoSession.Navi
private transient LinkedList<GeckoSession.ContentDelegate> mContentListeners;
private transient LinkedList<SessionChangeListener> mSessionChangeListeners;
private transient LinkedList<GeckoSession.TextInputDelegate> mTextInputListeners;
private transient LinkedList<GeckoSession.PromptDelegate> mPromptListeners;
private transient LinkedList<VideoAvailabilityListener> mVideoAvailabilityListeners;
private transient UserAgentOverride mUserAgentOverride;

private transient GeckoSession mCurrentSession;
private HashMap<Integer, SessionState> mSessions;
private Deque<Integer> mSessionsStack;
private transient GeckoSession.PermissionDelegate mPermissionDelegate;
private transient GeckoSession.PromptDelegate mPromptDelegate;
private int mPreviousGeckoSessionId = NO_SESSION;
private String mRegion;
private transient Context mContext;
Expand All @@ -91,7 +91,6 @@ protected SessionStack(Context context, GeckoRuntime runtime, boolean usePrivate
mContentListeners = new LinkedList<>();
mSessionChangeListeners = new LinkedList<>();
mTextInputListeners = new LinkedList<>();
mPromptListeners = new LinkedList<>();
mVideoAvailabilityListeners = new LinkedList<>();

if (mPrefs != null) {
Expand Down Expand Up @@ -201,6 +200,13 @@ public void setPermissionDelegate(GeckoSession.PermissionDelegate aDelegate) {
}
}

public void setPromptDelegate(GeckoSession.PromptDelegate aDelegate) {
mPromptDelegate = aDelegate;
for (HashMap.Entry<Integer, SessionState> entry : mSessions.entrySet()) {
entry.getValue().mSession.setPromptDelegate(aDelegate);
}
}

public void addNavigationListener(GeckoSession.NavigationDelegate aListener) {
mNavigationListeners.add(aListener);
dumpState(mCurrentSession, aListener);
Expand Down Expand Up @@ -244,14 +250,6 @@ public void removeTextInputListener(GeckoSession.TextInputDelegate aListener) {
mTextInputListeners.remove(aListener);
}

public void addPromptListener(GeckoSession.PromptDelegate aListener) {
mPromptListeners.add(aListener);
}

public void removePromptListener(GeckoSession.PromptDelegate aListener) {
mPromptListeners.remove(aListener);
}

public void addVideoAvailabilityListener(VideoAvailabilityListener aListener) {
mVideoAvailabilityListeners.add(aListener);
}
Expand Down Expand Up @@ -300,10 +298,10 @@ public void restore(SessionStack store, int currentSessionId) {

state.mSession.setNavigationDelegate(this);
state.mSession.setProgressDelegate(this);
state.mSession.setPromptDelegate(this);
state.mSession.setContentDelegate(this);
state.mSession.getTextInput().setDelegate(this);
state.mSession.setPermissionDelegate(mPermissionDelegate);
state.mSession.setPromptDelegate(mPromptDelegate);
state.mSession.setContentBlockingDelegate(this);
state.mSession.setMediaDelegate(this);
for (SessionChangeListener listener: mSessionChangeListeners) {
Expand Down Expand Up @@ -360,10 +358,10 @@ private int createSession(@NonNull SessionSettings aSettings) {
state.mSession.getSettings().setUserAgentMode(aSettings.getUserAgentMode());
state.mSession.setNavigationDelegate(this);
state.mSession.setProgressDelegate(this);
state.mSession.setPromptDelegate(this);
state.mSession.setContentDelegate(this);
state.mSession.getTextInput().setDelegate(this);
state.mSession.setPermissionDelegate(mPermissionDelegate);
state.mSession.setPromptDelegate(mPromptDelegate);
state.mSession.setContentBlockingDelegate(this);
state.mSession.setMediaDelegate(this);
for (SessionChangeListener listener: mSessionChangeListeners) {
Expand Down Expand Up @@ -1149,100 +1147,95 @@ public void updateCursorAnchorInfo(@NonNull GeckoSession aSession, @NonNull Curs

@Override
public void onContentBlocked(@NonNull final GeckoSession session, @NonNull final ContentBlocking.BlockEvent event) {
if ((event.categories & ContentBlocking.AT_AD) != 0) {
if ((event.getAntiTrackingCategory() & ContentBlocking.AntiTracking.AD) != 0) {
Log.i(LOGTAG, "Blocking Ad: " + event.uri);
}

if ((event.categories & ContentBlocking.AT_ANALYTIC) != 0) {
if ((event.getAntiTrackingCategory() & ContentBlocking.AntiTracking.ANALYTIC) != 0) {
Log.i(LOGTAG, "Blocking Analytic: " + event.uri);
}

if ((event.categories & ContentBlocking.AT_CONTENT) != 0) {
if ((event.getAntiTrackingCategory() & ContentBlocking.AntiTracking.CONTENT) != 0) {
Log.i(LOGTAG, "Blocking Content: " + event.uri);
}

if ((event.categories & ContentBlocking.AT_SOCIAL) != 0) {
if ((event.getAntiTrackingCategory() & ContentBlocking.AntiTracking.SOCIAL) != 0) {
Log.i(LOGTAG, "Blocking Social: " + event.uri);
}
}

// PromptDelegate

@Nullable
@Override
public void onAlert(@NonNull GeckoSession session, String title, String msg, @NonNull AlertCallback callback) {
if (session == mCurrentSession) {
for (GeckoSession.PromptDelegate listener : mPromptListeners) {
listener.onAlert(session, title, msg, callback);
}
}
}
public GeckoResult<PromptResponse> onAlertPrompt(@NonNull GeckoSession geckoSession, @NonNull AlertPrompt alertPrompt) {
if (mPromptDelegate != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I prefer to always use {} with if statements. I've fixed too may bugs in the past where they were left off and then some one added a second line with out realizing the curly brackets were missing. I just grepped the code and see we have a lot of if statements with out {} so I will file a follow up to update the code.

return mPromptDelegate.onAlertPrompt(geckoSession, alertPrompt);

@Override
public void onButtonPrompt(@NonNull GeckoSession session, String title, String msg, String[] btnMsg, @NonNull ButtonCallback callback) {
if (session == mCurrentSession) {
for (GeckoSession.PromptDelegate listener : mPromptListeners) {
listener.onButtonPrompt(session, title, msg, btnMsg, callback);
}
}
return GeckoResult.fromValue(alertPrompt.dismiss());
}

@Nullable
@Override
public void onTextPrompt(@NonNull GeckoSession session, String title, String msg, String value, @NonNull TextCallback callback) {
if (session == mCurrentSession) {
for (GeckoSession.PromptDelegate listener : mPromptListeners) {
listener.onTextPrompt(session, title, msg, value, callback);
}
}
public GeckoResult<PromptResponse> onButtonPrompt(@NonNull GeckoSession geckoSession, @NonNull ButtonPrompt buttonPrompt) {
if (mPromptDelegate != null)
return mPromptDelegate.onButtonPrompt(geckoSession, buttonPrompt);

return GeckoResult.fromValue(buttonPrompt.dismiss());
}

@Nullable
@Override
public void onAuthPrompt(@NonNull GeckoSession session, String title, String msg, @NonNull AuthOptions options, @NonNull AuthCallback callback) {
if (session == mCurrentSession) {
for (GeckoSession.PromptDelegate listener : mPromptListeners) {
listener.onAuthPrompt(session, title, msg, options, callback);
}
}
public GeckoResult<PromptResponse> onTextPrompt(@NonNull GeckoSession geckoSession, @NonNull TextPrompt textPrompt) {
if (mPromptDelegate != null)
return mPromptDelegate.onTextPrompt(geckoSession, textPrompt);

return GeckoResult.fromValue(textPrompt.dismiss());
}

@Nullable
@Override
public void onChoicePrompt(@NonNull GeckoSession session, String title, String msg, int type, @NonNull Choice[] choices, @NonNull ChoiceCallback callback) {
if (session == mCurrentSession) {
for (GeckoSession.PromptDelegate listener : mPromptListeners) {
listener.onChoicePrompt(session, title, msg, type, choices, callback);
}
}
public GeckoResult<PromptResponse> onAuthPrompt(@NonNull GeckoSession geckoSession, @NonNull AuthPrompt authPrompt) {
if (mPromptDelegate != null)
return mPromptDelegate.onAuthPrompt(geckoSession, authPrompt);

return GeckoResult.fromValue(authPrompt.dismiss());
}

@Nullable
@Override
public void onColorPrompt(@NonNull GeckoSession session, String title, String value, @NonNull TextCallback callback) {
if (session == mCurrentSession) {
for (GeckoSession.PromptDelegate listener : mPromptListeners) {
listener.onColorPrompt(session, title, value, callback);
}
}
public GeckoResult<PromptResponse> onChoicePrompt(@NonNull GeckoSession geckoSession, @NonNull ChoicePrompt choicePrompt) {
if (mPromptDelegate != null)
return mPromptDelegate.onChoicePrompt(geckoSession, choicePrompt);

return GeckoResult.fromValue(choicePrompt.dismiss());
}

@Nullable
@Override
public void onDateTimePrompt(@NonNull GeckoSession session, String title, int type, String value, String min, String max, @NonNull TextCallback callback) {
if (session == mCurrentSession) {
for (GeckoSession.PromptDelegate listener : mPromptListeners) {
listener.onDateTimePrompt(session, title, type, value, min, max, callback);
}
}
public GeckoResult<PromptResponse> onColorPrompt(@NonNull GeckoSession geckoSession, @NonNull ColorPrompt colorPrompt) {
if (mPromptDelegate != null)
return mPromptDelegate.onColorPrompt(geckoSession, colorPrompt);

return GeckoResult.fromValue(colorPrompt.dismiss());
}

@Nullable
@Override
public void onFilePrompt(@NonNull GeckoSession session, String title, int type, String[] mimeTypes, int capture, @NonNull FileCallback callback) {
if (session == mCurrentSession) {
for (GeckoSession.PromptDelegate listener : mPromptListeners) {
listener.onFilePrompt(session, title, type, mimeTypes, capture, callback);
}
}
public GeckoResult<PromptResponse> onDateTimePrompt(@NonNull GeckoSession geckoSession, @NonNull DateTimePrompt dateTimePrompt) {
if (mPromptDelegate != null)
return mPromptDelegate.onDateTimePrompt(geckoSession, dateTimePrompt);

return GeckoResult.fromValue(dateTimePrompt.dismiss());
}

@Nullable
@Override
public GeckoResult<AllowOrDeny> onPopupRequest(@NonNull final GeckoSession session, final String targetUri) {
return GeckoResult.fromValue(AllowOrDeny.DENY);
public GeckoResult<PromptResponse> onFilePrompt(@NonNull GeckoSession geckoSession, @NonNull FilePrompt filePrompt) {
if (mPromptDelegate != null)
return mPromptDelegate.onFilePrompt(geckoSession, filePrompt);

return GeckoResult.fromValue(filePrompt.dismiss());
}

// MediaDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void setContext(Context context, Bundle aExtras) {

GeckoRuntimeSettings.Builder runtimeSettingsBuilder = new GeckoRuntimeSettings.Builder();
runtimeSettingsBuilder.crashHandler(CrashReporterService.class);
runtimeSettingsBuilder.contentBlocking((new ContentBlocking.Settings.Builder())
.categories(ContentBlocking.AT_AD | ContentBlocking.AT_SOCIAL | ContentBlocking.AT_ANALYTIC)
runtimeSettingsBuilder.contentBlocking((new ContentBlocking.Settings.Builder()
.antiTracking(ContentBlocking.AntiTracking.AD | ContentBlocking.AntiTracking.SOCIAL| ContentBlocking.AntiTracking.ANALYTIC))
.build());
runtimeSettingsBuilder.consoleOutput(SettingsStore.getInstance(context).isConsoleLogsEnabled());
runtimeSettingsBuilder.displayDensityOverride(SettingsStore.getInstance(context).getDisplayDensity());
Expand Down
Loading