Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 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 #include "chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler .h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/command_line.h" | |
| 10 #include "base/prefs/pref_registry_simple.h" | |
| 11 #include "base/prefs/pref_service.h" | |
| 12 #include "base/values.h" | |
| 13 #include "chrome/browser/browser_process.h" | |
| 14 #include "chrome/browser/chromeos/login/help_app_launcher.h" | |
| 15 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | |
| 16 #include "chrome/common/pref_names.h" | |
| 17 #include "chrome/grit/chromium_strings.h" | |
| 18 #include "chrome/grit/generated_resources.h" | |
| 19 #include "chromeos/chromeos_switches.h" | |
| 20 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 21 #include "chromeos/dbus/debug_daemon_client.h" | |
| 22 #include "chromeos/dbus/power_manager_client.h" | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 const char kJsScreenPath[] = "login.EnableDebuggingScreen"; | |
| 27 | |
| 28 const char kEnableDebuggingScreen[] = "debugging"; | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 namespace chromeos { | |
| 33 | |
| 34 EnableDebuggingScreenHandler::EnableDebuggingScreenHandler() | |
| 35 : BaseScreenHandler(kJsScreenPath), | |
| 36 delegate_(NULL), | |
| 37 show_on_init_(false), | |
| 38 weak_ptr_factory_(this) { | |
| 39 } | |
| 40 | |
| 41 EnableDebuggingScreenHandler::~EnableDebuggingScreenHandler() { | |
| 42 if (delegate_) | |
| 43 delegate_->OnActorDestroyed(this); | |
| 44 } | |
| 45 | |
| 46 void EnableDebuggingScreenHandler::PrepareToShow() { | |
| 47 } | |
| 48 | |
| 49 void EnableDebuggingScreenHandler::ShowWithParams() { | |
| 50 base::DictionaryValue debugging_screen_params; | |
| 51 #if defined(OFFICIAL_BUILD) | |
| 52 debugging_screen_params.SetBoolean("isOfficialBuild", true); | |
| 53 #endif | |
| 54 ShowScreen(kEnableDebuggingScreen, &debugging_screen_params); | |
| 55 | |
| 56 // Check the status of debugging features. | |
| 57 chromeos::DebugDaemonClient* client = | |
| 58 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | |
| 59 client->QueryDebuggingFeatures( | |
| 60 base::Bind(&EnableDebuggingScreenHandler::OnQueryDebuggingFeatures, | |
| 61 weak_ptr_factory_.GetWeakPtr())); | |
| 62 } | |
| 63 | |
| 64 void EnableDebuggingScreenHandler::Show() { | |
| 65 if (!page_is_ready()) { | |
| 66 show_on_init_ = true; | |
| 67 return; | |
| 68 } | |
| 69 | |
| 70 ShowWithParams(); | |
| 71 } | |
| 72 | |
| 73 void EnableDebuggingScreenHandler::Hide() { | |
| 74 weak_ptr_factory_.InvalidateWeakPtrs(); | |
| 75 } | |
| 76 | |
| 77 void EnableDebuggingScreenHandler::SetDelegate(Delegate* delegate) { | |
| 78 delegate_ = delegate; | |
| 79 if (page_is_ready()) | |
| 80 Initialize(); | |
| 81 } | |
| 82 | |
| 83 void EnableDebuggingScreenHandler::DeclareLocalizedValues( | |
| 84 LocalizedValuesBuilder* builder) { | |
| 85 builder->Add("enableDebuggingScreenTitle", | |
| 86 IDS_ENABLE_DEBUGGING_SCREEN_TITLE); | |
| 87 builder->Add("enableDebuggingScreenAccessibleTitle", | |
| 88 IDS_ENABLE_DEBUGGING_SCREEN_TITLE); | |
| 89 builder->Add("enableDebuggingScreenIconTitle", IDS_EXCLAMATION_ICON_TITLE); | |
| 90 builder->Add("enableDebuggingCancelButton", IDS_CANCEL); | |
| 91 builder->Add("enableDebuggingOKButton", IDS_OK); | |
| 92 builder->Add("enableDebuggingRemoveButton", | |
| 93 IDS_ENABLE_DEBUGGING_REMOVE_ROOTFS_BUTTON); | |
| 94 builder->Add("enableDebuggingEnableButton", | |
| 95 IDS_ENABLE_DEBUGGING_ENABLE_BUTTON); | |
| 96 builder->Add("enableDebuggingRemveRootfsMessage", | |
| 97 IDS_ENABLE_DEBUGGING_SCREEN_ROOTFS_REMOVE_MSG); | |
| 98 builder->Add("enableDebuggingSetupMessage", | |
| 99 IDS_ENABLE_DEBUGGING_SETUP_MESSAGE); | |
| 100 builder->Add("enableDebuggingWaitMessage", | |
| 101 IDS_ENABLE_DEBUGGING_WAIT_MESSAGE); | |
| 102 builder->AddF("enableDebuggingWarningTitle", | |
| 103 IDS_ENABLE_DEBUGGING_SCREEN_WARNING_MSG, | |
| 104 IDS_SHORT_PRODUCT_NAME); | |
| 105 builder->AddF("enableDebuggingDoneMessage", | |
| 106 IDS_ENABLE_DEBUGGING_DONE_MESSAGE, | |
| 107 IDS_SHORT_PRODUCT_NAME); | |
| 108 builder->AddF("enableDebuggingErrorMessage", | |
| 109 IDS_ENABLE_DEBUGGING_ERROR_MESSAGE, | |
| 110 IDS_SHORT_PRODUCT_NAME); | |
| 111 builder->Add("enableDebuggingPasswordLabel", | |
| 112 IDS_ENABLE_DEBUGGING_ROOT_PASSWORD_LABEL); | |
| 113 builder->Add("enableDebuggingConfirmPasswordLabel", | |
| 114 IDS_ENABLE_DEBUGGING_CONFIRM_PASSWORD_LABEL); | |
| 115 builder->Add("enableDebuggingPasswordLengthNote", | |
| 116 IDS_ENABLE_DEBUGGING_EMPTY_ROOT_PASSWORD_LABEL); | |
| 117 } | |
| 118 | |
| 119 // static | |
| 120 void EnableDebuggingScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { | |
| 121 registry->RegisterBooleanPref(prefs::kDebuggingFeaturesRequested, false); | |
| 122 } | |
| 123 | |
| 124 void EnableDebuggingScreenHandler::Initialize() { | |
| 125 if (!page_is_ready() || !delegate_) | |
| 126 return; | |
| 127 | |
| 128 if (show_on_init_) { | |
| 129 Show(); | |
| 130 show_on_init_ = false; | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 void EnableDebuggingScreenHandler::RegisterMessages() { | |
| 135 AddCallback("enableDebuggingOnCancel", | |
| 136 &EnableDebuggingScreenHandler::HandleOnCancel); | |
| 137 AddCallback("enableDebuggingOnDone", | |
| 138 &EnableDebuggingScreenHandler::HandleOnDone); | |
| 139 AddCallback("enableDebuggingOnLearnMore", | |
| 140 &EnableDebuggingScreenHandler::HandleOnLearnMore); | |
| 141 AddCallback("enableDebuggingOnRemoveRootFSProtection", | |
| 142 &EnableDebuggingScreenHandler::HandleOnRemoveRootFSProtection); | |
| 143 AddCallback("enableDebuggingOnSetup", | |
| 144 &EnableDebuggingScreenHandler::HandleOnSetup); | |
| 145 } | |
| 146 | |
| 147 void EnableDebuggingScreenHandler::HandleOnCancel() { | |
| 148 if (delegate_) | |
| 149 delegate_->OnExit(false); | |
| 150 } | |
| 151 | |
| 152 void EnableDebuggingScreenHandler::HandleOnDone() { | |
| 153 if (delegate_) | |
| 154 delegate_->OnExit(true); | |
| 155 } | |
| 156 | |
| 157 void EnableDebuggingScreenHandler::HandleOnRemoveRootFSProtection() { | |
| 158 UpdateUIState(UI_STATE_WAIT); | |
| 159 chromeos::DebugDaemonClient* client = | |
| 160 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | |
| 161 client->RemoveRootfsVerification( | |
| 162 base::Bind(&EnableDebuggingScreenHandler::OnRemoveRootfsVerification, | |
| 163 weak_ptr_factory_.GetWeakPtr())); | |
| 164 } | |
| 165 | |
| 166 void EnableDebuggingScreenHandler::HandleOnSetup( | |
| 167 const std::string& password) { | |
| 168 UpdateUIState(UI_STATE_WAIT); | |
| 169 chromeos::DebugDaemonClient* client = | |
| 170 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | |
| 171 client->EnableDebuggingFeatures( | |
| 172 password, | |
| 173 base::Bind(&EnableDebuggingScreenHandler::OnEnableDebuggingFeatures, | |
| 174 weak_ptr_factory_.GetWeakPtr())); | |
| 175 } | |
| 176 | |
| 177 // Removes rootfs verification, add flag to start with enable debugging features | |
| 178 // screen and reboots the machine. | |
| 179 void EnableDebuggingScreenHandler::OnRemoveRootfsVerification(bool success) { | |
| 180 if (!success) { | |
| 181 UpdateUIState(UI_STATE_ERROR); | |
| 182 return; | |
| 183 } | |
| 184 | |
| 185 PrefService* prefs = g_browser_process->local_state(); | |
| 186 prefs->SetBoolean(prefs::kDebuggingFeaturesRequested, true); | |
| 187 prefs->CommitPendingWrite(); | |
| 188 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | |
| 189 } | |
| 190 | |
| 191 | |
| 192 void EnableDebuggingScreenHandler::OnEnableDebuggingFeatures(bool success) { | |
| 193 if (!success) { | |
| 194 UpdateUIState(UI_STATE_ERROR); | |
| 195 return; | |
| 196 } | |
| 197 | |
| 198 UpdateUIState(UI_STATE_DONE); | |
| 199 } | |
| 200 | |
| 201 | |
| 202 void EnableDebuggingScreenHandler::OnQueryDebuggingFeatures(bool success, | |
| 203 int features_flag) { | |
| 204 if (!success || features_flag == DebugDaemonClient::DEV_FEATURES_DISABLED) { | |
| 205 UpdateUIState(UI_STATE_ERROR); | |
| 206 return; | |
| 207 } | |
| 208 | |
| 209 if (features_flag == DebugDaemonClient::DEV_FEATURE_NONE) { | |
| 210 UpdateUIState(UI_STATE_REMOVE_PROTECTION); | |
| 211 return; | |
| 212 } | |
| 213 | |
| 214 if (features_flag & DebugDaemonClient::DEV_FEATURE_ALL_ENABLED) { | |
| 215 UpdateUIState(UI_STATE_DONE); | |
| 216 } else if (features_flag & | |
| 217 DebugDaemonClient::DEV_FEATURE_ROOTFS_VERIFICATION_REMOVED) { | |
| 218 UpdateUIState(UI_STATE_SETUP); | |
| 219 } else { | |
| 220 LOG(WARNING) << "Unexpected status of debugging features:" << features_flag; | |
| 221 UpdateUIState(UI_STATE_ERROR); | |
| 222 } | |
| 223 } | |
| 224 | |
| 225 void EnableDebuggingScreenHandler::UpdateUIState( | |
| 226 EnableDebuggingScreenHandler::UIState state) { | |
| 227 if (state == UI_STATE_ERROR || state == UI_STATE_DONE) { | |
| 228 PrefService* prefs = g_browser_process->local_state(); | |
| 229 prefs->ClearPref(prefs::kDebuggingFeaturesRequested); | |
| 230 prefs->CommitPendingWrite(); | |
| 231 } | |
| 232 | |
| 233 web_ui()->CallJavascriptFunction( | |
| 234 "login.EnableDebuggingScreen.updateState", | |
| 235 base::FundamentalValue(static_cast<int>(state))); | |
| 236 } | |
| 237 | |
| 238 void EnableDebuggingScreenHandler::HandleOnLearnMore() { | |
| 239 VLOG(1) << "Trying to view the help article about debugging features."; | |
| 240 if (!help_app_.get()) | |
| 241 help_app_ = new HelpAppLauncher(GetNativeWindow()); | |
| 242 help_app_->ShowHelpTopic(HelpAppLauncher::HELP_ENABLE_DEBUGGING); | |
|
Nikita (slow)
2014/11/05 17:33:15
I suggest commenting out this line till real help
| |
| 243 } | |
| 244 | |
| 245 } // namespace chromeos | |
| OLD | NEW |