| Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java
|
| index 62759734e461c3ed38ef94892463505d60fbef96..0ce31ff5fe2ce49382896b117e33fac8e3983def 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java
|
| @@ -87,9 +87,7 @@ public class CustomTabIntentDataProvider {
|
| private final int mTitleVisibilityState;
|
| private int mToolbarColor;
|
| private boolean mEnableUrlBarHiding;
|
| - private Drawable mCustomButtonIcon;
|
| - private String mCustomButtonDescription;
|
| - private PendingIntent mCustomButtonPendingIntent;
|
| + private ActionButtonParams mActionButtonParams;
|
| private Drawable mCloseButtonIcon;
|
| private List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>();
|
| private Bundle mAnimationBundle;
|
| @@ -110,26 +108,10 @@ public class CustomTabIntentDataProvider {
|
|
|
| Bundle actionButtonBundle =
|
| IntentUtils.safeGetBundleExtra(intent, CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE);
|
| - if (actionButtonBundle != null) {
|
| - Bitmap bitmap = IntentUtils.safeGetParcelable(actionButtonBundle,
|
| - CustomTabsIntent.KEY_ICON);
|
| - if (bitmap != null && !checkCustomButtonIconWithinBounds(context, bitmap)) {
|
| - bitmap.recycle();
|
| - bitmap = null;
|
| - } else if (bitmap != null) {
|
| - mCustomButtonPendingIntent = IntentUtils.safeGetParcelable(
|
| - actionButtonBundle, CustomTabsIntent.KEY_PENDING_INTENT);
|
| - boolean shouldTint = IntentUtils.safeGetBooleanExtra(intent,
|
| - EXTRA_TINT_ACTION_BUTTON, false);
|
| - if (shouldTint) {
|
| - mCustomButtonIcon = TintedDrawable
|
| - .constructTintedDrawable(context.getResources(), bitmap);
|
| - } else {
|
| - mCustomButtonIcon = new BitmapDrawable(context.getResources(), bitmap);
|
| - }
|
| - mCustomButtonDescription = IntentUtils.safeGetString(actionButtonBundle,
|
| - CustomTabsIntent.KEY_DESCRIPTION);
|
| - }
|
| + mActionButtonParams = ActionButtonParams.fromBundle(context, actionButtonBundle);
|
| + if (mActionButtonParams != null) {
|
| + mActionButtonParams.setTinted(
|
| + IntentUtils.safeGetBooleanExtra(intent, EXTRA_TINT_ACTION_BUTTON, false));
|
| }
|
|
|
| Bitmap bitmap = IntentUtils.safeGetParcelableExtra(intent, EXTRA_CLOSE_BUTTON_ICON);
|
| @@ -233,31 +215,14 @@ public class CustomTabIntentDataProvider {
|
| * action button.
|
| */
|
| public boolean shouldShowActionButton() {
|
| - return mCustomButtonIcon != null && mCustomButtonPendingIntent != null
|
| - && !TextUtils.isEmpty(mCustomButtonDescription);
|
| - }
|
| -
|
| - /**
|
| - * @return The icon used for the action button. Will be null if not set in the intent.
|
| - */
|
| - public Drawable getActionButtonIcon() {
|
| - return mCustomButtonIcon;
|
| - }
|
| -
|
| - /**
|
| - * @return The content description for the custom action button.
|
| - */
|
| - public String getActionButtonDescription() {
|
| - return mCustomButtonDescription;
|
| + return mActionButtonParams != null;
|
| }
|
|
|
| /**
|
| - * @return The {@link PendingIntent} that will be sent when the user clicks the action button.
|
| - * For testing only.
|
| + * Gets the {@link ActionButtonParams} representing the action button.
|
| */
|
| - @VisibleForTesting
|
| - public PendingIntent getActionButtonPendingIntentForTest() {
|
| - return mCustomButtonPendingIntent;
|
| + ActionButtonParams getActionButtonParams() {
|
| + return mActionButtonParams;
|
| }
|
|
|
| /**
|
| @@ -328,24 +293,16 @@ public class CustomTabIntentDataProvider {
|
| * @param url The url to attach as additional data to the {@link PendingIntent}.
|
| */
|
| public void sendButtonPendingIntentWithUrl(Context context, String url) {
|
| - assert mCustomButtonPendingIntent != null;
|
| + assert shouldShowActionButton();
|
| Intent addedIntent = new Intent();
|
| addedIntent.setData(Uri.parse(url));
|
| try {
|
| - mCustomButtonPendingIntent.send(context, 0, addedIntent, mOnFinished, null);
|
| + mActionButtonParams.getPendingIntent().send(context, 0, addedIntent, mOnFinished, null);
|
| } catch (CanceledException e) {
|
| Log.e(TAG, "CanceledException while sending pending intent in custom tab");
|
| }
|
| }
|
|
|
| - private boolean checkCustomButtonIconWithinBounds(Context context, Bitmap bitmap) {
|
| - int height = context.getResources().getDimensionPixelSize(R.dimen.toolbar_icon_height);
|
| - if (bitmap.getHeight() < height) return false;
|
| - int scaledWidth = bitmap.getWidth() / bitmap.getHeight() * height;
|
| - if (scaledWidth > 2 * height) return false;
|
| - return true;
|
| - }
|
| -
|
| private boolean checkCloseButtonSize(Context context, Bitmap bitmap) {
|
| int size = context.getResources().getDimensionPixelSize(R.dimen.toolbar_icon_height);
|
| if (bitmap.getHeight() == size && bitmap.getWidth() == size) return true;
|
|
|