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 #ifndef CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_CONTEXT_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_CONTEXT_H_ |
6 #define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_CONTEXT_H_ | 6 #define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_CONTEXT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/android/jni_android.h" | |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
12 | 13 |
13 // Encapsulates key parts of a Contextual Search Context, including surrounding | 14 // Encapsulates key parts of a Contextual Search Context, including surrounding |
14 // text. | 15 // text. |
15 struct ContextualSearchContext { | 16 struct ContextualSearchContext { |
16 public: | 17 public: |
18 ContextualSearchContext(JNIEnv* env, jobject obj); | |
19 // Constructor for tests. | |
17 ContextualSearchContext(const std::string& selected_text, | 20 ContextualSearchContext(const std::string& selected_text, |
18 const std::string& home_country, | 21 const std::string& home_country, |
19 const GURL& page_url, | 22 const GURL& page_url, |
20 const std::string& encoding); | 23 const std::string& encoding); |
21 ~ContextualSearchContext(); | 24 ~ContextualSearchContext(); |
22 | 25 |
23 const std::string selected_text; | 26 // Calls the destructor. Should be called when this native object is no |
24 const std::string home_country; | 27 // longer needed. |
25 const GURL page_url; | 28 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
26 const std::string encoding; | |
27 | 29 |
30 // Returns the native |ContextualSearchContext| given the java object. | |
Theresa
2017/03/09 22:46:37
nit: s/java/Java
Donn Denman
2017/03/10 01:29:43
Done.
| |
31 static ContextualSearchContext* FromJavaContextualSearchContext( | |
32 const base::android::JavaRef<jobject>& j_contextual_search_context); | |
33 | |
34 // Returns whether this context can be resolved. | |
35 // The context can be resolved only after calling SetResolveProperites. | |
36 bool CanResolve() const; | |
37 | |
38 // Returns whether the base page URL may be sent (according to the Java | |
39 // policy). | |
40 bool CanSendBasePageUrl() const; | |
41 | |
42 // Sets the properties needed to resolve a context. | |
43 void SetResolveProperties( | |
44 JNIEnv* env, | |
45 jobject obj, | |
46 const base::android::JavaParamRef<jstring>& j_selection, | |
47 const base::android::JavaParamRef<jstring>& j_home_country, | |
48 jboolean j_may_send_base_page_url); | |
49 | |
50 // Gets the URL of the base page. | |
51 const GURL GetBasePageUrl() const; | |
52 // Sets the URL of the base page. | |
53 void SetBasePageUrl(const GURL& base_page_url); | |
54 | |
55 // Gets the encoding of the base page. This is not very important, since | |
Theresa
2017/03/09 22:46:37
If it's not important, can we remove it?
Donn Denman
2017/03/10 01:29:43
Unfortunately no, not easily. We currently pass t
| |
56 // the surrounding text stored here in a base::string16 is implicitly encoded | |
57 // in UTF-16 (see http://www.chromium.org/developers/chromium-string-usage). | |
58 const std::string GetBasePageEncoding() const; | |
59 void SetBasePageEncoding(const std::string& base_page_encoding); | |
60 | |
61 // Gets the country code of the home country of the user, or an empty string. | |
62 const std::string GetHomeCountry() const; | |
63 | |
64 // Sets the selection and surroundings. | |
65 void SetSelectionSurroundings(int start_offset, | |
66 int end_offset, | |
67 const base::string16& surrounding_text); | |
68 | |
69 // Gets the original selection. | |
70 const std::string GetOriginalSelectedText() const; | |
71 | |
72 // Gets the text surrounding the selection (including the selection). | |
73 const base::string16 GetSurroundingText() const; | |
74 | |
75 // Gets the start offset of the selection within the surrounding text. | |
76 int GetStartOffset() const; | |
77 // Gets the end offset of the selection within the surrounding text. | |
Theresa
2017/03/09 22:46:37
Is this in characters or bytes?
Donn Denman
2017/03/10 01:29:43
Done.
| |
78 int GetEndOffset() const; | |
79 | |
80 private: | |
81 bool can_resolve; | |
82 bool can_send_base_page_url; | |
83 | |
84 std::string selected_text; | |
85 std::string home_country; | |
86 GURL base_page_url; | |
87 std::string base_page_encoding; | |
28 base::string16 surrounding_text; | 88 base::string16 surrounding_text; |
29 int start_offset; | 89 int start_offset; |
30 int end_offset; | 90 int end_offset; |
31 | 91 |
92 // The linked Java object. | |
93 base::android::ScopedJavaGlobalRef<jobject> java_object_; | |
94 | |
32 DISALLOW_COPY_AND_ASSIGN(ContextualSearchContext); | 95 DISALLOW_COPY_AND_ASSIGN(ContextualSearchContext); |
33 }; | 96 }; |
34 | 97 |
98 bool RegisterContextualSearchContext(JNIEnv* env); | |
99 | |
35 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_CONTEXT_H_ | 100 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_CONTEXT_H_ |
OLD | NEW |