| Index: chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java
 | 
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java b/chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java
 | 
| index b8b840b967d719ed591910d1cddc24ff7f144350..8332737d200b9914cb00eb3123bec6db85a1eb5a 100644
 | 
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java
 | 
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java
 | 
| @@ -6,8 +6,11 @@ package org.chromium.chrome.browser;
 | 
|  
 | 
|  import android.content.Intent;
 | 
|  import android.os.AsyncTask;
 | 
| +import android.support.annotation.Nullable;
 | 
| +import android.text.TextUtils;
 | 
|  
 | 
|  import org.chromium.base.ContextUtils;
 | 
| +import org.chromium.base.ThreadUtils;
 | 
|  import org.chromium.base.annotations.CalledByNative;
 | 
|  import org.chromium.chrome.browser.tab.Tab;
 | 
|  import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
 | 
| @@ -21,6 +24,7 @@ import org.chromium.content_public.browser.WebContents;
 | 
|  import org.chromium.content_public.common.Referrer;
 | 
|  import org.chromium.content_public.common.ResourceRequestBody;
 | 
|  import org.chromium.ui.base.PageTransition;
 | 
| +import org.chromium.ui.mojom.WindowOpenDisposition;
 | 
|  import org.chromium.webapk.lib.client.WebApkNavigationClient;
 | 
|  import org.chromium.webapk.lib.client.WebApkValidator;
 | 
|  
 | 
| @@ -39,21 +43,36 @@ public class ServiceTabLauncher {
 | 
|  
 | 
|      /**
 | 
|       * Launches the browser activity and launches a tab for |url|.
 | 
| -     *  @param requestId Id of the request for launching this tab.
 | 
| -     * @param incognito Whether the tab should be launched in incognito mode.
 | 
| -     * @param url The URL which should be launched in a tab.
 | 
| -     * @param disposition The disposition requested by the navigation source.
 | 
| -     * @param referrerUrl URL of the referrer which is opening the page.
 | 
| +     * @param requestId      Id of the request for launching this tab.
 | 
| +     * @param incognito      Whether the tab should be launched in incognito mode.
 | 
| +     * @param redirectUrl    The last redirect URL that occured before |url|.
 | 
| +     * @param url            The URL which should be launched in a tab.
 | 
| +     * @param disposition    The disposition requested by the navigation source.
 | 
| +     * @param referrerUrl    URL of the referrer which is opening the page.
 | 
|       * @param referrerPolicy The referrer policy to consider when applying the referrer.
 | 
| -     * @param extraHeaders Extra headers to apply when requesting the tab's URL.
 | 
| -     * @param postData Post-data to include in the tab URL's request body.
 | 
| +     * @param extraHeaders   Extra headers to apply when requesting the tab's URL.
 | 
| +     * @param postData       Post-data to include in the tab URL's request body.
 | 
|       */
 | 
|      @CalledByNative
 | 
| -    public static void launchTab(final int requestId, final boolean incognito, final String url,
 | 
| -            final int disposition, final String referrerUrl, final int referrerPolicy,
 | 
| -            final String extraHeaders, final ResourceRequestBody postData) {
 | 
| +    public static void launchTab(final int requestId, final boolean incognito,
 | 
| +            final String redirectUrl, final String url, final int disposition,
 | 
| +            final String referrerUrl, final int referrerPolicy, final String extraHeaders,
 | 
| +            final ResourceRequestBody postData) {
 | 
|          final TabDelegate tabDelegate = new TabDelegate(incognito);
 | 
|  
 | 
| +        // Open the url in popup custom tab over the tab showing the redirect url.
 | 
| +        if (disposition == WindowOpenDisposition.NEW_POPUP && !TextUtils.isEmpty(redirectUrl)) {
 | 
| +            if (!tabDelegate.createPopupCustomTab(requestId, redirectUrl, url)) {
 | 
| +                ThreadUtils.postOnUiThread(new Runnable() {
 | 
| +                    @Override
 | 
| +                    public void run() {
 | 
| +                        onWebContentsForRequestAvailable(requestId, null);
 | 
| +                    }
 | 
| +                });
 | 
| +            }
 | 
| +            return;
 | 
| +        }
 | 
| +
 | 
|          // 1. Launch WebAPK if one matches the target URL.
 | 
|          if (ChromeWebApkHost.isEnabled()) {
 | 
|              String webApkPackageName =
 | 
| @@ -122,11 +141,13 @@ public class ServiceTabLauncher {
 | 
|       * To be called by the activity when the WebContents for |requestId| has been created, or has
 | 
|       * been recycled from previous use. The |webContents| must not yet have started provisional
 | 
|       * load for the main frame.
 | 
| +     * The |webContents| could be null if the request is failed.
 | 
|       *
 | 
|       * @param requestId Id of the tab launching request which has been fulfilled.
 | 
|       * @param webContents The WebContents instance associated with this request.
 | 
|       */
 | 
| -    public static void onWebContentsForRequestAvailable(int requestId, WebContents webContents) {
 | 
| +    public static void onWebContentsForRequestAvailable(
 | 
| +            int requestId, @Nullable WebContents webContents) {
 | 
|          nativeOnWebContentsForRequestAvailable(requestId, webContents);
 | 
|      }
 | 
|  
 | 
| 
 |