Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9af67e8f authored by George Mount's avatar George Mount Committed by Android (Google) Code Review
Browse files

Merge "Add getDefaultUserAgent to WebSettings." into jb-mr1-dev

parents df8ef4b1 9f410c54
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
+13 −0
Original line number Diff line number Diff line
@@ -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
+17 −2
Original line number Diff line number Diff line
@@ -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);
    }
+1 −1
Original line number Diff line number Diff line
@@ -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();
+7 −0
Original line number Diff line number Diff line
@@ -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) {
Loading