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 #include "chrome/browser/ui/android/context_menu_helper.h" | 5 #include "chrome/browser/ui/android/context_menu_helper.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "content/public/browser/android/content_view_core.h" | 9 #include "content/public/browser/android/content_view_core.h" |
10 #include "content/public/browser/android/download_controller_android.h" | 10 #include "content/public/browser/android/download_controller_android.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 void ContextMenuHelper::ShowContextMenu( | 36 void ContextMenuHelper::ShowContextMenu( |
37 const content::ContextMenuParams& params) { | 37 const content::ContextMenuParams& params) { |
38 content::ContentViewCore* content_view_core = | 38 content::ContentViewCore* content_view_core = |
39 content::ContentViewCore::FromWebContents(web_contents_); | 39 content::ContentViewCore::FromWebContents(web_contents_); |
40 | 40 |
41 if (!content_view_core) | 41 if (!content_view_core) |
42 return; | 42 return; |
43 | 43 |
| 44 base::android::ScopedJavaLocalRef<jobject> jcontent_view_core( |
| 45 content_view_core->GetJavaObject()); |
| 46 |
| 47 if (jcontent_view_core.is_null()) |
| 48 return; |
| 49 |
44 JNIEnv* env = base::android::AttachCurrentThread(); | 50 JNIEnv* env = base::android::AttachCurrentThread(); |
45 context_menu_params_ = params; | 51 context_menu_params_ = params; |
46 Java_ContextMenuHelper_showContextMenu( | 52 Java_ContextMenuHelper_showContextMenu( |
47 env, | 53 env, |
48 java_obj_.obj(), | 54 java_obj_.obj(), |
49 content_view_core->GetJavaObject().obj(), | 55 jcontent_view_core.obj(), |
50 ContextMenuHelper::CreateJavaContextMenuParams(params).obj()); | 56 ContextMenuHelper::CreateJavaContextMenuParams(params).obj()); |
51 } | 57 } |
52 | 58 |
53 // Called to show a custom context menu. Used by the NTP. | 59 // Called to show a custom context menu. Used by the NTP. |
54 void ContextMenuHelper::ShowCustomContextMenu( | 60 void ContextMenuHelper::ShowCustomContextMenu( |
55 const content::ContextMenuParams& params, | 61 const content::ContextMenuParams& params, |
56 const base::Callback<void(int)>& callback) { | 62 const base::Callback<void(int)>& callback) { |
57 context_menu_callback_ = callback; | 63 context_menu_callback_ = callback; |
58 ShowContextMenu(params); | 64 ShowContextMenu(params); |
59 } | 65 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 content::DownloadControllerAndroid::Get()->StartContextMenuDownload( | 116 content::DownloadControllerAndroid::Get()->StartContextMenuDownload( |
111 context_menu_params_, | 117 context_menu_params_, |
112 web_contents_, | 118 web_contents_, |
113 jis_link); | 119 jis_link); |
114 } | 120 } |
115 | 121 |
116 bool RegisterContextMenuHelper(JNIEnv* env) { | 122 bool RegisterContextMenuHelper(JNIEnv* env) { |
117 return RegisterNativesImpl(env) && | 123 return RegisterNativesImpl(env) && |
118 ContextMenuParamsAndroid::RegisterNativesImpl(env); | 124 ContextMenuParamsAndroid::RegisterNativesImpl(env); |
119 } | 125 } |
OLD | NEW |