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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java

Issue 1291083004: [Custom Tabs]Add API for updating action button in service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cr.->cr_ Created 5 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java
index 3416d1006296c3a771d35a008f0ba56374c36781..4ae81a1abcb31598b69cc13c93b9ac314ab86dbf 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java
@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.customtabs;
import android.content.Intent;
+import android.graphics.Bitmap;
import android.net.Uri;
import android.os.IBinder;
import android.support.customtabs.CustomTabsCallback;
@@ -19,6 +20,7 @@ import android.view.Window;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Log;
+import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
@@ -93,6 +95,23 @@ public class CustomTabActivity extends ChromeActivity {
return true;
}
+ /**
+ * Checks whether the active {@link CustomTabContentHandler} belongs to the given session, and
+ * if true, update toolbar's action button.
+ * @param session The {@link IBinder} that the calling client represents.
+ * @param bitmap The new icon for action button.
+ * @param description The new content description for the action button.
+ * @return Whether the update is successful.
+ */
+ static boolean updateActionButton(IBinder session, Bitmap bitmap, String description) {
+ ThreadUtils.assertOnUiThread();
+ // Do nothing if there is no activity or the activity does not belong to this session.
+ if (sActiveContentHandler == null || !sActiveContentHandler.getSession().equals(session)) {
+ return false;
+ }
+ return sActiveContentHandler.updateActionButton(bitmap, description);
+ }
+
@Override
public boolean isCustomTab() {
return true;
@@ -146,17 +165,7 @@ public class CustomTabActivity extends ChromeActivity {
// Setting task title and icon to be null will preserve the client app's title and icon.
ApiCompatibilityUtils.setTaskDescription(this, null, null, toolbarColor);
- if (mIntentDataProvider.shouldShowActionButton()) {
- getToolbarManager().addCustomActionButton(mIntentDataProvider.getActionButtonIcon(),
- mIntentDataProvider.getActionButtonDescription(), new OnClickListener() {
- @Override
- public void onClick(View v) {
- mIntentDataProvider.sendButtonPendingIntentWithUrl(
- getApplicationContext(), mTab.getUrl());
- RecordUserAction.record("CustomTabsCustomActionButtonClick");
- }
- });
- }
+ showActionButton();
}
@Override
@@ -216,6 +225,12 @@ public class CustomTabActivity extends ChromeActivity {
public boolean shouldIgnoreIntent(Intent intent) {
return mIntentHandler.shouldIgnoreIntent(CustomTabActivity.this, intent);
}
+
+ @Override
+ public boolean updateActionButton(Bitmap bitmap, String description) {
+ mIntentDataProvider.getActionButtonParams().update(bitmap, description);
+ return showActionButton();
+ }
};
loadUrlInCurrentTab(new LoadUrlParams(url),
IntentHandler.getTimestampFromIntent(getIntent()));
@@ -236,7 +251,6 @@ public class CustomTabActivity extends ChromeActivity {
}
}
-
@Override
public void onPauseWithNative() {
super.onPauseWithNative();
@@ -324,6 +338,27 @@ public class CustomTabActivity extends ChromeActivity {
return true;
}
+ /**
+ * Properly setup action button on the toolbar. Does nothing if invalid data is provided by
+ * clients.
+ */
+ private boolean showActionButton() {
+ if (!mIntentDataProvider.shouldShowActionButton()) return false;
+ ActionButtonParams params = mIntentDataProvider.getActionButtonParams();
+ getToolbarManager().setCustomActionButton(
+ params.getIcon(getResources()),
+ params.getDescription(),
+ new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mIntentDataProvider.sendButtonPendingIntentWithUrl(
+ getApplicationContext(), mTab.getUrl());
+ RecordUserAction.record("CustomTabsCustomActionButtonClick");
+ }
+ });
+ return true;
+ }
+
@Override
public boolean shouldShowAppMenu() {
return mTab != null && getToolbarManager().isInitialized();

Powered by Google App Engine
This is Rietveld 408576698