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.net.Uri; | 8 import android.net.Uri; |
9 import android.text.TextUtils; | 9 import android.text.TextUtils; |
10 import android.view.MenuItem; | 10 import android.view.MenuItem; |
11 import android.view.View; | 11 import android.view.View; |
12 import android.view.View.OnClickListener; | 12 import android.view.View.OnClickListener; |
13 import android.view.ViewGroup; | 13 import android.view.ViewGroup; |
14 | 14 |
15 import org.chromium.base.ApiCompatibilityUtils; | 15 import org.chromium.base.ApiCompatibilityUtils; |
| 16 import org.chromium.base.Log; |
16 import org.chromium.base.VisibleForTesting; | 17 import org.chromium.base.VisibleForTesting; |
17 import org.chromium.base.metrics.RecordHistogram; | 18 import org.chromium.base.metrics.RecordHistogram; |
18 import org.chromium.base.metrics.RecordUserAction; | 19 import org.chromium.base.metrics.RecordUserAction; |
19 import org.chromium.chrome.R; | 20 import org.chromium.chrome.R; |
20 import org.chromium.chrome.browser.ChromeActivity; | 21 import org.chromium.chrome.browser.ChromeActivity; |
21 import org.chromium.chrome.browser.IntentHandler; | 22 import org.chromium.chrome.browser.IntentHandler; |
22 import org.chromium.chrome.browser.IntentHandler.ExternalAppId; | 23 import org.chromium.chrome.browser.IntentHandler.ExternalAppId; |
23 import org.chromium.chrome.browser.Tab; | 24 import org.chromium.chrome.browser.Tab; |
24 import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; | 25 import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; |
25 import org.chromium.chrome.browser.appmenu.ChromeAppMenuPropertiesDelegate; | 26 import org.chromium.chrome.browser.appmenu.ChromeAppMenuPropertiesDelegate; |
26 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchPanel.StateChangeReason; | 27 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchPanel.StateChangeReason; |
27 import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument; | 28 import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument; |
28 import org.chromium.chrome.browser.document.BrandColorUtils; | 29 import org.chromium.chrome.browser.document.BrandColorUtils; |
29 import org.chromium.chrome.browser.tabmodel.SingleTabModelSelector; | 30 import org.chromium.chrome.browser.tabmodel.SingleTabModelSelector; |
30 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 31 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
31 import org.chromium.chrome.browser.toolbar.ToolbarControlContainer; | 32 import org.chromium.chrome.browser.toolbar.ToolbarControlContainer; |
32 import org.chromium.chrome.browser.widget.findinpage.FindToolbarManager; | 33 import org.chromium.chrome.browser.widget.findinpage.FindToolbarManager; |
33 import org.chromium.content.browser.ContentViewCore; | 34 import org.chromium.content.browser.ContentViewCore; |
34 import org.chromium.content_public.browser.LoadUrlParams; | 35 import org.chromium.content_public.browser.LoadUrlParams; |
35 import org.chromium.content_public.browser.NavigationEntry; | 36 import org.chromium.content_public.browser.NavigationEntry; |
36 | 37 |
37 /** | 38 /** |
38 * The activity for custom tabs. It will be launched on top of a client's task. | 39 * The activity for custom tabs. It will be launched on top of a client's task. |
39 */ | 40 */ |
40 public class CustomTabActivity extends ChromeActivity { | 41 public class CustomTabActivity extends ChromeActivity { |
| 42 private static final String TAG = "cr.CustomTabActivity"; |
41 private static CustomTabContentHandler sActiveContentHandler; | 43 private static CustomTabContentHandler sActiveContentHandler; |
42 | 44 |
43 private CustomTab mTab; | 45 private CustomTab mTab; |
44 private FindToolbarManager mFindToolbarManager; | 46 private FindToolbarManager mFindToolbarManager; |
45 private CustomTabIntentDataProvider mIntentDataProvider; | 47 private CustomTabIntentDataProvider mIntentDataProvider; |
46 private long mSessionId; | 48 private long mSessionId; |
47 private CustomTabContentHandler mCustomTabContentHandler; | 49 private CustomTabContentHandler mCustomTabContentHandler; |
48 | 50 |
49 // This is to give the right package name while using the client's resources
during an | 51 // This is to give the right package name while using the client's resources
during an |
50 // overridePendingTransition call. | 52 // overridePendingTransition call. |
(...skipping 12 matching lines...) Expand all Loading... |
63 } | 65 } |
64 | 66 |
65 /** | 67 /** |
66 * Used to check whether an incoming intent can be handled by the | 68 * Used to check whether an incoming intent can be handled by the |
67 * current {@link CustomTabContentHandler}. | 69 * current {@link CustomTabContentHandler}. |
68 * @return Whether the active {@link CustomTabContentHandler} has handled th
e intent. | 70 * @return Whether the active {@link CustomTabContentHandler} has handled th
e intent. |
69 */ | 71 */ |
70 public static boolean handleInActiveContentIfNeeded(Intent intent) { | 72 public static boolean handleInActiveContentIfNeeded(Intent intent) { |
71 if (sActiveContentHandler == null) return false; | 73 if (sActiveContentHandler == null) return false; |
72 | 74 |
| 75 if (sActiveContentHandler.shouldIgnoreIntent(intent)) { |
| 76 Log.w(TAG, "Incoming intent to Custom Tab was ignored."); |
| 77 return false; |
| 78 } |
| 79 |
73 long intentSessionId = intent.getLongExtra( | 80 long intentSessionId = intent.getLongExtra( |
74 CustomTabIntentDataProvider.EXTRA_CUSTOM_TABS_SESSION_ID, | 81 CustomTabIntentDataProvider.EXTRA_CUSTOM_TABS_SESSION_ID, |
75 CustomTabIntentDataProvider.INVALID_SESSION_ID); | 82 CustomTabIntentDataProvider.INVALID_SESSION_ID); |
76 if (intentSessionId == CustomTabIntentDataProvider.INVALID_SESSION_ID) r
eturn false; | 83 if (intentSessionId == CustomTabIntentDataProvider.INVALID_SESSION_ID) r
eturn false; |
77 | 84 |
78 if (sActiveContentHandler.getSessionId() != intentSessionId) return fals
e; | 85 if (sActiveContentHandler.getSessionId() != intentSessionId) return fals
e; |
79 String url = IntentHandler.getUrlFromIntent(intent); | 86 String url = IntentHandler.getUrlFromIntent(intent); |
80 if (TextUtils.isEmpty(url)) return false; | 87 if (TextUtils.isEmpty(url)) return false; |
81 sActiveContentHandler.loadUrlAndTrackFromTimestamp(new LoadUrlParams(url
), | 88 sActiveContentHandler.loadUrlAndTrackFromTimestamp(new LoadUrlParams(url
), |
82 IntentHandler.getTimestampFromIntent(intent)); | 89 IntentHandler.getTimestampFromIntent(intent)); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 mCustomTabContentHandler = new CustomTabContentHandler() { | 180 mCustomTabContentHandler = new CustomTabContentHandler() { |
174 @Override | 181 @Override |
175 public void loadUrlAndTrackFromTimestamp(LoadUrlParams params, long
timestamp) { | 182 public void loadUrlAndTrackFromTimestamp(LoadUrlParams params, long
timestamp) { |
176 loadUrlInCurrentTab(params, timestamp); | 183 loadUrlInCurrentTab(params, timestamp); |
177 } | 184 } |
178 | 185 |
179 @Override | 186 @Override |
180 public long getSessionId() { | 187 public long getSessionId() { |
181 return mSessionId; | 188 return mSessionId; |
182 } | 189 } |
| 190 |
| 191 @Override |
| 192 public boolean shouldIgnoreIntent(Intent intent) { |
| 193 return mIntentHandler.shouldIgnoreIntent(CustomTabActivity.this,
intent); |
| 194 } |
183 }; | 195 }; |
184 super.finishNativeInitialization(); | 196 super.finishNativeInitialization(); |
185 } | 197 } |
186 | 198 |
187 @Override | 199 @Override |
188 public void onStartWithNative() { | 200 public void onStartWithNative() { |
189 super.onStartWithNative(); | 201 super.onStartWithNative(); |
190 setActiveContentHandler(mCustomTabContentHandler); | 202 setActiveContentHandler(mCustomTabContentHandler); |
191 | 203 |
192 if (!mRecordedStartupUma) { | 204 if (!mRecordedStartupUma) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 361 |
350 /** | 362 /** |
351 * @return The {@link CustomTabIntentDataProvider} for this {@link CustomTab
Activity}. For test | 363 * @return The {@link CustomTabIntentDataProvider} for this {@link CustomTab
Activity}. For test |
352 * purposes only. | 364 * purposes only. |
353 */ | 365 */ |
354 @VisibleForTesting | 366 @VisibleForTesting |
355 CustomTabIntentDataProvider getIntentDataProvider() { | 367 CustomTabIntentDataProvider getIntentDataProvider() { |
356 return mIntentDataProvider; | 368 return mIntentDataProvider; |
357 } | 369 } |
358 } | 370 } |
OLD | NEW |