mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
CB-3360 Allow setting a custom User-Agent (close #162)
This commit is contained in:
parent
d005359f89
commit
9873106785
@ -60,6 +60,7 @@ public class SystemWebViewEngine implements CordovaWebViewEngine {
|
|||||||
|
|
||||||
protected final SystemWebView webView;
|
protected final SystemWebView webView;
|
||||||
protected final SystemCookieManager cookieManager;
|
protected final SystemCookieManager cookieManager;
|
||||||
|
protected CordovaPreferences preferences;
|
||||||
protected CordovaBridge bridge;
|
protected CordovaBridge bridge;
|
||||||
protected CordovaWebViewEngine.Client client;
|
protected CordovaWebViewEngine.Client client;
|
||||||
protected CordovaWebView parentWebView;
|
protected CordovaWebView parentWebView;
|
||||||
@ -71,10 +72,15 @@ public class SystemWebViewEngine implements CordovaWebViewEngine {
|
|||||||
|
|
||||||
/** Used when created via reflection. */
|
/** Used when created via reflection. */
|
||||||
public SystemWebViewEngine(Context context, CordovaPreferences preferences) {
|
public SystemWebViewEngine(Context context, CordovaPreferences preferences) {
|
||||||
this(new SystemWebView(context));
|
this(new SystemWebView(context), preferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SystemWebViewEngine(SystemWebView webView) {
|
public SystemWebViewEngine(SystemWebView webView) {
|
||||||
|
this(webView, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SystemWebViewEngine(SystemWebView webView, CordovaPreferences preferences) {
|
||||||
|
this.preferences = preferences;
|
||||||
this.webView = webView;
|
this.webView = webView;
|
||||||
cookieManager = new SystemCookieManager(webView);
|
cookieManager = new SystemCookieManager(webView);
|
||||||
}
|
}
|
||||||
@ -86,6 +92,10 @@ public class SystemWebViewEngine implements CordovaWebViewEngine {
|
|||||||
if (this.cordova != null) {
|
if (this.cordova != null) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
// Needed when prefs are not passed by the constructor
|
||||||
|
if (preferences == null) {
|
||||||
|
preferences = parentWebView.getPreferences();
|
||||||
|
}
|
||||||
this.parentWebView = parentWebView;
|
this.parentWebView = parentWebView;
|
||||||
this.cordova = cordova;
|
this.cordova = cordova;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
@ -199,7 +209,19 @@ public class SystemWebViewEngine implements CordovaWebViewEngine {
|
|||||||
|
|
||||||
// Fix for CB-1405
|
// Fix for CB-1405
|
||||||
// Google issue 4641
|
// Google issue 4641
|
||||||
settings.getUserAgentString();
|
String defaultUserAgent = settings.getUserAgentString();
|
||||||
|
|
||||||
|
// Fix for CB-3360
|
||||||
|
String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
|
||||||
|
if (overrideUserAgent != null) {
|
||||||
|
settings.setUserAgentString(overrideUserAgent);
|
||||||
|
} else {
|
||||||
|
String appendUserAgent = preferences.getString("AppendUserAgent", null);
|
||||||
|
if (appendUserAgent != null) {
|
||||||
|
settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// End CB-3360
|
||||||
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
|
intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
|
||||||
|
Loading…
Reference in New Issue
Block a user