OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/supervised_user_internals_message_handler.h" | 5 #include "chrome/browser/ui/webui/supervised_user_internals_message_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 AddSectionEntry(section_user, "Given name", account.given_name); | 277 AddSectionEntry(section_user, "Given name", account.given_name); |
278 AddSectionEntry(section_user, "Hosted domain", account.hosted_domain); | 278 AddSectionEntry(section_user, "Hosted domain", account.hosted_domain); |
279 AddSectionEntry(section_user, "Locale", account.locale); | 279 AddSectionEntry(section_user, "Locale", account.locale); |
280 AddSectionEntry(section_user, "Is child", account.is_child_account); | 280 AddSectionEntry(section_user, "Is child", account.is_child_account); |
281 AddSectionEntry(section_user, "Is valid", account.IsValid()); | 281 AddSectionEntry(section_user, "Is valid", account.IsValid()); |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
285 base::DictionaryValue result; | 285 base::DictionaryValue result; |
286 result.Set("sections", std::move(section_list)); | 286 result.Set("sections", std::move(section_list)); |
287 web_ui()->CallJavascriptFunction( | 287 web_ui()->CallJavascriptFunctionUnsafe( |
288 "chrome.supervised_user_internals.receiveBasicInfo", result); | 288 "chrome.supervised_user_internals.receiveBasicInfo", result); |
289 | 289 |
290 // Trigger retrieval of the user settings | 290 // Trigger retrieval of the user settings |
291 SupervisedUserSettingsService* settings_service = | 291 SupervisedUserSettingsService* settings_service = |
292 SupervisedUserSettingsServiceFactory::GetForProfile(profile); | 292 SupervisedUserSettingsServiceFactory::GetForProfile(profile); |
293 user_settings_subscription_ = settings_service->Subscribe(base::Bind( | 293 user_settings_subscription_ = settings_service->Subscribe(base::Bind( |
294 &SupervisedUserInternalsMessageHandler::SendSupervisedUserSettings, | 294 &SupervisedUserInternalsMessageHandler::SendSupervisedUserSettings, |
295 weak_factory_.GetWeakPtr())); | 295 weak_factory_.GetWeakPtr())); |
296 } | 296 } |
297 | 297 |
298 void SupervisedUserInternalsMessageHandler::SendSupervisedUserSettings( | 298 void SupervisedUserInternalsMessageHandler::SendSupervisedUserSettings( |
299 const base::DictionaryValue* settings) { | 299 const base::DictionaryValue* settings) { |
300 web_ui()->CallJavascriptFunction( | 300 web_ui()->CallJavascriptFunctionUnsafe( |
301 "chrome.supervised_user_internals.receiveUserSettings", | 301 "chrome.supervised_user_internals.receiveUserSettings", |
302 *(settings ? settings : base::Value::CreateNullValue().get())); | 302 *(settings ? settings : base::Value::CreateNullValue().get())); |
303 } | 303 } |
304 | 304 |
305 void SupervisedUserInternalsMessageHandler::OnTryURLResult( | 305 void SupervisedUserInternalsMessageHandler::OnTryURLResult( |
306 const std::map<std::string, base::string16>& whitelists, | 306 const std::map<std::string, base::string16>& whitelists, |
307 SupervisedUserURLFilter::FilteringBehavior behavior, | 307 SupervisedUserURLFilter::FilteringBehavior behavior, |
308 supervised_user_error_page::FilteringBehaviorReason reason, | 308 supervised_user_error_page::FilteringBehaviorReason reason, |
309 bool uncertain) { | 309 bool uncertain) { |
310 std::vector<std::string> whitelists_list; | 310 std::vector<std::string> whitelists_list; |
311 for (const auto& whitelist : whitelists) { | 311 for (const auto& whitelist : whitelists) { |
312 whitelists_list.push_back( | 312 whitelists_list.push_back( |
313 base::StringPrintf("%s: %s", whitelist.first.c_str(), | 313 base::StringPrintf("%s: %s", whitelist.first.c_str(), |
314 base::UTF16ToUTF8(whitelist.second).c_str())); | 314 base::UTF16ToUTF8(whitelist.second).c_str())); |
315 } | 315 } |
316 std::string whitelists_str = base::JoinString(whitelists_list, "; "); | 316 std::string whitelists_str = base::JoinString(whitelists_list, "; "); |
317 base::DictionaryValue result; | 317 base::DictionaryValue result; |
318 result.SetString("allowResult", | 318 result.SetString("allowResult", |
319 FilteringBehaviorToString(behavior, uncertain)); | 319 FilteringBehaviorToString(behavior, uncertain)); |
320 result.SetBoolean("manual", reason == supervised_user_error_page::MANUAL && | 320 result.SetBoolean("manual", reason == supervised_user_error_page::MANUAL && |
321 behavior == SupervisedUserURLFilter::ALLOW); | 321 behavior == SupervisedUserURLFilter::ALLOW); |
322 result.SetString("whitelists", whitelists_str); | 322 result.SetString("whitelists", whitelists_str); |
323 web_ui()->CallJavascriptFunction( | 323 web_ui()->CallJavascriptFunctionUnsafe( |
324 "chrome.supervised_user_internals.receiveTryURLResult", result); | 324 "chrome.supervised_user_internals.receiveTryURLResult", result); |
325 } | 325 } |
326 | 326 |
327 void SupervisedUserInternalsMessageHandler::OnURLChecked( | 327 void SupervisedUserInternalsMessageHandler::OnURLChecked( |
328 const GURL& url, | 328 const GURL& url, |
329 SupervisedUserURLFilter::FilteringBehavior behavior, | 329 SupervisedUserURLFilter::FilteringBehavior behavior, |
330 supervised_user_error_page::FilteringBehaviorReason reason, | 330 supervised_user_error_page::FilteringBehaviorReason reason, |
331 bool uncertain) { | 331 bool uncertain) { |
332 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 332 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
333 base::DictionaryValue result; | 333 base::DictionaryValue result; |
334 result.SetString("url", url.possibly_invalid_spec()); | 334 result.SetString("url", url.possibly_invalid_spec()); |
335 result.SetString("result", FilteringBehaviorToString(behavior, uncertain)); | 335 result.SetString("result", FilteringBehaviorToString(behavior, uncertain)); |
336 result.SetString("reason", FilteringBehaviorReasonToString(reason)); | 336 result.SetString("reason", FilteringBehaviorReasonToString(reason)); |
337 web_ui()->CallJavascriptFunction( | 337 web_ui()->CallJavascriptFunctionUnsafe( |
338 "chrome.supervised_user_internals.receiveFilteringResult", result); | 338 "chrome.supervised_user_internals.receiveFilteringResult", result); |
339 } | 339 } |
OLD | NEW |