diff --git a/app/src/common/gecko/com/igalia/wolvic/browser/api/impl/GeckoWebExtension.kt b/app/src/common/gecko/com/igalia/wolvic/browser/api/impl/GeckoWebExtension.kt index f8d685b5bca..4244ab5f237 100644 --- a/app/src/common/gecko/com/igalia/wolvic/browser/api/impl/GeckoWebExtension.kt +++ b/app/src/common/gecko/com/igalia/wolvic/browser/api/impl/GeckoWebExtension.kt @@ -267,7 +267,7 @@ class GeckoWebExtension( val activeSession: Session = SessionStore.get().activeSession; val session: Session = SessionStore.get().createWebExtensionSession(false, activeSession.isPrivateMode); session.setParentSession(activeSession) - session.uaMode = GeckoSessionSettings.USER_AGENT_MODE_DESKTOP + session.setUaMode(GeckoSessionSettings.USER_AGENT_MODE_DESKTOP, true) val geckoEngineSession = WolvicEngineSession(session) ext.metaData?.optionsPageUrl?.let { optionsPageUrl -> tabHandler.onNewTab( diff --git a/app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java b/app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java index df1825af538..57d49d8fec2 100644 --- a/app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java +++ b/app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java @@ -83,6 +83,7 @@ SettingsStore getInstance(final @NonNull Context aContext) { public final static boolean SPEECH_DATA_COLLECTION_DEFAULT = false; public final static boolean SPEECH_DATA_COLLECTION_REVIEWED_DEFAULT = false; public final static int UA_MODE_DEFAULT = WSessionSettings.USER_AGENT_MODE_VR; + public final static boolean USE_WOLVIC_UA_DEFAULT = false; public final static int INPUT_MODE_DEFAULT = 1; public final static float DISPLAY_DENSITY_DEFAULT = 1.0f; public final static int WINDOW_WIDTH_DEFAULT = 800; @@ -342,6 +343,17 @@ public void setUaMode(int mode) { editor.commit(); } + public boolean getUseWolvicUA() { + return mPrefs.getBoolean( + mContext.getString(R.string.settings_key_use_wolvic_ua), USE_WOLVIC_UA_DEFAULT); + } + + public void setUseWolvicUA(boolean useWolvicUA) { + SharedPreferences.Editor editor = mPrefs.edit(); + editor.putBoolean(mContext.getString(R.string.settings_key_use_wolvic_ua), useWolvicUA); + editor.commit(); + } + public int getInputMode() { return mPrefs.getInt( mContext.getString(R.string.settings_key_input_mode), INPUT_MODE_DEFAULT); diff --git a/app/src/common/shared/com/igalia/wolvic/browser/components/WolvicWebExtensionRuntime.kt b/app/src/common/shared/com/igalia/wolvic/browser/components/WolvicWebExtensionRuntime.kt index eb07e513cc9..6e8ed53f58f 100644 --- a/app/src/common/shared/com/igalia/wolvic/browser/components/WolvicWebExtensionRuntime.kt +++ b/app/src/common/shared/com/igalia/wolvic/browser/components/WolvicWebExtensionRuntime.kt @@ -38,7 +38,7 @@ class WolvicWebExtensionRuntime( val activeSession = SessionStore.get().activeSession val session: Session = SessionStore.get().createWebExtensionSession(activeSession.isPrivateMode); session.setParentSession(activeSession) - session.uaMode = WSessionSettings.USER_AGENT_MODE_DESKTOP + session.setUaMode(WSessionSettings.USER_AGENT_MODE_DESKTOP, true) val engineSession = WolvicEngineSession(session) (context as WidgetManagerDelegate).windows.onTabSelect(session) return webExtensionDelegate?.onToggleActionPopup(extension, engineSession, action) diff --git a/app/src/common/shared/com/igalia/wolvic/browser/engine/Session.java b/app/src/common/shared/com/igalia/wolvic/browser/engine/Session.java index e5c87a8e89e..2bd621cfeb1 100644 --- a/app/src/common/shared/com/igalia/wolvic/browser/engine/Session.java +++ b/app/src/common/shared/com/igalia/wolvic/browser/engine/Session.java @@ -75,7 +75,10 @@ public class Session implements WContentBlocking.Delegate, WSession.NavigationDe private static UriOverride sUserAgentOverride; private static UriOverride sDesktopModeOverrides; private static final long KEEP_ALIVE_DURATION_MS = 1000; // 1 second. - private static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (Android 10; Mobile VR; rv:105.0) Gecko/105.0 Wolvic/" + BuildConfig.VERSION_NAME; + + private static final String WOLVIC_USER_AGENT_MOBILE = "Mozilla/5.0 (Android 10; Mobile; rv:105.0) Gecko/105.0 Wolvic/" + BuildConfig.VERSION_NAME; + // This matches GeckoViewSettings.jsm + private static final String WOLVIC_USER_AGENT_VR = WOLVIC_USER_AGENT_MOBILE.replace("Mobile", "Mobile VR"); private transient CopyOnWriteArrayList mNavigationListeners; private transient CopyOnWriteArrayList mProgressListeners; @@ -193,12 +196,11 @@ private void initialize() { mDrmStateStateListeners = new CopyOnWriteArrayList<>(); mMedia = new Media(); + mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); if (mPrefs != null) { mPrefs.registerOnSharedPreferenceChangeListener(this); } - mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); - InternalPages.PageResources pageResources = InternalPages.PageResources.create(R.raw.private_mode, R.raw.private_style); mPrivatePage = InternalPages.createAboutPage(mContext, pageResources); @@ -1025,10 +1027,15 @@ private boolean trySetUaMode(int mode) { return true; } - public void setUaMode(int mode) { + public void setUaMode(int mode, boolean reload) { + // the UA mode value did not change if (!trySetUaMode(mode)) return; + // the value did change, but we don't need to force a reload + if (!reload) + return; + String overrideUri = mode == WSessionSettings.USER_AGENT_MODE_DESKTOP ? checkForMobileSite(mState.mUri) : null; if (overrideUri != null) { mState.mSession.loadUri(overrideUri, WSession.LOAD_FLAGS_BYPASS_CACHE | WSession.LOAD_FLAGS_REPLACE_HISTORY); @@ -1135,18 +1142,17 @@ WResult onLoadRequest(@NonNull WSession aSession, @NonNull LoadReq Log.d(LOGTAG, "onLoadRequest: " + uri); if (aSession == mState.mSession) { - Log.d(LOGTAG, "Testing for UA override"); - String userAgentOverride = sUserAgentOverride.lookupOverride(uri); - // Here we set a default user agent if no override was found, BUT - // only if UA Mode is not Desktop, because the UA override - // takes precedence over mode overrides so if we set it, it will - // invalidate desktop mode UA. For VR and Mobile modes we don't change - // the UA so they are not affected. - if (mState.mSettings.getUserAgentMode() != WSessionSettings.USER_AGENT_MODE_DESKTOP && - userAgentOverride == null) { - userAgentOverride = DEFAULT_USER_AGENT; + Log.d(LOGTAG, "User-Agent override: " + userAgentOverride); + + // Update the User-Agent according to the current UA settings, + // unless we are in Desktop mode (which uses its own User-Agent value). + int mode = mState.mSettings.getUserAgentMode(); + if (mode != WSessionSettings.USER_AGENT_MODE_DESKTOP + && userAgentOverride == null + && SettingsStore.getInstance(mContext).getUseWolvicUA()) { + userAgentOverride = (mode == WSessionSettings.USER_AGENT_MODE_MOBILE) ? WOLVIC_USER_AGENT_MOBILE : WOLVIC_USER_AGENT_VR; } aSession.getSettings().setUserAgentOverride(userAgentOverride); @@ -1738,12 +1744,17 @@ public void onMediaPermissionRequest(@NonNull WSession aSession, @NonNull String @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (mContext != null) { - if (key.equals(mContext.getString(R.string.settings_key_geolocation_data))) { - GeolocationData data = GeolocationData.parse(sharedPreferences.getString(key, null)); - if (data != null) { - setRegion(data.getCountryCode()); - } + if (mContext == null) + return; + + if (key.equals(mContext.getString(R.string.settings_key_geolocation_data))) { + GeolocationData data = GeolocationData.parse(sharedPreferences.getString(key, null)); + if (data != null) { + setRegion(data.getCountryCode()); + } + } else if (key.equals(mContext.getString(R.string.settings_key_user_agent_version))) { + if (mState.mSettings.getUserAgentMode() != WSessionSettings.USER_AGENT_MODE_DESKTOP) { + setUaMode(SettingsStore.getInstance(mContext).getUaMode(), false); } } } diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/NavigationBarWidget.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/NavigationBarWidget.java index 25fe2f332b2..ebccce5adc5 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/NavigationBarWidget.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/NavigationBarWidget.java @@ -1229,11 +1229,11 @@ public void onSwitchMode() { if (uaMode == WSessionSettings.USER_AGENT_MODE_DESKTOP) { final int defaultUaMode = SettingsStore.getInstance(mAppContext).getUaMode(); mHamburgerMenu.setUAMode(defaultUaMode); - mAttachedWindow.getSession().setUaMode(defaultUaMode); + mAttachedWindow.getSession().setUaMode(defaultUaMode, true); } else { mHamburgerMenu.setUAMode(WSessionSettings.USER_AGENT_MODE_DESKTOP); - mAttachedWindow.getSession().setUaMode(WSessionSettings.USER_AGENT_MODE_DESKTOP); + mAttachedWindow.getSession().setUaMode(WSessionSettings.USER_AGENT_MODE_DESKTOP, true); } hideMenu(); diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/DeveloperOptionsView.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/DeveloperOptionsView.java index 01340edd465..2c81e447d58 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/DeveloperOptionsView.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/DeveloperOptionsView.java @@ -6,6 +6,7 @@ package com.igalia.wolvic.ui.widgets.settings; import android.content.Context; +import android.graphics.Point; import android.view.LayoutInflater; import android.view.View; @@ -16,8 +17,10 @@ import com.igalia.wolvic.browser.SettingsStore; import com.igalia.wolvic.browser.engine.SessionStore; import com.igalia.wolvic.databinding.OptionsDeveloperBinding; +import com.igalia.wolvic.ui.views.settings.RadioGroupSetting; import com.igalia.wolvic.ui.views.settings.SwitchSetting; import com.igalia.wolvic.ui.widgets.WidgetManagerDelegate; +import com.igalia.wolvic.ui.widgets.WidgetPlacement; class DeveloperOptionsView extends SettingsView { @@ -76,6 +79,13 @@ protected void updateUI() { mBinding.localAddonSwitch.setOnCheckedChangeListener(mLocalAddonListener); setLocalAddon(SettingsStore.getInstance(getContext()).isLocalAddonAllowed(), false); + + mBinding.wolvicUserAgentSwitch.setOnCheckedChangeListener(mUseWolvicUAListener); + setUseWolvicUA(SettingsStore.getInstance(getContext()).getUseWolvicUA(), false); + + int uaMode = SettingsStore.getInstance(getContext()).getUaMode(); + mBinding.uaRadio.setOnCheckedChangeListener(mUaModeListener); + setUaMode(mBinding.uaRadio.getIdForValue(uaMode), false); } private SwitchSetting.OnCheckedChangeListener mRemoteDebuggingListener = (compoundButton, value, doApply) -> { @@ -106,6 +116,13 @@ protected void updateUI() { setLocalAddon(value, doApply); }; + private SwitchSetting.OnCheckedChangeListener mUseWolvicUAListener = (compoundButton, enabled, apply) -> + setUseWolvicUA(enabled, true); + + private RadioGroupSetting.OnCheckedChangeListener mUaModeListener = (radioGroup, checkedId, doApply) -> { + setUaMode(checkedId, true); + }; + private OnClickListener mResetListener = (view) -> { boolean restart = false; if (mBinding.remoteDebuggingSwitch.isChecked() != SettingsStore.REMOTE_DEBUGGING_DEFAULT) { @@ -139,6 +156,14 @@ protected void updateUI() { setLocalAddon(SettingsStore.LOCAL_ADDON_ALLOWED, true); } + if (mBinding.wolvicUserAgentSwitch.isChecked() != SettingsStore.USE_WOLVIC_UA_DEFAULT) { + setUseWolvicUA(SettingsStore.USE_WOLVIC_UA_DEFAULT, true); + } + + if (!mBinding.uaRadio.getValueForId(mBinding.uaRadio.getCheckedRadioButtonId()).equals(SettingsStore.UA_MODE_DEFAULT)) { + setUaMode(mBinding.uaRadio.getIdForValue(SettingsStore.UA_MODE_DEFAULT), true); + } + if (restart) { showRestartDialog(); } @@ -219,9 +244,38 @@ private void setLocalAddon(boolean value, boolean doApply) { } } + private void setUseWolvicUA(boolean value, boolean doApply) { + mBinding.wolvicUserAgentSwitch.setOnCheckedChangeListener(null); + mBinding.wolvicUserAgentSwitch.setValue(value, false); + mBinding.wolvicUserAgentSwitch.setOnCheckedChangeListener(mUseWolvicUAListener); + + if (doApply) { + SettingsStore.getInstance(getContext()).setUseWolvicUA(value); + + if (value != SettingsStore.USE_WOLVIC_UA_DEFAULT) { + showAlert(getContext().getString(R.string.developer_options_wolvic_user_agent_warning_title), + getContext().getString(R.string.developer_options_wolvic_user_agent_warning_body)); + } + } + } + + private void setUaMode(int checkId, boolean doApply) { + mBinding.uaRadio.setOnCheckedChangeListener(null); + mBinding.uaRadio.setChecked(checkId, doApply); + mBinding.uaRadio.setOnCheckedChangeListener(mUaModeListener); + + SettingsStore.getInstance(getContext()).setUaMode((Integer) mBinding.uaRadio.getValueForId(checkId)); + } + + @Override + public Point getDimensions() { + return new Point(WidgetPlacement.dpDimension(getContext(), R.dimen.settings_dialog_width), + WidgetPlacement.dpDimension(getContext(), R.dimen.developer_options_height)); + } + @Override protected SettingViewType getType() { - return SettingViewType.LANGUAGE_VOICE; + return SettingViewType.DEVELOPER; } } diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/DisplayOptionsView.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/DisplayOptionsView.java index 2997161052e..0938177d1ef 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/DisplayOptionsView.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/DisplayOptionsView.java @@ -55,10 +55,6 @@ protected void updateUI() { mBinding.curvedDisplaySwitch.setOnCheckedChangeListener(mCurvedDisplayListener); setCurvedDisplay(SettingsStore.getInstance(getContext()).getCylinderDensity() > 0.0f, false); - int uaMode = SettingsStore.getInstance(getContext()).getUaMode(); - mBinding.uaRadio.setOnCheckedChangeListener(mUaModeListener); - setUaMode(mBinding.uaRadio.getIdForValue(uaMode), false); - int msaaLevel = SettingsStore.getInstance(getContext()).getMSAALevel(); mBinding.msaaRadio.setOnCheckedChangeListener(mMSSAChangeListener); setMSAAMode(mBinding.msaaRadio.getIdForValue(msaaLevel), false); @@ -123,10 +119,6 @@ public boolean isEditing() { return editing; } - private RadioGroupSetting.OnCheckedChangeListener mUaModeListener = (radioGroup, checkedId, doApply) -> { - setUaMode(checkedId, true); - }; - private RadioGroupSetting.OnCheckedChangeListener mMSSAChangeListener = (radioGroup, checkedId, doApply) -> { setMSAAMode(checkedId, true); }; @@ -178,9 +170,6 @@ public boolean isEditing() { private OnClickListener mResetListener = (view) -> { boolean restart = false; - if (!mBinding.uaRadio.getValueForId(mBinding.uaRadio.getCheckedRadioButtonId()).equals(SettingsStore.UA_MODE_DEFAULT)) { - setUaMode(mBinding.uaRadio.getIdForValue(SettingsStore.UA_MODE_DEFAULT), true); - } if (!mBinding.msaaRadio.getValueForId(mBinding.msaaRadio.getCheckedRadioButtonId()).equals(SettingsStore.MSAA_DEFAULT_LEVEL)) { setMSAAMode(mBinding.msaaRadio.getIdForValue(SettingsStore.MSAA_DEFAULT_LEVEL), true); } @@ -188,7 +177,6 @@ public boolean isEditing() { restart = restart | setDisplayDensity(SettingsStore.DISPLAY_DENSITY_DEFAULT); restart = restart | setDisplayDpi(SettingsStore.DISPLAY_DPI_DEFAULT); - setHomepage(mDefaultHomepageUrl); setAutoplay(SettingsStore.AUTOPLAY_ENABLED, true); setCurvedDisplay(false, true); @@ -227,14 +215,6 @@ private void setHomepage(String newHomepage) { mBinding.homepageEdit.setOnClickListener(mHomepageListener); } - private void setUaMode(int checkId, boolean doApply) { - mBinding.uaRadio.setOnCheckedChangeListener(null); - mBinding.uaRadio.setChecked(checkId, doApply); - mBinding.uaRadio.setOnCheckedChangeListener(mUaModeListener); - - SettingsStore.getInstance(getContext()).setUaMode((Integer)mBinding.uaRadio.getValueForId(checkId)); - } - private void setMSAAMode(int checkedId, boolean doApply) { mBinding.msaaRadio.setOnCheckedChangeListener(null); mBinding.msaaRadio.setChecked(checkedId, doApply); diff --git a/app/src/main/res/layout/options_developer.xml b/app/src/main/res/layout/options_developer.xml index 76f137b278d..3d43d238517 100644 --- a/app/src/main/res/layout/options_developer.xml +++ b/app/src/main/res/layout/options_developer.xml @@ -79,6 +79,20 @@ android:layout_height="wrap_content" app:description="@string/allow_local_addon_switch" /> + + + + diff --git a/app/src/main/res/layout/options_display.xml b/app/src/main/res/layout/options_display.xml index c13307b187c..7b2234bf903 100644 --- a/app/src/main/res/layout/options_display.xml +++ b/app/src/main/res/layout/options_display.xml @@ -44,13 +44,11 @@ android:layout_height="wrap_content" app:description="@string/developer_options_curved_display" /> - + app:description="@string/security_options_autoplay" /> - - 2x 4x + + Emplear el valor de \"User-Agent\" específico de Wolvic + + Atención + + Cambiar el valor por defecto de \"User-Agent\" es una functionalidad experimental que podría hacer que algunas páginas Web no funcionasen correctamente. - Modo de agente de usuario + Modo de \"User-Agent\" por defecto Almacenamiento predeterminado para descargas diff --git a/app/src/main/res/values-gl/strings.xml b/app/src/main/res/values-gl/strings.xml index e9344d613f9..c3b324839a3 100644 --- a/app/src/main/res/values-gl/strings.xml +++ b/app/src/main/res/values-gl/strings.xml @@ -183,7 +183,10 @@ 2x 4x Almacenamento por defecto para descargas - Modo User-Agent + Empregar o valor de \"User-Agent\" específico de Wolvic + Atención + Cambiar o valor por defecto de \"User-Agent\" é una functionalidade experimental que podería facer que algunhas páxinas Web non funcionasen correctamente. + Modo de \"User-Agent\" por defecto VR Interno Externo diff --git a/app/src/main/res/values/dimen.xml b/app/src/main/res/values/dimen.xml index 5c872d9f7f2..12507c9f5b4 100644 --- a/app/src/main/res/values/dimen.xml +++ b/app/src/main/res/values/dimen.xml @@ -245,6 +245,9 @@ 380dp + + 420dp + 1.2 diff --git a/app/src/main/res/values/non_L10n.xml b/app/src/main/res/values/non_L10n.xml index 76c6a1f196e..456f1a5136d 100644 --- a/app/src/main/res/values/non_L10n.xml +++ b/app/src/main/res/values/non_L10n.xml @@ -17,6 +17,7 @@ settings_tracking_protection_level settings_key_speech_data_collection settings_key_speech_data_collection_accept + settings_key_use_wolvic_user_agent settings_user_agent_version_v2 settings_touch_mode settings_display_density diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3f4668e30d6..1530cd2ee80 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -547,9 +547,19 @@ 4x + + Use Wolvic\'s own \"User-Agent\" + + + Warning + + + Changing the default \"User-Agent\" value is an experimental feature and might break some websites. + - User-Agent Mode + Default User-Agent Mode