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/contextualsearch/resolved_search_term.h" | 14 #include "chrome/browser/android/contextualsearch/resolved_search_term.h" |
15 #include "chrome/browser/android/tab_android.h" | 15 #include "chrome/browser/android/tab_android.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 17 #include "chrome/browser/search_engines/template_url_service_factory.h" |
18 #include "components/contextual_search/browser/contextual_search_js_api_service_
impl.h" | 18 #include "components/contextual_search/browser/contextual_search_js_api_service_
impl.h" |
19 #include "components/contextual_search/common/overlay_page_notifier_service.mojo
m.h" | 19 #include "components/contextual_search/common/overlay_page_notifier_service.mojo
m.h" |
20 #include "components/navigation_interception/intercept_navigation_delegate.h" | 20 #include "components/navigation_interception/intercept_navigation_delegate.h" |
21 #include "components/variations/variations_associated_data.h" | 21 #include "components/variations/variations_associated_data.h" |
22 #include "content/public/browser/android/content_view_core.h" | 22 #include "content/public/browser/android/content_view_core.h" |
23 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/common/service_registry.h" | |
26 #include "jni/ContextualSearchManager_jni.h" | 25 #include "jni/ContextualSearchManager_jni.h" |
27 #include "net/url_request/url_fetcher_impl.h" | 26 #include "net/url_request/url_fetcher_impl.h" |
| 27 #include "services/shell/public/cpp/interface_provider.h" |
| 28 #include "services/shell/public/cpp/interface_registry.h" |
28 | 29 |
29 using content::ContentViewCore; | 30 using content::ContentViewCore; |
30 | 31 |
31 // This class manages the native behavior of the Contextual Search feature. | 32 // This class manages the native behavior of the Contextual Search feature. |
32 // Instances of this class are owned by the Java ContextualSearchManager. | 33 // Instances of this class are owned by the Java ContextualSearchManager. |
33 // Most of the work is actually done in an associated delegate to this class: | 34 // Most of the work is actually done in an associated delegate to this class: |
34 // the ContextualSearchDelegate. | 35 // the ContextualSearchDelegate. |
35 ContextualSearchManager::ContextualSearchManager(JNIEnv* env, jobject obj) { | 36 ContextualSearchManager::ContextualSearchManager(JNIEnv* env, jobject obj) { |
36 java_manager_.Reset(env, obj); | 37 java_manager_.Reset(env, obj); |
37 Java_ContextualSearchManager_setNativeManager( | 38 Java_ContextualSearchManager_setNativeManager( |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 ContentViewCore* overlay_content_view_core = | 175 ContentViewCore* overlay_content_view_core = |
175 ContentViewCore::GetNativeContentViewCore(env, | 176 ContentViewCore::GetNativeContentViewCore(env, |
176 j_overlay_content_view_core); | 177 j_overlay_content_view_core); |
177 // Tell our Overlay Notifier Service that this is currently a CS page. | 178 // Tell our Overlay Notifier Service that this is currently a CS page. |
178 content::RenderFrameHost* render_frame_host = | 179 content::RenderFrameHost* render_frame_host = |
179 overlay_content_view_core->GetWebContents() | 180 overlay_content_view_core->GetWebContents() |
180 ->GetRenderViewHost() | 181 ->GetRenderViewHost() |
181 ->GetMainFrame(); | 182 ->GetMainFrame(); |
182 DCHECK(render_frame_host); | 183 DCHECK(render_frame_host); |
183 contextual_search::mojom::OverlayPageNotifierServicePtr page_notifier_service; | 184 contextual_search::mojom::OverlayPageNotifierServicePtr page_notifier_service; |
184 render_frame_host->GetServiceRegistry()->ConnectToRemoteService( | 185 render_frame_host->GetRemoteInterfaces()->GetInterface( |
185 mojo::GetProxy(&page_notifier_service)); | 186 &page_notifier_service); |
186 DCHECK(page_notifier_service); | 187 DCHECK(page_notifier_service); |
187 page_notifier_service->NotifyIsContextualSearchOverlay(); | 188 page_notifier_service->NotifyIsContextualSearchOverlay(); |
188 | 189 |
189 // Also set up the backchannel to call into this class from the JS API. | 190 // Also set up the backchannel to call into this class from the JS API. |
190 render_frame_host->GetServiceRegistry()->AddService( | 191 render_frame_host->GetInterfaceRegistry()->AddInterface( |
191 base::Bind(&contextual_search::CreateContextualSearchJsApiService, this)); | 192 base::Bind(&contextual_search::CreateContextualSearchJsApiService, this)); |
192 } | 193 } |
193 | 194 |
194 bool RegisterContextualSearchManager(JNIEnv* env) { | 195 bool RegisterContextualSearchManager(JNIEnv* env) { |
195 return RegisterNativesImpl(env); | 196 return RegisterNativesImpl(env); |
196 } | 197 } |
197 | 198 |
198 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 199 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
199 ContextualSearchManager* manager = new ContextualSearchManager(env, obj); | 200 ContextualSearchManager* manager = new ContextualSearchManager(env, obj); |
200 return reinterpret_cast<intptr_t>(manager); | 201 return reinterpret_cast<intptr_t>(manager); |
201 } | 202 } |
202 | 203 |
203 void ContextualSearchManager::SetCaption(std::string caption, | 204 void ContextualSearchManager::SetCaption(std::string caption, |
204 bool does_answer) { | 205 bool does_answer) { |
205 JNIEnv* env = base::android::AttachCurrentThread(); | 206 JNIEnv* env = base::android::AttachCurrentThread(); |
206 base::android::ScopedJavaLocalRef<jstring> j_caption = | 207 base::android::ScopedJavaLocalRef<jstring> j_caption = |
207 base::android::ConvertUTF8ToJavaString(env, caption.c_str()); | 208 base::android::ConvertUTF8ToJavaString(env, caption.c_str()); |
208 Java_ContextualSearchManager_onSetCaption(env, java_manager_.obj(), | 209 Java_ContextualSearchManager_onSetCaption(env, java_manager_.obj(), |
209 j_caption.obj(), does_answer); | 210 j_caption.obj(), does_answer); |
210 } | 211 } |
OLD | NEW |