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

Implement before unload prompt #3508

Merged
merged 1 commit into from
Jun 17, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.mozilla.vrbrowser.ui.widgets.prompts.ConfirmPromptWidget;
import org.mozilla.vrbrowser.ui.widgets.prompts.PromptWidget;
import org.mozilla.vrbrowser.ui.widgets.prompts.TextPromptWidget;
import org.mozilla.vrbrowser.utils.StringUtils;
import org.mozilla.vrbrowser.utils.UrlUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -303,6 +304,41 @@ public void dismiss() {
});
}

@Nullable
@Override
public GeckoResult<PromptResponse> onBeforeUnloadPrompt(@NonNull GeckoSession session, @NonNull BeforeUnloadPrompt prompt) {
final GeckoResult<PromptResponse> result = new GeckoResult<>();

mPrompt = new ConfirmPromptWidget(mContext);
mPrompt.getPlacement().parentHandle = mAttachedWindow.getHandle();
mPrompt.getPlacement().parentAnchorY = 0.0f;
mPrompt.getPlacement().translationY = WidgetPlacement.unitFromMeters(mContext, R.dimen.js_prompt_y_distance);
String message = mContext.getString(R.string.before_unload_prompt_message);
if (!StringUtils.isEmpty(prompt.title)) {
message = prompt.title;
}
mPrompt.setTitle(mContext.getString(R.string.before_unload_prompt_title));
mPrompt.setMessage(message);
((ConfirmPromptWidget)mPrompt).setButtons(new String[] {
mContext.getResources().getText(R.string.before_unload_prompt_leave).toString(),
mContext.getResources().getText(R.string.before_unload_prompt_stay).toString()
});
mPrompt.setPromptDelegate(new ConfirmPromptWidget.ConfirmPromptDelegate() {
@Override
public void confirm(int index) {
result.complete(prompt.confirm(index == 0 ? AllowOrDeny.ALLOW : AllowOrDeny.DENY));
}

@Override
public void dismiss() {
result.complete(prompt.dismiss());
}
});
mPrompt.show(UIWidget.REQUEST_FOCUS);

return result;
}

// WindowWidget.WindowListener

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,16 @@ public GeckoResult<PromptResponse> onFilePrompt(@NonNull GeckoSession aSession,
return GeckoResult.fromValue(filePrompt.dismiss());
}

@Nullable
@Override
public GeckoResult<PromptResponse> onBeforeUnloadPrompt(@NonNull GeckoSession aSession, @NonNull BeforeUnloadPrompt prompt) {
if (mPromptDelegate != null) {
return mPromptDelegate.onBeforeUnloadPrompt(aSession, prompt);
}
return GeckoResult.fromValue(prompt.dismiss());
}


// MediaDelegate

@Override
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,16 @@
'%1$s' will be replace at runtime with the app's name. -->
<string name="not_entitled_message">%1$s does not have permission to run on this device and will now exit.</string>


<!-- This string is displayed in the title of an Before Unload prompt, which asks for confirmation to stay or leave the current page. -->
<string name="before_unload_prompt_title">Leave page?</string>
<!-- This string is displayed in the message of an Before Unload prompt, which asks for confirmation to stay or leave the current page. -->
<string name="before_unload_prompt_message">This page is asking to confirm that you want to leave. Data you have entered may not be saved.</string>
<!-- This string is displayed in a button of the Before Unload prompt. Clicking it cancels the navigation and stays on the same page. -->
<string name="before_unload_prompt_stay">Stay on Page</string>
<!-- This string is displayed in a button of the Before Unload prompt. Clicking it confirms the navigation and leaves the page. -->
<string name="before_unload_prompt_leave">Leave Page</string>

<!-- This string is displayed in a button that when pressed allows a user to view a page that has been blocked from being displayed.-->
<string name="performance_unblock_page">Unblock Page</string>
<!-- This string is displayed as the title of a dialog displayed when poor web page performance has been detected. -->
Expand Down