Index: chrome/android/java/src/org/chromium/chrome/browser/browseraction/BrowserActionActivity.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/browseraction/BrowserActionActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/browseraction/BrowserActionActivity.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0e1a2545426ae43c307e878ddfc9d8041563840e |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/browseraction/BrowserActionActivity.java |
@@ -0,0 +1,106 @@ |
+// 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.browseraction; |
+ |
+import android.app.PendingIntent; |
+import android.content.Intent; |
+import android.graphics.Bitmap; |
+import android.net.Uri; |
+import android.os.Bundle; |
+import android.support.customtabs.browseraction.BrowserActionIntent; |
+import android.support.customtabs.browseraction.BrowserActionItem; |
+ |
+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 ArrayList<BrowserActionItem> mActions = new ArrayList<>(); |
+ |
+ /** Whether the native libraries have started loading */ |
+ private boolean mIsNativeLoading; |
+ |
+ /** Wether the native libraries have already loaded */ |
Yusuf
2017/03/31 23:43:12
Whether
ltian
2017/04/03 19:22:03
Done.
|
+ private boolean mIsNativeReady; |
+ |
+ @Override |
+ protected void setContentView() { |
Yusuf
2017/03/31 23:43:12
if you are going to call beginLoadingLibrary, I am
ltian
2017/04/03 19:22:03
New plan is here it should try to open a dialog an
|
+ if (getIntent() != null |
+ && BrowserActionIntent.ACTION_BROWSER_ACTION_OPEN.equals(getIntent().getAction())) { |
+ parseIntent(getIntent()); |
+ } |
+ if (mUri == null) { |
+ super.onDestroy(); |
+ } |
+ beginLoadingLibrary(); |
+ } |
+ |
+ /** |
+ * Opens a context menu based on the parsed data. |
+ */ |
+ public void openContextMenu() { |
+ return; |
+ } |
+ |
+ @Override |
+ public void finishNativeInitialization() { |
+ super.finishNativeInitialization(); |
+ mIsNativeReady = true; |
+ } |
+ |
+ private void beginLoadingLibrary() { |
+ if (mIsNativeLoading || mIsNativeReady) return; |
Yusuf
2017/03/31 23:43:12
not sure why we need these two booleans. setConten
ltian
2017/04/03 19:22:03
Done.
|
+ mIsNativeLoading = true; |
+ ChromeBrowserInitializer.getInstance(getApplicationContext()).handlePreNativeStartup(this); |
+ } |
+ |
+ @Override |
+ protected boolean shouldDelayBrowserStartup() { |
+ return true; |
+ } |
+ |
+ /** |
+ * Parses the data from {@link BrowserActionIntent}. |
+ * @param intent The {@link BrowserActionIntent} need to be parsed. |
+ */ |
+ private void parseIntent(Intent intent) { |
+ mUri = intent.getData(); |
+ mType = IntentUtils.safeGetIntExtra( |
+ intent, BrowserActionIntent.EXTRA_TYPE, BrowserActionIntent.MEDIA_TYPE_NONE); |
+ ArrayList<Bundle> bundles = IntentUtils.getParcelableArrayListExtra( |
+ intent, BrowserActionIntent.EXTRA_MENU_ITEMS); |
+ if (bundles != null) { |
+ parseBrowserActionItems(bundles); |
+ } |
+ } |
+ |
+ /** |
+ * Gets custom item list for browser action menu. |
+ * @param bundles Data for custom items from {@link BrowserActionIntent}. |
+ */ |
+ private void parseBrowserActionItems(ArrayList<Bundle> bundles) { |
+ for (int i = 0; i < bundles.size(); i++) { |
+ Bundle bundle = bundles.get(i); |
+ String title = IntentUtils.safeGetString(bundle, BrowserActionIntent.KEY_TITLE); |
+ PendingIntent action = |
+ IntentUtils.safeGetParcelable(bundle, BrowserActionIntent.KEY_ACTION); |
+ Bitmap icon = IntentUtils.safeGetParcelable(bundle, BrowserActionIntent.KEY_ICON); |
+ if (title != null && action != null) { |
+ BrowserActionItem item = new BrowserActionItem(title, action); |
+ if (icon != null) { |
+ item.setIcon(icon); |
+ } |
+ mActions.add(item); |
+ } |
+ } |
+ } |
+} |