Chromium Code Reviews| Index: chrome/browser/android/contextualsearch/contextual_search_context.h |
| diff --git a/chrome/browser/android/contextualsearch/contextual_search_context.h b/chrome/browser/android/contextualsearch/contextual_search_context.h |
| index 436a114e3344f9972bbeee6584ea0898284f7fc9..f0fcf16e787cd6e6b3ee1b2d7b9c4f8b171edacd 100644 |
| --- a/chrome/browser/android/contextualsearch/contextual_search_context.h |
| +++ b/chrome/browser/android/contextualsearch/contextual_search_context.h |
| @@ -7,6 +7,7 @@ |
| #include <string> |
| +#include "base/android/jni_android.h" |
| #include "base/macros.h" |
| #include "url/gurl.h" |
| @@ -14,22 +15,86 @@ |
| // text. |
| struct ContextualSearchContext { |
| public: |
| + ContextualSearchContext(JNIEnv* env, jobject obj); |
| + // Constructor for tests. |
| ContextualSearchContext(const std::string& selected_text, |
| const std::string& home_country, |
| const GURL& page_url, |
| const std::string& encoding); |
| ~ContextualSearchContext(); |
| - const std::string selected_text; |
| - const std::string home_country; |
| - const GURL page_url; |
| - const std::string encoding; |
| + // Calls the destructor. Should be called when this native object is no |
| + // longer needed. |
| + void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| + // 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.
|
| + static ContextualSearchContext* FromJavaContextualSearchContext( |
| + const base::android::JavaRef<jobject>& j_contextual_search_context); |
| + |
| + // Returns whether this context can be resolved. |
| + // The context can be resolved only after calling SetResolveProperites. |
| + bool CanResolve() const; |
| + |
| + // Returns whether the base page URL may be sent (according to the Java |
| + // policy). |
| + bool CanSendBasePageUrl() const; |
| + |
| + // Sets the properties needed to resolve a context. |
| + void SetResolveProperties( |
| + JNIEnv* env, |
| + jobject obj, |
| + const base::android::JavaParamRef<jstring>& j_selection, |
| + const base::android::JavaParamRef<jstring>& j_home_country, |
| + jboolean j_may_send_base_page_url); |
| + |
| + // Gets the URL of the base page. |
| + const GURL GetBasePageUrl() const; |
| + // Sets the URL of the base page. |
| + void SetBasePageUrl(const GURL& base_page_url); |
| + |
| + // 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
|
| + // the surrounding text stored here in a base::string16 is implicitly encoded |
| + // in UTF-16 (see http://www.chromium.org/developers/chromium-string-usage). |
| + const std::string GetBasePageEncoding() const; |
| + void SetBasePageEncoding(const std::string& base_page_encoding); |
| + |
| + // Gets the country code of the home country of the user, or an empty string. |
| + const std::string GetHomeCountry() const; |
| + |
| + // Sets the selection and surroundings. |
| + void SetSelectionSurroundings(int start_offset, |
| + int end_offset, |
| + const base::string16& surrounding_text); |
| + |
| + // Gets the original selection. |
| + const std::string GetOriginalSelectedText() const; |
| + |
| + // Gets the text surrounding the selection (including the selection). |
| + const base::string16 GetSurroundingText() const; |
| + |
| + // Gets the start offset of the selection within the surrounding text. |
| + int GetStartOffset() const; |
| + // 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.
|
| + int GetEndOffset() const; |
| + |
| + private: |
| + bool can_resolve; |
| + bool can_send_base_page_url; |
| + |
| + std::string selected_text; |
| + std::string home_country; |
| + GURL base_page_url; |
| + std::string base_page_encoding; |
| base::string16 surrounding_text; |
| int start_offset; |
| int end_offset; |
| + // The linked Java object. |
| + base::android::ScopedJavaGlobalRef<jobject> java_object_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ContextualSearchContext); |
| }; |
| +bool RegisterContextualSearchContext(JNIEnv* env); |
| + |
| #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_CONTEXT_H_ |