am 9af67e8f: Merge "Add getDefaultUserAgent to WebSettings." into jb-mr1-dev
* commit '9af67e8f6c7dd98baa6232ff2cda97510b827637': Add getDefaultUserAgent to WebSettings.
This commit is contained in:
@@ -26947,6 +26947,7 @@ package android.webkit {
|
|||||||
method public synchronized boolean getUseWideViewPort();
|
method public synchronized boolean getUseWideViewPort();
|
||||||
method public deprecated synchronized int getUserAgent();
|
method public deprecated synchronized int getUserAgent();
|
||||||
method public synchronized java.lang.String getUserAgentString();
|
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 setAllowContentAccess(boolean);
|
||||||
method public void setAllowFileAccess(boolean);
|
method public void setAllowFileAccess(boolean);
|
||||||
method public abstract void setAllowFileAccessFromFileURLs(boolean);
|
method public abstract void setAllowFileAccessFromFileURLs(boolean);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package android.webkit;
|
package android.webkit;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
@@ -1225,6 +1226,18 @@ public abstract class WebSettings {
|
|||||||
throw new MustOverrideException();
|
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
|
* Tells the WebView whether it needs to set a node to have focus when
|
||||||
* {@link WebView#requestFocus(int, android.graphics.Rect)} is called. The
|
* {@link WebView#requestFocus(int, android.graphics.Rect)} is called. The
|
||||||
|
|||||||
@@ -374,6 +374,21 @@ public class WebSettingsClassic extends WebSettings {
|
|||||||
synchronized(sLockForLocaleSettings) {
|
synchronized(sLockForLocaleSettings) {
|
||||||
locale = sLocale;
|
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();
|
StringBuffer buffer = new StringBuffer();
|
||||||
// Add version
|
// Add version
|
||||||
final String version = Build.VERSION.RELEASE;
|
final String version = Build.VERSION.RELEASE;
|
||||||
@@ -417,9 +432,9 @@ public class WebSettingsClassic extends WebSettings {
|
|||||||
buffer.append(" Build/");
|
buffer.append(" Build/");
|
||||||
buffer.append(id);
|
buffer.append(id);
|
||||||
}
|
}
|
||||||
String mobile = mContext.getResources().getText(
|
String mobile = context.getResources().getText(
|
||||||
com.android.internal.R.string.web_user_agent_target_content).toString();
|
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();
|
com.android.internal.R.string.web_user_agent).toString();
|
||||||
return String.format(base, buffer, mobile);
|
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
|
// 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.
|
// us honest and minimize usage of WebViewClassic internals when binding the proxy.
|
||||||
checkThread();
|
checkThread();
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
@@ -1308,6 +1309,12 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
public WebViewDatabase getWebViewDatabase(Context context) {
|
public WebViewDatabase getWebViewDatabase(Context context) {
|
||||||
return WebViewDatabaseClassic.getInstance(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) {
|
private void onHandleUiEvent(MotionEvent event, int eventType, int flags) {
|
||||||
|
|||||||
@@ -93,4 +93,14 @@ public interface WebViewFactoryProvider {
|
|||||||
* @return the singleton WebViewDatabase instance
|
* @return the singleton WebViewDatabase instance
|
||||||
*/
|
*/
|
||||||
WebViewDatabase getWebViewDatabase(Context context);
|
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