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

Commit 4945fc7

Browse files
authored
Added setting to disable autocomplete (#3551)
Do not get search suggestions in private mode! Completion fixes
1 parent af3cbb3 commit 4945fc7

9 files changed

Lines changed: 73 additions & 9 deletions

File tree

app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
106106
public final static boolean MULTI_E10S = false;
107107
public final static int DOWNLOADS_STORAGE_DEFAULT = INTERNAL;
108108
public final static int DOWNLOADS_SORTING_ORDER_DEFAULT = SortingContextMenuWidget.SORT_DATE_ASC;
109+
public final static boolean AUTOCOMPLETE_ENABLED = true;
109110

110111
// Enable telemetry by default (opt-out).
111112
public final static boolean CRASH_REPORTING_DEFAULT = false;
@@ -795,4 +796,14 @@ public String getRemotePropsVersionName() {
795796
return mPrefs.getString(mContext.getString(R.string.settings_key_remote_props_version_name), "0");
796797
}
797798

799+
public void setAutocompleteEnabled(boolean isEnabled) {
800+
SharedPreferences.Editor editor = mPrefs.edit();
801+
editor.putBoolean(mContext.getString(R.string.settings_key_autocomplete), isEnabled);
802+
editor.commit();
803+
}
804+
805+
public boolean isAutocompleteEnabled() {
806+
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_autocomplete), AUTOCOMPLETE_ENABLED);
807+
}
808+
798809
}

app/src/common/shared/org/mozilla/vrbrowser/search/SearchEngineWrapper.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
import androidx.annotation.NonNull;
1313

1414
import org.mozilla.vrbrowser.R;
15+
import org.mozilla.vrbrowser.VRBrowserActivity;
1516
import org.mozilla.vrbrowser.browser.SettingsStore;
17+
import org.mozilla.vrbrowser.browser.engine.Session;
18+
import org.mozilla.vrbrowser.browser.engine.SessionStore;
1619
import org.mozilla.vrbrowser.geolocation.GeolocationData;
17-
import org.mozilla.vrbrowser.search.suggestions.SearchSuggestionsCLientKt;
20+
import org.mozilla.vrbrowser.search.suggestions.SearchSuggestionsClientKt;
1821
import org.mozilla.vrbrowser.utils.SystemUtils;
1922

