dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame^] | 1 | // Copyright 2016 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_SETTINGS_ABOUT_HANDLER_H_ |
| 6 | #define CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
| 11 | #include "base/compiler_specific.h" |
| 12 | #include "base/macros.h" |
| 13 | #include "base/memory/weak_ptr.h" |
| 14 | #include "base/strings/string16.h" |
| 15 | #include "build/build_config.h" |
| 16 | #include "chrome/browser/ui/webui/help/version_updater.h" |
| 17 | #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" |
| 18 | #include "components/policy/core/common/policy_service.h" |
| 19 | #include "content/public/browser/notification_observer.h" |
| 20 | #include "content/public/browser/notification_registrar.h" |
| 21 | #include "content/public/browser/web_ui_message_handler.h" |
| 22 | |
| 23 | #if defined(OS_CHROMEOS) |
| 24 | #include "base/task/cancelable_task_tracker.h" |
| 25 | #include "chromeos/system/version_loader.h" |
| 26 | #endif // defined(OS_CHROMEOS) |
| 27 | |
| 28 | namespace base { |
| 29 | class DictionaryValue; |
| 30 | class FilePath; |
| 31 | class ListValue; |
| 32 | } |
| 33 | |
| 34 | namespace content { |
| 35 | class WebUIDataSource; |
| 36 | } |
| 37 | |
| 38 | class Profile; |
| 39 | |
| 40 | namespace settings { |
| 41 | |
| 42 | // WebUI message handler for the help page. |
| 43 | class AboutHandler : public settings::SettingsPageUIHandler, |
| 44 | public content::NotificationObserver { |
| 45 | public: |
| 46 | AboutHandler(); |
| 47 | ~AboutHandler() override; |
| 48 | |
| 49 | static AboutHandler* Create(content::WebUIDataSource* html_source, |
| 50 | Profile* profile); |
| 51 | |
| 52 | // WebUIMessageHandler implementation. |
| 53 | void RegisterMessages() override; |
| 54 | void OnJavascriptAllowed() override; |
| 55 | void OnJavascriptDisallowed() override; |
| 56 | |
| 57 | // NotificationObserver implementation. |
| 58 | void Observe(int type, |
| 59 | const content::NotificationSource& source, |
| 60 | const content::NotificationDetails& details) override; |
| 61 | |
| 62 | // Returns the browser version as a string. |
| 63 | static base::string16 BuildBrowserVersionString(); |
| 64 | |
| 65 | private: |
| 66 | void OnDeviceAutoUpdatePolicyChanged(const base::Value* previous_policy, |
| 67 | const base::Value* current_policy); |
| 68 | |
| 69 | // Called once when the page has loaded. On ChromeOS, this gets the current |
| 70 | // update status. On other platforms, it will request and perform an update |
| 71 | // (if one is available). |
| 72 | void HandleRefreshUpdateStatus(const base::ListValue* args); |
| 73 | void RefreshUpdateStatus(); |
| 74 | |
| 75 | #if defined(OS_MACOSX) |
| 76 | // Promotes the updater for all users. |
| 77 | void PromoteUpdater(const base::ListValue* args); |
| 78 | #endif |
| 79 | |
| 80 | // Relaunches the browser. |args| must be empty. |
| 81 | void HandleRelaunchNow(const base::ListValue* args); |
| 82 | |
| 83 | // Opens the feedback dialog. |args| must be empty. |
| 84 | void HandleOpenFeedbackDialog(const base::ListValue* args); |
| 85 | |
| 86 | // Opens the help page. |args| must be empty. |
| 87 | void HandleOpenHelpPage(const base::ListValue* args); |
| 88 | |
| 89 | #if defined(OS_CHROMEOS) |
| 90 | // Sets the release track version. |
| 91 | void HandleSetChannel(const base::ListValue* args); |
| 92 | |
| 93 | // Checks for and applies update, triggered by JS. |
| 94 | void HandleRequestUpdate(const base::ListValue* args); |
| 95 | |
| 96 | // Retrieves OS, ARC and firmware versions. |
| 97 | void HandleGetVersionInfo(const base::ListValue* args); |
| 98 | void OnGetVersionInfoReady( |
| 99 | std::string callback_id, |
| 100 | std::unique_ptr<base::DictionaryValue> version_info); |
| 101 | |
| 102 | void HandleGetCurrentChannel(const base::ListValue* args); |
| 103 | void HandleGetTargetChannel(const base::ListValue* args); |
| 104 | // C++ callback for either of |HandleGetCurrentChannel| or |
| 105 | // |HandleGetTargetChannel|, |
| 106 | void OnGetChannelReady(std::string callback_id, const std::string& channel); |
| 107 | #endif |
| 108 | |
| 109 | // Checks for and applies update. |
| 110 | void RequestUpdate(); |
| 111 | |
| 112 | // Callback method which forwards status updates to the page. |
| 113 | void SetUpdateStatus(VersionUpdater::Status status, |
| 114 | int progress, |
| 115 | const base::string16& fail_message); |
| 116 | |
| 117 | #if defined(OS_MACOSX) |
| 118 | // Callback method which forwards promotion state to the page. |
| 119 | void SetPromotionState(VersionUpdater::PromotionState state); |
| 120 | #endif |
| 121 | |
| 122 | #if defined(OS_CHROMEOS) |
| 123 | void HandleGetRegulatoryInfo(const base::ListValue* args); |
| 124 | |
| 125 | // Callback for when the directory with the regulatory label image and alt |
| 126 | // text has been found. |
| 127 | void OnRegulatoryLabelDirFound(std::string callback_id, |
| 128 | const base::FilePath& path); |
| 129 | |
| 130 | // Callback for when the regulatory text has been read. |
| 131 | void OnRegulatoryLabelTextRead(std::string callback_id, |
| 132 | const base::FilePath& path, |
| 133 | const std::string& text); |
| 134 | #endif |
| 135 | |
| 136 | // Specialized instance of the VersionUpdater used to update the browser. |
| 137 | std::unique_ptr<VersionUpdater> version_updater_; |
| 138 | |
| 139 | // Used to observe notifications. |
| 140 | content::NotificationRegistrar registrar_; |
| 141 | |
| 142 | // Used to observe changes in the |kDeviceAutoUpdateDisabled| policy. |
| 143 | std::unique_ptr<policy::PolicyChangeRegistrar> policy_registrar_; |
| 144 | |
| 145 | // Used for callbacks. |
| 146 | base::WeakPtrFactory<AboutHandler> weak_factory_; |
| 147 | |
| 148 | DISALLOW_COPY_AND_ASSIGN(AboutHandler); |
| 149 | }; |
| 150 | |
| 151 | } // namespace settings |
| 152 | |
| 153 | #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_ |