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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionActivity.java

Issue 2786283002: [Android] Add a transparent Activity in Chrome to handle Browser Action Intent (Closed)
Patch Set: Roll out changes in CCT support library to DEPS. Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « chrome/android/java/res/values-v17/styles.xml ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.browseractions;
6
7 import android.app.PendingIntent;
8 import android.content.Intent;
9 import android.graphics.Bitmap;
10 import android.net.Uri;
11 import android.os.Bundle;
12 import android.support.customtabs.browseractions.BrowserActionItem;
13 import android.support.customtabs.browseractions.BrowserActionsIntent;
14
15 import org.chromium.base.Log;
16 import org.chromium.base.annotations.SuppressFBWarnings;
17 import org.chromium.chrome.browser.IntentHandler;
18 import org.chromium.chrome.browser.UrlConstants;
19 import org.chromium.chrome.browser.init.AsyncInitializationActivity;
20 import org.chromium.chrome.browser.util.IntentUtils;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 /**
26 * A transparent {@link AsyncInitializationActivity} that displays the browser a ction context menu.
27 */
28 public class BrowserActionActivity extends AsyncInitializationActivity {
29 private static final String TAG = "BrowserActions";
30
31 private int mType;
32 private Uri mUri;
33 private String mCreatorPackageName;
34 private List<BrowserActionItem> mActions = new ArrayList<>();
35
36 @Override
37 protected void setContentView() {
38 openContextMenu();
39 }
40
41 @Override
42 @SuppressFBWarnings("URF_UNREAD_FIELD")
43 protected boolean isStartedUpCorrectly(Intent intent) {
44 if (intent == null
45 || !BrowserActionsIntent.ACTION_BROWSER_ACTIONS_OPEN.equals(inte nt.getAction())) {
46 return false;
47 }
48 mUri = Uri.parse(IntentHandler.getUrlFromIntent(intent));
49 mType = IntentUtils.safeGetIntExtra(
50 intent, BrowserActionsIntent.EXTRA_TYPE, BrowserActionsIntent.UR L_TYPE_NONE);
51 mCreatorPackageName = BrowserActionsIntent.getCreatorPackageName(intent) ;
52 ArrayList<Bundle> bundles = IntentUtils.getParcelableArrayListExtra(
53 intent, BrowserActionsIntent.EXTRA_MENU_ITEMS);
54 if (bundles != null) {
55 parseBrowserActionItems(bundles);
56 }
57 if (mUri == null) {
58 Log.e(TAG, "Missing url");
59 return false;
60 } else if (!UrlConstants.HTTP_SCHEME.equals(mUri.getScheme())
61 && !UrlConstants.HTTPS_SCHEME.equals(mUri.getScheme())) {
62 Log.e(TAG, "Url should only be HTTP or HTTPS scheme");
63 return false;
64 } else if (mCreatorPackageName == null) {
65 Log.e(TAG, "Missing creator's pacakge name");
66 return false;
67 } else if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
68 Log.e(TAG, "Intent should not be started with FLAG_ACTIVITY_NEW_TASK ");
69 return false;
70 } else if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) {
71 Log.e(TAG, "Intent should not be started with FLAG_ACTIVITY_NEW_DOCU MENT");
72 return false;
73 } else {
74 return true;
75 }
76 }
77
78 /**
79 * Opens a Browser Actions context menu based on the parsed data.
80 */
81 public void openContextMenu() {
82 return;
83 }
84
85 @Override
86 protected boolean shouldDelayBrowserStartup() {
87 return true;
88 }
89
90 @Override
91 public boolean shouldStartGpuProcess() {
92 return true;
93 }
94
95 /**
96 * Gets custom item list for browser action menu.
97 * @param bundles Data for custom items from {@link BrowserActionsIntent}.
98 */
99 private void parseBrowserActionItems(ArrayList<Bundle> bundles) {
100 for (int i = 0; i < bundles.size(); i++) {
101 Bundle bundle = bundles.get(i);
102 String title = IntentUtils.safeGetString(bundle, BrowserActionsInten t.KEY_TITLE);
103 PendingIntent action =
104 IntentUtils.safeGetParcelable(bundle, BrowserActionsIntent.K EY_ACTION);
105 Bitmap icon = IntentUtils.safeGetParcelable(bundle, BrowserActionsIn tent.KEY_ICON);
106 if (title != null && action != null) {
107 BrowserActionItem item = new BrowserActionItem(title, action);
108 if (icon != null) {
109 item.setIcon(icon);
110 }
111 mActions.add(item);
112 } else if (title != null) {
113 Log.e(TAG, "Missing action for item: " + i);
114 } else if (action != null) {
115 Log.e(TAG, "Missing title for item: " + i);
116 } else {
117 Log.e(TAG, "Missing title and action for item: " + i);
118 }
119 }
120 }
121
122 /**
123 * Callback when Browser Actions menu dialog is shown.
124 */
125 private void onMenuShown() {
126 beginLoadingLibrary();
127 }
128 }
OLDNEW
« no previous file with comments | « chrome/android/java/res/values-v17/styles.xml ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698