diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-07 00:00:12 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-07 00:00:12 +0000 |
commit | 6401e9a9d7552331beac22aca0dfa69532ea4b38 (patch) | |
tree | 25d717b46b6895178ab9a2acacdfdca513368ca1 /chrome | |
parent | 7dbcfc1c4bd26dacd41130910d8cc2b5a1375b49 (diff) | |
download | chromium_src-6401e9a9d7552331beac22aca0dfa69532ea4b38.zip chromium_src-6401e9a9d7552331beac22aca0dfa69532ea4b38.tar.gz chromium_src-6401e9a9d7552331beac22aca0dfa69532ea4b38.tar.bz2 |
Fix tips in OS X to respect system language settings instead of locale.
BUG= http://crbug.com/22727
TEST= Set preferred language to a different setting from the locale in the OS X system settings.
Make sure that the language of the tips matches the language setting (which
should be the same as that of the Chrome UI). If tips are not available in
the Chrome UI language, no tips should be shown.
Review URL: http://codereview.chromium.org/258037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28193 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.cc | 10 | ||||
-rw-r--r-- | chrome/browser/web_resource/web_resource_service.cc | 21 | ||||
-rw-r--r-- | chrome/browser/web_resource/web_resource_service.h | 3 |
3 files changed, 26 insertions, 8 deletions
diff --git a/chrome/browser/dom_ui/tips_handler.cc b/chrome/browser/dom_ui/tips_handler.cc index 888bfa1..68ce766 100644 --- a/chrome/browser/dom_ui/tips_handler.cc +++ b/chrome/browser/dom_ui/tips_handler.cc @@ -28,7 +28,7 @@ void TipsHandler::RegisterMessages() { } void TipsHandler::HandleGetTips(const Value* content) { - // List containing the tips to be displayed. + // List containing the tips to be displayed. ListValue list_value; // Holds the web resource data found in the preferences cache. @@ -38,15 +38,15 @@ void TipsHandler::HandleGetTips(const Value* content) { int current_tip_index; std::string current_tip; - // If tips are not correct for our locale, do not send. Wait for update. + // If tips are not correct for our language, do not send. Wait for update. // We need to check here because the new tab page calls for tips before // the tip service starts up. PrefService* current_prefs = dom_ui_->GetProfile()->GetPrefs(); if (current_prefs->HasPrefPath(prefs::kNTPTipsServer)) { std::wstring server = current_prefs->GetString(prefs::kNTPTipsServer); - std::wstring locale = ASCIIToWide( - g_browser_process->GetApplicationLocale()); - if (!EndsWith(server, locale, false)) { + std::wstring tips_language = WebResourceService::GetWebResourceLanguage( + current_prefs); + if (!EndsWith(server, tips_language, false)) { dom_ui_->CallJavascriptFunction(L"tips", list_value); return; } diff --git a/chrome/browser/web_resource/web_resource_service.cc b/chrome/browser/web_resource/web_resource_service.cc index f401807..b056822 100644 --- a/chrome/browser/web_resource/web_resource_service.cc +++ b/chrome/browser/web_resource/web_resource_service.cc @@ -205,19 +205,19 @@ void WebResourceService::Init() { resource_dispatcher_host_ = g_browser_process->resource_dispatcher_host(); web_resource_fetcher_ = new WebResourceFetcher(this); prefs_->RegisterStringPref(prefs::kNTPTipsCacheUpdate, L"0"); - std::wstring locale = ASCIIToWide(g_browser_process->GetApplicationLocale()); + std::wstring language = WebResourceService::GetWebResourceLanguage(prefs_); if (prefs_->HasPrefPath(prefs::kNTPTipsServer)) { web_resource_server_ = prefs_->GetString(prefs::kNTPTipsServer); // If we are in the correct locale, initialization is done. - if (EndsWith(web_resource_server_, locale, false)) + if (EndsWith(web_resource_server_, language, false)) return; } // If we have not yet set a server, or if the tips server is set to the wrong // locale, reset the server and force an immediate update of tips. web_resource_server_ = kDefaultResourceServer; - web_resource_server_.append(locale); + web_resource_server_.append(language); prefs_->SetString(prefs::kNTPTipsCacheUpdate, L""); } @@ -296,3 +296,18 @@ void WebResourceService::UpdateResourceCache(const std::string& json_data) { DoubleToWString(base::Time::Now().ToDoubleT())); prefs_->SetString(prefs::kNTPTipsServer, web_resource_server_); } + +// static +std::wstring WebResourceService::GetWebResourceLanguage(PrefService* prefs) { +#if defined OS_MACOSX + // OS X derives the language for the Chrome UI from the list of accepted + // languages, which can be different from the locale. + std::wstring languageList = prefs->GetString(prefs::kAcceptLanguages); + int pos = languageList.find(L","); + pos = pos >= 0 ? pos : languageList.length(); + return languageList.substr(0, pos); +#else + return ASCIIToWide(g_browser_process->GetApplicationLocale()); +#endif +} + diff --git a/chrome/browser/web_resource/web_resource_service.h b/chrome/browser/web_resource/web_resource_service.h index caf9d90..41f75f1 100644 --- a/chrome/browser/web_resource/web_resource_service.h +++ b/chrome/browser/web_resource/web_resource_service.h @@ -28,6 +28,9 @@ class WebResourceService // the process that will parse the JSON, and then update the cache. void UpdateResourceCache(const std::string& json_data); + // Get the language appropriate for delivery of the web resources. + static std::wstring GetWebResourceLanguage(PrefService* prefs); + static const wchar_t* kTipDictionaryPrefName; static const wchar_t* kCurrentTipPrefName; static const wchar_t* kTipCachePrefName; |