OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_MANAGER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_MANAGER_H_ |
| 7 |
| 8 #include "base/android/jni_android.h" |
| 9 #include "base/task/cancelable_task_tracker.h" |
| 10 #include "chrome/browser/android/contextualsearch/contextual_search_context.h" |
| 11 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h" |
| 12 |
| 13 namespace content { |
| 14 class WebContents; |
| 15 } // namespace content |
| 16 |
| 17 namespace web_contents_delegate_android { |
| 18 class WebContentsDelegateAndroid; |
| 19 } // namespace web_contents_delegate_android |
| 20 |
| 21 // Manages the native extraction and request logic for Contextual Search, |
| 22 // and interacts with the Java ContextualSearchManager for UX. |
| 23 // Most of the work is done by the associated ContextualSearchDelegate. |
| 24 class ContextualSearchManager { |
| 25 public: |
| 26 // Constructs a native manager associated with the Java manager. |
| 27 ContextualSearchManager(JNIEnv* env, jobject obj); |
| 28 virtual ~ContextualSearchManager(); |
| 29 |
| 30 // Called by the Java ContextualSearchManager when it is being destroyed. |
| 31 void Destroy(JNIEnv* env, jobject obj); |
| 32 |
| 33 // Starts the request to get the search terms to use for the given selection, |
| 34 // by accessing our server with the content of the page (from the given |
| 35 // content view core object). |
| 36 // Any outstanding server requests are canceled. |
| 37 // When the server responds with the search term, the Java object is notified |
| 38 // by |
| 39 // calling OnSearchTermResolutionResponse(). |
| 40 void StartSearchTermResolutionRequest(JNIEnv* env, |
| 41 jobject obj, |
| 42 jstring j_selection, |
| 43 jboolean j_use_resolved_search_term, |
| 44 jobject j_base_content_view_core); |
| 45 |
| 46 // Gathers the surrounding text around the selection and saves it locally. |
| 47 // Does not send a search term resolution request to the server. |
| 48 void GatherSurroundingText(JNIEnv* env, |
| 49 jobject obj, |
| 50 jstring j_selection, |
| 51 jboolean j_use_resolved_search_term, |
| 52 jobject j_base_content_view_core); |
| 53 |
| 54 // Continues making a Search Term Resolution request based on the context |
| 55 // set up through calling |GatherSurroundingText|. |
| 56 // When the server responds with the search term, the Java object is notified |
| 57 // by calling OnSearchTermResolutionResponse(). |
| 58 void ContinueSearchTermResolutionRequest(JNIEnv* env, jobject obj); |
| 59 |
| 60 // Removes a search URL from history. |search_start_time_ms| represents the |
| 61 // time at which |search_url| was committed. |
| 62 void RemoveLastSearchVisit(JNIEnv* env, |
| 63 jobject obj, |
| 64 jstring search_url, |
| 65 jlong search_start_time_ms); |
| 66 |
| 67 // Takes ownership of the WebContents associated with the given |
| 68 // |ContentViewCore| which holds the Contextual Search Results. |
| 69 void SetWebContents(JNIEnv* env, jobject obj, jobject jcontent_view_core, |
| 70 jobject jweb_contents_delegate); |
| 71 |
| 72 // Destroys the WebContents. |
| 73 void DestroyWebContents(JNIEnv* env, jobject jobj); |
| 74 |
| 75 // Release ownership of WebContents. |
| 76 void ReleaseWebContents(JNIEnv* env, jobject jobj); |
| 77 |
| 78 // Destroys the WebContents of a ContentViewCore. |
| 79 void DestroyWebContentsFromContentViewCore(JNIEnv* env, |
| 80 jobject jobj, |
| 81 jobject jcontent_view_core); |
| 82 |
| 83 // Whether the Promo Header should be hidden based on a Finch param. |
| 84 bool ShouldHidePromoHeader(JNIEnv* env, jobject jobj); |
| 85 |
| 86 // Sets the delegate used to convert navigations to intents. |
| 87 void SetInterceptNavigationDelegate(JNIEnv* env, |
| 88 jobject obj, |
| 89 jobject delegate, |
| 90 jobject jweb_contents); |
| 91 |
| 92 private: |
| 93 // TODO(donnd): encapsulate these response parameters? |
| 94 void OnSearchTermResolutionResponse(bool is_invalid, |
| 95 int response_code, |
| 96 const std::string& search_term, |
| 97 const std::string& display_text, |
| 98 const std::string& alternate_term, |
| 99 bool prevent_preload); |
| 100 |
| 101 // Calls back to Java with the surrounding text to be displayed. |
| 102 void OnSurroundingTextAvailable(const std::string& before_text, |
| 103 const std::string& after_text); |
| 104 |
| 105 // Calls back to Java with notification for Icing selection. |
| 106 void OnIcingSelectionAvailable(const std::string& encoding, |
| 107 const base::string16& surrounding_text, |
| 108 size_t start_offset, |
| 109 size_t end_offset); |
| 110 |
| 111 // Our global reference to the Java ContextualSearchManager. |
| 112 base::android::ScopedJavaGlobalRef<jobject> java_manager_; |
| 113 |
| 114 // The delegate we're using the do the real work. |
| 115 scoped_ptr<ContextualSearchDelegate> delegate_; |
| 116 |
| 117 // Used if we need to clear history. |
| 118 base::CancelableTaskTracker history_task_tracker_; |
| 119 |
| 120 // The WebContents that holds the Contextual Search Results. |
| 121 scoped_ptr<content::WebContents> web_contents_; |
| 122 scoped_ptr<web_contents_delegate_android::WebContentsDelegateAndroid> |
| 123 web_contents_delegate_; |
| 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(ContextualSearchManager); |
| 126 }; |
| 127 |
| 128 bool RegisterContextualSearchManager(JNIEnv* env); |
| 129 |
| 130 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_MANAGER_H_ |
OLD | NEW |