summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/dom_ui/tips_handler.cc10
-rw-r--r--chrome/browser/web_resource/web_resource_service.cc21
-rw-r--r--chrome/browser/web_resource/web_resource_service.h3
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;