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

Fixes #1857 Added option to disable domain autocomplete in the address bar #2618

Closed
wants to merge 3 commits into from
Closed
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 @@ -85,6 +85,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static boolean WHATS_NEW_DISPLAYED = false;
public final static long FXA_LAST_SYNC_NEVER = 0;
public final static boolean RESTORE_TABS_ENABLED = true;
public final static boolean AUTOCOMPLETE_ENABLED = true;

// Enable telemetry by default (opt-out).
public final static boolean CRASH_REPORTING_DEFAULT = false;
Expand Down Expand Up @@ -701,5 +702,15 @@ public boolean isRestoreTabsEnabled() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_restore_tabs), RESTORE_TABS_ENABLED);
}

public void setAutocompleteEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_autocomplete), isEnabled);
editor.commit();
}

public boolean isAutocompleteEnabled() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_autocomplete), AUTOCOMPLETE_ENABLED);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

public class SuggestionsProvider {

public static final int SUGGESTIONS = 0x1;
public static final int BOOKMARKS = 0x2;
public static final int HISTORY = 0x4;
public static final int ALL = SUGGESTIONS | BOOKMARKS | HISTORY;

private static final String LOGTAG = SuggestionsProvider.class.getSimpleName();

public class DefaultSuggestionsComparator implements Comparator {
Expand Down Expand Up @@ -180,11 +185,26 @@ public CompletableFuture<List<SuggestionItem>> getSearchEngineSuggestions(@NonNu
return future;
}

public CompletableFuture<List<SuggestionItem>> getSuggestions() {
return CompletableFuture.supplyAsync(() -> new ArrayList<SuggestionItem>())
.thenComposeAsync(this::getSearchEngineSuggestions)
.thenComposeAsync(this::getBookmarkSuggestions)
.thenComposeAsync(this::getHistorySuggestions);
public CompletableFuture<List<SuggestionItem>> getSuggestions(int flags) {
List<SuggestionItem> items = new ArrayList<>();

CompletableFuture<List<SuggestionItem>> result = new CompletableFuture<>();

List<CompletableFuture> futures = new ArrayList<>();
if ((flags & SUGGESTIONS) == SUGGESTIONS) {
futures.add(CompletableFuture.supplyAsync(() -> getSearchEngineSuggestions(items), mUIThreadExecutor));
}
if ((flags & BOOKMARKS) == BOOKMARKS) {
futures.add(CompletableFuture.supplyAsync(() -> getBookmarkSuggestions(items), mUIThreadExecutor));
}
if ((flags & HISTORY) == HISTORY) {
futures.add(CompletableFuture.supplyAsync(() -> getHistorySuggestions(items), mUIThreadExecutor));
}

CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
.thenApplyAsync(dummy -> result.complete(items), mUIThreadExecutor);

return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -958,24 +958,24 @@ public void onShowAwesomeBar() {
return;
}

int flags = SettingsStore.getInstance(getContext()).isAutocompleteEnabled() ? SuggestionsProvider.ALL : SuggestionsProvider.SUGGESTIONS;
mSuggestionsProvider.setText(text);
mSuggestionsProvider.setFilterText(originalText);
mSuggestionsProvider.getSuggestions()
.whenCompleteAsync((items, ex) -> {
if (mURLBar.hasFocus()) {
mAwesomeBar.updateItems(items);
mAwesomeBar.setHighlightedText(originalText);

if (!mAwesomeBar.isVisible()) {
mAwesomeBar.updatePlacement((int) WidgetPlacement.convertPixelsToDp(getContext(), mURLBar.getWidth()));
mAwesomeBar.show(CLEAR_FOCUS);
}
mSuggestionsProvider.getSuggestions(flags).whenCompleteAsync((items, ex) -> {
if (mURLBar.hasFocus()) {
mAwesomeBar.updateItems(items);
mAwesomeBar.setHighlightedText(originalText);

if (!mAwesomeBar.isVisible()) {
mAwesomeBar.updatePlacement((int) WidgetPlacement.convertPixelsToDp(getContext(), mURLBar.getWidth()));
mAwesomeBar.show(CLEAR_FOCUS);
}
}

}, mUIThreadExecutor).exceptionally(throwable -> {
Log.d(LOGTAG, "Error getting suggestions: " + throwable.getLocalizedMessage());
throwable.printStackTrace();
return null;
}, mUIThreadExecutor).exceptionally(throwable -> {
Log.d(LOGTAG, "Error getting suggestions: " + throwable.getLocalizedMessage());
throwable.printStackTrace();
return null;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ private void initialize(Context aContext) {

mBinding.restoreTabsSwitch.setOnCheckedChangeListener(mRestoreTabsListener);
setRestoreTabs(SettingsStore.getInstance(getContext()).isRestoreTabsEnabled(), false);

mBinding.autocompleteSwitch.setOnCheckedChangeListener(mAutocompleteListener);
setAutocomplete(SettingsStore.getInstance(getContext()).isAutocompleteEnabled(), false);
}

private void togglePermission(SwitchSetting aButton, String aPermission) {
Expand Down Expand Up @@ -178,6 +181,10 @@ public void reject() {
setRestoreTabs(value, doApply);
};

private SwitchSetting.OnCheckedChangeListener mAutocompleteListener = (compoundButton, value, doApply) -> {
setAutocomplete(value, doApply);
};

private void resetOptions() {
if (mBinding.drmContentPlaybackSwitch.isChecked() != SettingsStore.DRM_PLAYBACK_DEFAULT) {
setDrmContent(SettingsStore.DRM_PLAYBACK_DEFAULT, true);
Expand Down Expand Up @@ -210,6 +217,10 @@ private void resetOptions() {
if (mBinding.restoreTabsSwitch.isChecked() != SettingsStore.RESTORE_TABS_ENABLED) {
setRestoreTabs(SettingsStore.RESTORE_TABS_ENABLED, true);
}

if (mBinding.autocompleteSwitch.isChecked() != SettingsStore.AUTOCOMPLETE_ENABLED) {
setAutocomplete(SettingsStore.AUTOCOMPLETE_ENABLED, true);
}
}

private void setDrmContent(boolean value, boolean doApply) {
Expand Down Expand Up @@ -294,6 +305,16 @@ private void setRestoreTabs(boolean value, boolean doApply) {
}
}

private void setAutocomplete(boolean value, boolean doApply) {
mBinding.autocompleteSwitch.setOnCheckedChangeListener(null);
mBinding.autocompleteSwitch.setValue(value, false);
mBinding.autocompleteSwitch.setOnCheckedChangeListener(mAutocompleteListener);

if (doApply) {
SettingsStore.getInstance(getContext()).setAutocompleteEnabled(value);
}
}

@Override
public Point getDimensions() {
return new Point( WidgetPlacement.dpDimension(getContext(), R.dimen.privacy_options_width),
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/options_privacy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
app:buttonText="@string/developer_options_show"
app:description="@string/settings_privacy_policy" />

<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
android:id="@+id/autocompleteSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="@string/security_options_autocomplete" />

<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
android:id="@+id/restoreTabsSwitch"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/non_L10n.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<string name="settings_key_ui_hardware_acceleration" translatable="false">settings_key_ui_hardware_acceleration</string>
<string name="settings_key_fxa_last_sync" translatable="false">settings_key_fxa_last_sync</string>
<string name="settings_key_restore_tabs" translatable="false">settings_key_restore_tabs</string>
<string name="settings_key_autocomplete" translatable="false">settings_key_autocomplete</string>
<string name="environment_override_help_url" translatable="false">https://github.com/MozillaReality/FirefoxReality/wiki/Environments</string>
<string name="private_policy_url" translatable="false">https://www.mozilla.org/privacy/firefox/</string>
<string name="private_report_url" translatable="false">https://mixedreality.mozilla.org/fxr/report?src=browser-fxr&amp;label=browser-firefox-reality&amp;url=%1$s</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,10 @@
and is used to enable or disable the tabs restoration after a fresh app start. -->
<string name="security_options_restore_tabs">Restore tabs and windows after restart</string>

<!-- This string labels an Allow/Don't Allow switch in the Privacy and Security settings dialog
and is used to enable or disable the address bar autocomplete. -->
<string name="security_options_autocomplete">Address Bar Auto-complete</string>

<!-- This string labels an On/Off switch in the Privacy and Security settings dialog
and is used to enable or disable tracking protection. -->
<string name="security_options_tracking_protection">Tracking Protection</string>
Expand Down