Merge "Add getDefaultUserAgent to WebSettings." into jb-mr1-dev
This commit is contained in:
@@ -26947,6 +26947,7 @@ package android.webkit {
|
||||
method public synchronized boolean getUseWideViewPort();
|
||||
method public deprecated synchronized int getUserAgent();
|
||||
method public synchronized java.lang.String getUserAgentString();
|
||||
method public static java.lang.String getDefaultUserAgent(android.content.Context);
|
||||
method public void setAllowContentAccess(boolean);
|
||||
method public void setAllowFileAccess(boolean);
|
||||
method public abstract void setAllowFileAccessFromFileURLs(boolean);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.webkit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Message;
|
||||
import android.os.Build;
|
||||
|
||||
@@ -1225,6 +1226,18 @@ public abstract class WebSettings {
|
||||
throw new MustOverrideException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default User-Agent used by a WebView.
|
||||
* An instance of WebView could use a different User-Agent if a call
|
||||
* is made to {@link WebSettings#setUserAgent(int)} or
|
||||
* {@link WebSettings#setUserAgentString(String)}.
|
||||
*
|
||||
* @param context a Context object used to access application assets
|
||||
*/
|
||||
public static String getDefaultUserAgent(Context context) {
|
||||
return WebView.getFactory().getDefaultUserAgent(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the WebView whether it needs to set a node to have focus when
|
||||
* {@link WebView#requestFocus(int, android.graphics.Rect)} is called. The
|
||||
|
||||
@@ -374,6 +374,21 @@ public class WebSettingsClassic extends WebSettings {
|
||||
synchronized(sLockForLocaleSettings) {
|
||||
locale = sLocale;
|
||||
}
|
||||
return getDefaultUserAgentForLocale(mContext, locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default User-Agent used by a WebView.
|
||||
* An instance of WebView could use a different User-Agent if a call
|
||||
* is made to {@link WebSettings#setUserAgent(int)} or
|
||||
* {@link WebSettings#setUserAgentString(String)}.
|
||||
*
|
||||
* @param context a Context object used to access application assets
|
||||
* @param locale The Locale to use in the User-Agent string.
|
||||
* @see WebViewFactoryProvider#getDefaultUserAgent(Context)
|
||||
* @see WebView#getDefaultUserAgent(Context)
|
||||
*/
|
||||
public static String getDefaultUserAgentForLocale(Context context, Locale locale) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
// Add version
|
||||
final String version = Build.VERSION.RELEASE;
|
||||
@@ -417,9 +432,9 @@ public class WebSettingsClassic extends WebSettings {
|
||||
buffer.append(" Build/");
|
||||
buffer.append(id);
|
||||
}
|
||||
String mobile = mContext.getResources().getText(
|
||||
String mobile = context.getResources().getText(
|
||||
com.android.internal.R.string.web_user_agent_target_content).toString();
|
||||
final String base = mContext.getResources().getText(
|
||||
final String base = context.getResources().getText(
|
||||
com.android.internal.R.string.web_user_agent).toString();
|
||||
return String.format(base, buffer, mobile);
|
||||
}
|
||||
|
||||
@@ -1821,7 +1821,7 @@ public class WebView extends AbsoluteLayout
|
||||
}
|
||||
}
|
||||
|
||||
private static synchronized WebViewFactoryProvider getFactory() {
|
||||
static synchronized WebViewFactoryProvider getFactory() {
|
||||
// For now the main purpose of this function (and the factory abstration) is to keep
|
||||
// us honest and minimize usage of WebViewClassic internals when binding the proxy.
|
||||
checkThread();
|
||||
|
||||
@@ -132,6 +132,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
@@ -1308,6 +1309,12 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
||||
public WebViewDatabase getWebViewDatabase(Context context) {
|
||||
return WebViewDatabaseClassic.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultUserAgent(Context context) {
|
||||
return WebSettingsClassic.getDefaultUserAgentForLocale(context,
|
||||
Locale.getDefault());
|
||||
}
|
||||
}
|
||||
|
||||
private void onHandleUiEvent(MotionEvent event, int eventType, int flags) {
|
||||
|
||||
@@ -93,4 +93,14 @@ public interface WebViewFactoryProvider {
|
||||
* @return the singleton WebViewDatabase instance
|
||||
*/
|
||||
WebViewDatabase getWebViewDatabase(Context context);
|
||||
|
||||
/**
|
||||
* Returns the default User-Agent used by a WebView.
|
||||
* An instance of WebView could use a different User-Agent if a call
|
||||
* is made to {@link WebSettings#setUserAgent(int)} or
|
||||
* {@link WebSettings#setUserAgentString(String)}.
|
||||
*
|
||||
* @param context a Context object used to access application assets
|
||||
*/
|
||||
String getDefaultUserAgent(Context context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user