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