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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 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 #include "chrome/browser/ui/webui/settings/chromeos/device_keyboard_handler.h" 5 #include "chrome/browser/ui/webui/settings/chromeos/device_keyboard_handler.h"
6 6
7 #include "ash/new_window_delegate.h" 7 #include "ash/new_window_delegate.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 15 matching lines...) Expand all
26 26
27 return false; 27 return false;
28 } 28 }
29 29
30 } // namespace 30 } // namespace
31 31
32 namespace chromeos { 32 namespace chromeos {
33 namespace settings { 33 namespace settings {
34 34
35 KeyboardHandler::KeyboardHandler(content::WebUI* webui) 35 KeyboardHandler::KeyboardHandler(content::WebUI* webui)
36 : profile_(Profile::FromWebUI(webui)) { 36 : profile_(Profile::FromWebUI(webui)), observer_(this) {}
37 ui::DeviceDataManager::GetInstance()->AddObserver(this);
38 }
39 37
40 KeyboardHandler::~KeyboardHandler() { 38 KeyboardHandler::~KeyboardHandler() {
41 ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
42 } 39 }
43 40
44 void KeyboardHandler::RegisterMessages() { 41 void KeyboardHandler::RegisterMessages() {
45 web_ui()->RegisterMessageCallback( 42 web_ui()->RegisterMessageCallback(
46 "initializeKeyboardSettings", 43 "initializeKeyboardSettings",
47 base::Bind(&KeyboardHandler::HandleInitialize, 44 base::Bind(&KeyboardHandler::HandleInitialize,
48 base::Unretained(this))); 45 base::Unretained(this)));
49 web_ui()->RegisterMessageCallback( 46 web_ui()->RegisterMessageCallback(
50 "showKeyboardShortcutsOverlay", 47 "showKeyboardShortcutsOverlay",
51 base::Bind(&KeyboardHandler::HandleShowKeyboardShortcutsOverlay, 48 base::Bind(&KeyboardHandler::HandleShowKeyboardShortcutsOverlay,
52 base::Unretained(this))); 49 base::Unretained(this)));
53 } 50 }
54 51
52 void KeyboardHandler::OnJavascriptAllowed() {
53 observer_.Add(ui::DeviceDataManager::GetInstance());
54 }
55
56 void KeyboardHandler::OnJavascriptDisallowed() {
57 observer_.RemoveAll();
58 }
59
55 void KeyboardHandler::OnKeyboardDeviceConfigurationChanged() { 60 void KeyboardHandler::OnKeyboardDeviceConfigurationChanged() {
56 UpdateShowKeys(); 61 UpdateShowKeys();
57 } 62 }
58 63
59 void KeyboardHandler::HandleInitialize(const base::ListValue* args) { 64 void KeyboardHandler::HandleInitialize(const base::ListValue* args) {
65 AllowJavascript();
60 UpdateShowKeys(); 66 UpdateShowKeys();
61 } 67 }
62 68
63 void KeyboardHandler::HandleShowKeyboardShortcutsOverlay( 69 void KeyboardHandler::HandleShowKeyboardShortcutsOverlay(
64 const base::ListValue* args) const { 70 const base::ListValue* args) const {
65 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay(); 71 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay();
66 } 72 }
67 73
68 void KeyboardHandler::UpdateShowKeys() const { 74 void KeyboardHandler::UpdateShowKeys() {
69 const base::FundamentalValue has_caps_lock(HasExternalKeyboard()); 75 const base::FundamentalValue has_caps_lock(HasExternalKeyboard());
70 const base::FundamentalValue has_diamond_key( 76 const base::FundamentalValue has_diamond_key(
71 base::CommandLine::ForCurrentProcess()->HasSwitch( 77 base::CommandLine::ForCurrentProcess()->HasSwitch(
72 chromeos::switches::kHasChromeOSDiamondKey)); 78 chromeos::switches::kHasChromeOSDiamondKey));
73 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 79 CallJavascriptFunction("cr.webUIListenerCallback",
74 base::StringValue("show-keys-changed"), 80 base::StringValue("show-keys-changed"), has_caps_lock,
75 has_caps_lock, 81 has_diamond_key);
76 has_diamond_key);
77 } 82 }
78 83
79 } // namespace settings 84 } // namespace settings
80 } // namespace chromeos 85 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698