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 <vector> |
| 8 |
7 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
8 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
9 #include "chrome/browser/android/android_theme_resources.h" | 11 #include "chrome/browser/android/android_theme_resources.h" |
10 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/android/infobars/search_geolocation_disclosure_infob
ar.h" | 14 #include "chrome/browser/ui/android/infobars/search_geolocation_disclosure_infob
ar.h" |
13 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
14 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
15 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
16 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
(...skipping 14 matching lines...) Expand all Loading... |
31 "GeolocationDisclosure.DisclosureResult", | 33 "GeolocationDisclosure.DisclosureResult", |
32 static_cast<base::HistogramBase::Sample>(result_), | 34 static_cast<base::HistogramBase::Sample>(result_), |
33 static_cast<base::HistogramBase::Sample>(DisclosureResult::COUNT)); | 35 static_cast<base::HistogramBase::Sample>(DisclosureResult::COUNT)); |
34 UMA_HISTOGRAM_MEDIUM_TIMES("GeolocationDisclosure.InfoBarVisibleTime", | 36 UMA_HISTOGRAM_MEDIUM_TIMES("GeolocationDisclosure.InfoBarVisibleTime", |
35 base::Time::Now() - creation_time_); | 37 base::Time::Now() - creation_time_); |
36 } | 38 } |
37 | 39 |
38 // static | 40 // static |
39 void SearchGeolocationDisclosureInfoBarDelegate::Create( | 41 void SearchGeolocationDisclosureInfoBarDelegate::Create( |
40 content::WebContents* web_contents, | 42 content::WebContents* web_contents, |
41 const GURL& search_url) { | 43 const GURL& search_url, |
| 44 const base::string16& search_engine_name) { |
42 InfoBarService* infobar_service = | 45 InfoBarService* infobar_service = |
43 InfoBarService::FromWebContents(web_contents); | 46 InfoBarService::FromWebContents(web_contents); |
44 // Add the new delegate. | 47 // Add the new delegate. |
45 infobar_service->AddInfoBar( | 48 infobar_service->AddInfoBar( |
46 base::MakeUnique<SearchGeolocationDisclosureInfoBar>( | 49 base::MakeUnique<SearchGeolocationDisclosureInfoBar>( |
47 base::WrapUnique(new SearchGeolocationDisclosureInfoBarDelegate( | 50 base::WrapUnique(new SearchGeolocationDisclosureInfoBarDelegate( |
48 web_contents, search_url)))); | 51 web_contents, search_url, search_engine_name)))); |
49 } | 52 } |
50 | 53 |
51 // static | 54 // static |
52 bool SearchGeolocationDisclosureInfoBarDelegate:: | 55 bool SearchGeolocationDisclosureInfoBarDelegate:: |
53 IsSearchGeolocationDisclosureOpen(content::WebContents* web_contents) { | 56 IsSearchGeolocationDisclosureOpen(content::WebContents* web_contents) { |
54 InfoBarService* infobar_service = | 57 InfoBarService* infobar_service = |
55 InfoBarService::FromWebContents(web_contents); | 58 InfoBarService::FromWebContents(web_contents); |
56 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 59 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
57 infobars::InfoBar* existing_infobar = infobar_service->infobar_at(i); | 60 infobars::InfoBar* existing_infobar = infobar_service->infobar_at(i); |
58 if (existing_infobar->delegate()->GetIdentifier() == | 61 if (existing_infobar->delegate()->GetIdentifier() == |
59 infobars::InfoBarDelegate:: | 62 infobars::InfoBarDelegate:: |
60 SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE) { | 63 SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE) { |
61 return true; | 64 return true; |
62 } | 65 } |
63 } | 66 } |
64 | 67 |
65 return false; | 68 return false; |
66 } | 69 } |
67 | 70 |
68 void SearchGeolocationDisclosureInfoBarDelegate::RecordSettingsClicked() { | 71 void SearchGeolocationDisclosureInfoBarDelegate::RecordSettingsClicked() { |
69 result_ = DisclosureResult::SETTINGS_CLICKED; | 72 result_ = DisclosureResult::SETTINGS_CLICKED; |
70 // This counts as a dismissed so the dialog isn't shown again. | 73 // This counts as a dismissed so the dialog isn't shown again. |
71 pref_service_->SetBoolean(prefs::kSearchGeolocationDisclosureDismissed, true); | 74 pref_service_->SetBoolean(prefs::kSearchGeolocationDisclosureDismissed, true); |
72 } | 75 } |
73 | 76 |
74 SearchGeolocationDisclosureInfoBarDelegate:: | 77 SearchGeolocationDisclosureInfoBarDelegate:: |
75 SearchGeolocationDisclosureInfoBarDelegate( | 78 SearchGeolocationDisclosureInfoBarDelegate( |
76 content::WebContents* web_contents, | 79 content::WebContents* web_contents, |
77 const GURL& search_url) | 80 const GURL& search_url, |
| 81 const base::string16& search_engine_name) |
78 : infobars::InfoBarDelegate(), | 82 : infobars::InfoBarDelegate(), |
79 search_url_(search_url), | 83 search_url_(search_url), |
80 result_(DisclosureResult::IGNORED), | 84 result_(DisclosureResult::IGNORED), |
81 creation_time_(base::Time::Now()) { | 85 creation_time_(base::Time::Now()) { |
82 pref_service_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()) | 86 pref_service_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
83 ->GetPrefs(); | 87 ->GetPrefs(); |
84 base::string16 link = l10n_util::GetStringUTF16( | 88 base::string16 link = l10n_util::GetStringUTF16( |
85 IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_SETTINGS_LINK_TEXT); | 89 IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_SETTINGS_LINK_TEXT); |
86 size_t offset; | 90 std::vector<size_t> offsets; |
87 message_text_ = l10n_util::GetStringFUTF16( | 91 message_text_ = |
88 IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_TEXT, link, &offset); | 92 l10n_util::GetStringFUTF16(IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_TEXT, |
89 inline_link_range_ = gfx::Range(offset, offset + link.length()); | 93 search_engine_name, link, &offsets); |
| 94 inline_link_range_ = gfx::Range(offsets[1], offsets[1] + link.length()); |
90 } | 95 } |
91 | 96 |
92 void SearchGeolocationDisclosureInfoBarDelegate::InfoBarDismissed() { | 97 void SearchGeolocationDisclosureInfoBarDelegate::InfoBarDismissed() { |
93 result_ = DisclosureResult::DISMISSED; | 98 result_ = DisclosureResult::DISMISSED; |
94 pref_service_->SetBoolean(prefs::kSearchGeolocationDisclosureDismissed, true); | 99 pref_service_->SetBoolean(prefs::kSearchGeolocationDisclosureDismissed, true); |
95 } | 100 } |
96 | 101 |
97 infobars::InfoBarDelegate::Type | 102 infobars::InfoBarDelegate::Type |
98 SearchGeolocationDisclosureInfoBarDelegate::GetInfoBarType() const { | 103 SearchGeolocationDisclosureInfoBarDelegate::GetInfoBarType() const { |
99 return PAGE_ACTION_TYPE; | 104 return PAGE_ACTION_TYPE; |
100 } | 105 } |
101 | 106 |
102 infobars::InfoBarDelegate::InfoBarIdentifier | 107 infobars::InfoBarDelegate::InfoBarIdentifier |
103 SearchGeolocationDisclosureInfoBarDelegate::GetIdentifier() const { | 108 SearchGeolocationDisclosureInfoBarDelegate::GetIdentifier() const { |
104 return SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE; | 109 return SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE; |
105 } | 110 } |
106 | 111 |
107 int SearchGeolocationDisclosureInfoBarDelegate::GetIconId() const { | 112 int SearchGeolocationDisclosureInfoBarDelegate::GetIconId() const { |
108 return IDR_ANDROID_INFOBAR_GEOLOCATION; | 113 return IDR_ANDROID_INFOBAR_GEOLOCATION; |
109 } | 114 } |
OLD | NEW |