Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabUpdater.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabUpdater.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabUpdater.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..61d6f8ee43df00e406065f0861d7caf396679700 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabUpdater.java |
| @@ -0,0 +1,94 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.customtabs; |
| + |
| +import android.content.ContentProvider; |
| +import android.content.ContentValues; |
| +import android.database.Cursor; |
| +import android.graphics.Bitmap; |
| +import android.net.Uri; |
| +import android.os.Bundle; |
| +import android.os.IBinder; |
| +import android.support.customtabs.CustomTabsIntent; |
| +import android.text.TextUtils; |
| + |
| +import org.chromium.base.ThreadUtils; |
| +import org.chromium.chrome.browser.util.IntentUtils; |
| + |
| +import java.util.concurrent.Callable; |
| +import java.util.concurrent.ExecutionException; |
| + |
| +/** |
| + * A {@link ContentProvider} that interacts with clients to for updating existing custom tabs. |
| + */ |
| +public class CustomTabUpdater extends ContentProvider { |
| + @Override |
| + public boolean onCreate() { |
| + return true; |
| + } |
| + |
| + @Override |
| + public Bundle call(String method, String arg, Bundle extras) { |
| + if (TextUtils.equals(method, CustomTabsIntent.METHOD_UPDATE_ACTION_BUTTON)) { |
| + Bundle actionButtonBundle = extras |
| + .getBundle(CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE); |
| + if (actionButtonBundle == null) return constructResult(false); |
| + |
| + final Bitmap bitmap = ActionButtonParams.tryParseBitmapFromBundle(getContext(), |
| + actionButtonBundle); |
| + final String description = ActionButtonParams |
| + .tryParseDescriptionFromBundle(actionButtonBundle); |
| + if (bitmap == null || description == null) return constructResult(false); |
| + |
| + final IBinder session = IntentUtils.safeGetBinder(extras, |
| + CustomTabsIntent.EXTRA_SESSION); |
|
Ian Wen
2015/08/31 22:35:33
Here an alternative approach is to call Binder.get
Benoit L
2015/09/01 16:45:10
Novice question: are we sure that Binder.getCallin
|
| + |
| + try { |
| + return constructResult(ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() { |
| + @Override |
| + public Boolean call() throws Exception { |
| + return CustomTabActivity.updateActionButton(session, bitmap, description); |
| + } |
| + })); |
| + } catch (ExecutionException e) { |
| + return constructResult(false); |
| + } |
| + } |
| + return constructResult(false); |
| + } |
| + |
| + private Bundle constructResult(boolean success) { |
| + Bundle result = new Bundle(); |
| + result.putBoolean(CustomTabsIntent.EXTRA_RETURN, success); |
| + return result; |
| + } |
| + |
| + @Override |
| + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, |
| + String sortOrder) { |
| + throw new UnsupportedOperationException(); |
| + } |
| + |
| + @Override |
| + public String getType(Uri uri) { |
| + throw new UnsupportedOperationException(); |
| + } |
| + |
| + @Override |
| + public Uri insert(Uri uri, ContentValues values) { |
| + throw new UnsupportedOperationException(); |
| + } |
| + |
| + @Override |
| + public int delete(Uri uri, String selection, String[] selectionArgs) { |
| + throw new UnsupportedOperationException(); |
| + } |
| + |
| + @Override |
| + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { |
| + throw new UnsupportedOperationException(); |
| + } |
| + |
| +} |