Commit 9f63aac7 authored by benwells's avatar benwells Committed by Commit bot

Use the name of the default search engine in the search geo disclosure.

The disclosure can now be shown for and HTTPS search engine that has
been set to the default, and which uses the geolocation API.

BUG=700250

Review-Url: https://codereview.chromium.org/2909583002
Cr-Commit-Position: refs/heads/master@{#474941}
parent 0827cd52
......@@ -12273,8 +12273,8 @@ read aloud to screenreader users to announce that a completion is available.">
<!-- Consistent omnibox geolocation -->
<if expr="is_android">
<message name="IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_TEXT" desc="Text to put in the infobar disclosing Google Search's usage of location. The message contains a link to a settings page. The link text is a separate string in the translation console and appears here as a placeholder text.">
Google uses your location to give you local content. You can change this in <ph name="SETTINGS_LINK">$1<ex>Link to Settings page</ex></ph>.
<message name="IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_TEXT" desc="Text to put in the infobar disclosing the default search engine's usage of location. The message contains a link to a settings page. The link text is a separate string in the translation console and appears here as a placeholder text.">
<ph name="SEARCH_ENGINE_NAME">$1<ex>Google</ex></ph> uses your location to give you local content. You can change this in <ph name="SETTINGS_LINK">$2<ex>Settings</ex></ph>.
</message>
<message name="IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_SETTINGS_LINK_TEXT" desc="Text to put in the link to the Settings page in the search geolocation disclosure UI.">
Settings
......
......@@ -4,6 +4,8 @@
#include "chrome/browser/android/search_geolocation/search_geolocation_disclosure_infobar_delegate.h"
#include <vector>
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "chrome/browser/android/android_theme_resources.h"
......@@ -38,14 +40,15 @@ SearchGeolocationDisclosureInfoBarDelegate::
// static
void SearchGeolocationDisclosureInfoBarDelegate::Create(
content::WebContents* web_contents,
const GURL& search_url) {
const GURL& search_url,
const base::string16& search_engine_name) {
InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents);
// Add the new delegate.
infobar_service->AddInfoBar(
base::MakeUnique<SearchGeolocationDisclosureInfoBar>(
base::WrapUnique(new SearchGeolocationDisclosureInfoBarDelegate(
web_contents, search_url))));
web_contents, search_url, search_engine_name))));
}
// static
......@@ -74,7 +77,8 @@ void SearchGeolocationDisclosureInfoBarDelegate::RecordSettingsClicked() {
SearchGeolocationDisclosureInfoBarDelegate::
SearchGeolocationDisclosureInfoBarDelegate(
content::WebContents* web_contents,
const GURL& search_url)
const GURL& search_url,
const base::string16& search_engine_name)
: infobars::InfoBarDelegate(),
search_url_(search_url),
result_(DisclosureResult::IGNORED),
......@@ -83,10 +87,11 @@ SearchGeolocationDisclosureInfoBarDelegate::
->GetPrefs();
base::string16 link = l10n_util::GetStringUTF16(
IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_SETTINGS_LINK_TEXT);
size_t offset;
message_text_ = l10n_util::GetStringFUTF16(
IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_TEXT, link, &offset);
inline_link_range_ = gfx::Range(offset, offset + link.length());
std::vector<size_t> offsets;
message_text_ =
l10n_util::GetStringFUTF16(IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_TEXT,
search_engine_name, link, &offsets);
inline_link_range_ = gfx::Range(offsets[1], offsets[1] + link.length());
}
void SearchGeolocationDisclosureInfoBarDelegate::InfoBarDismissed() {
......
......@@ -35,7 +35,8 @@ class SearchGeolocationDisclosureInfoBarDelegate
// Create and show the infobar.
static void Create(content::WebContents* web_contents,
const GURL& search_url);
const GURL& search_url,
const base::string16& search_engine_name);
// Determine if there is a search geolocation disclosure infobar already open.
static bool IsSearchGeolocationDisclosureOpen(
......@@ -57,7 +58,8 @@ class SearchGeolocationDisclosureInfoBarDelegate
explicit SearchGeolocationDisclosureInfoBarDelegate(
content::WebContents* web_contents,
const GURL& search_url);
const GURL& search_url,
const base::string16& search_engine_name);
// InfoBarDelegate:
void InfoBarDismissed() override;
......
......@@ -204,7 +204,13 @@ void SearchGeolocationDisclosureTabHelper::MaybeShowDisclosureForValidUrl(
return;
// All good, let's show the disclosure and increment the shown count.
SearchGeolocationDisclosureInfoBarDelegate::Create(web_contents(), gurl);
TemplateURLService* template_url_service =
TemplateURLServiceFactory::GetForProfile(GetProfile());
const TemplateURL* template_url =
template_url_service->GetDefaultSearchProvider();
base::string16 search_engine_name = template_url->short_name();
SearchGeolocationDisclosureInfoBarDelegate::Create(web_contents(), gurl,
search_engine_name);
shown_count++;
prefs->SetInteger(prefs::kSearchGeolocationDisclosureShownCount, shown_count);
prefs->SetInt64(prefs::kSearchGeolocationDisclosureLastShowDate,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment