OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/manage_profile_handler.h" | 5 #include "chrome/browser/ui/webui/options/manage_profile_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 const base::ListValue* args) { | 289 const base::ListValue* args) { |
290 const ProfileAttributesStorage& storage = | 290 const ProfileAttributesStorage& storage = |
291 g_browser_process->profile_manager()->GetProfileAttributesStorage(); | 291 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
292 const size_t icon_index = storage.ChooseAvatarIconIndexForNewProfile(); | 292 const size_t icon_index = storage.ChooseAvatarIconIndexForNewProfile(); |
293 | 293 |
294 base::DictionaryValue profile_info; | 294 base::DictionaryValue profile_info; |
295 profile_info.SetString("name", storage.ChooseNameForNewProfile(icon_index)); | 295 profile_info.SetString("name", storage.ChooseNameForNewProfile(icon_index)); |
296 profile_info.SetString("iconURL", | 296 profile_info.SetString("iconURL", |
297 profiles::GetDefaultAvatarIconUrl(icon_index)); | 297 profiles::GetDefaultAvatarIconUrl(icon_index)); |
298 | 298 |
299 web_ui()->CallJavascriptFunction( | 299 web_ui()->CallJavascriptFunctionUnsafe( |
300 "ManageProfileOverlay.receiveNewProfileDefaults", profile_info); | 300 "ManageProfileOverlay.receiveNewProfileDefaults", profile_info); |
301 } | 301 } |
302 | 302 |
303 void ManageProfileHandler::SendProfileIconsAndNames( | 303 void ManageProfileHandler::SendProfileIconsAndNames( |
304 const base::StringValue& mode) { | 304 const base::StringValue& mode) { |
305 base::ListValue image_url_list; | 305 base::ListValue image_url_list; |
306 base::ListValue default_name_list; | 306 base::ListValue default_name_list; |
307 | 307 |
308 ProfileAttributesStorage& storage = | 308 ProfileAttributesStorage& storage = |
309 g_browser_process->profile_manager()->GetProfileAttributesStorage(); | 309 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
(...skipping 15 matching lines...) Expand all Loading... |
325 } | 325 } |
326 } | 326 } |
327 | 327 |
328 // Next add the default avatar icons and names. | 328 // Next add the default avatar icons and names. |
329 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) { | 329 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) { |
330 std::string url = profiles::GetDefaultAvatarIconUrl(i); | 330 std::string url = profiles::GetDefaultAvatarIconUrl(i); |
331 image_url_list.AppendString(url); | 331 image_url_list.AppendString(url); |
332 default_name_list.AppendString(storage.ChooseNameForNewProfile(i)); | 332 default_name_list.AppendString(storage.ChooseNameForNewProfile(i)); |
333 } | 333 } |
334 | 334 |
335 web_ui()->CallJavascriptFunction( | 335 web_ui()->CallJavascriptFunctionUnsafe( |
336 "ManageProfileOverlay.receiveDefaultProfileIconsAndNames", mode, | 336 "ManageProfileOverlay.receiveDefaultProfileIconsAndNames", mode, |
337 image_url_list, default_name_list); | 337 image_url_list, default_name_list); |
338 } | 338 } |
339 | 339 |
340 void ManageProfileHandler::SendExistingProfileNames() { | 340 void ManageProfileHandler::SendExistingProfileNames() { |
341 std::vector<ProfileAttributesEntry*> entries = | 341 std::vector<ProfileAttributesEntry*> entries = |
342 g_browser_process->profile_manager()-> | 342 g_browser_process->profile_manager()-> |
343 GetProfileAttributesStorage().GetAllProfilesAttributes(); | 343 GetProfileAttributesStorage().GetAllProfilesAttributes(); |
344 base::DictionaryValue profile_name_dict; | 344 base::DictionaryValue profile_name_dict; |
345 for (const ProfileAttributesEntry* entry : entries) | 345 for (const ProfileAttributesEntry* entry : entries) |
346 profile_name_dict.SetBoolean(base::UTF16ToUTF8(entry->GetName()), true); | 346 profile_name_dict.SetBoolean(base::UTF16ToUTF8(entry->GetName()), true); |
347 | 347 |
348 web_ui()->CallJavascriptFunction( | 348 web_ui()->CallJavascriptFunctionUnsafe( |
349 "ManageProfileOverlay.receiveExistingProfileNames", profile_name_dict); | 349 "ManageProfileOverlay.receiveExistingProfileNames", profile_name_dict); |
350 } | 350 } |
351 | 351 |
352 void ManageProfileHandler::ShowDisconnectManagedProfileDialog( | 352 void ManageProfileHandler::ShowDisconnectManagedProfileDialog( |
353 const base::ListValue* args) { | 353 const base::ListValue* args) { |
354 base::DictionaryValue replacements; | 354 base::DictionaryValue replacements; |
355 GenerateSignedinUserSpecificStrings(&replacements); | 355 GenerateSignedinUserSpecificStrings(&replacements); |
356 web_ui()->CallJavascriptFunction( | 356 web_ui()->CallJavascriptFunctionUnsafe( |
357 "ManageProfileOverlay.showDisconnectManagedProfileDialog", replacements); | 357 "ManageProfileOverlay.showDisconnectManagedProfileDialog", replacements); |
358 } | 358 } |
359 | 359 |
360 void ManageProfileHandler::SetProfileIconAndName(const base::ListValue* args) { | 360 void ManageProfileHandler::SetProfileIconAndName(const base::ListValue* args) { |
361 DCHECK(args); | 361 DCHECK(args); |
362 | 362 |
363 base::FilePath profile_file_path; | 363 base::FilePath profile_file_path; |
364 if (!GetProfilePathFromArgs(args, &profile_file_path)) | 364 if (!GetProfilePathFromArgs(args, &profile_file_path)) |
365 return; | 365 return; |
366 | 366 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 ProfileAttributesEntry* entry = nullptr; | 458 ProfileAttributesEntry* entry = nullptr; |
459 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). | 459 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
460 GetProfileAttributesWithPath(profile_file_path, &entry)) | 460 GetProfileAttributesWithPath(profile_file_path, &entry)) |
461 return; | 461 return; |
462 base::string16 gaia_name = entry->GetName(); | 462 base::string16 gaia_name = entry->GetName(); |
463 if (gaia_name.empty()) | 463 if (gaia_name.empty()) |
464 return; | 464 return; |
465 | 465 |
466 base::StringValue gaia_name_value(gaia_name); | 466 base::StringValue gaia_name_value(gaia_name); |
467 base::StringValue mode_value(kManageProfileIdentifier); | 467 base::StringValue mode_value(kManageProfileIdentifier); |
468 web_ui()->CallJavascriptFunction("ManageProfileOverlay.setProfileName", | 468 web_ui()->CallJavascriptFunctionUnsafe("ManageProfileOverlay.setProfileName", |
469 gaia_name_value, mode_value); | 469 gaia_name_value, mode_value); |
470 } | 470 } |
471 | 471 |
472 void ManageProfileHandler::RequestHasProfileShortcuts( | 472 void ManageProfileHandler::RequestHasProfileShortcuts( |
473 const base::ListValue* args) { | 473 const base::ListValue* args) { |
474 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 474 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
475 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 475 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
476 | 476 |
477 base::FilePath profile_file_path; | 477 base::FilePath profile_file_path; |
478 if (!GetProfilePathFromArgs(args, &profile_file_path)) | 478 if (!GetProfilePathFromArgs(args, &profile_file_path)) |
479 return; | 479 return; |
(...skipping 28 matching lines...) Expand all Loading... |
508 | 508 |
509 // |service| might be null if Sync is disabled from the command line. | 509 // |service| might be null if Sync is disabled from the command line. |
510 if (service) | 510 if (service) |
511 state = service->GetAuthError().state(); | 511 state = service->GetAuthError().state(); |
512 | 512 |
513 bool has_error = (!service || | 513 bool has_error = (!service || |
514 state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 514 state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
515 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || | 515 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || |
516 state == GoogleServiceAuthError::ACCOUNT_DELETED || | 516 state == GoogleServiceAuthError::ACCOUNT_DELETED || |
517 state == GoogleServiceAuthError::ACCOUNT_DISABLED); | 517 state == GoogleServiceAuthError::ACCOUNT_DISABLED); |
518 web_ui()->CallJavascriptFunction("CreateProfileOverlay.updateSignedInStatus", | 518 web_ui()->CallJavascriptFunctionUnsafe( |
519 base::StringValue(username), | 519 "CreateProfileOverlay.updateSignedInStatus", base::StringValue(username), |
520 base::FundamentalValue(has_error)); | 520 base::FundamentalValue(has_error)); |
521 | 521 |
522 OnCreateSupervisedUserPrefChange(); | 522 OnCreateSupervisedUserPrefChange(); |
523 } | 523 } |
524 | 524 |
525 void ManageProfileHandler::OnCreateSupervisedUserPrefChange() { | 525 void ManageProfileHandler::OnCreateSupervisedUserPrefChange() { |
526 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 526 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
527 base::FundamentalValue allowed( | 527 base::FundamentalValue allowed( |
528 prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed)); | 528 prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed)); |
529 web_ui()->CallJavascriptFunction( | 529 web_ui()->CallJavascriptFunctionUnsafe( |
530 "CreateProfileOverlay.updateSupervisedUsersAllowed", allowed); | 530 "CreateProfileOverlay.updateSupervisedUsersAllowed", allowed); |
531 } | 531 } |
532 | 532 |
533 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { | 533 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { |
534 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 534 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
535 | 535 |
536 const base::FundamentalValue has_shortcuts_value(has_shortcuts); | 536 const base::FundamentalValue has_shortcuts_value(has_shortcuts); |
537 web_ui()->CallJavascriptFunction( | 537 web_ui()->CallJavascriptFunctionUnsafe( |
538 "ManageProfileOverlay.receiveHasProfileShortcuts", has_shortcuts_value); | 538 "ManageProfileOverlay.receiveHasProfileShortcuts", has_shortcuts_value); |
539 } | 539 } |
540 | 540 |
541 void ManageProfileHandler::AddProfileShortcut(const base::ListValue* args) { | 541 void ManageProfileHandler::AddProfileShortcut(const base::ListValue* args) { |
542 base::FilePath profile_file_path; | 542 base::FilePath profile_file_path; |
543 if (!GetProfilePathFromArgs(args, &profile_file_path)) | 543 if (!GetProfilePathFromArgs(args, &profile_file_path)) |
544 return; | 544 return; |
545 | 545 |
546 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 546 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
547 ProfileShortcutManager* shortcut_manager = | 547 ProfileShortcutManager* shortcut_manager = |
(...skipping 20 matching lines...) Expand all Loading... |
568 | 568 |
569 // Update the UI buttons. | 569 // Update the UI buttons. |
570 OnHasProfileShortcuts(false); | 570 OnHasProfileShortcuts(false); |
571 } | 571 } |
572 | 572 |
573 void ManageProfileHandler::RefreshGaiaPicture(const base::ListValue* args) { | 573 void ManageProfileHandler::RefreshGaiaPicture(const base::ListValue* args) { |
574 profiles::UpdateGaiaProfileInfoIfNeeded(Profile::FromWebUI(web_ui())); | 574 profiles::UpdateGaiaProfileInfoIfNeeded(Profile::FromWebUI(web_ui())); |
575 } | 575 } |
576 | 576 |
577 } // namespace options | 577 } // namespace options |
OLD | NEW |