From 3fdb5648067f878ad835539c9b4d0ef70865a1af Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Fri, 10 Jan 2020 15:29:22 +0100 Subject: [PATCH 1/2] Added option to disable domain autocomplete in the address bar --- .../vrbrowser/browser/SettingsStore.java | 11 +++++++ .../suggestions/SuggestionsProvider.java | 30 +++++++++++++++---- .../ui/widgets/NavigationBarWidget.java | 28 ++++++++--------- .../ui/widgets/SuggestionsWidget.java | 2 -- .../widgets/settings/PrivacyOptionsView.java | 21 +++++++++++++ app/src/main/res/layout/options_privacy.xml | 6 ++++ app/src/main/res/values/non_L10n.xml | 1 + app/src/main/res/values/strings.xml | 4 +++ 8 files changed, 82 insertions(+), 21 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java b/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java index 44e432e55..392b5aed4 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java @@ -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; @@ -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); + } + } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/search/suggestions/SuggestionsProvider.java b/app/src/common/shared/org/mozilla/vrbrowser/search/suggestions/SuggestionsProvider.java index 7f87fb8e0..cb56dc8e5 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/search/suggestions/SuggestionsProvider.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/search/suggestions/SuggestionsProvider.java @@ -20,6 +20,11 @@ public class SuggestionsProvider { + public static final int SUGGESTIONS = 0x1; + public static final int BOOKMARKS = 0x2; + public static final int HISTORY = 0x3; + public static final int ALL = SUGGESTIONS | BOOKMARKS | HISTORY; + private static final String LOGTAG = SuggestionsProvider.class.getSimpleName(); public class DefaultSuggestionsComparator implements Comparator { @@ -180,11 +185,26 @@ public CompletableFuture> getSearchEngineSuggestions(@NonNu return future; } - public CompletableFuture> getSuggestions() { - return CompletableFuture.supplyAsync(() -> new ArrayList()) - .thenComposeAsync(this::getSearchEngineSuggestions) - .thenComposeAsync(this::getBookmarkSuggestions) - .thenComposeAsync(this::getHistorySuggestions); + public CompletableFuture> getSuggestions(int flags) { + List items = new ArrayList<>(); + + CompletableFuture> result = new CompletableFuture<>(); + + List 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; } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java index 45173425c..10000ef6a 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java @@ -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; }); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/SuggestionsWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/SuggestionsWidget.java index fe11962e9..a3233d28b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/SuggestionsWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/SuggestionsWidget.java @@ -15,12 +15,10 @@ import android.widget.ArrayAdapter; import android.widget.ImageButton; import android.widget.ImageView; -import android.widget.ListView; import android.widget.TextView; import androidx.annotation.NonNull; -import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.audio.AudioEngine; import org.mozilla.vrbrowser.ui.views.CustomListView; diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java index 8bfca8f07..775cb507a 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java @@ -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) { @@ -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); @@ -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) { @@ -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), diff --git a/app/src/main/res/layout/options_privacy.xml b/app/src/main/res/layout/options_privacy.xml index 39b8da946..21437c54e 100644 --- a/app/src/main/res/layout/options_privacy.xml +++ b/app/src/main/res/layout/options_privacy.xml @@ -45,6 +45,12 @@ app:buttonText="@string/developer_options_show" app:description="@string/settings_privacy_policy" /> + + settings_key_ui_hardware_acceleration settings_key_fxa_last_sync settings_key_restore_tabs + settings_key_autocomplete https://github.com/MozillaReality/FirefoxReality/wiki/Environments https://www.mozilla.org/privacy/firefox/ https://mixedreality.mozilla.org/fxr/report?src=browser-fxr&label=browser-firefox-reality&url=%1$s diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 69e172647..36187169e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -558,6 +558,10 @@ and is used to enable or disable the tabs restoration after a fresh app start. --> Restore tabs and windows after restart + + Address Bar Auto-complete + Tracking Protection From 86d3582ddeebace800d8fd1aa09454f25d73049a Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Thu, 16 Jan 2020 12:41:47 +0100 Subject: [PATCH 2/2] Fix field value --- .../vrbrowser/search/suggestions/SuggestionsProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/search/suggestions/SuggestionsProvider.java b/app/src/common/shared/org/mozilla/vrbrowser/search/suggestions/SuggestionsProvider.java index cb56dc8e5..bc1734673 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/search/suggestions/SuggestionsProvider.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/search/suggestions/SuggestionsProvider.java @@ -22,7 +22,7 @@ public class SuggestionsProvider { public static final int SUGGESTIONS = 0x1; public static final int BOOKMARKS = 0x2; - public static final int HISTORY = 0x3; + public static final int HISTORY = 0x4; public static final int ALL = SUGGESTIONS | BOOKMARKS | HISTORY; private static final String LOGTAG = SuggestionsProvider.class.getSimpleName();