OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/android/contextualsearch/contextual_search_manager.h" | 5 #include "chrome/browser/android/contextualsearch/contextual_search_manager.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h" | 13 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h" |
14 #include "chrome/browser/android/tab_android.h" | 14 #include "chrome/browser/android/tab_android.h" |
15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
16 #include "chrome/browser/search/contextual_search_api_controller.h" | |
16 #include "chrome/browser/search_engines/template_url_service_factory.h" | 17 #include "chrome/browser/search_engines/template_url_service_factory.h" |
17 #include "chrome/browser/ui/android/window_android_helper.h" | 18 #include "chrome/browser/ui/android/window_android_helper.h" |
18 #include "components/navigation_interception/intercept_navigation_delegate.h" | 19 #include "components/navigation_interception/intercept_navigation_delegate.h" |
19 #include "components/variations/variations_associated_data.h" | 20 #include "components/variations/variations_associated_data.h" |
20 #include "content/public/browser/android/content_view_core.h" | 21 #include "content/public/browser/android/content_view_core.h" |
22 #include "content/public/browser/render_process_host.h" | |
21 #include "jni/ContextualSearchManager_jni.h" | 23 #include "jni/ContextualSearchManager_jni.h" |
22 #include "net/url_request/url_fetcher_impl.h" | 24 #include "net/url_request/url_fetcher_impl.h" |
23 | 25 |
24 using content::ContentViewCore; | 26 using content::ContentViewCore; |
25 | 27 |
26 // This class manages the native behavior of the Contextual Search feature. | 28 // This class manages the native behavior of the Contextual Search feature. |
27 // Instances of this class are owned by the Java ContextualSearchManager. | 29 // Instances of this class are owned by the Java ContextualSearchManager. |
28 // Most of the work is actually done in an associated delegate to this class: | 30 // Most of the work is actually done in an associated delegate to this class: |
29 // the ContextualSearchDelegate. | 31 // the ContextualSearchDelegate. |
30 ContextualSearchManager::ContextualSearchManager(JNIEnv* env, jobject obj) { | 32 ContextualSearchManager::ContextualSearchManager(JNIEnv* env, jobject obj) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 JNIEnv* env = base::android::AttachCurrentThread(); | 133 JNIEnv* env = base::android::AttachCurrentThread(); |
132 base::android::ScopedJavaLocalRef<jstring> j_encoding = | 134 base::android::ScopedJavaLocalRef<jstring> j_encoding = |
133 base::android::ConvertUTF8ToJavaString(env, encoding.c_str()); | 135 base::android::ConvertUTF8ToJavaString(env, encoding.c_str()); |
134 base::android::ScopedJavaLocalRef<jstring> j_surrounding_text = | 136 base::android::ScopedJavaLocalRef<jstring> j_surrounding_text = |
135 base::android::ConvertUTF16ToJavaString(env, surrounding_text.c_str()); | 137 base::android::ConvertUTF16ToJavaString(env, surrounding_text.c_str()); |
136 Java_ContextualSearchManager_onIcingSelectionAvailable( | 138 Java_ContextualSearchManager_onIcingSelectionAvailable( |
137 env, java_manager_.obj(), j_encoding.obj(), j_surrounding_text.obj(), | 139 env, java_manager_.obj(), j_encoding.obj(), j_surrounding_text.obj(), |
138 start_offset, end_offset); | 140 start_offset, end_offset); |
139 } | 141 } |
140 | 142 |
143 void ContextualSearchManager::AddViewForContextualSearchApi( | |
144 JNIEnv* env, | |
145 jobject obj, | |
146 jobject j_overlay_content_view_core) { | |
147 ContentViewCore* overlay_content_view_core = | |
148 ContentViewCore::GetNativeContentViewCore(env, | |
149 j_overlay_content_view_core); | |
150 if (overlay_content_view_core != NULL) { | |
151 ContextualSearchApiController::GetInstance()->AddContextualSearchProcess( | |
pedro (no code reviews)
2015/10/23 05:43:54
Nit: What is being added is an ID, not a process,
Donn Denman
2015/10/23 18:58:07
Done.
| |
152 overlay_content_view_core->GetWebContents() | |
153 ->GetRenderProcessHost() | |
154 ->GetID()); | |
155 } | |
156 } | |
157 | |
158 void ContextualSearchManager::RemoveViewForContextualSearchApi( | |
159 JNIEnv* env, | |
160 jobject obj, | |
161 int render_process_host_id) { | |
162 ContextualSearchApiController::GetInstance()->RemoveContextualSearchProcess( | |
163 render_process_host_id); | |
164 } | |
165 | |
141 bool RegisterContextualSearchManager(JNIEnv* env) { | 166 bool RegisterContextualSearchManager(JNIEnv* env) { |
142 return RegisterNativesImpl(env); | 167 return RegisterNativesImpl(env); |
143 } | 168 } |
144 | 169 |
145 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 170 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
146 ContextualSearchManager* manager = new ContextualSearchManager(env, obj); | 171 ContextualSearchManager* manager = new ContextualSearchManager(env, obj); |
147 return reinterpret_cast<intptr_t>(manager); | 172 return reinterpret_cast<intptr_t>(manager); |
148 } | 173 } |
OLD | NEW |