| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 11 #include "chrome/browser/supervised_user/supervised_user_service.h" | 12 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 12 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 13 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 14 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 15 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" |
| 16 #include "components/signin/core/browser/account_tracker_service.h" |
| 13 #include "components/url_formatter/url_fixer.h" | 17 #include "components/url_formatter/url_fixer.h" |
| 14 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/web_ui.h" | 19 #include "content/public/browser/web_ui.h" |
| 16 | 20 |
| 17 using content::BrowserThread; | 21 using content::BrowserThread; |
| 18 | 22 |
| 19 namespace { | 23 namespace { |
| 20 | 24 |
| 21 // Creates a 'section' for display on about:supervised-user-internals, | 25 // Creates a 'section' for display on about:supervised-user-internals, |
| 22 // consisting of a title and a list of fields. Returns a pointer to the new | 26 // consisting of a title and a list of fields. Returns a pointer to the new |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 GetSupervisedUserService()->GetURLFilterForUIThread(); | 239 GetSupervisedUserService()->GetURLFilterForUIThread(); |
| 236 | 240 |
| 237 base::ListValue* section_filter = AddSection(section_list.get(), "Filter"); | 241 base::ListValue* section_filter = AddSection(section_list.get(), "Filter"); |
| 238 AddSectionEntry(section_filter, "Blacklist active", filter->HasBlacklist()); | 242 AddSectionEntry(section_filter, "Blacklist active", filter->HasBlacklist()); |
| 239 AddSectionEntry(section_filter, "Online checks active", | 243 AddSectionEntry(section_filter, "Online checks active", |
| 240 filter->HasAsyncURLChecker()); | 244 filter->HasAsyncURLChecker()); |
| 241 AddSectionEntry(section_filter, "Default behavior", | 245 AddSectionEntry(section_filter, "Default behavior", |
| 242 FilteringBehaviorToString( | 246 FilteringBehaviorToString( |
| 243 filter->GetDefaultFilteringBehavior())); | 247 filter->GetDefaultFilteringBehavior())); |
| 244 | 248 |
| 249 AccountTrackerService* account_tracker = |
| 250 AccountTrackerServiceFactory::GetForProfile(profile); |
| 251 |
| 252 for (const auto& account: account_tracker->GetAccounts()) { |
| 253 base::ListValue* section_user = AddSection(section_list.get(), |
| 254 "User Information for " + account.full_name); |
| 255 AddSectionEntry(section_user, "Account id", account.account_id); |
| 256 AddSectionEntry(section_user, "Gaia", account.gaia); |
| 257 AddSectionEntry(section_user, "Email", account.email); |
| 258 AddSectionEntry(section_user, "Given name", account.given_name); |
| 259 AddSectionEntry(section_user, "Hosted domain", account.hosted_domain); |
| 260 AddSectionEntry(section_user, "Locale", account.locale); |
| 261 AddSectionEntry(section_user, "Is child", account.is_child_account); |
| 262 AddSectionEntry(section_user, "Is valid", account.IsValid()); |
| 263 } |
| 264 |
| 245 base::DictionaryValue result; | 265 base::DictionaryValue result; |
| 246 result.Set("sections", section_list.Pass()); | 266 result.Set("sections", section_list.Pass()); |
| 247 web_ui()->CallJavascriptFunction( | 267 web_ui()->CallJavascriptFunction( |
| 248 "chrome.supervised_user_internals.receiveBasicInfo", result); | 268 "chrome.supervised_user_internals.receiveBasicInfo", result); |
| 269 |
| 270 // Trigger retrieval of the user settings |
| 271 SupervisedUserSettingsService* settings_service = |
| 272 SupervisedUserSettingsServiceFactory::GetForProfile(profile); |
| 273 user_settings_subscription_ = settings_service->Subscribe(base::Bind( |
| 274 &SupervisedUserInternalsMessageHandler::SendSupervisedUserSettings, |
| 275 weak_factory_.GetWeakPtr())); |
| 276 } |
| 277 |
| 278 void SupervisedUserInternalsMessageHandler::SendSupervisedUserSettings( |
| 279 const base::DictionaryValue* settings){ |
| 280 web_ui()->CallJavascriptFunction( |
| 281 "chrome.supervised_user_internals.receiveUserSettings", |
| 282 *settings); |
| 249 } | 283 } |
| 250 | 284 |
| 251 void SupervisedUserInternalsMessageHandler::OnTryURLResult( | 285 void SupervisedUserInternalsMessageHandler::OnTryURLResult( |
| 252 SupervisedUserURLFilter::FilteringBehavior behavior, | 286 SupervisedUserURLFilter::FilteringBehavior behavior, |
| 253 SupervisedUserURLFilter::FilteringBehaviorReason reason, | 287 SupervisedUserURLFilter::FilteringBehaviorReason reason, |
| 254 bool uncertain) { | 288 bool uncertain) { |
| 255 web_ui()->CallJavascriptFunction( | 289 web_ui()->CallJavascriptFunction( |
| 256 "chrome.supervised_user_internals.receiveTryURLResult", | 290 "chrome.supervised_user_internals.receiveTryURLResult", |
| 257 base::StringValue(FilteringBehaviorToString(behavior, uncertain))); | 291 base::StringValue(FilteringBehaviorToString(behavior, uncertain))); |
| 258 } | 292 } |
| 259 | 293 |
| 260 void SupervisedUserInternalsMessageHandler::OnURLChecked( | 294 void SupervisedUserInternalsMessageHandler::OnURLChecked( |
| 261 const GURL& url, | 295 const GURL& url, |
| 262 SupervisedUserURLFilter::FilteringBehavior behavior, | 296 SupervisedUserURLFilter::FilteringBehavior behavior, |
| 263 SupervisedUserURLFilter::FilteringBehaviorReason reason, | 297 SupervisedUserURLFilter::FilteringBehaviorReason reason, |
| 264 bool uncertain) { | 298 bool uncertain) { |
| 265 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 299 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 266 base::DictionaryValue result; | 300 base::DictionaryValue result; |
| 267 result.SetString("url", url.possibly_invalid_spec()); | 301 result.SetString("url", url.possibly_invalid_spec()); |
| 268 result.SetString("result", FilteringBehaviorToString(behavior, uncertain)); | 302 result.SetString("result", FilteringBehaviorToString(behavior, uncertain)); |
| 269 result.SetString("reason", FilteringBehaviorReasonToString(reason)); | 303 result.SetString("reason", FilteringBehaviorReasonToString(reason)); |
| 270 web_ui()->CallJavascriptFunction( | 304 web_ui()->CallJavascriptFunction( |
| 271 "chrome.supervised_user_internals.receiveFilteringResult", result); | 305 "chrome.supervised_user_internals.receiveFilteringResult", result); |
| 272 } | 306 } |
| OLD | NEW |