| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.content.Intent; | 7 import android.content.Intent; |
| 8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
| 9 import android.net.Uri; | 9 import android.net.Uri; |
| 10 import android.os.IBinder; | 10 import android.os.IBinder; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 import org.chromium.base.Log; | 22 import org.chromium.base.Log; |
| 23 import org.chromium.base.ThreadUtils; | 23 import org.chromium.base.ThreadUtils; |
| 24 import org.chromium.base.VisibleForTesting; | 24 import org.chromium.base.VisibleForTesting; |
| 25 import org.chromium.base.metrics.RecordHistogram; | 25 import org.chromium.base.metrics.RecordHistogram; |
| 26 import org.chromium.base.metrics.RecordUserAction; | 26 import org.chromium.base.metrics.RecordUserAction; |
| 27 import org.chromium.chrome.R; | 27 import org.chromium.chrome.R; |
| 28 import org.chromium.chrome.browser.ChromeActivity; | 28 import org.chromium.chrome.browser.ChromeActivity; |
| 29 import org.chromium.chrome.browser.IntentHandler; | 29 import org.chromium.chrome.browser.IntentHandler; |
| 30 import org.chromium.chrome.browser.IntentHandler.ExternalAppId; | 30 import org.chromium.chrome.browser.IntentHandler.ExternalAppId; |
| 31 import org.chromium.chrome.browser.KeyboardShortcuts; | 31 import org.chromium.chrome.browser.KeyboardShortcuts; |
| 32 import org.chromium.chrome.browser.WebContentsFactory; |
| 32 import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; | 33 import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; |
| 33 import org.chromium.chrome.browser.appmenu.ChromeAppMenuPropertiesDelegate; | 34 import org.chromium.chrome.browser.appmenu.ChromeAppMenuPropertiesDelegate; |
| 34 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange
Reason; | 35 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange
Reason; |
| 35 import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument; | 36 import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument; |
| 36 import org.chromium.chrome.browser.rappor.RapporServiceBridge; | 37 import org.chromium.chrome.browser.rappor.RapporServiceBridge; |
| 37 import org.chromium.chrome.browser.tab.Tab; | 38 import org.chromium.chrome.browser.tab.Tab; |
| 39 import org.chromium.chrome.browser.tab.TabIdManager; |
| 38 import org.chromium.chrome.browser.tabmodel.SingleTabModelSelector; | 40 import org.chromium.chrome.browser.tabmodel.SingleTabModelSelector; |
| 39 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 41 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 40 import org.chromium.chrome.browser.toolbar.ToolbarControlContainer; | 42 import org.chromium.chrome.browser.toolbar.ToolbarControlContainer; |
| 41 import org.chromium.chrome.browser.util.ColorUtils; | 43 import org.chromium.chrome.browser.util.ColorUtils; |
| 42 import org.chromium.chrome.browser.util.IntentUtils; | 44 import org.chromium.chrome.browser.util.IntentUtils; |
| 43 import org.chromium.chrome.browser.widget.findinpage.FindToolbarManager; | 45 import org.chromium.chrome.browser.widget.findinpage.FindToolbarManager; |
| 44 import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils; | 46 import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils; |
| 45 import org.chromium.content_public.browser.LoadUrlParams; | 47 import org.chromium.content_public.browser.LoadUrlParams; |
| 48 import org.chromium.content_public.browser.WebContents; |
| 46 import org.chromium.content_public.common.Referrer; | 49 import org.chromium.content_public.common.Referrer; |
| 47 | 50 |
| 48 /** | 51 /** |
| 49 * The activity for custom tabs. It will be launched on top of a client's task. | 52 * The activity for custom tabs. It will be launched on top of a client's task. |
| 50 */ | 53 */ |
| 51 public class CustomTabActivity extends ChromeActivity { | 54 public class CustomTabActivity extends ChromeActivity { |
| 52 private static final String TAG = "cr.CustomTabActivity"; | 55 private static final String TAG = "cr.CustomTabActivity"; |
| 53 private static CustomTabContentHandler sActiveContentHandler; | 56 private static CustomTabContentHandler sActiveContentHandler; |
| 54 | 57 |
| 55 private CustomTab mTab; | 58 private Tab mTab; |
| 56 private FindToolbarManager mFindToolbarManager; | 59 private FindToolbarManager mFindToolbarManager; |
| 57 private CustomTabIntentDataProvider mIntentDataProvider; | 60 private CustomTabIntentDataProvider mIntentDataProvider; |
| 58 private IBinder mSession; | 61 private IBinder mSession; |
| 59 private CustomTabContentHandler mCustomTabContentHandler; | 62 private CustomTabContentHandler mCustomTabContentHandler; |
| 60 | 63 |
| 61 // This is to give the right package name while using the client's resources
during an | 64 // This is to give the right package name while using the client's resources
during an |
| 62 // overridePendingTransition call. | 65 // overridePendingTransition call. |
| 63 // TODO(ianwen, yusufo): Figure out a solution to extract external resources
without having to | 66 // TODO(ianwen, yusufo): Figure out a solution to extract external resources
without having to |
| 64 // change the package name. | 67 // change the package name. |
| 65 private boolean mShouldOverridePackage; | 68 private boolean mShouldOverridePackage; |
| 66 | 69 |
| 67 private boolean mRecordedStartupUma; | 70 private boolean mRecordedStartupUma; |
| 71 private boolean mShouldReplaceCurrentEntry; |
| 72 private CustomTabObserver mTabObserver; |
| 68 | 73 |
| 69 /** | 74 /** |
| 70 * Sets the currently active {@link CustomTabContentHandler} in focus. | 75 * Sets the currently active {@link CustomTabContentHandler} in focus. |
| 71 * @param contentHandler {@link CustomTabContentHandler} to set. | 76 * @param contentHandler {@link CustomTabContentHandler} to set. |
| 72 */ | 77 */ |
| 73 public static void setActiveContentHandler(CustomTabContentHandler contentHa
ndler) { | 78 public static void setActiveContentHandler(CustomTabContentHandler contentHa
ndler) { |
| 74 sActiveContentHandler = contentHandler; | 79 sActiveContentHandler = contentHandler; |
| 75 } | 80 } |
| 76 | 81 |
| 77 /** | 82 /** |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 171 } |
| 167 | 172 |
| 168 // Setting task title and icon to be null will preserve the client app's
title and icon. | 173 // Setting task title and icon to be null will preserve the client app's
title and icon. |
| 169 ApiCompatibilityUtils.setTaskDescription(this, null, null, toolbarColor)
; | 174 ApiCompatibilityUtils.setTaskDescription(this, null, null, toolbarColor)
; |
| 170 showActionButton(); | 175 showActionButton(); |
| 171 } | 176 } |
| 172 | 177 |
| 173 @Override | 178 @Override |
| 174 public void finishNativeInitialization() { | 179 public void finishNativeInitialization() { |
| 175 mSession = mIntentDataProvider.getSession(); | 180 mSession = mIntentDataProvider.getSession(); |
| 176 String url = IntentHandler.getUrlFromIntent(getIntent()); | |
| 177 // Get any referrer that has been explicitly set by the app. | |
| 178 String referrerUrl = IntentHandler.getReferrerUrlIncludingExtraHeaders(g
etIntent(), this); | |
| 179 if (referrerUrl == null) { | |
| 180 Referrer referrer = CustomTabsConnection.getInstance(getApplication(
)) | |
| 181 .getReferrerForSession(mSession); | |
| 182 if (referrer != null) referrerUrl = referrer.getUrl(); | |
| 183 } | |
| 184 // If extra headers have been passed, cancel any current prerender, as | 181 // If extra headers have been passed, cancel any current prerender, as |
| 185 // prerendering doesn't support extra headers. | 182 // prerendering doesn't support extra headers. |
| 186 if (IntentHandler.getExtraHeadersFromIntent(getIntent()) != null) { | 183 if (IntentHandler.getExtraHeadersFromIntent(getIntent()) != null) { |
| 187 CustomTabsConnection.getInstance(getApplication()).cancelPrerender(m
Session); | 184 CustomTabsConnection.getInstance(getApplication()).cancelPrerender(m
Session); |
| 188 } | 185 } |
| 189 | 186 createTab(); |
| 190 mTab = new CustomTab(this, getWindowAndroid(), mSession, url, referrerUr
l, | |
| 191 Tab.INVALID_TAB_ID, mIntentDataProvider.shouldEnableUrlBarHiding
()); | |
| 192 getTabModelSelector().setTab(mTab); | 187 getTabModelSelector().setTab(mTab); |
| 193 | 188 |
| 194 ToolbarControlContainer controlContainer = (ToolbarControlContainer) fin
dViewById( | 189 ToolbarControlContainer controlContainer = (ToolbarControlContainer) fin
dViewById( |
| 195 R.id.control_container); | 190 R.id.control_container); |
| 196 LayoutManagerDocument layoutDriver = new LayoutManagerDocument(getCompos
itorViewHolder()); | 191 LayoutManagerDocument layoutDriver = new LayoutManagerDocument(getCompos
itorViewHolder()); |
| 197 initializeCompositorContent(layoutDriver, findViewById(R.id.url_bar), | 192 initializeCompositorContent(layoutDriver, findViewById(R.id.url_bar), |
| 198 (ViewGroup) findViewById(android.R.id.content), controlContainer
); | 193 (ViewGroup) findViewById(android.R.id.content), controlContainer
); |
| 199 mFindToolbarManager = new FindToolbarManager(this, getTabModelSelector()
, | 194 mFindToolbarManager = new FindToolbarManager(this, getTabModelSelector()
, |
| 200 getToolbarManager().getActionModeController().getActionModeCallb
ack()); | 195 getToolbarManager().getActionModeController().getActionModeCallb
ack()); |
| 201 if (getContextualSearchManager() != null) { | 196 if (getContextualSearchManager() != null) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 226 public boolean shouldIgnoreIntent(Intent intent) { | 221 public boolean shouldIgnoreIntent(Intent intent) { |
| 227 return mIntentHandler.shouldIgnoreIntent(CustomTabActivity.this,
intent); | 222 return mIntentHandler.shouldIgnoreIntent(CustomTabActivity.this,
intent); |
| 228 } | 223 } |
| 229 | 224 |
| 230 @Override | 225 @Override |
| 231 public boolean updateActionButton(Bitmap bitmap, String description)
{ | 226 public boolean updateActionButton(Bitmap bitmap, String description)
{ |
| 232 mIntentDataProvider.getActionButtonParams().update(bitmap, descr
iption); | 227 mIntentDataProvider.getActionButtonParams().update(bitmap, descr
iption); |
| 233 return showActionButton(); | 228 return showActionButton(); |
| 234 } | 229 } |
| 235 }; | 230 }; |
| 236 loadUrlInCurrentTab(new LoadUrlParams(url), | 231 loadUrlInCurrentTab(new LoadUrlParams(IntentHandler.getUrlFromIntent(get
Intent())), |
| 237 IntentHandler.getTimestampFromIntent(getIntent())); | 232 IntentHandler.getTimestampFromIntent(getIntent())); |
| 238 recordClientPackageName(); | 233 recordClientPackageName(); |
| 239 super.finishNativeInitialization(); | 234 super.finishNativeInitialization(); |
| 240 } | 235 } |
| 241 | 236 |
| 237 private void createTab() { |
| 238 String url = IntentHandler.getUrlFromIntent(getIntent()); |
| 239 // Get any referrer that has been explicitly set by the app. |
| 240 String referrerUrl = IntentHandler.getReferrerUrlIncludingExtraHeaders(g
etIntent(), this); |
| 241 if (referrerUrl == null) { |
| 242 Referrer referrer = CustomTabsConnection.getInstance(getApplication(
)) |
| 243 .getReferrerForSession(mSession); |
| 244 if (referrer != null) referrerUrl = referrer.getUrl(); |
| 245 } |
| 246 mTab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TA
B_ID), |
| 247 Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), |
| 248 TabLaunchType.FROM_EXTERNAL_APP, null, null) { |
| 249 @Override |
| 250 protected boolean isHidingTopControlsEnabled() { |
| 251 // TODO(yusufo) : Get rid of this call once all other Tab classe
s are removed. |
| 252 return mIntentDataProvider.shouldEnableUrlBarHiding() |
| 253 && super.isHidingTopControlsEnabled(); |
| 254 } |
| 255 }; |
| 256 CustomTabsConnection customTabsConnection = |
| 257 CustomTabsConnection.getInstance(getApplication()); |
| 258 WebContents webContents = |
| 259 customTabsConnection.takePrerenderedUrl(mSession, url, referrerU
rl); |
| 260 if (webContents == null) { |
| 261 webContents = customTabsConnection.takeSpareWebContents(); |
| 262 // TODO(lizeb): Remove this once crbug.com/521729 is fixed. |
| 263 if (webContents != null) mShouldReplaceCurrentEntry = true; |
| 264 } |
| 265 if (webContents == null) { |
| 266 webContents = WebContentsFactory.createWebContents(false, false); |
| 267 } |
| 268 mTab.initialize(webContents, getTabContentManager(), |
| 269 new CustomTabDelegateFactory(getApplication(), mSession), false)
; |
| 270 mTab.getView().requestFocus(); |
| 271 mTabObserver = new CustomTabObserver(getApplication(), mSession); |
| 272 mTab.addObserver(mTabObserver); |
| 273 } |
| 274 |
| 242 private void recordClientPackageName() { | 275 private void recordClientPackageName() { |
| 243 final String packageName = CustomTabsConnection.getInstance(getApplicati
on()) | 276 final String packageName = CustomTabsConnection.getInstance(getApplicati
on()) |
| 244 .getClientPackageNameForSession(mSession); | 277 .getClientPackageNameForSession(mSession); |
| 245 if (TextUtils.isEmpty(packageName) || packageName.contains(getPackageNam
e())) return; | 278 if (TextUtils.isEmpty(packageName) || packageName.contains(getPackageNam
e())) return; |
| 246 ThreadUtils.runOnUiThread(new Runnable() { | 279 ThreadUtils.runOnUiThread(new Runnable() { |
| 247 @Override | 280 @Override |
| 248 public void run() { | 281 public void run() { |
| 249 RapporServiceBridge.sampleString( | 282 RapporServiceBridge.sampleString( |
| 250 "CustomTabs.ServiceClient.PackageName", packageName); | 283 "CustomTabs.ServiceClient.PackageName", packageName); |
| 251 } | 284 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 272 CustomTabsConnection.getInstance(getApplication()).notifyNavigationEvent
( | 305 CustomTabsConnection.getInstance(getApplication()).notifyNavigationEvent
( |
| 273 mSession, CustomTabsCallback.TAB_HIDDEN); | 306 mSession, CustomTabsCallback.TAB_HIDDEN); |
| 274 } | 307 } |
| 275 | 308 |
| 276 @Override | 309 @Override |
| 277 public void onStopWithNative() { | 310 public void onStopWithNative() { |
| 278 super.onStopWithNative(); | 311 super.onStopWithNative(); |
| 279 setActiveContentHandler(null); | 312 setActiveContentHandler(null); |
| 280 } | 313 } |
| 281 | 314 |
| 315 /* (non-Javadoc) |
| 316 * @see org.chromium.chrome.browser.ChromeActivity#onDestroyInternal() |
| 317 */ |
| 318 @Override |
| 319 protected void onDestroyInternal() { |
| 320 mTab.removeObserver(mTabObserver); |
| 321 super.onDestroyInternal(); |
| 322 } |
| 323 |
| 282 /** | 324 /** |
| 283 * Loads the current tab with the given load params. Unlike | 325 * Loads the current tab with the given load params while taking client |
| 284 * {@link CustomTab#loadUrlAndTrackFromTimestamp(LoadUrlParams, long)}, this
method takes client | |
| 285 * referrer and extra headers into account. | 326 * referrer and extra headers into account. |
| 286 */ | 327 */ |
| 287 private void loadUrlInCurrentTab(LoadUrlParams params, long timeStamp) { | 328 void loadUrlInCurrentTab(LoadUrlParams params, long timeStamp) { |
| 288 Intent intent = getIntent(); | 329 Intent intent = getIntent(); |
| 289 IntentHandler.addReferrerAndHeaders(params, intent, this); | 330 IntentHandler.addReferrerAndHeaders(params, intent, this); |
| 290 if (params.getReferrer() == null) { | 331 if (params.getReferrer() == null) { |
| 291 params.setReferrer(CustomTabsConnection.getInstance(getApplication()
) | 332 params.setReferrer(CustomTabsConnection.getInstance(getApplication()
) |
| 292 .getReferrerForSession(mSession)); | 333 .getReferrerForSession(mSession)); |
| 293 } | 334 } |
| 294 mTab.loadUrlAndTrackFromTimestamp(params, timeStamp); | 335 mTabObserver.trackNextPageLoadFromTimestamp(timeStamp); |
| 336 if (mShouldReplaceCurrentEntry) params.setShouldReplaceCurrentEntry(true
); |
| 337 mShouldReplaceCurrentEntry = false; |
| 338 mTab.loadUrl(params); |
| 295 } | 339 } |
| 296 | 340 |
| 297 @Override | 341 @Override |
| 298 public void createContextualSearchTab(String searchUrl) { | 342 public void createContextualSearchTab(String searchUrl) { |
| 299 if (mTab == null) return; | 343 if (mTab == null) return; |
| 300 mTab.loadUrl(new LoadUrlParams(searchUrl)); | 344 mTab.loadUrl(new LoadUrlParams(searchUrl)); |
| 301 } | 345 } |
| 302 | 346 |
| 303 @Override | 347 @Override |
| 304 public SingleTabModelSelector getTabModelSelector() { | 348 public SingleTabModelSelector getTabModelSelector() { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 | 511 |
| 468 /** | 512 /** |
| 469 * @return The {@link CustomTabIntentDataProvider} for this {@link CustomTab
Activity}. For test | 513 * @return The {@link CustomTabIntentDataProvider} for this {@link CustomTab
Activity}. For test |
| 470 * purposes only. | 514 * purposes only. |
| 471 */ | 515 */ |
| 472 @VisibleForTesting | 516 @VisibleForTesting |
| 473 CustomTabIntentDataProvider getIntentDataProvider() { | 517 CustomTabIntentDataProvider getIntentDataProvider() { |
| 474 return mIntentDataProvider; | 518 return mIntentDataProvider; |
| 475 } | 519 } |
| 476 } | 520 } |
| OLD | NEW |