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
12namespace base {
13class DictionaryValue;
14class ListValue;
15}
16
17namespace 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.
21class LanguageOptionsHandlerCommon
22    : public OptionsPageUIHandler,
23      public SpellcheckHunspellDictionary::Observer {
24 public:
25  LanguageOptionsHandlerCommon();
26  virtual ~LanguageOptionsHandlerCommon();
27
28  // OptionsPageUIHandler implementation.
29  virtual void GetLocalizedValues(
30      base::DictionaryValue* localized_strings) OVERRIDE;
31  virtual void Uninitialize() OVERRIDE;
32
33  // DOMMessageHandler implementation.
34  virtual void RegisterMessages() OVERRIDE;
35
36  // SpellcheckHunspellDictionary::Observer implementation.
37  virtual void OnHunspellDictionaryInitialized() OVERRIDE;
38  virtual void OnHunspellDictionaryDownloadBegin() OVERRIDE;
39  virtual void OnHunspellDictionaryDownloadSuccess() OVERRIDE;
40  virtual void OnHunspellDictionaryDownloadFailure() OVERRIDE;
41
42  // The following static methods are public for ease of testing.
43
44  // Gets the set of language codes that can be used as UI language.
45  // The return value will look like:
46  // {'en-US': true, 'fi': true, 'fr': true, ...}
47  //
48  // Note that true in values does not mean anything. We just use the
49  // dictionary as a set.
50  static base::DictionaryValue* GetUILanguageCodeSet();
51
52  // Gets the set of language codes that can be used for spellchecking.
53  // The return value will look like:
54  // {'en-US': true, 'fi': true, 'fr': true, ...}
55  //
56  // Note that true in values does not mean anything. We just use the
57  // dictionary as a set.
58  static base::DictionaryValue* GetSpellCheckLanguageCodeSet();
59
60 private:
61  // Returns the name of the product (ex. "Chrome" or "Chrome OS").
62  virtual base::string16 GetProductName() = 0;
63
64  // Sets the application locale.
65  virtual void SetApplicationLocale(const std::string& language_code) = 0;
66
67  // Called when the language options is opened.
68  void LanguageOptionsOpenCallback(const base::ListValue* args);
69
70  // Called when the UI language is changed.
71  // |args| will contain the language code as string (ex. "fr").
72  void UiLanguageChangeCallback(const base::ListValue* args);
73
74  // Called when the spell check language is changed.
75  // |args| will contain the language code as string (ex. "fr").
76  void SpellCheckLanguageChangeCallback(const base::ListValue* args);
77
78  // Called when the user clicks "Retry" button for a spellcheck dictionary that
79  // has failed to download.
80  void RetrySpellcheckDictionaryDownload(const base::ListValue* args);
81
82  // Called when the user saves the language list preferences.
83  void UpdateLanguageListCallback(const base::ListValue* args);
84
85  // Updates the hunspell dictionary that is used for spellchecking.
86  void RefreshHunspellDictionary();
87
88  // Returns the hunspell dictionary that is used for spellchecking. Never null.
89  base::WeakPtr<SpellcheckHunspellDictionary>& GetHunspellDictionary();
90
91  // The hunspell dictionary that is used for spellchecking. Might be null.
92  base::WeakPtr<SpellcheckHunspellDictionary> hunspell_dictionary_;
93
94  DISALLOW_COPY_AND_ASSIGN(LanguageOptionsHandlerCommon);
95};
96
97}  // namespace options
98
99#endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_LANGUAGE_OPTIONS_HANDLER_COMMON_H_
100