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" |
weidongg | 0469523 | 2017-06-09 00:01:05 | [diff] [blame] | 18 | #include "chrome/browser/upgrade_observer.h" |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 19 | #include "components/policy/core/common/policy_service.h" |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 20 | #include "content/public/browser/web_ui_message_handler.h" |
| 21 | |
| 22 | #if defined(OS_CHROMEOS) |
| 23 | #include "base/task/cancelable_task_tracker.h" |
Mattias Nissler | 3b52d69 | 2018-05-24 09:50:37 | [diff] [blame] | 24 | #include "chrome/browser/chromeos/tpm_firmware_update.h" |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 25 | #endif // defined(OS_CHROMEOS) |
| 26 | |
| 27 | namespace base { |
| 28 | class DictionaryValue; |
| 29 | class FilePath; |
| 30 | class ListValue; |
| 31 | } |
| 32 | |
| 33 | namespace content { |
| 34 | class WebUIDataSource; |
| 35 | } |
| 36 | |
| 37 | class Profile; |
| 38 | |
| 39 | namespace settings { |
| 40 | |
| 41 | // WebUI message handler for the help page. |
| 42 | class AboutHandler : public settings::SettingsPageUIHandler, |
weidongg | 0469523 | 2017-06-09 00:01:05 | [diff] [blame] | 43 | public UpgradeObserver { |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 44 | public: |
| 45 | AboutHandler(); |
| 46 | ~AboutHandler() override; |
| 47 | |
| 48 | static AboutHandler* Create(content::WebUIDataSource* html_source, |
| 49 | Profile* profile); |
| 50 | |
| 51 | // WebUIMessageHandler implementation. |
| 52 | void RegisterMessages() override; |
| 53 | void OnJavascriptAllowed() override; |
| 54 | void OnJavascriptDisallowed() override; |
| 55 | |
weidongg | 0469523 | 2017-06-09 00:01:05 | [diff] [blame] | 56 | // UpgradeObserver implementation. |
| 57 | void OnUpgradeRecommended() override; |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 58 | |
| 59 | // Returns the browser version as a string. |
| 60 | static base::string16 BuildBrowserVersionString(); |
| 61 | |
| 62 | private: |
| 63 | void OnDeviceAutoUpdatePolicyChanged(const base::Value* previous_policy, |
| 64 | const base::Value* current_policy); |
| 65 | |
dpapad | 03bb8f0 | 2016-05-19 04:27:05 | [diff] [blame] | 66 | // Called once the JS page is ready to be called, serves as a signal to the |
| 67 | // handler to register C++ observers. |
| 68 | void HandlePageReady(const base::ListValue* args); |
| 69 | |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 70 | // Called once when the page has loaded. On ChromeOS, this gets the current |
| 71 | // update status. On other platforms, it will request and perform an update |
| 72 | // (if one is available). |
| 73 | void HandleRefreshUpdateStatus(const base::ListValue* args); |
| 74 | void RefreshUpdateStatus(); |
| 75 | |
| 76 | #if defined(OS_MACOSX) |
| 77 | // Promotes the updater for all users. |
| 78 | void PromoteUpdater(const base::ListValue* args); |
| 79 | #endif |
| 80 | |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 81 | // Opens the feedback dialog. |args| must be empty. |
| 82 | void HandleOpenFeedbackDialog(const base::ListValue* args); |
| 83 | |
| 84 | // Opens the help page. |args| must be empty. |
| 85 | void HandleOpenHelpPage(const base::ListValue* args); |
| 86 | |
| 87 | #if defined(OS_CHROMEOS) |
| 88 | // Sets the release track version. |
| 89 | void HandleSetChannel(const base::ListValue* args); |
| 90 | |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 91 | // Retrieves OS, ARC and firmware versions. |
| 92 | void HandleGetVersionInfo(const base::ListValue* args); |
| 93 | void OnGetVersionInfoReady( |
| 94 | std::string callback_id, |
| 95 | std::unique_ptr<base::DictionaryValue> version_info); |
| 96 | |
stevenjb | 9d01f7a4 | 2016-12-08 01:46:40 | [diff] [blame] | 97 | // Retrieves combined channel info. |
| 98 | void HandleGetChannelInfo(const base::ListValue* args); |
| 99 | // Callbacks for version_updater_->GetChannel calls. |
| 100 | void OnGetCurrentChannel(std::string callback_id, |
| 101 | const std::string& current_channel); |
| 102 | void OnGetTargetChannel(std::string callback_id, |
| 103 | const std::string& current_channel, |
| 104 | const std::string& target_channel); |
| 105 | |
| 106 | // Checks for and applies update, triggered by JS. |
| 107 | void HandleRequestUpdate(const base::ListValue* args); |
| 108 | |
weidongg | f472642f | 2017-05-14 22:10:02 | [diff] [blame] | 109 | // Checks for and applies update over cellular connection, triggered by JS. |
Weidong Guo | 8f8b70016 | 2017-07-28 19:37:02 | [diff] [blame] | 110 | // Update version and size should be included in the list of arguments. |
weidongg | f472642f | 2017-05-14 22:10:02 | [diff] [blame] | 111 | void HandleRequestUpdateOverCellular(const base::ListValue* args); |
| 112 | |
Weidong Guo | 8f8b70016 | 2017-07-28 19:37:02 | [diff] [blame] | 113 | // Checks for and applies update over cellular connection. |
| 114 | void RequestUpdateOverCellular(const std::string& update_version, |
| 115 | int64_t update_size); |
weidongg | f472642f | 2017-05-14 22:10:02 | [diff] [blame] | 116 | |
Mattias Nissler | bc43a83 | 2017-09-27 12:13:56 | [diff] [blame] | 117 | // Called once when the page has loaded to retrieve the TPM firmware update |
| 118 | // status. |
| 119 | void HandleRefreshTPMFirmwareUpdateStatus(const base::ListValue* args); |
Mattias Nissler | 3b52d69 | 2018-05-24 09:50:37 | [diff] [blame] | 120 | void RefreshTPMFirmwareUpdateStatus( |
| 121 | const std::set<chromeos::tpm_firmware_update::Mode>& modes); |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 122 | #endif |
| 123 | |
| 124 | // Checks for and applies update. |
| 125 | void RequestUpdate(); |
| 126 | |
| 127 | // Callback method which forwards status updates to the page. |
| 128 | void SetUpdateStatus(VersionUpdater::Status status, |
| 129 | int progress, |
Marton Hunyady | 37ecdeb | 2018-07-20 18:10:07 | [diff] [blame] | 130 | bool rollback, |
weidongg | f472642f | 2017-05-14 22:10:02 | [diff] [blame] | 131 | const std::string& version, |
| 132 | int64_t size, |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 133 | const base::string16& fail_message); |
| 134 | |
| 135 | #if defined(OS_MACOSX) |
| 136 | // Callback method which forwards promotion state to the page. |
| 137 | void SetPromotionState(VersionUpdater::PromotionState state); |
| 138 | #endif |
| 139 | |
| 140 | #if defined(OS_CHROMEOS) |
| 141 | void HandleGetRegulatoryInfo(const base::ListValue* args); |
| 142 | |
| 143 | // Callback for when the directory with the regulatory label image and alt |
| 144 | // text has been found. |
| 145 | void OnRegulatoryLabelDirFound(std::string callback_id, |
michaelpg | 807efe5 | 2016-06-28 00:13:08 | [diff] [blame] | 146 | const base::FilePath& label_dir_path); |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 147 | |
| 148 | // Callback for when the regulatory text has been read. |
| 149 | void OnRegulatoryLabelTextRead(std::string callback_id, |
michaelpg | 807efe5 | 2016-06-28 00:13:08 | [diff] [blame] | 150 | const base::FilePath& label_dir_path, |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 151 | const std::string& text); |
Sarah Hu | 32816fa7 | 2018-02-28 02:20:38 | [diff] [blame] | 152 | |
| 153 | // Retrieves device end of life status. |
| 154 | // Will asynchronously resolve the provided callback with a boolean |
| 155 | // indicating whether the device has reached end-of-life status (will no |
| 156 | // longer receive updates). |
| 157 | void HandleGetHasEndOfLife(const base::ListValue* args); |
| 158 | |
| 159 | // Callbacks for version_updater_->GetEolStatus calls. |
| 160 | void OnGetEndOfLifeStatus(std::string callback_id, |
| 161 | update_engine::EndOfLifeStatus status); |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 162 | #endif |
| 163 | |
| 164 | // Specialized instance of the VersionUpdater used to update the browser. |
| 165 | std::unique_ptr<VersionUpdater> version_updater_; |
| 166 | |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 167 | // Used to observe changes in the |kDeviceAutoUpdateDisabled| policy. |
| 168 | std::unique_ptr<policy::PolicyChangeRegistrar> policy_registrar_; |
| 169 | |
weidongg | 0469523 | 2017-06-09 00:01:05 | [diff] [blame] | 170 | // If true changes to UpgradeObserver are applied, if false they are ignored. |
| 171 | bool apply_changes_from_upgrade_observer_; |
| 172 | |
dpapad | 30d3baf | 2016-05-11 02:14:28 | [diff] [blame] | 173 | // Used for callbacks. |
| 174 | base::WeakPtrFactory<AboutHandler> weak_factory_; |
| 175 | |
| 176 | DISALLOW_COPY_AND_ASSIGN(AboutHandler); |
| 177 | }; |
| 178 | |
| 179 | } // namespace settings |
| 180 | |
| 181 | #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_ |