Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / locale_change_guard.cc
index 4ffb7b3..7ad07cd 100644 (file)
@@ -4,6 +4,8 @@
 
 #include "chrome/browser/chromeos/locale_change_guard.h"
 
+#include <algorithm>
+
 #include "ash/shell.h"
 #include "ash/system/tray/system_tray.h"
 #include "ash/system/tray/system_tray_notifier.h"
@@ -21,7 +23,6 @@
 #include "chrome/browser/ui/host_desktop.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/grit/generated_resources.h"
-#include "chrome/grit/theme_resources.h"
 #include "content/public/browser/notification_service.h"
 #include "content/public/browser/notification_source.h"
 #include "content/public/browser/user_metrics.h"
@@ -33,6 +34,17 @@ using content::WebContents;
 
 namespace chromeos {
 
+namespace {
+
+// This is the list of languages that do not require user notification when
+// locale is switched automatically between regions within the same language.
+//
+// New language in kAcceptLanguageList should be added either here or to
+// to the exception list in unit test.
+const char* const kSkipShowNotificationLanguages[4] = {"en", "de", "fr", "it"};
+
+}  // anonymous namespace
+
 LocaleChangeGuard::LocaleChangeGuard(Profile* profile)
     : profile_(profile),
       reverted_(false),
@@ -153,7 +165,11 @@ void LocaleChangeGuard::Check() {
   if (prefs->GetString(prefs::kApplicationLocaleAccepted) == to_locale)
     return;  // Already accepted.
 
-  // Locale change detected, showing notification.
+  // Locale change detected.
+  if (!ShouldShowLocaleChangeNotification(from_locale, to_locale))
+    return;
+
+  // Showing notification.
   if (from_locale_ != from_locale || to_locale_ != to_locale) {
     // Falling back to showing message in current locale.
     LOG(ERROR) <<
@@ -161,8 +177,11 @@ void LocaleChangeGuard::Check() {
     PrepareChangingLocale(from_locale, to_locale);
   }
 
+#if !defined(USE_ATHENA)
+  // TODO(dpolukhin): Support locale change, crbug.com/411884.
   ash::Shell::GetInstance()->system_tray_notifier()->NotifyLocaleChanged(
       this, cur_locale, from_locale_, to_locale_);
+#endif
 }
 
 void LocaleChangeGuard::AcceptLocaleChange() {
@@ -212,4 +231,35 @@ void LocaleChangeGuard::PrepareChangingLocale(
   }
 }
 
+// static
+bool LocaleChangeGuard::ShouldShowLocaleChangeNotification(
+    const std::string& from_locale,
+    const std::string& to_locale) {
+  const std::string from_lang = l10n_util::GetLanguage(from_locale);
+  const std::string to_lang = l10n_util::GetLanguage(to_locale);
+
+  if (from_locale == to_locale)
+    return false;
+
+  if (from_lang != to_lang)
+    return true;
+
+  const char* const* begin = kSkipShowNotificationLanguages;
+  const char* const* end = kSkipShowNotificationLanguages +
+                           arraysize(kSkipShowNotificationLanguages);
+
+  return std::find(begin, end, from_lang) == end;
+}
+
+// static
+const char* const*
+LocaleChangeGuard::GetSkipShowNotificationLanguagesForTesting() {
+  return kSkipShowNotificationLanguages;
+}
+
+// static
+size_t LocaleChangeGuard::GetSkipShowNotificationLanguagesSizeForTesting() {
+  return arraysize(kSkipShowNotificationLanguages);
+}
+
 }  // namespace chromeos