2023
import java.util.ArrayList;
@@ -64,10 +67,12 @@ SearchEngineWrapper get(final @NonNull Context aContext) {
6467
private SearchEngine mSearchEngine;
6568
private SearchSuggestionClient mSuggestionsClient;
6669
private SharedPreferences mPrefs;
70+
private boolean mAutocompleteEnabled;
6771

6872
private SearchEngineWrapper(@NonNull Context aContext) {
6973
mContext = aContext;
7074
mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
75+
mAutocompleteEnabled = SettingsStore.getInstance(mContext).isAutocompleteEnabled();
7176

7277
setupSearchEngine(aContext, EMPTY);
7378
}
@@ -100,8 +105,7 @@ public String getSearchURL(String aQuery) {
100105
}
101106

102107
public CompletableFuture<List<String>> getSuggestions(String aQuery) {
103-
String query = mSearchEngine.buildSuggestionsURL(aQuery);
104-
return SearchSuggestionsCLientKt.getSuggestionsAsync(mSuggestionsClient, query != null ? query : "");
108+
return SearchSuggestionsClientKt.getSuggestionsAsync(mSuggestionsClient, aQuery != null ? aQuery : "");
105109
}
106110

107111
public String getResourceURL() {
@@ -167,7 +171,14 @@ private void setupSearchEngine(@NonNull Context aContext, String userPref) {
167171

168172
// A name can be used if the user get's to choose among the available engines
169173
mSearchEngine = mSearchEngineManager.getDefaultSearchEngine(aContext, userPref);
170-
mSuggestionsClient = new SearchSuggestionClient(mSearchEngine, (s, continuation) -> null);
174+
mSuggestionsClient = new SearchSuggestionClient(
175+
mSearchEngine,
176+
(searchUrl, continuation) -> {
177+
return (mAutocompleteEnabled && !((VRBrowserActivity)mContext).getWindows().isInPrivateMode()) ?
178+
SearchSuggestionsClientKt.fetchSearchSuggestions(mContext, searchUrl) :
179+
null;
180+
}
181+
);
171182
}
172183

173184
private String getEngine(String aCountryCode) {
@@ -181,6 +192,9 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
181192
if (mContext != null) {
182193
if (key.equals(mContext.getString(R.string.settings_key_geolocation_data))) {
183194
setupSearchEngine(mContext, EMPTY);
195+
196+
} else if (key.equals(mContext.getString(R.string.settings_key_autocomplete))) {
197+
mAutocompleteEnabled = SettingsStore.getInstance(mContext).isAutocompleteEnabled();
184198
}
185199
}
186200
}

app/src/common/shared/org/mozilla/vrbrowser/search/suggestions/SearchSuggestionsCLient.kt renamed to app/src/common/shared/org/mozilla/vrbrowser/search/suggestions/SearchSuggestionsClient.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package org.mozilla.vrbrowser.search.suggestions
22

3+
import android.content.Context
34
import kotlinx.coroutines.GlobalScope
45
import kotlinx.coroutines.future.future
56
import mozilla.components.browser.search.suggestions.SearchSuggestionClient
7+
import mozilla.components.concept.fetch.Request
8+
import org.mozilla.vrbrowser.browser.engine.EngineProvider
9+
import java.nio.charset.StandardCharsets
610
import java.util.concurrent.CompletableFuture
711

812
fun getSuggestionsAsync(client: SearchSuggestionClient, query: String): CompletableFuture<List<String>?> =
913
GlobalScope.future {
1014
client.getSuggestions(query)
11-
}
15+
}
16+
17+
fun fetchSearchSuggestions(context: Context, searchUrl: String): String? {
18+
val request = Request(searchUrl);
19+
return EngineProvider.getDefaultClient(context).fetch(request).body.string(StandardCharsets.UTF_8)
20+
}

app/src/common/shared/org/mozilla/vrbrowser/search/suggestions/SuggestionsProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private CompletableFuture<List<SuggestionItem>> getSearchEngineSuggestions(@NonN
134134
CompletableFuture<List<SuggestionItem>> future = new CompletableFuture<>();
135135

136136
// Completion from browser-domains
137-
if (!mText.equals(mFilterText)) {
137+
if (!mText.equals(mFilterText) && UrlUtils.isDomain(mText)) {
138138
items.add(SuggestionItem.create(
139139
mText,
140140
getSearchURLOrDomain(mText),

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ public void onShowAwesomeBar() {
989989
.whenCompleteAsync((items, ex) -> {
990990
if (mBinding.navigationBarNavigation.urlBar.hasFocus()) {
991991
mAwesomeBar.updateItems(items);
992-
mAwesomeBar.setHighlightedText(originalText);
992+
mAwesomeBar.setHighlightedText(mBinding.navigationBarNavigation.urlBar.getOriginalText().trim());
993993

994994
if (!mAwesomeBar.isVisible()) {
995995
mAwesomeBar.updatePlacement((int) WidgetPlacement.convertPixelsToDp(getContext(), mBinding.navigationBarNavigation.urlBar.getWidth()));

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
import org.mozilla.geckoview.StorageController;
2323
import org.mozilla.vrbrowser.R;
2424
import org.mozilla.vrbrowser.browser.SettingsStore;
25-
import org.mozilla.vrbrowser.browser.engine.SessionState;
2625
import org.mozilla.vrbrowser.browser.engine.SessionStore;
2726
import org.mozilla.vrbrowser.databinding.OptionsPrivacyBinding;
28-
import org.mozilla.vrbrowser.db.SitePermission;
2927
import org.mozilla.vrbrowser.ui.views.settings.RadioGroupSetting;
3028
import org.mozilla.vrbrowser.ui.views.settings.SwitchSetting;
3129
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
@@ -132,6 +130,9 @@ protected void updateUI() {
132130
mBinding.restoreTabsSwitch.setOnCheckedChangeListener(mRestoreTabsListener);
133131
setRestoreTabs(SettingsStore.getInstance(getContext()).isRestoreTabsEnabled(), false);
134132

133+
mBinding.autocompleteSwitch.setOnCheckedChangeListener(mAutocompleteListener);
134+
setAutocomplete(SettingsStore.getInstance(getContext()).isAutocompleteEnabled(), false);
135+
135136
mBinding.webxrSwitch.setOnCheckedChangeListener(mWebXRListener);
136137
setWebXR(SettingsStore.getInstance(getContext()).isWebXREnabled(), false);
137138
mBinding.webxrExceptionsButton.setOnClickListener(v -> mDelegate.showView(SettingViewType.WEBXR_EXCEPTIONS));
@@ -202,6 +203,10 @@ public void reject() {
202203
setRestoreTabs(value, doApply);
203204
};
204205

206+
private SwitchSetting.OnCheckedChangeListener mAutocompleteListener = (compoundButton, value, doApply) -> {
207+
setAutocomplete(value, doApply);
208+
};
209+
205210
private SwitchSetting.OnCheckedChangeListener mWebXRListener = (compoundButton, value, doApply) -> {
206211
setWebXR(value, doApply);
207212
};
@@ -243,6 +248,10 @@ private void resetOptions() {
243248
setRestoreTabs(SettingsStore.RESTORE_TABS_ENABLED, true);
244249
}
245250

251+
if (mBinding.autocompleteSwitch.isChecked() != SettingsStore.AUTOCOMPLETE_ENABLED) {
252+
setAutocomplete(SettingsStore.AUTOCOMPLETE_ENABLED, true);
253+
}
254+
246255
if (mBinding.webxrSwitch.isChecked() != SettingsStore.WEBXR_ENABLED_DEFAULT) {
247256
setWebXR(SettingsStore.WEBXR_ENABLED_DEFAULT, true);
248257
}
@@ -332,6 +341,16 @@ private void setRestoreTabs(boolean value, boolean doApply) {
332341
}
333342
}
334343

344+
private void setAutocomplete(boolean value, boolean doApply) {
345+
mBinding.autocompleteSwitch.setOnCheckedChangeListener(null);
346+
mBinding.autocompleteSwitch.setValue(value, false);
347+
mBinding.autocompleteSwitch.setOnCheckedChangeListener(mAutocompleteListener);
348+
349+
if (doApply) {
350+
SettingsStore.getInstance(getContext()).setAutocompleteEnabled(value);
351+
}
352+
}
353+
335354
private void setWebXR(boolean value, boolean doApply) {
336355
mBinding.webxrSwitch.setOnCheckedChangeListener(null);
337356
mBinding.webxrSwitch.setValue(value, false);

app/src/main/res/layout/options_privacy.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
app:buttonText="@string/developer_options_show"
5050
app:description="@string/settings_privacy_policy" />
5151

52+
<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
53+
android:id="@+id/autocompleteSwitch"
54+
android:layout_width="match_parent"
55+
android:layout_height="wrap_content"
56+
app:description="@string/security_options_autocomplete" />
57+
5258
<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
5359
android:id="@+id/drmContentPlaybackSwitch"
5460
android:layout_width="match_parent"

app/src/main/res/values/non_L10n.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<string name="settings_key_downloads_sorting_order" translatable="false">settings_key_downloads_sorting_order</string>
5757
<string name="settings_key_remote_props_version_name" translatable="false">settings_key_remote_props_version_name</string>
5858
<string name="settings_key_remote_props" translatable="false">settings_key_remote_props</string>
59+
<string name="settings_key_autocomplete" translatable="false">settings_key_autocomplete</string>
5960
<string name="environment_override_help_url" translatable="false">https://github.com/MozillaReality/FirefoxReality/wiki/Environments</string>
6061
<string name="private_policy_url" translatable="false">https://www.mozilla.org/privacy/firefox/</string>
6162
<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>

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@
642642
and is used to enable or disable the tabs restoration after a fresh app start. -->
643643
<string name="security_options_restore_tabs">Restore tabs and windows after restart</string>
644644

645+
<!-- This string labels an Allow/Don't Allow switch in the Privacy and Security settings dialog
646+
and is used to enable or disable the address bar autocomplete. -->
647+
<string name="security_options_autocomplete">Address Bar Auto-complete</string>
648+
645649
<!-- This string labels an On/Off switch in the Privacy and Security settings dialog
646650
and is used to enable or disable tracking protection. -->
647651
<string name="security_options_tracking_protection">Tracking Protection</string>

0 commit comments

Comments
 (0)