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.app.Activity; | 7 import android.app.Activity; |
8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
9 import android.app.PendingIntent.CanceledException; | 9 import android.app.PendingIntent.CanceledException; |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.graphics.Bitmap; | 12 import android.graphics.Bitmap; |
13 import android.graphics.Color; | 13 import android.graphics.Color; |
14 import android.graphics.drawable.BitmapDrawable; | 14 import android.graphics.drawable.BitmapDrawable; |
15 import android.graphics.drawable.Drawable; | 15 import android.graphics.drawable.Drawable; |
16 import android.net.Uri; | 16 import android.net.Uri; |
17 import android.os.Build; | 17 import android.os.Build; |
18 import android.os.Bundle; | 18 import android.os.Bundle; |
19 import android.os.IBinder; | 19 import android.os.IBinder; |
20 import android.support.customtabs.CustomTabsIntent; | 20 import android.support.customtabs.CustomTabsIntent; |
21 import android.text.TextUtils; | 21 import android.text.TextUtils; |
22 import android.util.Pair; | 22 import android.util.Pair; |
| 23 import android.widget.RemoteViews; |
23 | 24 |
24 import org.chromium.base.ApiCompatibilityUtils; | 25 import org.chromium.base.ApiCompatibilityUtils; |
25 import org.chromium.base.Log; | 26 import org.chromium.base.Log; |
26 import org.chromium.base.VisibleForTesting; | 27 import org.chromium.base.VisibleForTesting; |
27 import org.chromium.chrome.R; | 28 import org.chromium.chrome.R; |
28 import org.chromium.chrome.browser.ChromeActivity; | 29 import org.chromium.chrome.browser.ChromeActivity; |
29 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; | 30 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
30 import org.chromium.chrome.browser.util.IntentUtils; | 31 import org.chromium.chrome.browser.util.IntentUtils; |
31 import org.chromium.chrome.browser.widget.TintedDrawable; | 32 import org.chromium.chrome.browser.widget.TintedDrawable; |
32 | 33 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 private int mToolbarColor; | 70 private int mToolbarColor; |
70 private int mBottomBarColor; | 71 private int mBottomBarColor; |
71 private boolean mEnableUrlBarHiding; | 72 private boolean mEnableUrlBarHiding; |
72 private List<CustomButtonParams> mCustomButtonParams; | 73 private List<CustomButtonParams> mCustomButtonParams; |
73 private Drawable mCloseButtonIcon; | 74 private Drawable mCloseButtonIcon; |
74 private List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>(); | 75 private List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>(); |
75 private Bundle mAnimationBundle; | 76 private Bundle mAnimationBundle; |
76 private boolean mShowShareItem; | 77 private boolean mShowShareItem; |
77 private CustomButtonParams mToolbarButton; | 78 private CustomButtonParams mToolbarButton; |
78 private List<CustomButtonParams> mBottombarButtons = new ArrayList<>(2); | 79 private List<CustomButtonParams> mBottombarButtons = new ArrayList<>(2); |
| 80 private RemoteViews mRemoteViews; |
79 // OnFinished listener for PendingIntents. Used for testing only. | 81 // OnFinished listener for PendingIntents. Used for testing only. |
80 private PendingIntent.OnFinished mOnFinished; | 82 private PendingIntent.OnFinished mOnFinished; |
81 | 83 |
82 /** Herb: "Open in Browser" will send the Tab to the Browser and kill this A
ctivity. */ | 84 /** Herb: "Open in Browser" will send the Tab to the Browser and kill this A
ctivity. */ |
83 private boolean mFinishAfterOpeningInBrowser; | 85 private boolean mFinishAfterOpeningInBrowser; |
84 | 86 |
85 /** Herb: Whether or not this CustomTabActivity was opened by the Browser di
rectly. */ | 87 /** Herb: Whether or not this CustomTabActivity was opened by the Browser di
rectly. */ |
86 private boolean mIsOpenedByBrowser; | 88 private boolean mIsOpenedByBrowser; |
87 | 89 |
88 /** | 90 /** |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 mMenuEntries.add(new Pair<String, PendingIntent>(title, pendingI
ntent)); | 128 mMenuEntries.add(new Pair<String, PendingIntent>(title, pendingI
ntent)); |
127 } | 129 } |
128 } | 130 } |
129 | 131 |
130 mAnimationBundle = IntentUtils.safeGetBundleExtra( | 132 mAnimationBundle = IntentUtils.safeGetBundleExtra( |
131 intent, CustomTabsIntent.EXTRA_EXIT_ANIMATION_BUNDLE); | 133 intent, CustomTabsIntent.EXTRA_EXIT_ANIMATION_BUNDLE); |
132 mTitleVisibilityState = IntentUtils.safeGetIntExtra(intent, | 134 mTitleVisibilityState = IntentUtils.safeGetIntExtra(intent, |
133 CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.
NO_TITLE); | 135 CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.
NO_TITLE); |
134 mShowShareItem = IntentUtils.safeGetBooleanExtra(intent, | 136 mShowShareItem = IntentUtils.safeGetBooleanExtra(intent, |
135 CustomTabsIntent.EXTRA_DEFAULT_SHARE_MENU_ITEM, false); | 137 CustomTabsIntent.EXTRA_DEFAULT_SHARE_MENU_ITEM, false); |
| 138 mRemoteViews = IntentUtils.safeGetParcelableExtra(intent, |
| 139 CustomTabsIntent.EXTRA_SECONDARY_TOOLBAR_REMOTEVIEWS); |
136 } | 140 } |
137 | 141 |
138 /** | 142 /** |
139 * Gets custom buttons from the intent and updates {@link #mCustomButtonPara
ms}, | 143 * Gets custom buttons from the intent and updates {@link #mCustomButtonPara
ms}, |
140 * {@link #mBottombarButtons} and {@link #mToolbarButton}. | 144 * {@link #mBottombarButtons} and {@link #mToolbarButton}. |
141 */ | 145 */ |
142 private void retrieveCustomButtons(Intent intent, Context context) { | 146 private void retrieveCustomButtons(Intent intent, Context context) { |
143 mCustomButtonParams = CustomButtonParams.fromIntent(context, intent); | 147 mCustomButtonParams = CustomButtonParams.fromIntent(context, intent); |
144 if (mCustomButtonParams != null) { | 148 if (mCustomButtonParams != null) { |
145 for (CustomButtonParams params : mCustomButtonParams) { | 149 for (CustomButtonParams params : mCustomButtonParams) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 * @return The list of params representing the buttons on the bottombar. | 252 * @return The list of params representing the buttons on the bottombar. |
249 */ | 253 */ |
250 public List<CustomButtonParams> getCustomButtonsOnBottombar() { | 254 public List<CustomButtonParams> getCustomButtonsOnBottombar() { |
251 return mBottombarButtons; | 255 return mBottombarButtons; |
252 } | 256 } |
253 | 257 |
254 /** | 258 /** |
255 * @return Whether the bottom bar should be shown. | 259 * @return Whether the bottom bar should be shown. |
256 */ | 260 */ |
257 public boolean shouldShowBottomBar() { | 261 public boolean shouldShowBottomBar() { |
258 return !mBottombarButtons.isEmpty(); | 262 return !mBottombarButtons.isEmpty() || mRemoteViews != null; |
259 } | 263 } |
260 | 264 |
261 /** | 265 /** |
262 * @return The color of the bottom bar, or {@link #getToolbarColor()} if not
specified. | 266 * @return The color of the bottom bar, or {@link #getToolbarColor()} if not
specified. |
263 */ | 267 */ |
264 public int getBottomBarColor() { | 268 public int getBottomBarColor() { |
265 return mBottomBarColor; | 269 return mBottomBarColor; |
266 } | 270 } |
267 | 271 |
268 /** | 272 /** |
| 273 * @return The {@link RemoteViews} to show on the bottom bar, or null if the
extra is not |
| 274 * specified. |
| 275 */ |
| 276 public RemoteViews getBottomBarRemoteViews() { |
| 277 return mRemoteViews; |
| 278 } |
| 279 |
| 280 /** |
269 * Gets params for all custom buttons, which is the combination of | 281 * Gets params for all custom buttons, which is the combination of |
270 * {@link #getCustomButtonsOnBottombar()} and {@link #getCustomButtonOnToolb
ar()}. | 282 * {@link #getCustomButtonsOnBottombar()} and {@link #getCustomButtonOnToolb
ar()}. |
271 */ | 283 */ |
272 public List<CustomButtonParams> getAllCustomButtons() { | 284 public List<CustomButtonParams> getAllCustomButtons() { |
273 return mCustomButtonParams; | 285 return mCustomButtonParams; |
274 } | 286 } |
275 | 287 |
276 /** | 288 /** |
277 * @return The {@link CustomButtonParams} having the given id. Returns null
if no such params | 289 * @return The {@link CustomButtonParams} having the given id. Returns null
if no such params |
278 * can be found. | 290 * can be found. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 */ | 412 */ |
401 private void parseHerbExtras(Intent intent) { | 413 private void parseHerbExtras(Intent intent) { |
402 if (TextUtils.isEmpty(ChromePreferenceManager.getHerbFlavor())) return; | 414 if (TextUtils.isEmpty(ChromePreferenceManager.getHerbFlavor())) return; |
403 | 415 |
404 mFinishAfterOpeningInBrowser = IntentUtils.safeGetBooleanExtra( | 416 mFinishAfterOpeningInBrowser = IntentUtils.safeGetBooleanExtra( |
405 intent, EXTRA_FINISH_AFTER_OPENING_IN_BROWSER, false); | 417 intent, EXTRA_FINISH_AFTER_OPENING_IN_BROWSER, false); |
406 mIsOpenedByBrowser = IntentUtils.safeGetBooleanExtra( | 418 mIsOpenedByBrowser = IntentUtils.safeGetBooleanExtra( |
407 intent, EXTRA_OPENED_BY_BROWSER, false); | 419 intent, EXTRA_OPENED_BY_BROWSER, false); |
408 } | 420 } |
409 } | 421 } |
OLD | NEW |