Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionActivity.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionActivity.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d4299c45660827f0587f7d9a4f6fdb40f6048f77 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionActivity.java |
| @@ -0,0 +1,113 @@ |
| +// Copyright 2017 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.browseractions; |
| + |
| +import android.app.PendingIntent; |
| +import android.content.Intent; |
| +import android.graphics.Bitmap; |
| +import android.net.Uri; |
| +import android.os.Bundle; |
| +import android.support.customtabs.browseractions.BrowserActionItem; |
| +import android.support.customtabs.browseractions.BrowserActionsIntent; |
| + |
| +import org.chromium.base.Log; |
| +import org.chromium.base.annotations.SuppressFBWarnings; |
| +import org.chromium.chrome.browser.IntentHandler; |
| +import org.chromium.chrome.browser.init.AsyncInitializationActivity; |
| +import org.chromium.chrome.browser.util.IntentUtils; |
| + |
| +import java.util.ArrayList; |
| + |
| +/** |
| + * A transparent {@link AsyncInitializationActivity} that displays the browser action context menu. |
| + */ |
| +public class BrowserActionActivity extends AsyncInitializationActivity { |
| + private static final String TAG = "BrowserActions"; |
| + private int mType; |
|
Ted C
2017/04/25 17:30:33
nit, I would put a blank link above this.
ltian
2017/04/26 18:43:01
Done.
|
| + private Uri mUri; |
| + private String mCreatorPackageName; |
| + private ArrayList<BrowserActionItem> mActions = new ArrayList<>(); |
|
Ted C
2017/04/25 17:30:33
let's make the left side a generic List<>
ltian
2017/04/26 18:43:01
Done.
|
| + |
| + @Override |
| + protected void setContentView() { |
| + openContextMenu(); |
| + } |
| + |
| + @Override |
| + @SuppressFBWarnings("URF_UNREAD_FIELD") |
| + protected boolean isStartedUpCorrectly(Intent intent) { |
|
Ted C
2017/04/25 17:30:33
This is pretty nicely unit testable. Can we add s
ltian
2017/04/26 18:43:01
Done.
|
| + if (intent == null |
| + && !BrowserActionsIntent.ACTION_BROWSER_ACTIONS_OPEN.equals( |
|
Ted C
2017/04/25 17:30:33
Should this be || ?
ltian
2017/04/26 18:43:01
Oh, sorry, it is ||. Thanks for pointing out.
|
| + getIntent().getAction())) { |
|
Ted C
2017/04/25 17:30:33
should we be using the intent param vs getIntent()
ltian
2017/04/26 18:43:01
Done.
|
| + return false; |
| + } |
| + mUri = Uri.parse(IntentHandler.getUrlFromIntent(intent)); |
| + mType = IntentUtils.safeGetIntExtra( |
| + intent, BrowserActionsIntent.EXTRA_TYPE, BrowserActionsIntent.URL_TYPE_NONE); |
| + mCreatorPackageName = BrowserActionsIntent.getCreatorPackageName(intent); |
| + ArrayList<Bundle> bundles = IntentUtils.getParcelableArrayListExtra( |
| + intent, BrowserActionsIntent.EXTRA_MENU_ITEMS); |
| + if (bundles != null) { |
| + parseBrowserActionItems(bundles); |
| + } |
| + if (mUri == null || mCreatorPackageName == null |
|
Ted C
2017/04/25 17:30:33
I would put each of these conditions on a separate
ltian
2017/04/26 18:43:01
Done.
|
| + || (intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0 |
| + || (intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { |
| + return false; |
| + } |
| + return true; |
| + } |
| + |
| + /** |
| + * Opens a Browser Actions context menu based on the parsed data. |
| + */ |
| + public void openContextMenu() { |
| + return; |
| + } |
| + |
| + @Override |
| + protected boolean shouldDelayBrowserStartup() { |
| + return true; |
| + } |
| + |
| + @Override |
| + public boolean shouldStartGpuProcess() { |
| + return true; |
| + } |
| + |
| + /** |
| + * Gets custom item list for browser action menu. |
| + * @param bundles Data for custom items from {@link BrowserActionsIntent}. |
| + */ |
| + private void parseBrowserActionItems(ArrayList<Bundle> bundles) { |
| + for (int i = 0; i < bundles.size(); i++) { |
| + Bundle bundle = bundles.get(i); |
| + String title = IntentUtils.safeGetString(bundle, BrowserActionsIntent.KEY_TITLE); |
| + PendingIntent action = |
| + IntentUtils.safeGetParcelable(bundle, BrowserActionsIntent.KEY_ACTION); |
| + Bitmap icon = IntentUtils.safeGetParcelable(bundle, BrowserActionsIntent.KEY_ICON); |
| + if (title != null && action != null) { |
| + BrowserActionItem item = new BrowserActionItem(title, action); |
| + if (icon != null) { |
| + item.setIcon(icon); |
| + } |
| + mActions.add(item); |
| + } else if (title != null) { |
| + Log.e(TAG, "Missing action for item: " + i); |
| + } else if (action != null) { |
| + Log.e(TAG, "Missing title for item: " + i); |
| + } else { |
| + Log.e(TAG, "Missing title and action for item: " + i); |
| + } |
| + } |
| + } |
| + |
| + /** |
| + * Callback when Browser Actions menu dialog is shown. |
| + */ |
| + private void onMenuShown() { |
| + beginLoadingLibrary(); |
| + } |
| +} |