Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(553)

Side by Side Diff: chrome/browser/android/contextualsearch/contextual_search_manager.cc

Issue 1532743002: [Contextual Search] Use Mojo API for Quick Answers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated a comment. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/ui/android/view_android_helper.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/navigation_interception/intercept_navigation_delegate.h" 20 #include "components/navigation_interception/intercept_navigation_delegate.h"
20 #include "components/variations/variations_associated_data.h" 21 #include "components/variations/variations_associated_data.h"
21 #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"
24 #include "content/public/browser/render_view_host.h"
25 #include "content/public/common/service_registry.h"
22 #include "jni/ContextualSearchManager_jni.h" 26 #include "jni/ContextualSearchManager_jni.h"
23 #include "net/url_request/url_fetcher_impl.h" 27 #include "net/url_request/url_fetcher_impl.h"
24 28
25 using content::ContentViewCore; 29 using content::ContentViewCore;
26 30
27 // This class manages the native behavior of the Contextual Search feature. 31 // This class manages the native behavior of the Contextual Search feature.
28 // Instances of this class are owned by the Java ContextualSearchManager. 32 // Instances of this class are owned by the Java ContextualSearchManager.
29 // Most of the work is actually done in an associated delegate to this class: 33 // Most of the work is actually done in an associated delegate to this class:
30 // the ContextualSearchDelegate. 34 // the ContextualSearchDelegate.
31 ContextualSearchManager::ContextualSearchManager(JNIEnv* env, jobject obj) { 35 ContextualSearchManager::ContextualSearchManager(JNIEnv* env, jobject obj) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 JNIEnv* env = base::android::AttachCurrentThread(); 159 JNIEnv* env = base::android::AttachCurrentThread();
156 base::android::ScopedJavaLocalRef<jstring> j_encoding = 160 base::android::ScopedJavaLocalRef<jstring> j_encoding =
157 base::android::ConvertUTF8ToJavaString(env, encoding.c_str()); 161 base::android::ConvertUTF8ToJavaString(env, encoding.c_str());
158 base::android::ScopedJavaLocalRef<jstring> j_surrounding_text = 162 base::android::ScopedJavaLocalRef<jstring> j_surrounding_text =
159 base::android::ConvertUTF16ToJavaString(env, surrounding_text.c_str()); 163 base::android::ConvertUTF16ToJavaString(env, surrounding_text.c_str());
160 Java_ContextualSearchManager_onIcingSelectionAvailable( 164 Java_ContextualSearchManager_onIcingSelectionAvailable(
161 env, java_manager_.obj(), j_encoding.obj(), j_surrounding_text.obj(), 165 env, java_manager_.obj(), j_encoding.obj(), j_surrounding_text.obj(),
162 start_offset, end_offset); 166 start_offset, end_offset);
163 } 167 }
164 168
169 void ContextualSearchManager::EnableContextualSearchJsApiForOverlay(
170 JNIEnv* env,
171 jobject obj,
172 jobject j_overlay_content_view_core) {
173 ContentViewCore* overlay_content_view_core =
174 ContentViewCore::GetNativeContentViewCore(env,
175 j_overlay_content_view_core);
176 // Tell our Overlay Notifier Service that this is currently a CS page.
177 content::RenderFrameHost* render_frame_host =
178 overlay_content_view_core->GetWebContents()
179 ->GetRenderViewHost()
180 ->GetMainFrame();
181 DCHECK(render_frame_host);
182 contextual_search::OverlayPageNotifierServicePtr page_notifier_service;
183 render_frame_host->GetServiceRegistry()->ConnectToRemoteService(
184 mojo::GetProxy(&page_notifier_service));
185 DCHECK(page_notifier_service);
186 page_notifier_service->NotifyIsContextualSearchOverlay();
187
188 // Also set up the backchannel to call into this class from the JS API.
189 render_frame_host->GetServiceRegistry()->AddService(
190 base::Bind(&contextual_search::CreateContextualSearchJsApiService, this));
191 }
192
165 bool RegisterContextualSearchManager(JNIEnv* env) { 193 bool RegisterContextualSearchManager(JNIEnv* env) {
166 return RegisterNativesImpl(env); 194 return RegisterNativesImpl(env);
167 } 195 }
168 196
169 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 197 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
170 ContextualSearchManager* manager = new ContextualSearchManager(env, obj); 198 ContextualSearchManager* manager = new ContextualSearchManager(env, obj);
171 return reinterpret_cast<intptr_t>(manager); 199 return reinterpret_cast<intptr_t>(manager);
172 } 200 }
201
202 void ContextualSearchManager::SetCaption(std::string caption,
203 bool does_answer) {
204 JNIEnv* env = base::android::AttachCurrentThread();
205 base::android::ScopedJavaLocalRef<jstring> j_caption =
206 base::android::ConvertUTF8ToJavaString(env, caption.c_str());
207 Java_ContextualSearchManager_onSetCaption(env, java_manager_.obj(),
208 j_caption.obj(), does_answer);
209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698