Index: chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java |
index c011fcd41d7eb8ffad494f1c07aa9e2ed96b0fb2..5464f78d4a9eadb2e990e720345a5c52798cf01c 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java |
@@ -10,9 +10,13 @@ import android.content.Intent; |
import android.net.Uri; |
import android.os.Bundle; |
import android.provider.Browser; |
+import android.support.customtabs.CustomTabsIntent; |
import org.chromium.base.ApiCompatibilityUtils; |
+import org.chromium.base.ApplicationStatus; |
import org.chromium.base.ContextUtils; |
+import org.chromium.chrome.R; |
+import org.chromium.chrome.browser.ChromeActivity; |
import org.chromium.chrome.browser.IntentHandler; |
import org.chromium.chrome.browser.ServiceTabLauncher; |
import org.chromium.chrome.browser.TabState; |
@@ -94,6 +98,44 @@ public class TabDelegate extends TabCreator { |
activity.startActivity(intent); |
} |
+ /** |
+ * Creates a popup custom tab to open the url. The new tab is displayed over the tab showing |
+ * redirectUrl. |
+ * |
+ * @param requestId Id of the request for launching this tab. |
+ * @param redirectUrl The url of the background tab showing. |
please use gerrit instead
2017/05/25 14:53:26
I feel that this should be called sourceUrl. Other
gogerald1
2017/05/25 16:53:32
I named it according to the redirect_chain in Open
please use gerrit instead
2017/05/25 17:56:12
Acknowledged.
|
+ * @param url The url to open in the new tab. |
+ */ |
+ public boolean createPopupCustomTab(int requestId, String redirectUrl, String url) { |
+ // The activity contains the background tab must be active, otherwise do not open the new |
please use gerrit instead
2017/05/25 14:53:26
The activity *that* contains...
gogerald1
2017/05/25 16:53:32
Done.
|
+ // tab. |
+ Activity lastTrackedActivity = ApplicationStatus.getLastTrackedFocusedActivity(); |
+ if (!(lastTrackedActivity instanceof ChromeActivity)) return false; |
+ WebContents webcontents = |
+ ((ChromeActivity) lastTrackedActivity).getActivityTab().getWebContents(); |
+ if (webcontents == null) return false; |
+ |
+ // Do not open new tab if the current active tab is not showing the redirect url. |
+ if (!redirectUrl.equalsIgnoreCase(webcontents.getLastCommittedUrl())) return false; |
please use gerrit instead
2017/05/25 14:53:26
Let's be more restrictive and require the URLs to
gogerald1
2017/05/25 16:53:32
Done.
|
+ |
+ CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); |
+ builder.setShowTitle(true); |
+ builder.setStartAnimations(lastTrackedActivity, R.anim.slide_in_up, 0); |
+ builder.setExitAnimations(lastTrackedActivity, 0, R.anim.slide_out_down); |
+ CustomTabsIntent customTabsIntent = builder.build(); |
+ customTabsIntent.intent.setData(Uri.parse(url)); |
+ customTabsIntent.intent.setPackage(ContextUtils.getApplicationContext().getPackageName()); |
+ customTabsIntent.intent.putExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA, requestId); |
+ customTabsIntent.intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, mIsIncognito); |
+ customTabsIntent.intent.putExtra(Browser.EXTRA_APPLICATION_ID, |
+ ContextUtils.getApplicationContext().getPackageName()); |
+ |
+ lastTrackedActivity.startActivity( |
+ customTabsIntent.intent, customTabsIntent.startAnimationBundle); |
+ |
+ return true; |
+ } |
+ |
@Override |
public Tab launchUrl(String url, TabLaunchType type) { |
return createNewTab(new LoadUrlParams(url), type, null); |