Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.browseractions; | 5 package org.chromium.chrome.browser.browseractions; |
| 6 | 6 |
| 7 import android.app.PendingIntent; | 7 import android.app.PendingIntent; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 10 import android.net.Uri; | 10 import android.net.Uri; |
| 11 import android.os.Bundle; | 11 import android.os.Bundle; |
| 12 import android.support.customtabs.browseractions.BrowserActionItem; | 12 import android.support.customtabs.browseractions.BrowserActionItem; |
| 13 import android.support.customtabs.browseractions.BrowserActionsIntent; | 13 import android.support.customtabs.browseractions.BrowserActionsIntent; |
| 14 import android.view.Menu; | |
| 15 import android.view.View; | |
| 14 | 16 |
| 15 import org.chromium.base.Log; | 17 import org.chromium.base.Log; |
| 16 import org.chromium.base.annotations.SuppressFBWarnings; | 18 import org.chromium.base.annotations.SuppressFBWarnings; |
| 17 import org.chromium.chrome.browser.IntentHandler; | 19 import org.chromium.chrome.browser.IntentHandler; |
| 18 import org.chromium.chrome.browser.UrlConstants; | 20 import org.chromium.chrome.browser.UrlConstants; |
| 21 import org.chromium.chrome.browser.contextmenu.ContextMenuParams; | |
| 19 import org.chromium.chrome.browser.init.AsyncInitializationActivity; | 22 import org.chromium.chrome.browser.init.AsyncInitializationActivity; |
| 20 import org.chromium.chrome.browser.util.IntentUtils; | 23 import org.chromium.chrome.browser.util.IntentUtils; |
| 24 import org.chromium.content_public.common.Referrer; | |
| 21 | 25 |
| 22 import java.util.ArrayList; | 26 import java.util.ArrayList; |
| 23 import java.util.List; | 27 import java.util.List; |
| 24 | 28 |
| 25 /** | 29 /** |
| 26 * A transparent {@link AsyncInitializationActivity} that displays the browser a ction context menu. | 30 * A transparent {@link AsyncInitializationActivity} that displays the Browser A ctions context menu. |
| 27 */ | 31 */ |
| 28 public class BrowserActionActivity extends AsyncInitializationActivity { | 32 public class BrowserActionActivity extends AsyncInitializationActivity { |
| 29 private static final String TAG = "BrowserActions"; | 33 private static final String TAG = "BrowserActions"; |
| 30 | 34 |
| 31 private int mType; | 35 private int mType; |
| 32 private Uri mUri; | 36 private Uri mUri; |
| 33 private String mCreatorPackageName; | 37 private String mCreatorPackageName; |
| 34 private List<BrowserActionItem> mActions = new ArrayList<>(); | 38 private List<BrowserActionItem> mActions = new ArrayList<>(); |
| 39 private BrowserActionsContextMenuHelper mHelper; | |
| 35 | 40 |
| 36 @Override | 41 @Override |
| 37 protected void setContentView() { | 42 protected void setContentView() { |
| 38 openContextMenu(); | 43 View view = new View(this); |
| 44 setContentView(view); | |
| 45 openContextMenu(view); | |
| 39 } | 46 } |
| 40 | 47 |
| 41 @Override | 48 @Override |
| 42 @SuppressFBWarnings("URF_UNREAD_FIELD") | 49 @SuppressFBWarnings("URF_UNREAD_FIELD") |
| 43 protected boolean isStartedUpCorrectly(Intent intent) { | 50 protected boolean isStartedUpCorrectly(Intent intent) { |
| 44 if (intent == null | 51 if (intent == null |
| 45 || !BrowserActionsIntent.ACTION_BROWSER_ACTIONS_OPEN.equals(inte nt.getAction())) { | 52 || !BrowserActionsIntent.ACTION_BROWSER_ACTIONS_OPEN.equals(inte nt.getAction())) { |
| 46 return false; | 53 return false; |
| 47 } | 54 } |
| 48 mUri = Uri.parse(IntentHandler.getUrlFromIntent(intent)); | 55 mUri = Uri.parse(IntentHandler.getUrlFromIntent(intent)); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 71 Log.e(TAG, "Intent should not be started with FLAG_ACTIVITY_NEW_DOCU MENT"); | 78 Log.e(TAG, "Intent should not be started with FLAG_ACTIVITY_NEW_DOCU MENT"); |
| 72 return false; | 79 return false; |
| 73 } else { | 80 } else { |
| 74 return true; | 81 return true; |
| 75 } | 82 } |
| 76 } | 83 } |
| 77 | 84 |
| 78 /** | 85 /** |
| 79 * Opens a Browser Actions context menu based on the parsed data. | 86 * Opens a Browser Actions context menu based on the parsed data. |
| 80 */ | 87 */ |
| 81 public void openContextMenu() { | 88 @Override |
| 89 public void openContextMenu(View view) { | |
| 90 ContextMenuParams params = getContextMenuParams(); | |
| 91 mHelper = new BrowserActionsContextMenuHelper(this, params, mActions); | |
| 92 mHelper.displayBrowserActionsMenu(view); | |
| 82 return; | 93 return; |
| 83 } | 94 } |
| 84 | 95 |
| 96 /** | |
| 97 * Populates a {@link ContextMenuParams} with given Uri and type. | |
| 98 * @return The ContextMenuParams used to construct context menu. | |
| 99 */ | |
| 100 private ContextMenuParams getContextMenuParams() { | |
|
Ted C
2017/05/12 23:35:25
s/get/create
ltian
2017/05/15 21:47:03
Done.
| |
| 101 Referrer referrer = IntentHandler.constructValidReferrerForAuthority(mCr eatorPackageName); | |
| 102 return new ContextMenuParams(mType, mUri.toString(), mUri.toString(), mU ri.toString(), | |
| 103 mUri.toString(), mUri.toString(), mUri.toString(), false /* imag eWasFetchedLoFi */, | |
| 104 referrer, false /* canSaveMedia */); | |
| 105 } | |
| 106 | |
| 85 @Override | 107 @Override |
| 86 protected boolean shouldDelayBrowserStartup() { | 108 protected boolean shouldDelayBrowserStartup() { |
| 87 return true; | 109 return true; |
| 88 } | 110 } |
| 89 | 111 |
| 90 @Override | 112 @Override |
| 91 public boolean shouldStartGpuProcess() { | 113 public boolean shouldStartGpuProcess() { |
| 92 return true; | 114 return true; |
| 93 } | 115 } |
| 94 | 116 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 115 Log.e(TAG, "Missing title for item: " + i); | 137 Log.e(TAG, "Missing title for item: " + i); |
| 116 } else { | 138 } else { |
| 117 Log.e(TAG, "Missing title and action for item: " + i); | 139 Log.e(TAG, "Missing title and action for item: " + i); |
| 118 } | 140 } |
| 119 } | 141 } |
| 120 } | 142 } |
| 121 | 143 |
| 122 /** | 144 /** |
| 123 * Callback when Browser Actions menu dialog is shown. | 145 * Callback when Browser Actions menu dialog is shown. |
| 124 */ | 146 */ |
| 125 private void onMenuShown() { | 147 public void onMenuShown() { |
| 126 beginLoadingLibrary(); | 148 beginLoadingLibrary(); |
| 127 } | 149 } |
| 150 | |
| 151 @Override | |
| 152 public void onContextMenuClosed(Menu menu) { | |
| 153 super.onContextMenuClosed(menu); | |
| 154 if (mHelper != null) { | |
| 155 mHelper.onContextMenuClosed(); | |
| 156 } | |
| 157 } | |
| 128 } | 158 } |
| OLD | NEW |