Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3289)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java

Issue 2893823004: [Payments] Implement openWindow for service worker based payment handler (Closed)
Patch Set: format Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a3863c27736e25a4fb829ac2b64dccd4729a6018 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;
@@ -23,6 +27,7 @@ import org.chromium.chrome.browser.tab.TabIdManager;
import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager.TabCreator;
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
+import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.PageTransition;
@@ -94,6 +99,50 @@ 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.
Yusuf 2017/05/31 18:28:59 Does requestId have any context in other contexts?
gogerald1 2017/05/31 19:49:53 Done. This requestId is the same as the request Id
+ * @param redirectUrl The url of the background tab showing.
Yusuf 2017/05/31 18:28:59 I do understand how these params represent your us
gogerald1 2017/05/31 19:49:53 I named this parameter according to 'redirect_chai
+ * @param url The url to open in the new tab.
+ */
+ public boolean createPopupCustomTab(int requestId, String redirectUrl, String url) {
+ // The activity that contains the background tab must be active, otherwise do not open the
+ // new 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 foreground web page is not showing redirect_url.
+ // TODO(gogerald): Match url instead of origin after passed in redirect_url is changed in
+ // PaymentRequestEvent::openWindow.
+ String redirectOrigin = UrlFormatter.formatUrlForSecurityDisplay(redirectUrl, true);
+ if (!redirectOrigin.equals(UrlFormatter.formatUrlForSecurityDisplay(
+ webcontents.getLastCommittedUrl(), true))) {
Yusuf 2017/05/31 18:28:59 how does this differ from getUrl in Tab? Can we no
gogerald1 2017/05/31 19:49:53 The counterpart of getUrl in C++ is deprecated (ht
+ return false;
+ }
+
+ 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));
Yusuf 2017/05/31 18:28:59 you can use CustomTabsIntent#launchUrl for this at
gogerald1 2017/05/31 19:49:53 Done.
+ 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);
Yusuf 2017/05/31 18:28:59 do we open incognito tabs in this CL's context?
gogerald1 2017/05/31 19:49:53 Yes, payment request is allowed in incognito tabs
+ 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);

Powered by Google App Engine
This is Rietveld 408576698