Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuItemDelegate.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuItemDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuItemDelegate.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..794c7b1b0bb4b40f0f9e38a45ff11ef997051ffb |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuItemDelegate.java |
| @@ -0,0 +1,88 @@ |
| +// 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.Activity; |
| +import android.app.PendingIntent; |
| +import android.app.PendingIntent.CanceledException; |
| +import android.content.Context; |
| +import android.content.Intent; |
| +import android.net.Uri; |
| +import android.provider.Browser; |
| + |
| +import org.chromium.base.ContextUtils; |
| +import org.chromium.base.Log; |
| +import org.chromium.chrome.browser.IntentHandler; |
| +import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
| +import org.chromium.chrome.browser.util.IntentUtils; |
| + |
| +/** |
| + * A delegate responsible for taking actions based on browser action context menu selections. |
| + */ |
| +public class BrowserActionsContextMenuItemDelegate { |
| + private static final String TAG = "BrowserActionsItem"; |
| + |
| + private final Context mContext; |
| + private final Activity mActivity; |
|
Ted C
2017/05/12 23:35:26
Activity isn't used
ltian
2017/05/15 21:47:04
It will be used for next CL when showing the toast
Ted C
2017/05/17 15:40:38
Toast doesn't need an activity. A Context is fine
Ted C
2017/05/17 19:31:52
Still need to remove this
|
| + |
| + /** |
| + * Builds a {@link BrowserActionsContextMenuItemDelegate} instance. |
| + */ |
| + public BrowserActionsContextMenuItemDelegate(Activity activity) { |
| + mContext = ContextUtils.getApplicationContext(); |
| + mActivity = activity; |
| + } |
| + |
| + /** |
| + * Called when the {@code text} should be saved to the clipboard. |
| + * @param text The text to save to the clipboard. |
| + */ |
| + public void onSaveToClipboard(String text) {} |
| + |
| + /** |
| + * Called when the {@code linkUrl} should be opened in Chrome incognito tab. |
| + * @param linkUrl The url to open. |
| + */ |
| + public void onOpenInIncognitoTab(String linkUrl) { |
| + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl)); |
| + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| + intent.setPackage(mContext.getPackageName()); |
| + intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false); |
| + intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true); |
| + intent.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName()); |
| + IntentHandler.addTrustedIntentExtras(intent); |
| + IntentUtils.safeStartActivity(mContext, intent); |
| + } |
| + |
| + /** |
| + * Called when the {@code linkUrl} should be opened in Chrome in the background. |
| + * @param linkUrl The url to open. |
| + */ |
| + public void onOpenInBackground(String linkUrl) {} |
| + |
| + /** |
| + * Called when a custom item of Browser action menu is selected. |
| + * @param action The PendingIntent action to be launched. |
| + */ |
| + public void onCustomItemSelected(PendingIntent action) { |
| + try { |
| + action.send(); |
| + } catch (CanceledException e) { |
| + Log.e(TAG, "Browser Action in Chrome failed to send pending intent."); |
| + } |
| + } |
| + |
| + /** |
| + * Called when the page of the {@code linkUrl} should be downloaded. |
| + * @param linkUrl The url of the page to download. |
| + */ |
| + public void startDownload(String linkUrl) {} |
| + |
| + /** |
| + * Called when the {@code linkUrl} should be shared. |
| + * @param linkUrl The url to share. |
| + */ |
| + public void share(String linkUrl) {} |
| +} |