blob: 4c8ae08a2928dde251b3a19dade789c10de81fde [file] [log] [blame]
dpapad30d3baf2016-05-11 02:14:281// 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"
weidongg04695232017-06-09 00:01:0518#include "chrome/browser/upgrade_observer.h"
dpapad30d3baf2016-05-11 02:14:2819#include "components/policy/core/common/policy_service.h"
dpapad30d3baf2016-05-11 02:14:2820#include "content/public/browser/web_ui_message_handler.h"
21
22#if defined(OS_CHROMEOS)
23#include "base/task/cancelable_task_tracker.h"
Mattias Nissler3b52d692018-05-24 09:50:3724#include "chrome/browser/chromeos/tpm_firmware_update.h"
dpapad30d3baf2016-05-11 02:14:2825#endif // defined(OS_CHROMEOS)
26
27namespace base {
28class DictionaryValue;
29class FilePath;
30class ListValue;
31}
32
33namespace content {
34class WebUIDataSource;
35}
36
37class Profile;
38
39namespace settings {
40
41// WebUI message handler for the help page.
42class AboutHandler : public settings::SettingsPageUIHandler,
weidongg04695232017-06-09 00:01:0543 public UpgradeObserver {
dpapad30d3baf2016-05-11 02:14:2844 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
weidongg04695232017-06-09 00:01:0556 // UpgradeObserver implementation.
57 void OnUpgradeRecommended() override;
dpapad30d3baf2016-05-11 02:14:2858
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
dpapad03bb8f02016-05-19 04:27:0566 // 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
dpapad30d3baf2016-05-11 02:14:2870 // 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
dpapad30d3baf2016-05-11 02:14:2881 // 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
dpapad30d3baf2016-05-11 02:14:2891 // 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
stevenjb9d01f7a42016-12-08 01:46:4097 // 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
weidonggf472642f2017-05-14 22:10:02109 // Checks for and applies update over cellular connection, triggered by JS.
Weidong Guo8f8b700162017-07-28 19:37:02110 // Update version and size should be included in the list of arguments.
weidonggf472642f2017-05-14 22:10:02111 void HandleRequestUpdateOverCellular(const base::ListValue* args);
112
Weidong Guo8f8b700162017-07-28 19:37:02113 // Checks for and applies update over cellular connection.
114 void RequestUpdateOverCellular(const std::string& update_version,
115 int64_t update_size);
weidonggf472642f2017-05-14 22:10:02116
Mattias Nisslerbc43a832017-09-27 12:13:56117 // Called once when the page has loaded to retrieve the TPM firmware update
118 // status.
119 void HandleRefreshTPMFirmwareUpdateStatus(const base::ListValue* args);
Mattias Nissler3b52d692018-05-24 09:50:37120 void RefreshTPMFirmwareUpdateStatus(
121 const std::set<chromeos::tpm_firmware_update::Mode>& modes);
dpapad30d3baf2016-05-11 02:14:28122#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 Hunyady37ecdeb2018-07-20 18:10:07130 bool rollback,
weidonggf472642f2017-05-14 22:10:02131 const std::string& version,
132 int64_t size,
dpapad30d3baf2016-05-11 02:14:28133 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,
michaelpg807efe52016-06-28 00:13:08146 const base::FilePath& label_dir_path);
dpapad30d3baf2016-05-11 02:14:28147
148 // Callback for when the regulatory text has been read.
149 void OnRegulatoryLabelTextRead(std::string callback_id,
michaelpg807efe52016-06-28 00:13:08150 const base::FilePath& label_dir_path,
dpapad30d3baf2016-05-11 02:14:28151 const std::string& text);
Sarah Hu32816fa72018-02-28 02:20:38152
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);
dpapad30d3baf2016-05-11 02:14:28162#endif
163
164 // Specialized instance of the VersionUpdater used to update the browser.
165 std::unique_ptr<VersionUpdater> version_updater_;
166
dpapad30d3baf2016-05-11 02:14:28167 // Used to observe changes in the |kDeviceAutoUpdateDisabled| policy.
168 std::unique_ptr<policy::PolicyChangeRegistrar> policy_registrar_;
169
weidongg04695232017-06-09 00:01:05170 // If true changes to UpgradeObserver are applied, if false they are ignored.
171 bool apply_changes_from_upgrade_observer_;
172
dpapad30d3baf2016-05-11 02:14:28173 // 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_