OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/options/chromeos/options_stylus_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/options_stylus_handler.h" |
6 | 6 |
7 #include "ash/common/system/chromeos/palette/palette_utils.h" | 7 #include "ash/common/system/chromeos/palette/palette_utils.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 const base::ListValue* args) { | 92 const base::ListValue* args) { |
93 if (ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()) | 93 if (ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()) |
94 SendHasStylus(); | 94 SendHasStylus(); |
95 } | 95 } |
96 | 96 |
97 void OptionsStylusHandler::SendHasStylus() { | 97 void OptionsStylusHandler::SendHasStylus() { |
98 DCHECK(ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()); | 98 DCHECK(ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()); |
99 | 99 |
100 web_ui()->CallJavascriptFunctionUnsafe( | 100 web_ui()->CallJavascriptFunctionUnsafe( |
101 "BrowserOptions.setStylusInputStatus", | 101 "BrowserOptions.setStylusInputStatus", |
102 base::FundamentalValue(ash::palette_utils::HasStylusInput())); | 102 base::Value(ash::palette_utils::HasStylusInput())); |
103 } | 103 } |
104 | 104 |
105 void OptionsStylusHandler::UpdateNoteTakingApps() { | 105 void OptionsStylusHandler::UpdateNoteTakingApps() { |
106 bool waiting_for_android = false; | 106 bool waiting_for_android = false; |
107 note_taking_app_ids_.clear(); | 107 note_taking_app_ids_.clear(); |
108 base::ListValue apps_list; | 108 base::ListValue apps_list; |
109 | 109 |
110 NoteTakingHelper* helper = NoteTakingHelper::Get(); | 110 NoteTakingHelper* helper = NoteTakingHelper::Get(); |
111 if (helper->android_enabled() && !helper->android_apps_received()) { | 111 if (helper->android_enabled() && !helper->android_apps_received()) { |
112 // If Android is enabled but not ready yet, let the JS know so it can | 112 // If Android is enabled but not ready yet, let the JS know so it can |
113 // disable the menu and display an explanatory message. | 113 // disable the menu and display an explanatory message. |
114 waiting_for_android = true; | 114 waiting_for_android = true; |
115 } else { | 115 } else { |
116 for (const NoteTakingAppInfo& info : | 116 for (const NoteTakingAppInfo& info : |
117 NoteTakingHelper::Get()->GetAvailableApps( | 117 NoteTakingHelper::Get()->GetAvailableApps( |
118 Profile::FromWebUI(web_ui()))) { | 118 Profile::FromWebUI(web_ui()))) { |
119 std::unique_ptr<base::DictionaryValue> dict( | 119 std::unique_ptr<base::DictionaryValue> dict( |
120 new base::DictionaryValue()); | 120 new base::DictionaryValue()); |
121 dict->SetString(kAppNameKey, info.name); | 121 dict->SetString(kAppNameKey, info.name); |
122 dict->SetString(kAppIdKey, info.app_id); | 122 dict->SetString(kAppIdKey, info.app_id); |
123 dict->SetBoolean(kAppPreferredKey, info.preferred); | 123 dict->SetBoolean(kAppPreferredKey, info.preferred); |
124 apps_list.Append(std::move(dict)); | 124 apps_list.Append(std::move(dict)); |
125 | 125 |
126 note_taking_app_ids_.insert(info.app_id); | 126 note_taking_app_ids_.insert(info.app_id); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 web_ui()->CallJavascriptFunctionUnsafe( | 130 web_ui()->CallJavascriptFunctionUnsafe("StylusOverlay.updateNoteTakingApps", |
131 "StylusOverlay.updateNoteTakingApps", apps_list, | 131 apps_list, |
132 base::FundamentalValue(waiting_for_android)); | 132 base::Value(waiting_for_android)); |
133 } | 133 } |
134 | 134 |
135 void OptionsStylusHandler::SetPreferredNoteTakingApp( | 135 void OptionsStylusHandler::SetPreferredNoteTakingApp( |
136 const base::ListValue* args) { | 136 const base::ListValue* args) { |
137 std::string app_id; | 137 std::string app_id; |
138 CHECK(args->GetString(0, &app_id)); | 138 CHECK(args->GetString(0, &app_id)); |
139 | 139 |
140 // Sanity check: make sure that the ID we got back from WebUI is in the | 140 // Sanity check: make sure that the ID we got back from WebUI is in the |
141 // currently-available set. | 141 // currently-available set. |
142 if (!note_taking_app_ids_.count(app_id)) { | 142 if (!note_taking_app_ids_.count(app_id)) { |
143 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\""; | 143 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\""; |
144 return; | 144 return; |
145 } | 145 } |
146 | 146 |
147 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()), | 147 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()), |
148 app_id); | 148 app_id); |
149 } | 149 } |
150 | 150 |
151 } // namespace options | 151 } // namespace options |
152 } // namespace chromeos | 152 } // namespace chromeos |
OLD | NEW |