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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_LANGUAGE_OPTIONS_HANDLER_COMMON_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_LANGUAGE_OPTIONS_HANDLER_COMMON_H_
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"
13 class DictionaryValue
;
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
{
25 LanguageOptionsHandlerCommon();
26 ~LanguageOptionsHandlerCommon() override
;
28 // OptionsPageUIHandler implementation.
29 void GetLocalizedValues(base::DictionaryValue
* localized_strings
) override
;
30 void Uninitialize() override
;
32 // DOMMessageHandler implementation.
33 void RegisterMessages() override
;
35 // SpellcheckHunspellDictionary::Observer implementation.
36 void OnHunspellDictionaryInitialized() override
;
37 void OnHunspellDictionaryDownloadBegin() override
;
38 void OnHunspellDictionaryDownloadSuccess() override
;
39 void OnHunspellDictionaryDownloadFailure() override
;
41 // The following static methods are public for ease of testing.
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, ...}
47 // Note that true in values does not mean anything. We just use the
48 // dictionary as a set.
49 static base::DictionaryValue
* GetUILanguageCodeSet();
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, ...}
55 // Note that true in values does not mean anything. We just use the
56 // dictionary as a set.
57 static base::DictionaryValue
* GetSpellCheckLanguageCodeSet();
60 // Returns the name of the product (ex. "Chrome" or "Chrome OS").
61 virtual base::string16
GetProductName() = 0;
63 // Sets the application locale.
64 virtual void SetApplicationLocale(const std::string
& language_code
) = 0;
66 // Called when the language options is opened.
67 void LanguageOptionsOpenCallback(const base::ListValue
* args
);
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
);
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
);
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
);
81 // Called when the user saves the language list preferences.
82 void UpdateLanguageListCallback(const base::ListValue
* args
);
84 // Updates the hunspell dictionary that is used for spellchecking.
85 void RefreshHunspellDictionary();
87 // Returns the hunspell dictionary that is used for spellchecking. Null when
88 // no languages are selected for spellchecking.
89 base::WeakPtr
<SpellcheckHunspellDictionary
>& GetHunspellDictionary();
91 // The hunspell dictionary that is used for spellchecking. Might be null.
92 base::WeakPtr
<SpellcheckHunspellDictionary
> hunspell_dictionary_
;
94 DISALLOW_COPY_AND_ASSIGN(LanguageOptionsHandlerCommon
);
97 } // namespace options
99 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_LANGUAGE_OPTIONS_HANDLER_COMMON_H_