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

Side by Side Diff: chrome/browser/ui/webui/settings/chromeos/device_stylus_handler.cc

Issue 2682413002: cros: Fix crash when enabling arc in md-settings. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_stylus_handler.h" 5 #include "chrome/browser/ui/webui/settings/chromeos/device_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/bind.h" 8 #include "base/bind.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "ui/events/devices/input_device_manager.h" 10 #include "ui/events/devices/input_device_manager.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 note_taking_app_ids_.clear(); 59 note_taking_app_ids_.clear();
60 base::ListValue apps_list; 60 base::ListValue apps_list;
61 61
62 NoteTakingHelper* helper = NoteTakingHelper::Get(); 62 NoteTakingHelper* helper = NoteTakingHelper::Get();
63 if (helper->android_enabled() && !helper->android_apps_received()) { 63 if (helper->android_enabled() && !helper->android_apps_received()) {
64 // If Android is enabled but not ready yet, let the JS know so it can 64 // If Android is enabled but not ready yet, let the JS know so it can
65 // disable the menu and display an explanatory message. 65 // disable the menu and display an explanatory message.
66 waiting_for_android = true; 66 waiting_for_android = true;
67 } else { 67 } else {
68 std::vector<NoteTakingAppInfo> available_apps = 68 std::vector<NoteTakingAppInfo> available_apps =
69 NoteTakingHelper::Get()->GetAvailableApps(Profile::FromWebUI(web_ui())); 69 helper->GetAvailableApps(Profile::FromWebUI(web_ui()));
70 for (const NoteTakingAppInfo& info : available_apps) { 70 for (const NoteTakingAppInfo& info : available_apps) {
71 auto dict = base::MakeUnique<base::DictionaryValue>(); 71 auto dict = base::MakeUnique<base::DictionaryValue>();
72 dict->SetString(kAppNameKey, info.name); 72 dict->SetString(kAppNameKey, info.name);
73 dict->SetString(kAppIdKey, info.app_id); 73 dict->SetString(kAppIdKey, info.app_id);
74 dict->SetBoolean(kAppPreferredKey, info.preferred); 74 dict->SetBoolean(kAppPreferredKey, info.preferred);
75 apps_list.Append(std::move(dict)); 75 apps_list.Append(std::move(dict));
76 76
77 note_taking_app_ids_.insert(info.app_id); 77 note_taking_app_ids_.insert(info.app_id);
78 } 78 }
79 } 79 }
80 80
81 AllowJavascript();
81 CallJavascriptFunction( 82 CallJavascriptFunction(
82 "cr.webUIListenerCallback", base::StringValue("onNoteTakingAppsUpdated"), 83 "cr.webUIListenerCallback", base::StringValue("onNoteTakingAppsUpdated"),
83 apps_list, base::FundamentalValue(waiting_for_android)); 84 apps_list, base::FundamentalValue(waiting_for_android));
84 } 85 }
85 86
86 void StylusHandler::RequestApps(const base::ListValue* unused_args) { 87 void StylusHandler::RequestApps(const base::ListValue* unused_args) {
87 AllowJavascript();
88 UpdateNoteTakingApps(); 88 UpdateNoteTakingApps();
89 } 89 }
90 90
91 void StylusHandler::SetPreferredNoteTakingApp(const base::ListValue* args) { 91 void StylusHandler::SetPreferredNoteTakingApp(const base::ListValue* args) {
92 std::string app_id; 92 std::string app_id;
93 CHECK(args->GetString(0, &app_id)); 93 CHECK(args->GetString(0, &app_id));
94 94
95 // Sanity check: make sure that the ID we got back from WebUI is in the 95 // Sanity check: make sure that the ID we got back from WebUI is in the
96 // currently-available set. 96 // currently-available set.
97 if (!note_taking_app_ids_.count(app_id)) { 97 if (!note_taking_app_ids_.count(app_id)) {
98 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\""; 98 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\"";
99 return; 99 return;
100 } 100 }
101 101
102 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()), 102 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()),
103 app_id); 103 app_id);
104 } 104 }
105 105
106 void StylusHandler::HandleInitialize(const base::ListValue* args) { 106 void StylusHandler::HandleInitialize(const base::ListValue* args) {
107 AllowJavascript();
108 if (ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()) 107 if (ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete())
109 SendHasStylus(); 108 SendHasStylus();
110 } 109 }
111 110
112 void StylusHandler::SendHasStylus() { 111 void StylusHandler::SendHasStylus() {
113 DCHECK(ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()); 112 DCHECK(ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete());
113 AllowJavascript();
114 CallJavascriptFunction( 114 CallJavascriptFunction(
115 "cr.webUIListenerCallback", base::StringValue("has-stylus-changed"), 115 "cr.webUIListenerCallback", base::StringValue("has-stylus-changed"),
116 base::FundamentalValue(ash::palette_utils::HasStylusInput())); 116 base::FundamentalValue(ash::palette_utils::HasStylusInput()));
117 } 117 }
118 118
119 } // namespace settings 119 } // namespace settings
120 } // namespace chromeos 120 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698