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

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

Issue 2706333002: [TTS] Add a Java Context linked to existing native (Closed)
Patch Set: Nothing, I think. Created 3 years, 9 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
« no previous file with comments | « chrome/browser/android/contextualsearch/contextual_search_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 59
60 void ContextualSearchManager::Destroy(JNIEnv* env, 60 void ContextualSearchManager::Destroy(JNIEnv* env,
61 const JavaParamRef<jobject>& obj) { 61 const JavaParamRef<jobject>& obj) {
62 delete this; 62 delete this;
63 } 63 }
64 64
65 void ContextualSearchManager::StartSearchTermResolutionRequest( 65 void ContextualSearchManager::StartSearchTermResolutionRequest(
66 JNIEnv* env, 66 JNIEnv* env,
67 const JavaParamRef<jobject>& obj, 67 const JavaParamRef<jobject>& obj,
68 const JavaParamRef<jstring>& j_selection, 68 const base::android::JavaParamRef<jobject>& j_contextual_search_context,
69 const JavaParamRef<jstring>& j_home_country, 69 const JavaParamRef<jobject>& j_base_web_contents) {
70 const JavaParamRef<jobject>& j_base_web_contents,
71 jboolean j_may_send_base_page_url) {
72 WebContents* base_web_contents = 70 WebContents* base_web_contents =
73 WebContents::FromJavaWebContents(j_base_web_contents); 71 WebContents::FromJavaWebContents(j_base_web_contents);
74 DCHECK(base_web_contents); 72 DCHECK(base_web_contents);
75 std::string selection( 73 ContextualSearchContext* contextual_search_context =
76 base::android::ConvertJavaStringToUTF8(env, j_selection)); 74 ContextualSearchContext::FromJavaContextualSearchContext(
77 std::string home_country( 75 j_contextual_search_context);
78 base::android::ConvertJavaStringToUTF8(env, j_home_country));
79 bool may_send_base_page_url = j_may_send_base_page_url;
80 // Calls back to OnSearchTermResolutionResponse. 76 // Calls back to OnSearchTermResolutionResponse.
81 delegate_->StartSearchTermResolutionRequest( 77 delegate_->StartSearchTermResolutionRequest(contextual_search_context,
82 selection, home_country, base_web_contents, may_send_base_page_url); 78 base_web_contents);
83 } 79 }
84 80
85 void ContextualSearchManager::GatherSurroundingText( 81 void ContextualSearchManager::GatherSurroundingText(
86 JNIEnv* env, 82 JNIEnv* env,
87 const JavaParamRef<jobject>& obj, 83 const JavaParamRef<jobject>& obj,
88 const JavaParamRef<jstring>& j_selection, 84 const base::android::JavaParamRef<jobject>& j_contextual_search_context,
89 const JavaParamRef<jstring>& j_home_country, 85 const JavaParamRef<jobject>& j_base_web_contents) {
90 const JavaParamRef<jobject>& j_base_web_contents,
91 jboolean j_may_send_base_page_url) {
92 WebContents* base_web_contents = 86 WebContents* base_web_contents =
93 WebContents::FromJavaWebContents(j_base_web_contents); 87 WebContents::FromJavaWebContents(j_base_web_contents);
94 DCHECK(base_web_contents); 88 DCHECK(base_web_contents);
95 std::string selection( 89 ContextualSearchContext* contextual_search_context =
96 base::android::ConvertJavaStringToUTF8(env, j_selection)); 90 ContextualSearchContext::FromJavaContextualSearchContext(
97 std::string home_country( 91 j_contextual_search_context);
98 base::android::ConvertJavaStringToUTF8(env, j_home_country)); 92 delegate_->GatherAndSaveSurroundingText(contextual_search_context,
99 bool may_send_base_page_url = j_may_send_base_page_url; 93 base_web_contents);
100 delegate_->GatherAndSaveSurroundingText(
101 selection, home_country, base_web_contents, may_send_base_page_url);
102 } 94 }
103 95
104 base::android::ScopedJavaLocalRef<jstring> 96 base::android::ScopedJavaLocalRef<jstring>
105 ContextualSearchManager::GetTargetLanguage(JNIEnv* env, 97 ContextualSearchManager::GetTargetLanguage(JNIEnv* env,
106 const JavaParamRef<jobject>& obj) { 98 const JavaParamRef<jobject>& obj) {
107 DCHECK(delegate_); 99 DCHECK(delegate_);
108 std::string target_language(delegate_->GetTargetLanguage()); 100 std::string target_language(delegate_->GetTargetLanguage());
109 base::android::ScopedJavaLocalRef<jstring> j_target_language = 101 base::android::ScopedJavaLocalRef<jstring> j_target_language =
110 base::android::ConvertUTF8ToJavaString(env, target_language.c_str()); 102 base::android::ConvertUTF8ToJavaString(env, target_language.c_str());
111 return j_target_language; 103 return j_target_language;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 207 }
216 208
217 void ContextualSearchManager::SetCaption(std::string caption, 209 void ContextualSearchManager::SetCaption(std::string caption,
218 bool does_answer) { 210 bool does_answer) {
219 JNIEnv* env = base::android::AttachCurrentThread(); 211 JNIEnv* env = base::android::AttachCurrentThread();
220 base::android::ScopedJavaLocalRef<jstring> j_caption = 212 base::android::ScopedJavaLocalRef<jstring> j_caption =
221 base::android::ConvertUTF8ToJavaString(env, caption.c_str()); 213 base::android::ConvertUTF8ToJavaString(env, caption.c_str());
222 Java_ContextualSearchManager_onSetCaption(env, java_manager_, j_caption, 214 Java_ContextualSearchManager_onSetCaption(env, java_manager_, j_caption,
223 does_answer); 215 does_answer);
224 } 216 }
OLDNEW
« no previous file with comments | « chrome/browser/android/contextualsearch/contextual_search_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698