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

Commit f2c9b2c0 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 20706

* changes:
  Improve Browser performance by 1-2%. To address domain sanity bug, http://b/issue?id=1022797, we decoded/encoded the url for each request. As the url can be long, getBytes() and String.init are taking 1.5% in nytimes.com and 2.4% in cnn.com. By doing a simple URL encoding test, we can shave 1-2 secs thread time during loading.
parents c5127603 758bf410
Loading
Loading
Loading
Loading
+7 −11
Original line number Diff line number Diff line
@@ -95,19 +95,15 @@ class FrameLoader {
    public boolean executeLoad() {
        String url = mListener.url();

        // Attempt to decode the percent-encoded url.
        try {
            url = new String(URLUtil.decode(url.getBytes()));
        } catch (IllegalArgumentException e) {
            // Fail with a bad url error if the decode fails.
        if (URLUtil.isNetworkUrl(url)){
            if (mSettings.getBlockNetworkLoads()) {
                mListener.error(EventHandler.ERROR_BAD_URL,
                        mListener.getContext().getString(
                                com.android.internal.R.string.httpErrorBadUrl));
                return false;
            }

        if (URLUtil.isNetworkUrl(url)){
            if (mSettings.getBlockNetworkLoads()) {
            // Make sure it is correctly URL encoded before sending the request
            if (!URLUtil.verifyURLEncoding(url)) {
                mListener.error(EventHandler.ERROR_BAD_URL,
                        mListener.getContext().getString(
                        com.android.internal.R.string.httpErrorBadUrl));
+26 −0
Original line number Diff line number Diff line
@@ -126,6 +126,32 @@ public final class URLUtil {
        return retData;
    }

    /**
     * @return True iff the url is correctly URL encoded
     */
    static boolean verifyURLEncoding(String url) {
        int count = url.length();
        if (count == 0) {
            return false;
        }

        int index = url.indexOf('%');
        while (index >= 0 && index < count) {
            if (index < count - 2) {
                try {
                    parseHex((byte) url.charAt(++index));
                    parseHex((byte) url.charAt(++index));
                } catch (IllegalArgumentException e) {
                    return false;
                }
            } else {
                return false;
            }
            index = url.indexOf('%', index + 1);
        }
        return true;
    }

    private static int parseHex(byte b) {
        if (b >= '0' && b <= '9') return (b - '0');
        if (b >= 'A' && b <= 'F') return (b - 'A' + 10);