Index: chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler.cc |
diff --git a/chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b0a92245a00a97f7aeab378773b733f0637c7122 |
--- /dev/null |
+++ b/chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler.cc |
@@ -0,0 +1,227 @@ |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler.h" |
+ |
+#include <string> |
+ |
+#include "base/command_line.h" |
+#include "base/metrics/histogram.h" |
xiyuan
2014/10/30 03:52:09
nit: seems not used.
zel
2014/10/31 01:22:26
Done.
|
+#include "base/prefs/pref_registry_simple.h" |
+#include "base/prefs/pref_service.h" |
+#include "base/values.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/chromeos/login/help_app_launcher.h" |
+#include "chrome/browser/chromeos/reset/metrics.h" |
xiyuan
2014/10/30 03:52:09
nit: seems not needed.
zel
2014/10/31 01:22:26
Done.
|
+#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
+#include "chrome/common/pref_names.h" |
+#include "chrome/grit/chromium_strings.h" |
+#include "chrome/grit/generated_resources.h" |
+#include "chromeos/chromeos_switches.h" |
+#include "chromeos/dbus/dbus_thread_manager.h" |
+#include "chromeos/dbus/debug_daemon_client.h" |
+#include "chromeos/dbus/power_manager_client.h" |
+#include "chromeos/dbus/session_manager_client.h" |
xiyuan
2014/10/30 03:52:09
nit: seems not used
zel
2014/10/31 01:22:26
Done.
|
+#include "content/public/browser/browser_thread.h" |
xiyuan
2014/10/30 03:52:08
nit: seems not used.
zel
2014/10/31 01:22:26
Done.
|
+ |
+namespace { |
+ |
+const char kJsScreenPath[] = "login.EnableDebuggingScreen"; |
+ |
+// Reset screen id. |
xiyuan
2014/10/30 03:52:08
nit: update comment or just get rid of it.
zel
2014/10/31 01:22:26
Done.
|
+const char kEnableDebuggingScreen[] = "debugging"; |
+ |
+} // namespace |
+ |
+namespace chromeos { |
+ |
+EnableDebuggingScreenHandler::EnableDebuggingScreenHandler() |
+ : BaseScreenHandler(kJsScreenPath), |
+ delegate_(NULL), |
+ show_on_init_(false), |
+ ready_for_setup_(false), |
+ weak_ptr_factory_(this) { |
+} |
+ |
+EnableDebuggingScreenHandler::~EnableDebuggingScreenHandler() { |
+ if (delegate_) |
+ delegate_->OnActorDestroyed(this); |
+} |
+ |
+void EnableDebuggingScreenHandler::PrepareToShow() { |
+} |
+ |
+void EnableDebuggingScreenHandler::ShowWithParams() { |
+ PrefService* prefs = g_browser_process->local_state(); |
+ prefs->SetBoolean(prefs::kDebuggingFeaturesRequested, false); |
xiyuan
2014/10/30 03:52:08
nit: how about call ClearPref()?
zel
2014/10/31 01:22:26
Done.
|
+ prefs->CommitPendingWrite(); |
+ base::DictionaryValue debugging_screen_params; |
+ debugging_screen_params.SetBoolean("needsRootfsRemoval", |
+ !ready_for_setup_); |
+#if defined(OFFICIAL_BUILD) |
+ debugging_screen_params.SetBoolean("isOfficialBuild", true); |
+#endif |
+ ShowScreen(kEnableDebuggingScreen, &debugging_screen_params); |
+} |
+ |
+void EnableDebuggingScreenHandler::Show() { |
+ if (!page_is_ready()) { |
+ show_on_init_ = true; |
+ return; |
+ } |
+ |
+ ChooseAndApplyShowScenario(); |
+} |
+ |
+void EnableDebuggingScreenHandler::ChooseAndApplyShowScenario() { |
+ PrefService* prefs = g_browser_process->local_state(); |
+ bool fresh_start = !CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kFirstExecAfterBoot); |
+ |
+ // TODO: Check if we have permission to show anything here. |
+ if (fresh_start) { // First exec after boot. |
+ ready_for_setup_ = prefs->GetBoolean(prefs::kDebuggingFeaturesRequested); |
+ } |
+ ShowWithParams(); |
+} |
+ |
+void EnableDebuggingScreenHandler::Hide() { |
+} |
+ |
+void EnableDebuggingScreenHandler::SetDelegate(Delegate* delegate) { |
+ delegate_ = delegate; |
+ if (page_is_ready()) |
+ Initialize(); |
+} |
+ |
+void EnableDebuggingScreenHandler::DeclareLocalizedValues( |
+ LocalizedValuesBuilder* builder) { |
+ builder->Add("enableDebuggingScreenTitle", |
+ IDS_ENABLE_DEBUGGING_SCREEN_TITLE); |
+ builder->Add("enableDebuggingScreenAccessibleTitle", |
+ IDS_ENABLE_DEBUGGING_SCREEN_TITLE); |
+ builder->Add("enableDebuggingScreenIconTitle", IDS_EXCLAMATION_ICON_TITLE); |
+ builder->Add("enableDebuggingCancelButton", IDS_CANCEL); |
+ builder->Add("enableDebuggingOKButton", IDS_OK); |
+ builder->Add("enableDebuggingRemoveButton", |
+ IDS_ENABLE_DEBUGGING_REMOVE_ROOTFS_BUTTON); |
+ builder->Add("enableDebuggingEnableButton", |
+ IDS_ENABLE_DEBUGGING_ENABLE_BUTTON); |
+ builder->Add("enableDebuggingRemveRootfsMessage", |
+ IDS_ENABLE_DEBUGGING_SCREEN_ROOTFS_REMOVE_MSG); |
+ builder->Add("enableDebuggingSetupMessage", |
+ IDS_ENABLE_DEBUGGING_SETUP_MESSAGE); |
+ builder->Add("enableDebuggingWaitMessage", |
+ IDS_ENABLE_DEBUGGING_WAIT_MESSAGE); |
+ builder->AddF("enableDebuggingWarningTitle", |
+ IDS_ENABLE_DEBUGGING_SCREEN_WARNING_MSG, |
+ IDS_SHORT_PRODUCT_NAME); |
+ builder->AddF("enableDebuggingDoneMessage", |
+ IDS_ENABLE_DEBUGGING_DONE_MESSAGE, |
+ IDS_SHORT_PRODUCT_NAME); |
+ builder->Add("enableDebuggingPasswordLabel", |
+ IDS_ENABLE_DEBUGGING_ROOT_PASSWORD_LABEL); |
+ builder->Add("enableDebuggingConfirmPasswordLabel", |
+ IDS_ENABLE_DEBUGGING_CONFIRM_PASSWORD_LABEL); |
+ builder->Add("enableDebuggingPasswordLengthNote", |
+ IDS_ENABLE_DEBUGGING_EMPTY_ROOT_PASSWORD_LABEL); |
+} |
+ |
+// static |
+void EnableDebuggingScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { |
+ registry->RegisterBooleanPref(prefs::kDebuggingFeaturesRequested, false); |
+} |
+ |
+void EnableDebuggingScreenHandler::Initialize() { |
+ if (!page_is_ready() || !delegate_) |
+ return; |
+ |
+ if (show_on_init_) { |
+ Show(); |
+ show_on_init_ = false; |
+ } |
+} |
+ |
+void EnableDebuggingScreenHandler::RegisterMessages() { |
+ AddCallback("enableDebuggingOnCancel", |
+ &EnableDebuggingScreenHandler::HandleOnCancel); |
+ AddCallback("enableDebuggingOnDone", |
+ &EnableDebuggingScreenHandler::HandleOnDone); |
+ AddCallback("enableDebuggingOnLearnMore", |
+ &EnableDebuggingScreenHandler::HandleOnLearnMore); |
+ AddCallback("enableDebuggingOnRemoveRootFSProtection", |
+ &EnableDebuggingScreenHandler::HandleOnRemoveRootFSProtection); |
+ AddCallback("enableDebuggingOnSetup", |
+ &EnableDebuggingScreenHandler::HandleOnSetup); |
+} |
+ |
+void EnableDebuggingScreenHandler::HandleOnCancel() { |
+ if (delegate_) |
+ delegate_->OnExit(false); |
+} |
+ |
+void EnableDebuggingScreenHandler::HandleOnDone() { |
+ if (delegate_) |
+ delegate_->OnExit(true); |
+} |
+ |
+void EnableDebuggingScreenHandler::HandleOnRemoveRootFSProtection() { |
+ UpdateUIState(UI_STATE_WAIT); |
+ chromeos::DebugDaemonClient* client = |
+ chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
+ client->RemoveRootfsVerification( |
+ base::Bind(&EnableDebuggingScreenHandler::OnRemoveRootfsVerification, |
+ weak_ptr_factory_.GetWeakPtr())); |
+} |
+ |
+void EnableDebuggingScreenHandler::HandleOnSetup( |
+ const std::string& password) { |
+ UpdateUIState(UI_STATE_WAIT); |
+ chromeos::DebugDaemonClient* client = |
+ chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
+ client->EnableDebuggingFeatures( |
+ password, |
+ base::Bind(&EnableDebuggingScreenHandler::OnEnableDebuggingFeatures, |
+ weak_ptr_factory_.GetWeakPtr())); |
+} |
+ |
+// Removes rootfs verification, add flag to start with enable debugging features |
+// screen and reboots the machine. |
+void EnableDebuggingScreenHandler::OnRemoveRootfsVerification(bool success) { |
+ if (!success) { |
+ UpdateUIState(UI_STATE_ERROR); |
+ return; |
+ } |
+ |
+ PrefService* prefs = g_browser_process->local_state(); |
+ prefs->SetBoolean(prefs::kDebuggingFeaturesRequested, true); |
+ prefs->CommitPendingWrite(); |
+ chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
+} |
+ |
+ |
+void EnableDebuggingScreenHandler::OnEnableDebuggingFeatures(bool success) { |
+ if (!success) { |
+ UpdateUIState(UI_STATE_ERROR); |
+ return; |
+ } |
+ |
+ UpdateUIState(UI_STATE_DONE); |
+} |
+ |
+void EnableDebuggingScreenHandler::UpdateUIState( |
+ EnableDebuggingScreenHandler::UIState state) { |
+ web_ui()->CallJavascriptFunction( |
+ "login.EnableDebuggingScreen.updateState", |
+ base::FundamentalValue(static_cast<int>(state))); |
+} |
+ |
+void EnableDebuggingScreenHandler::HandleOnLearnMore() { |
+ VLOG(1) << "Trying to view the help article about debugging features."; |
+ if (!help_app_.get()) |
+ help_app_ = new HelpAppLauncher(GetNativeWindow()); |
+ help_app_->ShowHelpTopic(HelpAppLauncher::HELP_ENABLE_DEBUGGING); |
+} |
+ |
+} // namespace chromeos |