OLD | NEW |
---|---|
(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.Activity; | |
8 import android.app.PendingIntent; | |
9 import android.app.PendingIntent.CanceledException; | |
10 import android.content.Context; | |
11 import android.content.Intent; | |
12 import android.net.Uri; | |
13 import android.provider.Browser; | |
14 | |
15 import org.chromium.base.ContextUtils; | |
16 import org.chromium.base.Log; | |
17 import org.chromium.chrome.browser.IntentHandler; | |
18 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | |
19 import org.chromium.chrome.browser.util.IntentUtils; | |
20 | |
21 /** | |
22 * A delegate responsible for taking actions based on browser action context men u selections. | |
23 */ | |
24 public class BrowserActionsContextMenuItemDelegate { | |
25 private static final String TAG = "BrowserActionsItem"; | |
26 | |
27 private final Context mContext; | |
28 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
| |
29 | |
30 /** | |
31 * Builds a {@link BrowserActionsContextMenuItemDelegate} instance. | |
32 */ | |
33 public BrowserActionsContextMenuItemDelegate(Activity activity) { | |
34 mContext = ContextUtils.getApplicationContext(); | |
35 mActivity = activity; | |
36 } | |
37 | |
38 /** | |
39 * Called when the {@code text} should be saved to the clipboard. | |
40 * @param text The text to save to the clipboard. | |
41 */ | |
42 public void onSaveToClipboard(String text) {} | |
43 | |
44 /** | |
45 * Called when the {@code linkUrl} should be opened in Chrome incognito tab. | |
46 * @param linkUrl The url to open. | |
47 */ | |
48 public void onOpenInIncognitoTab(String linkUrl) { | |
49 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl)); | |
50 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
51 intent.setPackage(mContext.getPackageName()); | |
52 intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PAR ENT, false); | |
53 intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true); | |
54 intent.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName()) ; | |
55 IntentHandler.addTrustedIntentExtras(intent); | |
56 IntentUtils.safeStartActivity(mContext, intent); | |
57 } | |
58 | |
59 /** | |
60 * Called when the {@code linkUrl} should be opened in Chrome in the backgro und. | |
61 * @param linkUrl The url to open. | |
62 */ | |
63 public void onOpenInBackground(String linkUrl) {} | |
64 | |
65 /** | |
66 * Called when a custom item of Browser action menu is selected. | |
67 * @param action The PendingIntent action to be launched. | |
68 */ | |
69 public void onCustomItemSelected(PendingIntent action) { | |
70 try { | |
71 action.send(); | |
72 } catch (CanceledException e) { | |
73 Log.e(TAG, "Browser Action in Chrome failed to send pending intent." ); | |
74 } | |
75 } | |
76 | |
77 /** | |
78 * Called when the page of the {@code linkUrl} should be downloaded. | |
79 * @param linkUrl The url of the page to download. | |
80 */ | |
81 public void startDownload(String linkUrl) {} | |
82 | |
83 /** | |
84 * Called when the {@code linkUrl} should be shared. | |
85 * @param linkUrl The url to share. | |
86 */ | |
87 public void share(String linkUrl) {} | |
88 } | |
OLD | NEW |