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 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h" | 5 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 const char kContextualSearchServerEndpoint[] = "_/contextualsearch?"; | 48 const char kContextualSearchServerEndpoint[] = "_/contextualsearch?"; |
| 49 const int kContextualSearchRequestVersion = 2; | 49 const int kContextualSearchRequestVersion = 2; |
| 50 const int kContextualSearchMaxSelection = 100; | 50 const int kContextualSearchMaxSelection = 100; |
| 51 const char kXssiEscape[] = ")]}'\n"; | 51 const char kXssiEscape[] = ")]}'\n"; |
| 52 const char kDiscourseContextHeaderPrefix[] = "X-Additional-Discourse-Context: "; | 52 const char kDiscourseContextHeaderPrefix[] = "X-Additional-Discourse-Context: "; |
| 53 const char kDoPreventPreloadValue[] = "1"; | 53 const char kDoPreventPreloadValue[] = "1"; |
| 54 | 54 |
| 55 // The number of characters that should be shown after the selected expression. | 55 // The number of characters that should be shown after the selected expression. |
| 56 const int kSurroundingSizeForUI = 60; | 56 const int kSurroundingSizeForUI = 60; |
| 57 | 57 |
| 58 // The version of the Now on Tap API that we want to invoke; | |
|
Theresa
2016/09/15 05:03:32
nit: replace the semi-colon with a period
Donn Denman
2016/09/15 21:59:59
Done.
| |
| 59 const int kNowOnTapVersion = 1; | |
| 60 | |
| 58 } // namespace | 61 } // namespace |
| 59 | 62 |
| 60 // URLFetcher ID, only used for tests: we only have one kind of fetcher. | 63 // URLFetcher ID, only used for tests: we only have one kind of fetcher. |
| 61 const int ContextualSearchDelegate::kContextualSearchURLFetcherID = 1; | 64 const int ContextualSearchDelegate::kContextualSearchURLFetcherID = 1; |
| 62 | 65 |
| 63 // Handles tasks for the ContextualSearchManager in a separable, testable way. | 66 // Handles tasks for the ContextualSearchManager in a separable, testable way. |
| 64 ContextualSearchDelegate::ContextualSearchDelegate( | 67 ContextualSearchDelegate::ContextualSearchDelegate( |
| 65 net::URLRequestContextGetter* url_request_context, | 68 net::URLRequestContextGetter* url_request_context, |
| 66 TemplateURLService* template_url_service, | 69 TemplateURLService* template_url_service, |
| 67 const ContextualSearchDelegate::SearchTermResolutionCallback& | 70 const ContextualSearchDelegate::SearchTermResolutionCallback& |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 !template_url_service_->GetDefaultSearchProvider()) { | 203 !template_url_service_->GetDefaultSearchProvider()) { |
| 201 return std::string(); | 204 return std::string(); |
| 202 } | 205 } |
| 203 | 206 |
| 204 std::string selected_text(net::EscapeQueryParamValue(selection, true)); | 207 std::string selected_text(net::EscapeQueryParamValue(selection, true)); |
| 205 TemplateURL* template_url = template_url_service_->GetDefaultSearchProvider(); | 208 TemplateURL* template_url = template_url_service_->GetDefaultSearchProvider(); |
| 206 | 209 |
| 207 TemplateURLRef::SearchTermsArgs search_terms_args = | 210 TemplateURLRef::SearchTermsArgs search_terms_args = |
| 208 TemplateURLRef::SearchTermsArgs(base::string16()); | 211 TemplateURLRef::SearchTermsArgs(base::string16()); |
| 209 | 212 |
| 213 int now_on_tap_version = | |
| 214 field_trial_->IsNowOnTapBarIntegrationEnabled() ? kNowOnTapVersion : 0; | |
| 215 | |
| 210 TemplateURLRef::SearchTermsArgs::ContextualSearchParams params( | 216 TemplateURLRef::SearchTermsArgs::ContextualSearchParams params( |
| 211 kContextualSearchRequestVersion, selected_text, "", true); | 217 kContextualSearchRequestVersion, selected_text, "", now_on_tap_version); |
| 212 | 218 |
| 213 search_terms_args.contextual_search_params = params; | 219 search_terms_args.contextual_search_params = params; |
| 214 | 220 |
| 215 std::string request( | 221 std::string request( |
| 216 template_url->contextual_search_url_ref().ReplaceSearchTerms( | 222 template_url->contextual_search_url_ref().ReplaceSearchTerms( |
| 217 search_terms_args, | 223 search_terms_args, |
| 218 template_url_service_->search_terms_data(), | 224 template_url_service_->search_terms_data(), |
| 219 NULL)); | 225 NULL)); |
| 220 | 226 |
| 221 // The switch/param should be the URL up to and including the endpoint. | 227 // The switch/param should be the URL up to and including the endpoint. |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 end_offset -= trim; | 532 end_offset -= trim; |
| 527 } | 533 } |
| 528 if (result_text.length() > end_offset + padding_each_side_pinned) { | 534 if (result_text.length() > end_offset + padding_each_side_pinned) { |
| 529 // Trim the end. | 535 // Trim the end. |
| 530 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); | 536 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); |
| 531 } | 537 } |
| 532 *start = start_offset; | 538 *start = start_offset; |
| 533 *end = end_offset; | 539 *end = end_offset; |
| 534 return result_text; | 540 return result_text; |
| 535 } | 541 } |
| OLD | NEW |