| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/search_geolocation/search_geolocation_disclosur
e_infobar_delegate.h" | 5 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur
e_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "chrome/browser/android/android_theme_resources.h" | 9 #include "chrome/browser/android/android_theme_resources.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/android/infobars/search_geolocation_disclosure_infob
ar.h" | 12 #include "chrome/browser/ui/android/infobars/search_geolocation_disclosure_infob
ar.h" |
| 13 #include "chrome/common/chrome_features.h" | |
| 14 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 16 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
| 17 #include "components/variations/variations_associated_data.h" | |
| 18 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 20 | 18 |
| 21 namespace { | |
| 22 | |
| 23 const char kUseControlTextVariation[] = "UseControlText"; | |
| 24 | |
| 25 int ShouldUseControlText() { | |
| 26 std::string variation = variations::GetVariationParamValueByFeature( | |
| 27 features::kConsistentOmniboxGeolocation, kUseControlTextVariation); | |
| 28 return !variation.empty(); | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 // This enum is used in histograms, and is thus append only. Do not remove or | 19 // This enum is used in histograms, and is thus append only. Do not remove or |
| 34 // re-order items. | 20 // re-order items. |
| 35 enum class SearchGeolocationDisclosureInfoBarDelegate::DisclosureResult { | 21 enum class SearchGeolocationDisclosureInfoBarDelegate::DisclosureResult { |
| 36 IGNORED = 0, | 22 IGNORED = 0, |
| 37 SETTINGS_CLICKED, | 23 SETTINGS_CLICKED, |
| 38 DISMISSED, | 24 DISMISSED, |
| 39 COUNT, | 25 COUNT, |
| 40 }; | 26 }; |
| 41 | 27 |
| 42 SearchGeolocationDisclosureInfoBarDelegate:: | 28 SearchGeolocationDisclosureInfoBarDelegate:: |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 : infobars::InfoBarDelegate(), | 78 : infobars::InfoBarDelegate(), |
| 93 search_url_(search_url), | 79 search_url_(search_url), |
| 94 result_(DisclosureResult::IGNORED), | 80 result_(DisclosureResult::IGNORED), |
| 95 creation_time_(base::Time::Now()) { | 81 creation_time_(base::Time::Now()) { |
| 96 pref_service_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()) | 82 pref_service_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
| 97 ->GetPrefs(); | 83 ->GetPrefs(); |
| 98 base::string16 link = l10n_util::GetStringUTF16( | 84 base::string16 link = l10n_util::GetStringUTF16( |
| 99 IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_SETTINGS_LINK_TEXT); | 85 IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_SETTINGS_LINK_TEXT); |
| 100 size_t offset; | 86 size_t offset; |
| 101 message_text_ = l10n_util::GetStringFUTF16( | 87 message_text_ = l10n_util::GetStringFUTF16( |
| 102 ShouldUseControlText() | 88 IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_TEXT, link, &offset); |
| 103 ? IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_CONTROL_TEXT | |
| 104 : IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_TEXT, | |
| 105 link, &offset); | |
| 106 inline_link_range_ = gfx::Range(offset, offset + link.length()); | 89 inline_link_range_ = gfx::Range(offset, offset + link.length()); |
| 107 } | 90 } |
| 108 | 91 |
| 109 void SearchGeolocationDisclosureInfoBarDelegate::InfoBarDismissed() { | 92 void SearchGeolocationDisclosureInfoBarDelegate::InfoBarDismissed() { |
| 110 result_ = DisclosureResult::DISMISSED; | 93 result_ = DisclosureResult::DISMISSED; |
| 111 pref_service_->SetBoolean(prefs::kSearchGeolocationDisclosureDismissed, true); | 94 pref_service_->SetBoolean(prefs::kSearchGeolocationDisclosureDismissed, true); |
| 112 } | 95 } |
| 113 | 96 |
| 114 infobars::InfoBarDelegate::Type | 97 infobars::InfoBarDelegate::Type |
| 115 SearchGeolocationDisclosureInfoBarDelegate::GetInfoBarType() const { | 98 SearchGeolocationDisclosureInfoBarDelegate::GetInfoBarType() const { |
| 116 return PAGE_ACTION_TYPE; | 99 return PAGE_ACTION_TYPE; |
| 117 } | 100 } |
| 118 | 101 |
| 119 infobars::InfoBarDelegate::InfoBarIdentifier | 102 infobars::InfoBarDelegate::InfoBarIdentifier |
| 120 SearchGeolocationDisclosureInfoBarDelegate::GetIdentifier() const { | 103 SearchGeolocationDisclosureInfoBarDelegate::GetIdentifier() const { |
| 121 return SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE; | 104 return SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE; |
| 122 } | 105 } |
| 123 | 106 |
| 124 int SearchGeolocationDisclosureInfoBarDelegate::GetIconId() const { | 107 int SearchGeolocationDisclosureInfoBarDelegate::GetIconId() const { |
| 125 return IDR_ANDROID_INFOBAR_GEOLOCATION; | 108 return IDR_ANDROID_INFOBAR_GEOLOCATION; |
| 126 } | 109 } |
| OLD | NEW |