| 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_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_ | 6 #define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/android/contextualsearch/contextual_search_context.h" | 17 #include "chrome/browser/android/contextualsearch/contextual_search_context.h" |
| 18 #include "chrome/browser/android/contextualsearch/resolved_search_term.h" | 18 #include "chrome/browser/android/contextualsearch/resolved_search_term.h" |
| 19 #include "content/public/browser/android/content_view_core.h" | 19 #include "content/public/browser/android/content_view_core.h" |
| 20 #include "net/url_request/url_fetcher_delegate.h" | 20 #include "net/url_request/url_fetcher_delegate.h" |
| 21 | 21 |
| 22 namespace content { |
| 23 class WebContents; |
| 24 } |
| 25 |
| 22 namespace net { | 26 namespace net { |
| 23 class URLRequestContextGetter; | 27 class URLRequestContextGetter; |
| 24 } // namespace net | 28 } // namespace net |
| 25 | 29 |
| 26 class Profile; | 30 class Profile; |
| 27 class TemplateURLService; | 31 class TemplateURLService; |
| 28 class ContextualSearchFieldTrial; | 32 class ContextualSearchFieldTrial; |
| 29 | 33 |
| 30 // Handles tasks for the ContextualSearchManager in a separable and testable | 34 // Handles tasks for the ContextualSearchManager in a separable and testable |
| 31 // way, without the complication of being connected to a Java object. | 35 // way, without the complication of being connected to a Java object. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 61 const IcingCallback& icing_callback); | 65 const IcingCallback& icing_callback); |
| 62 ~ContextualSearchDelegate() override; | 66 ~ContextualSearchDelegate() override; |
| 63 | 67 |
| 64 // Gathers surrounding text and starts an asynchronous search term resolution | 68 // Gathers surrounding text and starts an asynchronous search term resolution |
| 65 // request. The "search term" is the best query to issue for a section of text | 69 // request. The "search term" is the best query to issue for a section of text |
| 66 // in the context of a web page. When the response is available the callback | 70 // in the context of a web page. When the response is available the callback |
| 67 // specified in the constructor is run. | 71 // specified in the constructor is run. |
| 68 void StartSearchTermResolutionRequest( | 72 void StartSearchTermResolutionRequest( |
| 69 const std::string& selection, | 73 const std::string& selection, |
| 70 bool use_resolved_search_term, | 74 bool use_resolved_search_term, |
| 71 content::ContentViewCore* content_view_core, | 75 content::WebContents* web_contents, |
| 72 bool may_send_base_page_url); | 76 bool may_send_base_page_url); |
| 73 | 77 |
| 74 // Gathers surrounding text and saves it locally for a future query. | 78 // Gathers surrounding text and saves it locally for a future query. |
| 75 void GatherAndSaveSurroundingText(const std::string& selection, | 79 void GatherAndSaveSurroundingText(const std::string& selection, |
| 76 bool use_resolved_search_term, | 80 bool use_resolved_search_term, |
| 77 content::ContentViewCore* content_view_core, | 81 content::WebContents* web_contents, |
| 78 bool may_send_base_page_url); | 82 bool may_send_base_page_url); |
| 79 | 83 |
| 80 // Continues making a Search Term Resolution request, once the surrounding | 84 // Continues making a Search Term Resolution request, once the surrounding |
| 81 // text has been gathered. | 85 // text has been gathered. |
| 82 void ContinueSearchTermResolutionRequest(); | 86 void ContinueSearchTermResolutionRequest(); |
| 83 | 87 |
| 84 // Gets the target language for translation purposes for this user. | 88 // Gets the target language for translation purposes for this user. |
| 85 std::string GetTargetLanguage(); | 89 std::string GetTargetLanguage(); |
| 86 | 90 |
| 87 // Returns the accept languages preference string. | 91 // Returns the accept languages preference string. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 111 DecodeSearchTermFromJsonResponse); | 115 DecodeSearchTermFromJsonResponse); |
| 112 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, DecodeStringMentions); | 116 FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest, DecodeStringMentions); |
| 113 | 117 |
| 114 // net::URLFetcherDelegate: | 118 // net::URLFetcherDelegate: |
| 115 void OnURLFetchComplete(const net::URLFetcher* source) override; | 119 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 116 | 120 |
| 117 // Builds the ContextualSearchContext in the current context from | 121 // Builds the ContextualSearchContext in the current context from |
| 118 // the given parameters. | 122 // the given parameters. |
| 119 void BuildContext(const std::string& selection, | 123 void BuildContext(const std::string& selection, |
| 120 bool use_resolved_search_term, | 124 bool use_resolved_search_term, |
| 121 content::ContentViewCore* content_view_core, | 125 content::WebContents* web_contents, |
| 122 bool may_send_base_page_url); | 126 bool may_send_base_page_url); |
| 123 | 127 |
| 124 // Builds and returns the search term resolution request URL. | 128 // Builds and returns the search term resolution request URL. |
| 125 // |selection| is used as the default query. | 129 // |selection| is used as the default query. |
| 126 std::string BuildRequestUrl(std::string selection); | 130 std::string BuildRequestUrl(std::string selection); |
| 127 | 131 |
| 128 // Uses the TemplateURL service to construct a search term resolution URL from | 132 // Uses the TemplateURL service to construct a search term resolution URL from |
| 129 // the given parameters. | 133 // the given parameters. |
| 130 std::string GetSearchTermResolutionUrlString( | 134 std::string GetSearchTermResolutionUrlString( |
| 131 const std::string& selected_text, | 135 const std::string& selected_text, |
| 132 const std::string& base_page_url, | 136 const std::string& base_page_url, |
| 133 const bool may_send_base_page_url); | 137 const bool may_send_base_page_url); |
| 134 | 138 |
| 135 // Will gather the surrounding text from the |content_view_core| and call the | 139 // Will gather the surrounding text from the |content_view_core| and call the |
| 136 // |callback|. | 140 // |callback|. |
| 137 void GatherSurroundingTextWithCallback( | 141 void GatherSurroundingTextWithCallback( |
| 138 const std::string& selection, | 142 const std::string& selection, |
| 139 bool use_resolved_search_term, | 143 bool use_resolved_search_term, |
| 140 content::ContentViewCore* content_view_core, | 144 content::WebContents* web_contents, |
| 141 bool may_send_base_page_url, | 145 bool may_send_base_page_url, |
| 142 HandleSurroundingsCallback callback); | 146 HandleSurroundingsCallback callback); |
| 143 | 147 |
| 144 // Callback for GatherSurroundingTextWithCallback(). Will start the search | 148 // Callback for GatherSurroundingTextWithCallback(). Will start the search |
| 145 // term resolution request. | 149 // term resolution request. |
| 146 void StartSearchTermRequestFromSelection( | 150 void StartSearchTermRequestFromSelection( |
| 147 const base::string16& surrounding_text, | 151 const base::string16& surrounding_text, |
| 148 int start_offset, | 152 int start_offset, |
| 149 int end_offset); | 153 int end_offset); |
| 150 | 154 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // The callback for notifications of Icing selection being available. | 237 // The callback for notifications of Icing selection being available. |
| 234 IcingCallback icing_callback_; | 238 IcingCallback icing_callback_; |
| 235 | 239 |
| 236 // Used to hold the context until an upcoming search term request is started. | 240 // Used to hold the context until an upcoming search term request is started. |
| 237 std::unique_ptr<ContextualSearchContext> context_; | 241 std::unique_ptr<ContextualSearchContext> context_; |
| 238 | 242 |
| 239 DISALLOW_COPY_AND_ASSIGN(ContextualSearchDelegate); | 243 DISALLOW_COPY_AND_ASSIGN(ContextualSearchDelegate); |
| 240 }; | 244 }; |
| 241 | 245 |
| 242 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_ | 246 #endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_DELEGATE_H_ |
| OLD | NEW |