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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 quick_action_category)); | 238 quick_action_category)); |
239 } | 239 } |
240 | 240 |
241 std::string ContextualSearchDelegate::BuildRequestUrl( | 241 std::string ContextualSearchDelegate::BuildRequestUrl( |
242 std::string home_country) { | 242 std::string home_country) { |
243 if (!template_url_service_ || | 243 if (!template_url_service_ || |
244 !template_url_service_->GetDefaultSearchProvider()) { | 244 !template_url_service_->GetDefaultSearchProvider()) { |
245 return std::string(); | 245 return std::string(); |
246 } | 246 } |
247 | 247 |
248 TemplateURL* template_url = template_url_service_->GetDefaultSearchProvider(); | 248 const TemplateURL* template_url = |
| 249 template_url_service_->GetDefaultSearchProvider(); |
249 | 250 |
250 TemplateURLRef::SearchTermsArgs search_terms_args = | 251 TemplateURLRef::SearchTermsArgs search_terms_args = |
251 TemplateURLRef::SearchTermsArgs(base::string16()); | 252 TemplateURLRef::SearchTermsArgs(base::string16()); |
252 | 253 |
253 int contextual_cards_version = kContextualCardsBarIntegration; | 254 int contextual_cards_version = kContextualCardsBarIntegration; |
254 if (base::FeatureList::IsEnabled( | 255 if (base::FeatureList::IsEnabled( |
255 chrome::android::kContextualSearchSingleActions)) { | 256 chrome::android::kContextualSearchSingleActions)) { |
256 contextual_cards_version = kContextualCardsSingleAction; | 257 contextual_cards_version = kContextualCardsSingleAction; |
257 } | 258 } |
258 if (base::FeatureList::IsEnabled( | 259 if (base::FeatureList::IsEnabled( |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 bool ContextualSearchDelegate::CanSendPageURL( | 367 bool ContextualSearchDelegate::CanSendPageURL( |
367 const GURL& current_page_url, | 368 const GURL& current_page_url, |
368 Profile* profile, | 369 Profile* profile, |
369 TemplateURLService* template_url_service) { | 370 TemplateURLService* template_url_service) { |
370 // Check whether there is a Finch parameter preventing us from sending the | 371 // Check whether there is a Finch parameter preventing us from sending the |
371 // page URL. | 372 // page URL. |
372 if (field_trial_->IsSendBasePageURLDisabled()) | 373 if (field_trial_->IsSendBasePageURLDisabled()) |
373 return false; | 374 return false; |
374 | 375 |
375 // Ensure that the default search provider is Google. | 376 // Ensure that the default search provider is Google. |
376 TemplateURL* default_search_provider = | 377 const TemplateURL* default_search_provider = |
377 template_url_service->GetDefaultSearchProvider(); | 378 template_url_service->GetDefaultSearchProvider(); |
378 bool is_default_search_provider_google = | 379 bool is_default_search_provider_google = |
379 default_search_provider && | 380 default_search_provider && |
380 default_search_provider->url_ref().HasGoogleBaseURLs( | 381 default_search_provider->url_ref().HasGoogleBaseURLs( |
381 template_url_service->search_terms_data()); | 382 template_url_service->search_terms_data()); |
382 if (!is_default_search_provider_google) | 383 if (!is_default_search_provider_google) |
383 return false; | 384 return false; |
384 | 385 |
385 // Only allow HTTP URLs or HTTPS URLs. | 386 // Only allow HTTP URLs or HTTPS URLs. |
386 if (current_page_url.scheme() != url::kHttpScheme && | 387 if (current_page_url.scheme() != url::kHttpScheme && |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 end_offset -= trim; | 556 end_offset -= trim; |
556 } | 557 } |
557 if (result_text.length() > end_offset + padding_each_side_pinned) { | 558 if (result_text.length() > end_offset + padding_each_side_pinned) { |
558 // Trim the end. | 559 // Trim the end. |
559 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); | 560 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); |
560 } | 561 } |
561 *start = start_offset; | 562 *start = start_offset; |
562 *end = end_offset; | 563 *end = end_offset; |
563 return result_text; | 564 return result_text; |
564 } | 565 } |
OLD | NEW |