Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / language_options_handler_common.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_LANGUAGE_OPTIONS_HANDLER_COMMON_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_LANGUAGE_OPTIONS_HANDLER_COMMON_H_
7
8 #include "base/memory/weak_ptr.h"
9 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h"
10 #include "chrome/browser/ui/webui/options/options_ui.h"
11
12 namespace base {
13 class DictionaryValue;
14 class ListValue;
15 }
16
17 namespace options {
18
19 // The base class for language options page UI handlers.  This class has code
20 // common to the Chrome OS and non-Chrome OS implementation of the handler.
21 class LanguageOptionsHandlerCommon
22     : public OptionsPageUIHandler,
23       public SpellcheckHunspellDictionary::Observer {
24  public:
25   LanguageOptionsHandlerCommon();
26   ~LanguageOptionsHandlerCommon() override;
27
28   // OptionsPageUIHandler implementation.
29   void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
30   void Uninitialize() override;
31
32   // DOMMessageHandler implementation.
33   void RegisterMessages() override;
34
35   // SpellcheckHunspellDictionary::Observer implementation.
36   void OnHunspellDictionaryInitialized() override;
37   void OnHunspellDictionaryDownloadBegin() override;
38   void OnHunspellDictionaryDownloadSuccess() override;
39   void OnHunspellDictionaryDownloadFailure() override;
40
41   // The following static methods are public for ease of testing.
42
43   // Gets the set of language codes that can be used as UI language.
44   // The return value will look like:
45   // {'en-US': true, 'fi': true, 'fr': true, ...}
46   //
47   // Note that true in values does not mean anything. We just use the
48   // dictionary as a set.
49   static base::DictionaryValue* GetUILanguageCodeSet();
50
51   // Gets the set of language codes that can be used for spellchecking.
52   // The return value will look like:
53   // {'en-US': true, 'fi': true, 'fr': true, ...}
54   //
55   // Note that true in values does not mean anything. We just use the
56   // dictionary as a set.
57   static base::DictionaryValue* GetSpellCheckLanguageCodeSet();
58
59  private:
60   // Returns the name of the product (ex. "Chrome" or "Chrome OS").
61   virtual base::string16 GetProductName() = 0;
62
63   // Sets the application locale.
64   virtual void SetApplicationLocale(const std::string& language_code) = 0;
65
66   // Called when the language options is opened.
67   void LanguageOptionsOpenCallback(const base::ListValue* args);
68
69   // Called when the UI language is changed.
70   // |args| will contain the language code as string (ex. "fr").
71   void UiLanguageChangeCallback(const base::ListValue* args);
72
73   // Called when the spell check language is changed.
74   // |args| will contain the language code as string (ex. "fr").
75   void SpellCheckLanguageChangeCallback(const base::ListValue* args);
76
77   // Called when the user clicks "Retry" button for a spellcheck dictionary that
78   // has failed to download.
79   void RetrySpellcheckDictionaryDownload(const base::ListValue* args);
80
81   // Called when the user saves the language list preferences.
82   void UpdateLanguageListCallback(const base::ListValue* args);
83
84   // Updates the hunspell dictionary that is used for spellchecking.
85   void RefreshHunspellDictionary();
86
87   // Returns the hunspell dictionary that is used for spellchecking. Never null.
88   base::WeakPtr<SpellcheckHunspellDictionary>& GetHunspellDictionary();
89
90   // The hunspell dictionary that is used for spellchecking. Might be null.
91   base::WeakPtr<SpellcheckHunspellDictionary> hunspell_dictionary_;
92
93   DISALLOW_COPY_AND_ASSIGN(LanguageOptionsHandlerCommon);
94 };
95
96 }  // namespace options
97
98 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_LANGUAGE_OPTIONS_HANDLER_COMMON_H_