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