Chromium Code Reviews| 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: |
| 17 ContextualSearchContext(const std::string& selected_text, | 18 ContextualSearchContext(JNIEnv* env, jobject obj); |
| 18 const std::string& home_country, | 19 // Constructor for tests. |
| 19 const GURL& page_url, | 20 ContextualSearchContext(); |
| 20 const std::string& encoding); | |
| 21 ~ContextualSearchContext(); | 21 ~ContextualSearchContext(); |
| 22 | 22 |
| 23 const std::string selected_text; | 23 // Calls the destructor. Should be called when this native object is no |
| 24 const std::string home_country; | 24 // longer needed. |
| 25 const GURL page_url; | 25 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 26 const std::string encoding; | |
| 27 | 26 |
| 27 // Returns the native |ContextualSearchContext| given the java object. | |
| 28 static ContextualSearchContext* FromJavaContextualSearchContext( | |
| 29 const base::android::JavaRef<jobject>& j_contextual_search_context); | |
| 30 | |
| 31 // Returns whether the content associated with this context is brief. | |
| 32 // If not, then this context may be resolved, but not otherwise. | |
| 33 bool IsBrief(); | |
| 34 | |
| 35 // Returns whether the base page URL may be sent (according to the Java | |
| 36 // context). | |
| 37 bool MaySendBasePageUrl(); | |
| 38 | |
| 39 // Sets whether the content associated with this context is brief or not. | |
| 40 void SetUseBriefPageContent(JNIEnv* env, | |
|
Theresa
2017/03/08 01:54:38
Can this be combined with setProperties?
Donn Denman
2017/03/09 17:35:05
Done.
Changed the model from brief/normal context
| |
| 41 jobject obj, | |
| 42 jboolean j_use_brief_page_content); | |
| 43 | |
| 44 // Sets most of the properties on a context. | |
| 45 void SetProperties(JNIEnv* env, | |
| 46 jobject obj, | |
| 47 const base::android::JavaParamRef<jstring>& j_selection, | |
| 48 const base::android::JavaParamRef<jstring>& j_home_country, | |
| 49 jboolean j_may_send_base_page_url); | |
| 50 | |
| 51 // Sets most of the properties in a way that's convenient for tests. | |
| 52 void SetPropertiesInternal(std::string selection, | |
| 53 std::string home_country, | |
| 54 bool may_send_base_page_url); | |
| 55 | |
| 56 // Data. TODO(donnd): make private? | |
| 57 std::string selected_text; | |
| 58 std::string home_country; | |
| 59 GURL page_url; | |
| 60 std::string encoding; | |
| 28 base::string16 surrounding_text; | 61 base::string16 surrounding_text; |
| 29 int start_offset; | 62 int start_offset; |
| 30 int end_offset; | 63 int end_offset; |
| 31 | 64 |
| 65 private: | |
| 66 bool is_brief_surrounding_text; | |
| 67 bool may_send_base_page_url; | |
| 68 | |
| 69 // The linked Java object. | |
| 70 base::android::ScopedJavaGlobalRef<jobject> java_object_; | |
| 71 | |
| 32 DISALLOW_COPY_AND_ASSIGN(ContextualSearchContext); | 72 DISALLOW_COPY_AND_ASSIGN(ContextualSearchContext); |
| 33 }; | 73 }; |
| 34 | 74 |
| 75 bool RegisterContextualSearchContext(JNIEnv* env); | |
| 76 | |
| 35 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_CONTEXT_H_ | 77 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_CONTEXT_H_ |
| OLD | NEW |