Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java

Issue 1509713004: Add a default share button to the menu of Custom Tabs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23
24 import org.chromium.base.ApiCompatibilityUtils; 24 import org.chromium.base.ApiCompatibilityUtils;
25 import org.chromium.base.Log; 25 import org.chromium.base.Log;
26 import org.chromium.base.VisibleForTesting; 26 import org.chromium.base.VisibleForTesting;
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.util.IntentUtils; 29 import org.chromium.chrome.browser.util.IntentUtils;
29 import org.chromium.chrome.browser.widget.TintedDrawable; 30 import org.chromium.chrome.browser.widget.TintedDrawable;
30 31
31 import java.util.ArrayList; 32 import java.util.ArrayList;
32 import java.util.List; 33 import java.util.List;
33 34
34 /** 35 /**
35 * A model class that parses intent from third-party apps and provides results t o 36 * A model class that parses intent from third-party apps and provides results t o
36 * {@link CustomTabActivity}. 37 * {@link CustomTabActivity}.
37 */ 38 */
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 ANIMATION_BUNDLE_PREFIX + "animExitRes"; 85 ANIMATION_BUNDLE_PREFIX + "animExitRes";
85 private final IBinder mSession; 86 private final IBinder mSession;
86 private final Intent mKeepAliveServiceIntent; 87 private final Intent mKeepAliveServiceIntent;
87 private final int mTitleVisibilityState; 88 private final int mTitleVisibilityState;
88 private int mToolbarColor; 89 private int mToolbarColor;
89 private boolean mEnableUrlBarHiding; 90 private boolean mEnableUrlBarHiding;
90 private ActionButtonParams mActionButtonParams; 91 private ActionButtonParams mActionButtonParams;
91 private Drawable mCloseButtonIcon; 92 private Drawable mCloseButtonIcon;
92 private List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>(); 93 private List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>();
93 private Bundle mAnimationBundle; 94 private Bundle mAnimationBundle;
95 private boolean mShowShareItem;
94 // OnFinished listener for PendingIntents. Used for testing only. 96 // OnFinished listener for PendingIntents. Used for testing only.
95 private PendingIntent.OnFinished mOnFinished; 97 private PendingIntent.OnFinished mOnFinished;
96 98
97 /** 99 /**
98 * Constructs a {@link CustomTabIntentDataProvider}. 100 * Constructs a {@link CustomTabIntentDataProvider}.
99 */ 101 */
100 public CustomTabIntentDataProvider(Intent intent, Context context) { 102 public CustomTabIntentDataProvider(Intent intent, Context context) {
101 if (intent == null) assert false; 103 if (intent == null) assert false;
102 104
103 mSession = IntentUtils.safeGetBinderExtra(intent, CustomTabsIntent.EXTRA _SESSION); 105 mSession = IntentUtils.safeGetBinderExtra(intent, CustomTabsIntent.EXTRA _SESSION);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 IntentUtils.safeGetParcelable(bundle, CustomTabsIntent.K EY_PENDING_INTENT); 139 IntentUtils.safeGetParcelable(bundle, CustomTabsIntent.K EY_PENDING_INTENT);
138 if (TextUtils.isEmpty(title) || pendingIntent == null) continue; 140 if (TextUtils.isEmpty(title) || pendingIntent == null) continue;
139 mMenuEntries.add(new Pair<String, PendingIntent>(title, pendingI ntent)); 141 mMenuEntries.add(new Pair<String, PendingIntent>(title, pendingI ntent));
140 } 142 }
141 } 143 }
142 144
143 mAnimationBundle = IntentUtils.safeGetBundleExtra( 145 mAnimationBundle = IntentUtils.safeGetBundleExtra(
144 intent, CustomTabsIntent.EXTRA_EXIT_ANIMATION_BUNDLE); 146 intent, CustomTabsIntent.EXTRA_EXIT_ANIMATION_BUNDLE);
145 mTitleVisibilityState = 147 mTitleVisibilityState =
146 IntentUtils.safeGetIntExtra(intent, EXTRA_TITLE_VISIBILITY_STATE , NO_TITLE); 148 IntentUtils.safeGetIntExtra(intent, EXTRA_TITLE_VISIBILITY_STATE , NO_TITLE);
149 mShowShareItem = IntentUtils.safeGetBooleanExtra(intent,
150 CustomTabsIntent.EXTRA_DEFAULT_SHARE_MENU_ITEM, false);
147 } 151 }
148 152
149 /** 153 /**
150 * Processes the color passed from the client app and updates {@link #mToolb arColor}. 154 * Processes the color passed from the client app and updates {@link #mToolb arColor}.
151 */ 155 */
152 private void retrieveToolbarColor(Intent intent, Context context) { 156 private void retrieveToolbarColor(Intent intent, Context context) {
153 int color = IntentUtils.safeGetIntExtra(intent, CustomTabsIntent.EXTRA_T OOLBAR_COLOR, 157 int color = IntentUtils.safeGetIntExtra(intent, CustomTabsIntent.EXTRA_T OOLBAR_COLOR,
154 ApiCompatibilityUtils.getColor(context.getResources(), 158 ApiCompatibilityUtils.getColor(context.getResources(),
155 R.color.default_primary_color)); 159 R.color.default_primary_color));
156 int defaultColor = ApiCompatibilityUtils.getColor(context.getResources() , 160 int defaultColor = ApiCompatibilityUtils.getColor(context.getResources() ,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 208
205 /** 209 /**
206 * @return The title visibility state for the toolbar. 210 * @return The title visibility state for the toolbar.
207 * Default is {@link CustomTabIntentDataProvider#NO_TITLE}. 211 * Default is {@link CustomTabIntentDataProvider#NO_TITLE}.
208 */ 212 */
209 public int getTitleVisibilityState() { 213 public int getTitleVisibilityState() {
210 return mTitleVisibilityState; 214 return mTitleVisibilityState;
211 } 215 }
212 216
213 /** 217 /**
218 * @return Whether the default share item should be shown in the menu.
219 */
220 public boolean shouldShowShareMenuItem() {
221 return mShowShareItem;
222 }
223
224 /**
214 * @return Whether the client app has provided sufficient info for the toolb ar to show the 225 * @return Whether the client app has provided sufficient info for the toolb ar to show the
215 * action button. 226 * action button.
216 */ 227 */
217 public boolean shouldShowActionButton() { 228 public boolean shouldShowActionButton() {
218 return mActionButtonParams != null; 229 return mActionButtonParams != null;
219 } 230 }
220 231
221 /** 232 /**
222 * Gets the {@link ActionButtonParams} representing the action button. 233 * Gets the {@link ActionButtonParams} representing the action button.
223 */ 234 */
(...skipping 10 matching lines...) Expand all
234 list.add(pair.first); 245 list.add(pair.first);
235 } 246 }
236 return list; 247 return list;
237 } 248 }
238 249
239 /** 250 /**
240 * Triggers the client-defined action when the user clicks a custom menu ite m. 251 * Triggers the client-defined action when the user clicks a custom menu ite m.
241 * @param menuIndex The index that the menu item is shown in the result of 252 * @param menuIndex The index that the menu item is shown in the result of
242 * {@link #getMenuTitles()} 253 * {@link #getMenuTitles()}
243 */ 254 */
244 public void clickMenuItemWithUrl(Context context, int menuIndex, String url) { 255 public void clickMenuItemWithUrl(ChromeActivity activity, int menuIndex, Str ing url) {
245 Intent addedIntent = new Intent(); 256 Intent addedIntent = new Intent();
246 addedIntent.setData(Uri.parse(url)); 257 addedIntent.setData(Uri.parse(url));
247 try { 258 try {
248 PendingIntent pendingIntent = mMenuEntries.get(menuIndex).second; 259 PendingIntent pendingIntent = mMenuEntries.get(menuIndex).second;
249 pendingIntent.send(context, 0, addedIntent, mOnFinished, null); 260 pendingIntent.send(activity, 0, addedIntent, mOnFinished, null);
250 } catch (CanceledException e) { 261 } catch (CanceledException e) {
251 Log.e(TAG, "Custom tab in Chrome failed to send pending intent."); 262 Log.e(TAG, "Custom tab in Chrome failed to send pending intent.");
252 } 263 }
253 } 264 }
254 265
255 /** 266 /**
256 * @return Whether chrome should animate when it finishes. We show animation s only if the client 267 * @return Whether chrome should animate when it finishes. We show animation s only if the client
257 * app has supplied the correct animation resources via intent extra . 268 * app has supplied the correct animation resources via intent extra .
258 */ 269 */
259 public boolean shouldAnimateOnFinish() { 270 public boolean shouldAnimateOnFinish() {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 322
312 /** 323 /**
313 * Set the callback object for {@link PendingIntent}s that are sent in this class. For testing 324 * Set the callback object for {@link PendingIntent}s that are sent in this class. For testing
314 * purpose only. 325 * purpose only.
315 */ 326 */
316 @VisibleForTesting 327 @VisibleForTesting
317 void setPendingIntentOnFinishedForTesting(PendingIntent.OnFinished onFinishe d) { 328 void setPendingIntentOnFinishedForTesting(PendingIntent.OnFinished onFinishe d) {
318 mOnFinished = onFinished; 329 mOnFinished = onFinished;
319 } 330 }
320 } 331 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698