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..97c31c382cd639394609622e38e167b16c2dba3c |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionActivity.java |
| @@ -0,0 +1,108 @@ |
| +// 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.chrome.browser.init.AsyncInitializationActivity; |
| +import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
| +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 int mType; |
| + private Uri mUri; |
| + private String mCreatorPackageName; |
| + private ArrayList<BrowserActionItem> mActions = new ArrayList<>(); |
| + |
| + @Override |
| + protected void setContentView() { |
| + if (getIntent() != null |
|
Ted C
2017/04/24 20:23:17
I think this block of code should probably go into
ltian
2017/04/24 23:59:28
Done.
|
| + && BrowserActionsIntent.ACTION_BROWSER_ACTIONS_OPEN.equals( |
| + getIntent().getAction())) { |
| + parseIntent(getIntent()); |
| + } |
| + if (mUri == null || mCreatorPackageName == null) { |
| + super.onDestroy(); |
|
Ted C
2017/04/24 20:23:17
This doesn't actually do anything.
ltian
2017/04/24 23:59:28
Done.
|
| + } |
| + openContextMenu(); |
| + } |
| + |
| + /** |
| + * Opens a Browser Actions context menu based on the parsed data. |
| + */ |
| + public void openContextMenu() { |
| + return; |
| + } |
| + |
| + @Override |
| + protected void beginLoadingLibrary() { |
| + ChromeBrowserInitializer.getInstance(getApplicationContext()).handlePreNativeStartup(this); |
|
Ted C
2017/04/24 20:23:17
I think this is what the super class does. Can we
ltian
2017/04/24 23:59:28
Done.
|
| + } |
| + |
| + @Override |
| + protected boolean shouldDelayBrowserStartup() { |
| + return true; |
| + } |
| + |
| + @Override |
| + public boolean shouldStartGpuProcess() { |
| + return true; |
| + } |
| + |
| + /** |
| + * Parses the data from {@link BrowserActionsIntent}. |
| + * @param intent The {@link BrowserActionsIntent} need to be parsed. |
| + */ |
| + private void parseIntent(Intent intent) { |
| + mUri = intent.getData(); |
|
Ted C
2017/04/24 20:23:17
Should we use IntentHandler#getUrlFromIntent?
ltian
2017/04/24 23:59:28
Done.
|
| + 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); |
| + } |
| + } |
| + |
| + /** |
| + * 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); |
| + } |
|
Ted C
2017/04/24 20:23:17
should we consider logging something in an else li
ltian
2017/04/24 23:59:28
Done.
|
| + } |
| + } |
| + |
| + /** |
| + * Callback when Browser Actions menu dialog is shown. |
| + */ |
| + private void onMenuShown() { |
| + beginLoadingLibrary(); |
| + } |
| +} |