Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / help / help_handler.h
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_HELP_HELP_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_HELP_HELP_HANDLER_H_
7
8 #include <string>
9
10 #include "base/compiler_specific.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/strings/string16.h"
13 #include "chrome/browser/ui/webui/help/version_updater.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
18 #if defined(OS_CHROMEOS)
19 #include "base/task/cancelable_task_tracker.h"
20 #include "chrome/browser/chromeos/version_loader.h"
21 #endif  // defined(OS_CHROMEOS)
22
23 namespace base {
24 class DictionaryValue;
25 class ListValue;
26 }
27
28 // WebUI message handler for the help page.
29 class HelpHandler : public content::WebUIMessageHandler,
30                     public content::NotificationObserver {
31  public:
32   HelpHandler();
33   ~HelpHandler() override;
34
35   // WebUIMessageHandler implementation.
36   void RegisterMessages() override;
37
38   // Adds string values for the UI to |localized_strings|.
39   static void GetLocalizedValues(base::DictionaryValue* localized_strings);
40
41   // NotificationObserver implementation.
42   void Observe(int type,
43                const content::NotificationSource& source,
44                const content::NotificationDetails& details) override;
45
46   // Returns the browser version as a string.
47   static base::string16 BuildBrowserVersionString();
48
49  private:
50   // Initializes querying values for the page.
51   void OnPageLoaded(const base::ListValue* args);
52
53 #if defined(OS_MACOSX)
54   // Promotes the updater for all users.
55   void PromoteUpdater(const base::ListValue* args);
56 #endif
57
58   // Relaunches the browser. |args| must be empty.
59   void RelaunchNow(const base::ListValue* args);
60
61   // Opens the feedback dialog. |args| must be empty.
62   void OpenFeedbackDialog(const base::ListValue* args);
63
64   // Opens the help page. |args| must be empty.
65   void OpenHelpPage(const base::ListValue* args);
66
67 #if defined(OS_CHROMEOS)
68   // Sets the release track version.
69   void SetChannel(const base::ListValue* args);
70
71   // Performs relaunch and powerwash.
72   void RelaunchAndPowerwash(const base::ListValue* args);
73 #endif
74
75   // Checks for and applies update.
76   void RequestUpdate(const base::ListValue* args);
77
78   // Callback method which forwards status updates to the page.
79   void SetUpdateStatus(VersionUpdater::Status status, int progress,
80                        const base::string16& fail_message);
81
82 #if defined(OS_MACOSX)
83   // Callback method which forwards promotion state to the page.
84   void SetPromotionState(VersionUpdater::PromotionState state);
85 #endif
86
87 #if defined(OS_CHROMEOS)
88   // Callbacks from VersionLoader.
89   void OnOSVersion(const std::string& version);
90   void OnOSFirmware(const std::string& firmware);
91   void OnCurrentChannel(const std::string& channel);
92   void OnTargetChannel(const std::string& channel);
93
94   // Callback for loading FCC label alt text.
95   void LoadFCCLabelText();
96 #endif
97
98   // Specialized instance of the VersionUpdater used to update the browser.
99   scoped_ptr<VersionUpdater> version_updater_;
100
101   // Used to observe notifications.
102   content::NotificationRegistrar registrar_;
103
104 #if defined(OS_CHROMEOS)
105   // Handles asynchronously loading the CrOS version info.
106   chromeos::VersionLoader loader_;
107
108   // Used to request the version.
109   base::CancelableTaskTracker tracker_;
110 #endif  // defined(OS_CHROMEOS)
111
112   // Used for callbacks.
113   base::WeakPtrFactory<HelpHandler> weak_factory_;
114
115   DISALLOW_COPY_AND_ASSIGN(HelpHandler);
116 };
117
118 #endif  // CHROME_BROWSER_UI_WEBUI_HELP_HELP_HANDLER_H_