Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / translate_internals / translate_internals_handler.h
1 // Copyright 2013 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_TRANSLATE_INTERNALS_TRANSLATE_INTERNALS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_TRANSLATE_INTERNALS_TRANSLATE_INTERNALS_HANDLER_H_
7
8 #include <string>
9
10 #include "base/callback_list.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/translate/core/browser/translate_language_list.h"
13 #include "components/translate/core/browser/translate_manager.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/web_ui_message_handler.h"
17 #include "content/public/common/webplugininfo.h"
18
19 namespace translate {
20 struct LanguageDetectionDetails;
21 struct TranslateErrorDetails;
22 struct TranslateEventDetails;
23 }
24
25 namespace base {
26 class DictionaryValue;
27 class ListValue;
28 class Value;
29 }
30
31 namespace content {
32 class NotificationDetails;
33 class NotificationSource;
34 }
35
36 // The handler class for TranslateInternals page operations.
37 class TranslateInternalsHandler : public content::WebUIMessageHandler,
38                                   public content::NotificationObserver {
39  public:
40   TranslateInternalsHandler();
41   virtual ~TranslateInternalsHandler();
42
43   // content::WebUIMessageHandler methods:
44   virtual void RegisterMessages() OVERRIDE;
45
46  private:
47   // content::NotificationObserver implementation:
48   virtual void Observe(int type,
49                        const content::NotificationSource& source,
50                        const content::NotificationDetails& details) OVERRIDE;
51
52   // Callback for translate errors.
53   void OnTranslateError(const translate::TranslateErrorDetails& details);
54
55   // Callback for translate events.
56   virtual void OnTranslateEvent(
57       const translate::TranslateEventDetails& details);
58
59   // Handles the Javascript message 'removePrefItem'. This message is sent
60   // when UI requests to remove an item in the preference.
61   void OnRemovePrefItem(const base::ListValue* args);
62
63   // Handles the Javascript message 'requestInfo'. This message is sent
64   // when UI needs to show information concerned with the translation.
65   // For now, this returns only prefs to Javascript.
66   // |args| is not used.
67   void OnRequestInfo(const base::ListValue* args);
68
69   // Sends a messsage to Javascript.
70   void SendMessageToJs(const std::string& message, const base::Value& value);
71
72   // Sends the current preference to Javascript.
73   void SendPrefsToJs();
74
75   // Sends the languages currently supported by the server to JavaScript.
76   void SendSupportedLanguagesToJs();
77
78   // Subscription for translate events coming from the translate language list.
79   scoped_ptr<translate::TranslateLanguageList::EventCallbackList::Subscription>
80       event_subscription_;
81
82   // Subscription for translate errors coming from the translate manager.
83   scoped_ptr<
84       translate::TranslateManager::TranslateErrorCallbackList::Subscription>
85       error_subscription_;
86
87   content::NotificationRegistrar notification_registrar_;
88
89   DISALLOW_COPY_AND_ASSIGN(TranslateInternalsHandler);
90 };
91
92 #endif  // CHROME_BROWSER_UI_WEBUI_TRANSLATE_INTERNALS_TRANSLATE_INTERNALS_HANDLER_H_