| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/search_geolocation_disclosure_infobar_delegate.
h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "base/metrics/histogram_macros.h" | |
| 9 #include "chrome/browser/android/android_theme_resources.h" | |
| 10 #include "chrome/browser/infobars/infobar_service.h" | |
| 11 #include "chrome/browser/profiles/profile.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" | |
| 15 #include "chrome/grit/generated_resources.h" | |
| 16 #include "components/prefs/pref_service.h" | |
| 17 #include "components/variations/variations_associated_data.h" | |
| 18 #include "content/public/browser/web_contents.h" | |
| 19 #include "ui/base/l10n/l10n_util.h" | |
| 20 | |
| 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 | |
| 34 // re-order items. | |
| 35 enum class SearchGeolocationDisclosureInfoBarDelegate::DisclosureResult { | |
| 36 IGNORED = 0, | |
| 37 SETTINGS_CLICKED, | |
| 38 DISMISSED, | |
| 39 COUNT, | |
| 40 }; | |
| 41 | |
| 42 SearchGeolocationDisclosureInfoBarDelegate:: | |
| 43 ~SearchGeolocationDisclosureInfoBarDelegate() { | |
| 44 UMA_HISTOGRAM_ENUMERATION( | |
| 45 "GeolocationDisclosure.DisclosureResult", | |
| 46 static_cast<base::HistogramBase::Sample>(result_), | |
| 47 static_cast<base::HistogramBase::Sample>(DisclosureResult::COUNT)); | |
| 48 UMA_HISTOGRAM_MEDIUM_TIMES("GeolocationDisclosure.InfoBarVisibleTime", | |
| 49 base::Time::Now() - creation_time_); | |
| 50 } | |
| 51 | |
| 52 // static | |
| 53 void SearchGeolocationDisclosureInfoBarDelegate::Create( | |
| 54 content::WebContents* web_contents, | |
| 55 const GURL& search_url) { | |
| 56 InfoBarService* infobar_service = | |
| 57 InfoBarService::FromWebContents(web_contents); | |
| 58 // Add the new delegate. | |
| 59 infobar_service->AddInfoBar( | |
| 60 base::MakeUnique<SearchGeolocationDisclosureInfoBar>( | |
| 61 base::WrapUnique(new SearchGeolocationDisclosureInfoBarDelegate( | |
| 62 web_contents, search_url)))); | |
| 63 } | |
| 64 | |
| 65 // static | |
| 66 bool SearchGeolocationDisclosureInfoBarDelegate:: | |
| 67 IsSearchGeolocationDisclosureOpen(content::WebContents* web_contents) { | |
| 68 InfoBarService* infobar_service = | |
| 69 InfoBarService::FromWebContents(web_contents); | |
| 70 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | |
| 71 infobars::InfoBar* existing_infobar = infobar_service->infobar_at(i); | |
| 72 if (existing_infobar->delegate()->GetIdentifier() == | |
| 73 infobars::InfoBarDelegate:: | |
| 74 SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE) { | |
| 75 return true; | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 return false; | |
| 80 } | |
| 81 | |
| 82 void SearchGeolocationDisclosureInfoBarDelegate::RecordSettingsClicked() { | |
| 83 result_ = DisclosureResult::SETTINGS_CLICKED; | |
| 84 // This counts as a dismissed so the dialog isn't shown again. | |
| 85 pref_service_->SetBoolean(prefs::kSearchGeolocationDisclosureDismissed, true); | |
| 86 } | |
| 87 | |
| 88 SearchGeolocationDisclosureInfoBarDelegate:: | |
| 89 SearchGeolocationDisclosureInfoBarDelegate( | |
| 90 content::WebContents* web_contents, | |
| 91 const GURL& search_url) | |
| 92 : infobars::InfoBarDelegate(), | |
| 93 search_url_(search_url), | |
| 94 result_(DisclosureResult::IGNORED), | |
| 95 creation_time_(base::Time::Now()) { | |
| 96 pref_service_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()) | |
| 97 ->GetPrefs(); | |
| 98 base::string16 link = l10n_util::GetStringUTF16( | |
| 99 IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_SETTINGS_LINK_TEXT); | |
| 100 size_t offset; | |
| 101 message_text_ = l10n_util::GetStringFUTF16( | |
| 102 ShouldUseControlText() | |
| 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()); | |
| 107 } | |
| 108 | |
| 109 void SearchGeolocationDisclosureInfoBarDelegate::InfoBarDismissed() { | |
| 110 result_ = DisclosureResult::DISMISSED; | |
| 111 pref_service_->SetBoolean(prefs::kSearchGeolocationDisclosureDismissed, true); | |
| 112 } | |
| 113 | |
| 114 infobars::InfoBarDelegate::Type | |
| 115 SearchGeolocationDisclosureInfoBarDelegate::GetInfoBarType() const { | |
| 116 return PAGE_ACTION_TYPE; | |
| 117 } | |
| 118 | |
| 119 infobars::InfoBarDelegate::InfoBarIdentifier | |
| 120 SearchGeolocationDisclosureInfoBarDelegate::GetIdentifier() const { | |
| 121 return SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE; | |
| 122 } | |
| 123 | |
| 124 int SearchGeolocationDisclosureInfoBarDelegate::GetIconId() const { | |
| 125 return IDR_ANDROID_INFOBAR_GEOLOCATION; | |
| 126 } | |
| OLD | NEW |