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

Side by Side Diff: chrome/browser/android/contextualsearch/contextual_search_context.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
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_context.h" 5 #include <chrome/browser/android/contextualsearch/contextual_search_context.h>
6
7 #include "base/android/jni_string.h"
8 #include "content/public/browser/browser_thread.h"
9
10 #include "jni/ContextualSearchContext_jni.h"
11
12 ContextualSearchContext::ContextualSearchContext(JNIEnv* env, jobject obj)
13 : can_resolve(false),
14 can_send_base_page_url(false),
15 start_offset(0),
16 end_offset(0) {
17 java_object_.Reset(env, obj);
18 }
6 19
7 ContextualSearchContext::ContextualSearchContext( 20 ContextualSearchContext::ContextualSearchContext(
8 const std::string& selected_text, 21 const std::string& selected_text,
9 const std::string& home_country, 22 const std::string& home_country,
10 const GURL& page_url, 23 const GURL& page_url,
11 const std::string& encoding) 24 const std::string& encoding)
12 : selected_text(selected_text), 25 : selected_text(selected_text),
13 home_country(home_country), 26 home_country(home_country),
14 page_url(page_url), 27 base_page_url(page_url),
15 encoding(encoding) {} 28 base_page_encoding(encoding) {
29 java_object_ = nullptr;
30 }
16 31
17 ContextualSearchContext::~ContextualSearchContext() { 32 ContextualSearchContext::~ContextualSearchContext() {
18 } 33 }
34
35 // static
36 ContextualSearchContext*
37 ContextualSearchContext::FromJavaContextualSearchContext(
38 const base::android::JavaRef<jobject>& j_contextual_search_context) {
39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
40 if (j_contextual_search_context.is_null())
41 return NULL;
42
43 ContextualSearchContext* contextual_search_context =
44 reinterpret_cast<ContextualSearchContext*>(
45 Java_ContextualSearchContext_getNativePointer(
46 base::android::AttachCurrentThread(),
47 j_contextual_search_context));
48 return contextual_search_context;
49 }
50
51 void ContextualSearchContext::SetResolveProperties(
52 JNIEnv* env,
53 jobject obj,
54 const base::android::JavaParamRef<jstring>& j_selection,
55 const base::android::JavaParamRef<jstring>& j_home_country,
56 jboolean j_may_send_base_page_url) {
57 can_resolve = true;
58 selected_text = base::android::ConvertJavaStringToUTF8(env, j_selection);
59 home_country = base::android::ConvertJavaStringToUTF8(env, j_home_country);
60 can_send_base_page_url = j_may_send_base_page_url;
61 }
62
63 // Accessors
64
65 bool ContextualSearchContext::CanResolve() const {
66 return can_resolve;
67 }
68
69 bool ContextualSearchContext::CanSendBasePageUrl() const {
70 return can_send_base_page_url;
71 }
72
73 const GURL ContextualSearchContext::GetBasePageUrl() const {
74 return base_page_url;
75 }
76
77 void ContextualSearchContext::SetBasePageUrl(const GURL& base_page_url) {
78 this->base_page_url = base_page_url;
79 }
80
81 const std::string ContextualSearchContext::GetBasePageEncoding() const {
82 return base_page_encoding;
83 }
84
85 void ContextualSearchContext::SetBasePageEncoding(
86 const std::string& base_page_encoding) {
87 this->base_page_encoding = base_page_encoding;
88 }
89
90 const std::string ContextualSearchContext::GetHomeCountry() const {
91 return home_country;
92 }
93
94 void ContextualSearchContext::SetSelectionSurroundings(
95 int start_offset,
96 int end_offset,
97 const base::string16& surrounding_text) {
98 this->start_offset = start_offset;
99 this->end_offset = end_offset;
100 this->surrounding_text = surrounding_text;
101 }
102
103 const std::string ContextualSearchContext::GetOriginalSelectedText() const {
104 return selected_text;
105 }
106
107 const base::string16 ContextualSearchContext::GetSurroundingText() const {
108 return surrounding_text;
109 }
110
111 int ContextualSearchContext::GetStartOffset() const {
112 return start_offset;
113 }
114
115 int ContextualSearchContext::GetEndOffset() const {
116 return end_offset;
117 }
118
119 // Java wrapper boilerplate
120
121 void ContextualSearchContext::Destroy(
122 JNIEnv* env,
123 const base::android::JavaParamRef<jobject>& obj) {
124 delete this;
125 }
126
127 bool RegisterContextualSearchContext(JNIEnv* env) {
128 return RegisterNativesImpl(env);
129 }
130
131 jlong Init(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj) {
132 ContextualSearchContext* context = new ContextualSearchContext(env, obj);
133 return reinterpret_cast<intptr_t>(context);
134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698