| 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.customtabs; | 5 package org.chromium.chrome.browser.customtabs; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.ComponentName; |
| 8 import android.content.Context; | 9 import android.content.Context; |
| 9 import android.content.Intent; | 10 import android.content.Intent; |
| 10 import android.content.pm.ResolveInfo; | 11 import android.content.pm.ResolveInfo; |
| 11 import android.text.TextUtils; | 12 import android.text.TextUtils; |
| 12 | 13 |
| 14 import org.chromium.base.ContextUtils; |
| 13 import org.chromium.base.VisibleForTesting; | 15 import org.chromium.base.VisibleForTesting; |
| 16 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 14 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator; | 17 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator; |
| 15 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator; | 18 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator; |
| 16 import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl; | 19 import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl; |
| 17 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; | 20 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; |
| 18 import org.chromium.chrome.browser.fullscreen.BrowserStateBrowserControlsVisibil
ityDelegate; | 21 import org.chromium.chrome.browser.fullscreen.BrowserStateBrowserControlsVisibil
ityDelegate; |
| 19 import org.chromium.chrome.browser.fullscreen.ComposedBrowserControlsVisibilityD
elegate; | 22 import org.chromium.chrome.browser.fullscreen.ComposedBrowserControlsVisibilityD
elegate; |
| 23 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; |
| 20 import org.chromium.chrome.browser.tab.BrowserControlsVisibilityDelegate; | 24 import org.chromium.chrome.browser.tab.BrowserControlsVisibilityDelegate; |
| 21 import org.chromium.chrome.browser.tab.InterceptNavigationDelegateImpl; | 25 import org.chromium.chrome.browser.tab.InterceptNavigationDelegateImpl; |
| 22 import org.chromium.chrome.browser.tab.Tab; | 26 import org.chromium.chrome.browser.tab.Tab; |
| 23 import org.chromium.chrome.browser.tab.TabContextMenuItemDelegate; | 27 import org.chromium.chrome.browser.tab.TabContextMenuItemDelegate; |
| 24 import org.chromium.chrome.browser.tab.TabDelegateFactory; | 28 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
| 25 import org.chromium.chrome.browser.tab.TabStateBrowserControlsVisibilityDelegate
; | 29 import org.chromium.chrome.browser.tab.TabStateBrowserControlsVisibilityDelegate
; |
| 26 import org.chromium.chrome.browser.tab.TabWebContentsDelegateAndroid; | 30 import org.chromium.chrome.browser.tab.TabWebContentsDelegateAndroid; |
| 31 import org.chromium.chrome.browser.tabmodel.TabModel; |
| 32 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 33 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; |
| 34 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
| 27 import org.chromium.chrome.browser.util.IntentUtils; | 35 import org.chromium.chrome.browser.util.IntentUtils; |
| 28 import org.chromium.chrome.browser.util.UrlUtilities; | 36 import org.chromium.chrome.browser.util.UrlUtilities; |
| 37 import org.chromium.content_public.browser.LoadUrlParams; |
| 38 import org.chromium.content_public.common.ResourceRequestBody; |
| 39 import org.chromium.ui.mojom.WindowOpenDisposition; |
| 29 | 40 |
| 30 /** | 41 /** |
| 31 * A {@link TabDelegateFactory} class to be used in all {@link Tab} owned | 42 * A {@link TabDelegateFactory} class to be used in all {@link Tab} owned |
| 32 * by a {@link CustomTabActivity}. | 43 * by a {@link CustomTabActivity}. |
| 33 */ | 44 */ |
| 34 public class CustomTabDelegateFactory extends TabDelegateFactory { | 45 public class CustomTabDelegateFactory extends TabDelegateFactory { |
| 35 /** | 46 /** |
| 36 * A custom external navigation delegate that forbids the intent picker from
showing up. | 47 * A custom external navigation delegate that forbids the intent picker from
showing up. |
| 37 */ | 48 */ |
| 38 static class CustomTabNavigationDelegate extends ExternalNavigationDelegateI
mpl { | 49 static class CustomTabNavigationDelegate extends ExternalNavigationDelegateI
mpl { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 141 |
| 131 @Override | 142 @Override |
| 132 public boolean shouldResumeRequestsForCreatedWindow() { | 143 public boolean shouldResumeRequestsForCreatedWindow() { |
| 133 return true; | 144 return true; |
| 134 } | 145 } |
| 135 | 146 |
| 136 @Override | 147 @Override |
| 137 protected void bringActivityToForeground() { | 148 protected void bringActivityToForeground() { |
| 138 // No-op here. If client's task is in background Chrome is unable to
foreground it. | 149 // No-op here. If client's task is in background Chrome is unable to
foreground it. |
| 139 } | 150 } |
| 151 |
| 152 @Override |
| 153 public void openNewTab(String url, String extraHeaders, ResourceRequestB
ody postData, |
| 154 int disposition, boolean isRendererInitiated) { |
| 155 // If attempting to open an incognito tab, always send the user to t
abbed mode. |
| 156 if (disposition == WindowOpenDisposition.OFF_THE_RECORD) { |
| 157 if (isRendererInitiated) { |
| 158 throw new IllegalStateException( |
| 159 "Invalid attempt to open an incognito tab from the r
enderer"); |
| 160 } |
| 161 LoadUrlParams loadUrlParams = new LoadUrlParams(url); |
| 162 loadUrlParams.setVerbatimHeaders(extraHeaders); |
| 163 loadUrlParams.setPostData(postData); |
| 164 loadUrlParams.setIsRendererInitiated(isRendererInitiated); |
| 165 |
| 166 Class<? extends ChromeTabbedActivity> tabbedClass = |
| 167 MultiWindowUtils.getInstance().getTabbedActivityForInten
t( |
| 168 null, ContextUtils.getApplicationContext()); |
| 169 AsyncTabCreationParams tabParams = new AsyncTabCreationParams(lo
adUrlParams, |
| 170 new ComponentName(ContextUtils.getApplicationContext(),
tabbedClass)); |
| 171 new TabDelegate(true).createNewTab(tabParams, |
| 172 TabLaunchType.FROM_LONGPRESS_FOREGROUND, TabModel.INVALI
D_TAB_INDEX); |
| 173 return; |
| 174 } |
| 175 |
| 176 super.openNewTab(url, extraHeaders, postData, disposition, isRendere
rInitiated); |
| 177 } |
| 140 } | 178 } |
| 141 | 179 |
| 142 private final boolean mShouldHideBrowserControls; | 180 private final boolean mShouldHideBrowserControls; |
| 143 private final boolean mIsOpenedByChrome; | 181 private final boolean mIsOpenedByChrome; |
| 144 private final BrowserStateBrowserControlsVisibilityDelegate mBrowserStateVis
ibilityDelegate; | 182 private final BrowserStateBrowserControlsVisibilityDelegate mBrowserStateVis
ibilityDelegate; |
| 145 | 183 |
| 146 private ExternalNavigationDelegateImpl mNavigationDelegate; | 184 private ExternalNavigationDelegateImpl mNavigationDelegate; |
| 147 private ExternalNavigationHandler mNavigationHandler; | 185 private ExternalNavigationHandler mNavigationHandler; |
| 148 | 186 |
| 149 /** | 187 /** |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 @VisibleForTesting | 245 @VisibleForTesting |
| 208 ExternalNavigationDelegateImpl getExternalNavigationDelegate() { | 246 ExternalNavigationDelegateImpl getExternalNavigationDelegate() { |
| 209 return mNavigationDelegate; | 247 return mNavigationDelegate; |
| 210 } | 248 } |
| 211 | 249 |
| 212 @Override | 250 @Override |
| 213 public boolean canShowAppBanners(Tab tab) { | 251 public boolean canShowAppBanners(Tab tab) { |
| 214 return false; | 252 return false; |
| 215 } | 253 } |
| 216 } | 254 } |
| OLD | NEW |