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(const std::string
& language
) override
;
37 void OnHunspellDictionaryDownloadBegin(const std::string
& language
) override
;
38 void OnHunspellDictionaryDownloadSuccess(
39 const std::string
& language
) override
;
40 void OnHunspellDictionaryDownloadFailure(
41 const std::string
& language
) override
;
43 // The following static methods are public for ease of testing.
45 // Gets the set of language codes that can be used as UI language.
46 // The return value will look like:
47 // {'en-US': true, 'fi': true, 'fr': true, ...}
49 // Note that true in values does not mean anything. We just use the
50 // dictionary as a set.
51 static base::DictionaryValue
* GetUILanguageCodeSet();
53 // Gets the set of language codes that can be used for spellchecking.
54 // The return value will look like:
55 // {'en-US': true, 'fi': true, 'fr': true, ...}
57 // Note that true in values does not mean anything. We just use the
58 // dictionary as a set.
59 static base::DictionaryValue
* GetSpellCheckLanguageCodeSet();
62 // Returns the name of the product (ex. "Chrome" or "Chrome OS").
63 virtual base::string16
GetProductName() = 0;
65 // Sets the application locale.
66 virtual void SetApplicationLocale(const std::string
& language_code
) = 0;
68 // Called when the language options is opened.
69 void LanguageOptionsOpenCallback(const base::ListValue
* args
);
71 // Called when the UI language is changed.
72 // |args| will contain the language code as string (ex. "fr").
73 void UiLanguageChangeCallback(const base::ListValue
* args
);
75 // Called when the spell check language is changed.
76 // |args| will contain the language code as string (ex. "fr").
77 void SpellCheckLanguageChangeCallback(const base::ListValue
* args
);
79 // Called when the user clicks "Retry" button for a spellcheck dictionary that
80 // has failed to download. |args| will contain the language code as a string
82 void RetrySpellcheckDictionaryDownload(const base::ListValue
* args
);
84 // Called when the user saves the language list preferences.
85 void UpdateLanguageListCallback(const base::ListValue
* args
);
87 // Returns a pointer to the browser SpellcheckService. Can be null if the
88 // service has already shut down.
89 SpellcheckService
* GetSpellcheckService();
91 DISALLOW_COPY_AND_ASSIGN(LanguageOptionsHandlerCommon
);
94 } // namespace options
96 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_LANGUAGE_OPTIONS_HANDLER_COMMON_H_