AW: workaround Samsung mail app issue

This applies a workaround for one of Samsung's OEM mail apps which was
negatively affected by PlzNavigate. This is meant as a minimal temporary
workaround until we finish investigation on the issue.

The app is loading 2 URLs (a file:// URL followed by
loadDataWithBaseUrl) in quick succession. This workaround posts the
second load by 200ms. In my testing, I've found that 40ms is more than
enough, so 200ms should be very safe (but still fast enough to not
adversely impact user experience).

Bug: 781535
Test: manual - with the actual Samsung mail app
Change-Id: I1fdb002c377af083158a5dc4e0e7ce067a176d30
Reviewed-on: https://chromium-review.googlesource.com/924115
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: Changwan Ryu <changwan@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#537428}(cherry picked from commit da8150a61216a0eaa65428613d375968bec2fecc)
Reviewed-on: https://chromium-review.googlesource.com/935401
Reviewed-by: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/branch-heads/3325@{#577}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java
index c091189..8567a7e 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -132,6 +132,10 @@
 
     private static final double MIN_SCREEN_HEIGHT_PERCENTAGE_FOR_INTERSTITIAL = 0.7;
 
+    private static final String SAMSUNG_WORKAROUND_PACKAGE_NAME = "com.android.email";
+    private static final String SAMSUNG_WORKAROUND_BASE_URL = "email://";
+    private static final int SAMSUNG_WORKAROUND_DELAY = 200;
+
     private static class ForceAuxiliaryBitmapRendering {
         private static final boolean sResult = lazyCheck();
         private static boolean lazyCheck() {
@@ -1686,6 +1690,15 @@
                 return;
             }
         }
+
+        // This is a workaround for an issue with PlzNavigate and one of Samsung's OEM mail apps.
+        // See http://crbug.com/781535.
+        if (SAMSUNG_WORKAROUND_PACKAGE_NAME.equals(mContext.getPackageName())
+                && SAMSUNG_WORKAROUND_BASE_URL.equals(loadUrlParams.getBaseUrl())) {
+            ThreadUtils.postOnUiThreadDelayed(
+                    () -> loadUrl(loadUrlParams), SAMSUNG_WORKAROUND_DELAY);
+            return;
+        }
         loadUrl(loadUrlParams);
     }