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_service.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::EnableContextualSearchServiceForView( |
| 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 ContextualSearchService::GetInstance()->SetContextualSearchProcess( |
| 152 overlay_content_view_core->GetWebContents() |
| 153 ->GetRenderProcessHost() |
| 154 ->GetID()); |
| 155 } |
| 156 } |
| 157 |
141 bool RegisterContextualSearchManager(JNIEnv* env) { | 158 bool RegisterContextualSearchManager(JNIEnv* env) { |
142 return RegisterNativesImpl(env); | 159 return RegisterNativesImpl(env); |
143 } | 160 } |
144 | 161 |
145 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 162 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
146 ContextualSearchManager* manager = new ContextualSearchManager(env, obj); | 163 ContextualSearchManager* manager = new ContextualSearchManager(env, obj); |
147 return reinterpret_cast<intptr_t>(manager); | 164 return reinterpret_cast<intptr_t>(manager); |
148 } | 165 } |
OLD | NEW |