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_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_MANAGER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_MANAGER_H_ | 6 #define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_MANAGER_H_ |
| 7 | 7 |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/task/cancelable_task_tracker.h" | 9 #include "base/task/cancelable_task_tracker.h" |
| 10 #include "chrome/browser/android/contextualsearch/contextual_search_context.h" | 10 #include "chrome/browser/android/contextualsearch/contextual_search_context.h" |
| 11 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h" | 11 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h" |
| 12 #include "components/contextual_search/browser/contextual_search_ui_handle.h" | |
| 12 | 13 |
| 13 // Manages the native extraction and request logic for Contextual Search, | 14 // Manages the native extraction and request logic for Contextual Search, |
| 14 // and interacts with the Java ContextualSearchManager for UX. | 15 // and interacts with the Java ContextualSearchManager for UX. |
| 15 // Most of the work is done by the associated ContextualSearchDelegate. | 16 // Most of the work is done by the associated ContextualSearchDelegate. |
| 16 class ContextualSearchManager { | 17 class ContextualSearchManager |
| 18 : public contextual_search::ContextualSearchUIHandle { | |
| 17 public: | 19 public: |
| 18 // Constructs a native manager associated with the Java manager. | 20 // Constructs a native manager associated with the Java manager. |
| 19 ContextualSearchManager(JNIEnv* env, jobject obj); | 21 ContextualSearchManager(JNIEnv* env, jobject obj); |
| 20 virtual ~ContextualSearchManager(); | 22 ~ContextualSearchManager() override; |
| 21 | 23 |
| 22 // Called by the Java ContextualSearchManager when it is being destroyed. | 24 // Called by the Java ContextualSearchManager when it is being destroyed. |
| 23 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 25 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 24 | 26 |
| 25 // Starts the request to get the search terms to use for the given selection, | 27 // Starts the request to get the search terms to use for the given selection, |
| 26 // by accessing our server with the content of the page (from the given | 28 // by accessing our server with the content of the page (from the given |
| 27 // content view core object). | 29 // content view core object). |
| 28 // Any outstanding server requests are canceled. | 30 // Any outstanding server requests are canceled. |
| 29 // When the server responds with the search term, the Java object is notified | 31 // When the server responds with the search term, the Java object is notified |
| 30 // by | 32 // by |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 50 // Gets the target language for translation purposes. | 52 // Gets the target language for translation purposes. |
| 51 base::android::ScopedJavaLocalRef<jstring> GetTargetLanguage( | 53 base::android::ScopedJavaLocalRef<jstring> GetTargetLanguage( |
| 52 JNIEnv* env, | 54 JNIEnv* env, |
| 53 const base::android::JavaParamRef<jobject>& obj); | 55 const base::android::JavaParamRef<jobject>& obj); |
| 54 | 56 |
| 55 // Gets the accept-languages preference string. | 57 // Gets the accept-languages preference string. |
| 56 base::android::ScopedJavaLocalRef<jstring> GetAcceptLanguages( | 58 base::android::ScopedJavaLocalRef<jstring> GetAcceptLanguages( |
| 57 JNIEnv* env, | 59 JNIEnv* env, |
| 58 const base::android::JavaParamRef<jobject>& obj); | 60 const base::android::JavaParamRef<jobject>& obj); |
| 59 | 61 |
| 62 // Enables the Contextual Search JS API for the given |ContentViewCore|. | |
| 63 void AddViewForContextualSearchApi(JNIEnv* env, | |
|
pedro (no code reviews)
2015/12/22 23:15:39
Nit: It would be nice being consistent with the te
Donn Denman
2016/01/08 18:59:09
Done.
| |
| 64 jobject obj, | |
| 65 jobject j_overlay_content_view_core); | |
| 66 | |
| 67 // ContextualSearchUIHandle overrides: | |
| 68 void SetCaption(std::string caption, bool does_answer) override; | |
| 69 | |
| 60 private: | 70 private: |
| 61 void OnSearchTermResolutionResponse( | 71 void OnSearchTermResolutionResponse( |
| 62 const ResolvedSearchTerm& resolved_search_term); | 72 const ResolvedSearchTerm& resolved_search_term); |
| 63 | 73 |
| 64 // Calls back to Java with the surrounding text to be displayed. | 74 // Calls back to Java with the surrounding text to be displayed. |
| 65 void OnSurroundingTextAvailable(const std::string& after_text); | 75 void OnSurroundingTextAvailable(const std::string& after_text); |
| 66 | 76 |
| 67 // Calls back to Java with notification for Icing selection. | 77 // Calls back to Java with notification for Icing selection. |
| 68 void OnIcingSelectionAvailable(const std::string& encoding, | 78 void OnIcingSelectionAvailable(const std::string& encoding, |
| 69 const base::string16& surrounding_text, | 79 const base::string16& surrounding_text, |
| 70 size_t start_offset, | 80 size_t start_offset, |
| 71 size_t end_offset); | 81 size_t end_offset); |
| 72 | 82 |
| 73 // Our global reference to the Java ContextualSearchManager. | 83 // Our global reference to the Java ContextualSearchManager. |
| 74 base::android::ScopedJavaGlobalRef<jobject> java_manager_; | 84 base::android::ScopedJavaGlobalRef<jobject> java_manager_; |
| 75 | 85 |
| 76 // The delegate we're using the do the real work. | 86 // The delegate we're using the do the real work. |
| 77 scoped_ptr<ContextualSearchDelegate> delegate_; | 87 scoped_ptr<ContextualSearchDelegate> delegate_; |
| 78 | 88 |
| 79 DISALLOW_COPY_AND_ASSIGN(ContextualSearchManager); | 89 DISALLOW_COPY_AND_ASSIGN(ContextualSearchManager); |
| 80 }; | 90 }; |
| 81 | 91 |
| 82 bool RegisterContextualSearchManager(JNIEnv* env); | 92 bool RegisterContextualSearchManager(JNIEnv* env); |
| 83 | 93 |
| 84 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_MANAGER_H_ | 94 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_MANAGER_H_ |
| OLD | NEW |