Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Unified Diff: chrome/browser/ui/webui/settings/chromeos/device_keyboard_handler.cc

Issue 1961183002: MD Settings: Update some Settings handlers to use new JS lifecycle management. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/settings/chromeos/device_keyboard_handler.cc
diff --git a/chrome/browser/ui/webui/settings/chromeos/device_keyboard_handler.cc b/chrome/browser/ui/webui/settings/chromeos/device_keyboard_handler.cc
index d2a9f317a36ff6a0a6fd5186f1c473bf09f0879a..ba65d6e641a76aae36fe10e220cc98507a004502 100644
--- a/chrome/browser/ui/webui/settings/chromeos/device_keyboard_handler.cc
+++ b/chrome/browser/ui/webui/settings/chromeos/device_keyboard_handler.cc
@@ -33,12 +33,9 @@ namespace chromeos {
namespace settings {
KeyboardHandler::KeyboardHandler(content::WebUI* webui)
- : profile_(Profile::FromWebUI(webui)) {
- ui::DeviceDataManager::GetInstance()->AddObserver(this);
-}
+ : profile_(Profile::FromWebUI(webui)), observer_(this) {}
KeyboardHandler::~KeyboardHandler() {
- ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
}
void KeyboardHandler::RegisterMessages() {
@@ -52,11 +49,20 @@ void KeyboardHandler::RegisterMessages() {
base::Unretained(this)));
}
+void KeyboardHandler::OnJavascriptAllowed() {
+ observer_.Add(ui::DeviceDataManager::GetInstance());
+}
+
+void KeyboardHandler::OnJavascriptDisallowed() {
+ observer_.RemoveAll();
+}
+
void KeyboardHandler::OnKeyboardDeviceConfigurationChanged() {
UpdateShowKeys();
}
void KeyboardHandler::HandleInitialize(const base::ListValue* args) {
+ AllowJavascript();
UpdateShowKeys();
}
@@ -65,15 +71,14 @@ void KeyboardHandler::HandleShowKeyboardShortcutsOverlay(
ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay();
}
-void KeyboardHandler::UpdateShowKeys() const {
+void KeyboardHandler::UpdateShowKeys() {
const base::FundamentalValue has_caps_lock(HasExternalKeyboard());
const base::FundamentalValue has_diamond_key(
base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kHasChromeOSDiamondKey));
- web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
- base::StringValue("show-keys-changed"),
- has_caps_lock,
- has_diamond_key);
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("show-keys-changed"), has_caps_lock,
+ has_diamond_key);
}
} // namespace settings

Powered by Google App Engine
This is Rietveld 408576698