OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.contextmenu; | 5 package org.chromium.chrome.browser.contextmenu; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.view.ContextMenu; | 8 import android.view.ContextMenu; |
9 import android.view.ContextMenu.ContextMenuInfo; | 9 import android.view.ContextMenu.ContextMenuInfo; |
10 import android.view.HapticFeedbackConstants; | 10 import android.view.HapticFeedbackConstants; |
11 import android.view.MenuItem; | 11 import android.view.MenuItem; |
12 import android.view.MenuItem.OnMenuItemClickListener; | 12 import android.view.MenuItem.OnMenuItemClickListener; |
13 import android.view.View; | 13 import android.view.View; |
14 import android.view.View.OnCreateContextMenuListener; | 14 import android.view.View.OnCreateContextMenuListener; |
15 | 15 |
16 import org.chromium.base.VisibleForTesting; | 16 import org.chromium.base.VisibleForTesting; |
17 import org.chromium.base.annotations.CalledByNative; | 17 import org.chromium.base.annotations.CalledByNative; |
18 import org.chromium.base.metrics.RecordHistogram; | 18 import org.chromium.base.metrics.RecordHistogram; |
19 import org.chromium.chrome.browser.share.ShareHelper; | 19 import org.chromium.chrome.browser.share.ShareHelper; |
20 import org.chromium.content.browser.ContentViewCore; | 20 import org.chromium.content.browser.ContentViewCore; |
21 import org.chromium.content_public.browser.WebContents; | 21 import org.chromium.content_public.browser.WebContents; |
22 import org.chromium.ui.base.WindowAndroid; | 22 import org.chromium.ui.base.WindowAndroid; |
23 | 23 |
24 /** | 24 /** |
25 * A helper class that handles generating context menus for {@link ContentViewCo
re}s. | 25 * A helper class that handles generating context menus for {@link ContentViewCo
re}s. |
26 */ | 26 */ |
27 public class ContextMenuHelper implements OnCreateContextMenuListener, OnMenuIte
mClickListener { | 27 public class ContextMenuHelper implements OnCreateContextMenuListener, OnMenuIte
mClickListener { |
28 private static final String DATA_REDUCTION_PROXY_PASSTHROUGH_HEADER = | |
29 "Chrome-Proxy: pass-through\r\n"; | |
30 | |
31 private long mNativeContextMenuHelper; | 28 private long mNativeContextMenuHelper; |
32 | 29 |
33 private ContextMenuPopulator mPopulator; | 30 private ContextMenuPopulator mPopulator; |
34 private ContextMenuParams mCurrentContextMenuParams; | 31 private ContextMenuParams mCurrentContextMenuParams; |
35 | 32 |
36 private ContextMenuHelper(long nativeContextMenuHelper) { | 33 private ContextMenuHelper(long nativeContextMenuHelper) { |
37 mNativeContextMenuHelper = nativeContextMenuHelper; | 34 mNativeContextMenuHelper = nativeContextMenuHelper; |
38 } | 35 } |
39 | 36 |
40 @CalledByNative | 37 @CalledByNative |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 82 } |
86 return false; | 83 return false; |
87 } | 84 } |
88 | 85 |
89 /** | 86 /** |
90 * Starts a download based on the current {@link ContextMenuParams}. | 87 * Starts a download based on the current {@link ContextMenuParams}. |
91 * @param isLink Whether or not the download target is a link. | 88 * @param isLink Whether or not the download target is a link. |
92 */ | 89 */ |
93 public void startContextMenuDownload(boolean isLink, boolean isDataReduction
ProxyEnabled) { | 90 public void startContextMenuDownload(boolean isLink, boolean isDataReduction
ProxyEnabled) { |
94 if (mNativeContextMenuHelper != 0) { | 91 if (mNativeContextMenuHelper != 0) { |
95 nativeOnStartDownload(mNativeContextMenuHelper, isLink, | 92 nativeOnStartDownload(mNativeContextMenuHelper, isLink, isDataReduct
ionProxyEnabled); |
96 isDataReductionProxyEnabled ? DATA_REDUCTION_PROXY_PASSTHROU
GH_HEADER : null); | |
97 } | 93 } |
98 } | 94 } |
99 | 95 |
100 /** | 96 /** |
101 * Trigger an image search for the current image that triggered the context
menu. | 97 * Trigger an image search for the current image that triggered the context
menu. |
102 */ | 98 */ |
103 public void searchForImage() { | 99 public void searchForImage() { |
104 if (mNativeContextMenuHelper == 0) return; | 100 if (mNativeContextMenuHelper == 0) return; |
105 nativeSearchForImage(mNativeContextMenuHelper); | 101 nativeSearchForImage(mNativeContextMenuHelper); |
106 } | 102 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 @VisibleForTesting | 141 @VisibleForTesting |
146 public ContextMenuPopulator getPopulator() { | 142 public ContextMenuPopulator getPopulator() { |
147 return mPopulator; | 143 return mPopulator; |
148 } | 144 } |
149 | 145 |
150 private boolean shouldShowMenu(ContextMenuParams params) { | 146 private boolean shouldShowMenu(ContextMenuParams params) { |
151 return (mPopulator != null && mPopulator.shouldShowContextMenu(params)); | 147 return (mPopulator != null && mPopulator.shouldShowContextMenu(params)); |
152 } | 148 } |
153 | 149 |
154 private native void nativeOnStartDownload( | 150 private native void nativeOnStartDownload( |
155 long nativeContextMenuHelper, boolean isLink, String headers); | 151 long nativeContextMenuHelper, boolean isLink, boolean isDataReductio
nProxyEnabled); |
156 private native void nativeSearchForImage(long nativeContextMenuHelper); | 152 private native void nativeSearchForImage(long nativeContextMenuHelper); |
157 private native void nativeShareImage(long nativeContextMenuHelper); | 153 private native void nativeShareImage(long nativeContextMenuHelper); |
158 } | 154 } |
OLD | NEW |