Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.tabmodel.document; | 5 package org.chromium.chrome.browser.tabmodel.document; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.ComponentName; | 8 import android.content.ComponentName; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.net.Uri; | 10 import android.net.Uri; |
| 11 import android.os.Bundle; | 11 import android.os.Bundle; |
| 12 import android.provider.Browser; | 12 import android.provider.Browser; |
| 13 import android.support.customtabs.CustomTabsIntent; | |
| 13 | 14 |
| 14 import org.chromium.base.ApiCompatibilityUtils; | 15 import org.chromium.base.ApiCompatibilityUtils; |
| 16 import org.chromium.base.ApplicationStatus; | |
| 15 import org.chromium.base.ContextUtils; | 17 import org.chromium.base.ContextUtils; |
| 18 import org.chromium.chrome.R; | |
| 19 import org.chromium.chrome.browser.ChromeActivity; | |
| 16 import org.chromium.chrome.browser.IntentHandler; | 20 import org.chromium.chrome.browser.IntentHandler; |
| 17 import org.chromium.chrome.browser.ServiceTabLauncher; | 21 import org.chromium.chrome.browser.ServiceTabLauncher; |
| 18 import org.chromium.chrome.browser.TabState; | 22 import org.chromium.chrome.browser.TabState; |
| 19 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | 23 import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
| 20 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; | 24 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; |
| 21 import org.chromium.chrome.browser.tab.Tab; | 25 import org.chromium.chrome.browser.tab.Tab; |
| 22 import org.chromium.chrome.browser.tab.TabIdManager; | 26 import org.chromium.chrome.browser.tab.TabIdManager; |
| 23 import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager; | 27 import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager; |
| 24 import org.chromium.chrome.browser.tabmodel.TabCreatorManager.TabCreator; | 28 import org.chromium.chrome.browser.tabmodel.TabCreatorManager.TabCreator; |
| 25 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 29 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 30 import org.chromium.components.url_formatter.UrlFormatter; | |
| 26 import org.chromium.content_public.browser.LoadUrlParams; | 31 import org.chromium.content_public.browser.LoadUrlParams; |
| 27 import org.chromium.content_public.browser.WebContents; | 32 import org.chromium.content_public.browser.WebContents; |
| 28 import org.chromium.ui.base.PageTransition; | 33 import org.chromium.ui.base.PageTransition; |
| 29 | 34 |
| 30 import java.util.Map; | 35 import java.util.Map; |
| 31 | 36 |
| 32 /** | 37 /** |
| 33 * Asynchronously creates Tabs by creating/starting up Activities. | 38 * Asynchronously creates Tabs by creating/starting up Activities. |
| 34 */ | 39 */ |
| 35 public class TabDelegate extends TabCreator { | 40 public class TabDelegate extends TabCreator { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 Class<? extends Activity> targetActivity = | 92 Class<? extends Activity> targetActivity = |
| 88 MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(acti vity); | 93 MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(acti vity); |
| 89 if (targetActivity == null) return; | 94 if (targetActivity == null) return; |
| 90 | 95 |
| 91 MultiWindowUtils.setOpenInOtherWindowIntentExtras(intent, activity, targ etActivity); | 96 MultiWindowUtils.setOpenInOtherWindowIntentExtras(intent, activity, targ etActivity); |
| 92 IntentHandler.addTrustedIntentExtras(intent); | 97 IntentHandler.addTrustedIntentExtras(intent); |
| 93 MultiWindowUtils.onMultiInstanceModeStarted(); | 98 MultiWindowUtils.onMultiInstanceModeStarted(); |
| 94 activity.startActivity(intent); | 99 activity.startActivity(intent); |
| 95 } | 100 } |
| 96 | 101 |
| 102 /** | |
| 103 * Creates a popup custom tab to open the url. The new tab is displayed over the tab showing | |
| 104 * redirectUrl. | |
| 105 * | |
| 106 * @param requestId The tab launch request ID from the {@link ServiceTabLa uncher}. | |
| 107 * @param redirectUrl The url of the background tab showing. | |
| 108 * @param url The url to open in the new tab. | |
| 109 */ | |
| 110 public boolean createPopupCustomTab(int requestId, String redirectUrl, Strin g url) { | |
|
please use gerrit instead
2017/06/01 17:50:37
Let's be clear when this method would be called: i
gogerald1
2017/06/02 03:33:11
Acknowledged.
| |
| 111 // The activity that contains the background tab must be active, otherwi se do not open the | |
| 112 // new tab. | |
| 113 Activity lastTrackedActivity = ApplicationStatus.getLastTrackedFocusedAc tivity(); | |
| 114 if (!(lastTrackedActivity instanceof ChromeActivity)) return false; | |
| 115 WebContents webcontents = | |
| 116 ((ChromeActivity) lastTrackedActivity).getActivityTab().getWebCo ntents(); | |
| 117 if (webcontents == null) return false; | |
| 118 | |
| 119 // Do not open new tab if the foreground web page is not showing redirec t_url. | |
| 120 // TODO(gogerald): Match url instead of origin after passed in redirect_ url is changed in | |
| 121 // PaymentRequestEvent::openWindow. | |
| 122 String redirectOrigin = UrlFormatter.formatUrlForSecurityDisplay(redirec tUrl, true); | |
| 123 if (!redirectOrigin.equals(UrlFormatter.formatUrlForSecurityDisplay( | |
|
please use gerrit instead
2017/06/01 17:50:37
I don't think this check is useful, because the us
gogerald1
2017/06/02 03:33:11
Done.
| |
| 124 webcontents.getLastCommittedUrl(), true))) { | |
| 125 return false; | |
| 126 } | |
| 127 | |
| 128 CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); | |
| 129 builder.setShowTitle(true); | |
| 130 builder.setStartAnimations(lastTrackedActivity, R.anim.slide_in_up, 0); | |
| 131 builder.setExitAnimations(lastTrackedActivity, 0, R.anim.slide_out_down) ; | |
| 132 CustomTabsIntent customTabsIntent = builder.build(); | |
| 133 customTabsIntent.intent.setPackage(ContextUtils.getApplicationContext(). getPackageName()); | |
| 134 customTabsIntent.intent.putExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EX TRA, requestId); | |
| 135 customTabsIntent.intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_ TAB, mIsIncognito); | |
| 136 customTabsIntent.intent.putExtra(Browser.EXTRA_APPLICATION_ID, | |
| 137 ContextUtils.getApplicationContext().getPackageName()); | |
| 138 | |
| 139 customTabsIntent.launchUrl(lastTrackedActivity, Uri.parse(url)); | |
| 140 | |
| 141 return true; | |
| 142 } | |
| 143 | |
| 97 @Override | 144 @Override |
| 98 public Tab launchUrl(String url, TabLaunchType type) { | 145 public Tab launchUrl(String url, TabLaunchType type) { |
| 99 return createNewTab(new LoadUrlParams(url), type, null); | 146 return createNewTab(new LoadUrlParams(url), type, null); |
| 100 } | 147 } |
| 101 | 148 |
| 102 @Override | 149 @Override |
| 103 public Tab createNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent) { | 150 public Tab createNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent) { |
| 104 AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(loadUrlP arams); | 151 AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(loadUrlP arams); |
| 105 createNewTab(asyncParams, type, parent == null ? Tab.INVALID_TAB_ID : pa rent.getId()); | 152 createNewTab(asyncParams, type, parent == null ? Tab.INVALID_TAB_ID : pa rent.getId()); |
| 106 return null; | 153 return null; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 * Passes the supplied web app launch intent to the IntentHandler. | 225 * Passes the supplied web app launch intent to the IntentHandler. |
| 179 * @param intent Web app launch intent. | 226 * @param intent Web app launch intent. |
| 180 */ | 227 */ |
| 181 public void createNewStandaloneFrame(Intent intent) { | 228 public void createNewStandaloneFrame(Intent intent) { |
| 182 assert intent != null; | 229 assert intent != null; |
| 183 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 230 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 184 | ApiCompatibilityUtils.getActivityNewDocumentFlag()); | 231 | ApiCompatibilityUtils.getActivityNewDocumentFlag()); |
| 185 IntentHandler.startActivityForTrustedIntent(intent); | 232 IntentHandler.startActivityForTrustedIntent(intent); |
| 186 } | 233 } |
| 187 } | 234 } |
| OLD | NEW |