| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "components/variations/variations_associated_data.h" | 21 #include "components/variations/variations_associated_data.h" |
| 22 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
| 23 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "jni/ContextualSearchManager_jni.h" | 25 #include "jni/ContextualSearchManager_jni.h" |
| 26 #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" | 27 #include "services/shell/public/cpp/interface_provider.h" |
| 28 #include "services/shell/public/cpp/interface_registry.h" | 28 #include "services/shell/public/cpp/interface_registry.h" |
| 29 | 29 |
| 30 using base::android::JavaParamRef; | 30 using base::android::JavaParamRef; |
| 31 using base::android::JavaRef; |
| 31 using content::WebContents; | 32 using content::WebContents; |
| 32 | 33 |
| 33 // This class manages the native behavior of the Contextual Search feature. | 34 // This class manages the native behavior of the Contextual Search feature. |
| 34 // Instances of this class are owned by the Java ContextualSearchManager. | 35 // Instances of this class are owned by the Java ContextualSearchManager. |
| 35 // Most of the work is actually done in an associated delegate to this class: | 36 // Most of the work is actually done in an associated delegate to this class: |
| 36 // the ContextualSearchDelegate. | 37 // the ContextualSearchDelegate. |
| 37 ContextualSearchManager::ContextualSearchManager(JNIEnv* env, jobject obj) { | 38 ContextualSearchManager::ContextualSearchManager(JNIEnv* env, |
| 38 java_manager_.Reset(env, obj); | 39 const JavaRef<jobject>& obj) { |
| 40 java_manager_.Reset(obj); |
| 39 Java_ContextualSearchManager_setNativeManager( | 41 Java_ContextualSearchManager_setNativeManager( |
| 40 env, obj, reinterpret_cast<intptr_t>(this)); | 42 env, obj, reinterpret_cast<intptr_t>(this)); |
| 41 Profile* profile = ProfileManager::GetActiveUserProfile(); | 43 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 42 delegate_.reset(new ContextualSearchDelegate( | 44 delegate_.reset(new ContextualSearchDelegate( |
| 43 profile->GetRequestContext(), | 45 profile->GetRequestContext(), |
| 44 TemplateURLServiceFactory::GetForProfile(profile), | 46 TemplateURLServiceFactory::GetForProfile(profile), |
| 45 base::Bind(&ContextualSearchManager::OnSearchTermResolutionResponse, | 47 base::Bind(&ContextualSearchManager::OnSearchTermResolutionResponse, |
| 46 base::Unretained(this)), | 48 base::Unretained(this)), |
| 47 base::Bind(&ContextualSearchManager::OnSurroundingTextAvailable, | 49 base::Bind(&ContextualSearchManager::OnSurroundingTextAvailable, |
| 48 base::Unretained(this)), | 50 base::Unretained(this)), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 61 } | 63 } |
| 62 | 64 |
| 63 void ContextualSearchManager::StartSearchTermResolutionRequest( | 65 void ContextualSearchManager::StartSearchTermResolutionRequest( |
| 64 JNIEnv* env, | 66 JNIEnv* env, |
| 65 const JavaParamRef<jobject>& obj, | 67 const JavaParamRef<jobject>& obj, |
| 66 const JavaParamRef<jstring>& j_selection, | 68 const JavaParamRef<jstring>& j_selection, |
| 67 jboolean j_use_resolved_search_term, | 69 jboolean j_use_resolved_search_term, |
| 68 const JavaParamRef<jobject>& j_base_web_contents, | 70 const JavaParamRef<jobject>& j_base_web_contents, |
| 69 jboolean j_may_send_base_page_url) { | 71 jboolean j_may_send_base_page_url) { |
| 70 WebContents* base_web_contents = | 72 WebContents* base_web_contents = |
| 71 WebContents::FromJavaWebContents(j_base_web_contents.obj()); | 73 WebContents::FromJavaWebContents(j_base_web_contents); |
| 72 DCHECK(base_web_contents); | 74 DCHECK(base_web_contents); |
| 73 std::string selection( | 75 std::string selection( |
| 74 base::android::ConvertJavaStringToUTF8(env, j_selection)); | 76 base::android::ConvertJavaStringToUTF8(env, j_selection)); |
| 75 bool use_resolved_search_term = j_use_resolved_search_term; | 77 bool use_resolved_search_term = j_use_resolved_search_term; |
| 76 bool may_send_base_page_url = j_may_send_base_page_url; | 78 bool may_send_base_page_url = j_may_send_base_page_url; |
| 77 // Calls back to OnSearchTermResolutionResponse. | 79 // Calls back to OnSearchTermResolutionResponse. |
| 78 delegate_->StartSearchTermResolutionRequest( | 80 delegate_->StartSearchTermResolutionRequest( |
| 79 selection, use_resolved_search_term, base_web_contents, | 81 selection, use_resolved_search_term, base_web_contents, |
| 80 may_send_base_page_url); | 82 may_send_base_page_url); |
| 81 } | 83 } |
| 82 | 84 |
| 83 void ContextualSearchManager::GatherSurroundingText( | 85 void ContextualSearchManager::GatherSurroundingText( |
| 84 JNIEnv* env, | 86 JNIEnv* env, |
| 85 const JavaParamRef<jobject>& obj, | 87 const JavaParamRef<jobject>& obj, |
| 86 const JavaParamRef<jstring>& j_selection, | 88 const JavaParamRef<jstring>& j_selection, |
| 87 jboolean j_use_resolved_search_term, | 89 jboolean j_use_resolved_search_term, |
| 88 const JavaParamRef<jobject>& j_base_web_contents, | 90 const JavaParamRef<jobject>& j_base_web_contents, |
| 89 jboolean j_may_send_base_page_url) { | 91 jboolean j_may_send_base_page_url) { |
| 90 WebContents* base_web_contents = | 92 WebContents* base_web_contents = |
| 91 WebContents::FromJavaWebContents(j_base_web_contents.obj()); | 93 WebContents::FromJavaWebContents(j_base_web_contents); |
| 92 DCHECK(base_web_contents); | 94 DCHECK(base_web_contents); |
| 93 std::string selection( | 95 std::string selection( |
| 94 base::android::ConvertJavaStringToUTF8(env, j_selection)); | 96 base::android::ConvertJavaStringToUTF8(env, j_selection)); |
| 95 bool use_resolved_search_term = j_use_resolved_search_term; | 97 bool use_resolved_search_term = j_use_resolved_search_term; |
| 96 bool may_send_base_page_url = j_may_send_base_page_url; | 98 bool may_send_base_page_url = j_may_send_base_page_url; |
| 97 delegate_->GatherAndSaveSurroundingText(selection, use_resolved_search_term, | 99 delegate_->GatherAndSaveSurroundingText(selection, use_resolved_search_term, |
| 98 base_web_contents, | 100 base_web_contents, |
| 99 may_send_base_page_url); | 101 may_send_base_page_url); |
| 100 } | 102 } |
| 101 | 103 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 Java_ContextualSearchManager_onIcingSelectionAvailable( | 169 Java_ContextualSearchManager_onIcingSelectionAvailable( |
| 168 env, java_manager_, j_encoding, j_surrounding_text, start_offset, | 170 env, java_manager_, j_encoding, j_surrounding_text, start_offset, |
| 169 end_offset); | 171 end_offset); |
| 170 } | 172 } |
| 171 | 173 |
| 172 void ContextualSearchManager::EnableContextualSearchJsApiForOverlay( | 174 void ContextualSearchManager::EnableContextualSearchJsApiForOverlay( |
| 173 JNIEnv* env, | 175 JNIEnv* env, |
| 174 jobject obj, | 176 jobject obj, |
| 175 const JavaParamRef<jobject>& j_overlay_web_contents) { | 177 const JavaParamRef<jobject>& j_overlay_web_contents) { |
| 176 WebContents* overlay_web_contents = | 178 WebContents* overlay_web_contents = |
| 177 WebContents::FromJavaWebContents(j_overlay_web_contents.obj()); | 179 WebContents::FromJavaWebContents(j_overlay_web_contents); |
| 178 DCHECK(overlay_web_contents); | 180 DCHECK(overlay_web_contents); |
| 179 // Tell our Overlay Notifier Service that this is currently a CS page. | 181 // Tell our Overlay Notifier Service that this is currently a CS page. |
| 180 content::RenderFrameHost* render_frame_host = | 182 content::RenderFrameHost* render_frame_host = |
| 181 overlay_web_contents->GetRenderViewHost()->GetMainFrame(); | 183 overlay_web_contents->GetRenderViewHost()->GetMainFrame(); |
| 182 DCHECK(render_frame_host); | 184 DCHECK(render_frame_host); |
| 183 contextual_search::mojom::OverlayPageNotifierServicePtr page_notifier_service; | 185 contextual_search::mojom::OverlayPageNotifierServicePtr page_notifier_service; |
| 184 render_frame_host->GetRemoteInterfaces()->GetInterface( | 186 render_frame_host->GetRemoteInterfaces()->GetInterface( |
| 185 &page_notifier_service); | 187 &page_notifier_service); |
| 186 DCHECK(page_notifier_service); | 188 DCHECK(page_notifier_service); |
| 187 page_notifier_service->NotifyIsContextualSearchOverlay(); | 189 page_notifier_service->NotifyIsContextualSearchOverlay(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 201 } | 203 } |
| 202 | 204 |
| 203 void ContextualSearchManager::SetCaption(std::string caption, | 205 void ContextualSearchManager::SetCaption(std::string caption, |
| 204 bool does_answer) { | 206 bool does_answer) { |
| 205 JNIEnv* env = base::android::AttachCurrentThread(); | 207 JNIEnv* env = base::android::AttachCurrentThread(); |
| 206 base::android::ScopedJavaLocalRef<jstring> j_caption = | 208 base::android::ScopedJavaLocalRef<jstring> j_caption = |
| 207 base::android::ConvertUTF8ToJavaString(env, caption.c_str()); | 209 base::android::ConvertUTF8ToJavaString(env, caption.c_str()); |
| 208 Java_ContextualSearchManager_onSetCaption(env, java_manager_, j_caption, | 210 Java_ContextualSearchManager_onSetCaption(env, java_manager_, j_caption, |
| 209 does_answer); | 211 does_answer); |
| 210 } | 212 } |
| OLD | NEW |