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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 quick_action_category)); | 243 quick_action_category)); |
244 } | 244 } |
245 | 245 |
246 std::string ContextualSearchDelegate::BuildRequestUrl( | 246 std::string ContextualSearchDelegate::BuildRequestUrl( |
247 std::string home_country) { | 247 std::string home_country) { |
248 if (!template_url_service_ || | 248 if (!template_url_service_ || |
249 !template_url_service_->GetDefaultSearchProvider()) { | 249 !template_url_service_->GetDefaultSearchProvider()) { |
250 return std::string(); | 250 return std::string(); |
251 } | 251 } |
252 | 252 |
253 TemplateURL* template_url = template_url_service_->GetDefaultSearchProvider(); | 253 const TemplateURL* template_url = |
| 254 template_url_service_->GetDefaultSearchProvider(); |
254 | 255 |
255 TemplateURLRef::SearchTermsArgs search_terms_args = | 256 TemplateURLRef::SearchTermsArgs search_terms_args = |
256 TemplateURLRef::SearchTermsArgs(base::string16()); | 257 TemplateURLRef::SearchTermsArgs(base::string16()); |
257 | 258 |
258 int contextual_cards_version = kContextualCardsBarIntegration; | 259 int contextual_cards_version = kContextualCardsBarIntegration; |
259 if (base::FeatureList::IsEnabled( | 260 if (base::FeatureList::IsEnabled( |
260 chrome::android::kContextualSearchSingleActions)) { | 261 chrome::android::kContextualSearchSingleActions)) { |
261 contextual_cards_version = kContextualCardsSingleAction; | 262 contextual_cards_version = kContextualCardsSingleAction; |
262 } | 263 } |
263 if (base::FeatureList::IsEnabled( | 264 if (base::FeatureList::IsEnabled( |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 bool ContextualSearchDelegate::CanSendPageURL( | 396 bool ContextualSearchDelegate::CanSendPageURL( |
396 const GURL& current_page_url, | 397 const GURL& current_page_url, |
397 Profile* profile, | 398 Profile* profile, |
398 TemplateURLService* template_url_service) { | 399 TemplateURLService* template_url_service) { |
399 // Check whether there is a Finch parameter preventing us from sending the | 400 // Check whether there is a Finch parameter preventing us from sending the |
400 // page URL. | 401 // page URL. |
401 if (field_trial_->IsSendBasePageURLDisabled()) | 402 if (field_trial_->IsSendBasePageURLDisabled()) |
402 return false; | 403 return false; |
403 | 404 |
404 // Ensure that the default search provider is Google. | 405 // Ensure that the default search provider is Google. |
405 TemplateURL* default_search_provider = | 406 const TemplateURL* default_search_provider = |
406 template_url_service->GetDefaultSearchProvider(); | 407 template_url_service->GetDefaultSearchProvider(); |
407 bool is_default_search_provider_google = | 408 bool is_default_search_provider_google = |
408 default_search_provider && | 409 default_search_provider && |
409 default_search_provider->url_ref().HasGoogleBaseURLs( | 410 default_search_provider->url_ref().HasGoogleBaseURLs( |
410 template_url_service->search_terms_data()); | 411 template_url_service->search_terms_data()); |
411 if (!is_default_search_provider_google) | 412 if (!is_default_search_provider_google) |
412 return false; | 413 return false; |
413 | 414 |
414 // Only allow HTTP URLs or HTTPS URLs. | 415 // Only allow HTTP URLs or HTTPS URLs. |
415 if (current_page_url.scheme() != url::kHttpScheme && | 416 if (current_page_url.scheme() != url::kHttpScheme && |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 end_offset -= trim; | 585 end_offset -= trim; |
585 } | 586 } |
586 if (result_text.length() > end_offset + padding_each_side_pinned) { | 587 if (result_text.length() > end_offset + padding_each_side_pinned) { |
587 // Trim the end. | 588 // Trim the end. |
588 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); | 589 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); |
589 } | 590 } |
590 *start = start_offset; | 591 *start = start_offset; |
591 *end = end_offset; | 592 *end = end_offset; |
592 return result_text; | 593 return result_text; |
593 } | 594 } |
OLD | NEW |