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 virtual ~HelpHandler(); 34 35 // WebUIMessageHandler implementation. 36 virtual 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 virtual void Observe(int type, const content::NotificationSource& source, 43 const content::NotificationDetails& details) OVERRIDE; 44 45 // Returns the browser version as a string. 46 static base::string16 BuildBrowserVersionString(); 47 48 private: 49 // Initializes querying values for the page. 50 void OnPageLoaded(const base::ListValue* args); 51 52 #if defined(OS_MACOSX) 53 // Promotes the updater for all users. 54 void PromoteUpdater(const base::ListValue* args); 55 #endif 56 57 // Relaunches the browser. |args| must be empty. 58 void RelaunchNow(const base::ListValue* args); 59 60 // Opens the feedback dialog. |args| must be empty. 61 void OpenFeedbackDialog(const base::ListValue* args); 62 63 // Opens the help page. |args| must be empty. 64 void OpenHelpPage(const base::ListValue* args); 65 66 #if defined(OS_CHROMEOS) 67 // Sets the release track version. 68 void SetChannel(const base::ListValue* args); 69 70 // Performs relaunch and powerwash. 71 void RelaunchAndPowerwash(const base::ListValue* args); 72 #endif 73 74 // Checks for and applies update. 75 void RequestUpdate(const base::ListValue* args); 76 77 // Callback method which forwards status updates to the page. 78 void SetUpdateStatus(VersionUpdater::Status status, int progress, 79 const base::string16& fail_message); 80 81 #if defined(OS_MACOSX) 82 // Callback method which forwards promotion state to the page. 83 void SetPromotionState(VersionUpdater::PromotionState state); 84 #endif 85 86 #if defined(OS_CHROMEOS) 87 // Callbacks from VersionLoader. 88 void OnOSVersion(const std::string& version); 89 void OnOSFirmware(const std::string& firmware); 90 void OnCurrentChannel(const std::string& channel); 91 void OnTargetChannel(const std::string& channel); 92 #endif 93 94 // Specialized instance of the VersionUpdater used to update the browser. 95 scoped_ptr<VersionUpdater> version_updater_; 96 97 // Used to observe notifications. 98 content::NotificationRegistrar registrar_; 99 100 #if defined(OS_CHROMEOS) 101 // Handles asynchronously loading the CrOS version info. 102 chromeos::VersionLoader loader_; 103 104 // Used to request the version. 105 base::CancelableTaskTracker tracker_; 106 #endif // defined(OS_CHROMEOS) 107 108 // Used for callbacks. 109 base::WeakPtrFactory<HelpHandler> weak_factory_; 110 111 DISALLOW_COPY_AND_ASSIGN(HelpHandler); 112 }; 113 114 #endif // CHROME_BROWSER_UI_WEBUI_HELP_HELP_HANDLER_H_ 115