| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/profiles/profile_shortcut_manager.h" | 21 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
| 22 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
| 23 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/web_ui.h" | 27 #include "content/public/browser/web_ui.h" |
| 28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 29 #include "ui/webui/web_ui_util.h" | 29 #include "ui/webui/web_ui_util.h" |
| 30 | 30 |
| 31 #if defined(ENABLE_SETTINGS_APP) |
| 32 #include "chrome/browser/ui/app_list/app_list_util.h" |
| 33 #include "content/public/browser/web_contents.h" |
| 34 #endif |
| 35 |
| 31 namespace options { | 36 namespace options { |
| 32 | 37 |
| 33 namespace { | 38 namespace { |
| 34 | 39 |
| 35 const char kCreateProfileIconGridName[] = "create-profile-icon-grid"; | 40 const char kCreateProfileIconGridName[] = "create-profile-icon-grid"; |
| 36 const char kManageProfileIconGridName[] = "manage-profile-icon-grid"; | 41 const char kManageProfileIconGridName[] = "manage-profile-icon-grid"; |
| 37 | 42 |
| 38 // Given |args| from the WebUI, parses value 0 as a FilePath |profile_file_path| | 43 // Given |args| from the WebUI, parses value 0 as a FilePath |profile_file_path| |
| 39 // and returns true on success. | 44 // and returns true on success. |
| 40 bool GetProfilePathFromArgs(const ListValue* args, | 45 bool GetProfilePathFromArgs(const ListValue* args, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 base::Unretained(this))); | 112 base::Unretained(this))); |
| 108 web_ui()->RegisterMessageCallback("requestNewProfileDefaults", | 113 web_ui()->RegisterMessageCallback("requestNewProfileDefaults", |
| 109 base::Bind(&ManageProfileHandler::RequestNewProfileDefaults, | 114 base::Bind(&ManageProfileHandler::RequestNewProfileDefaults, |
| 110 base::Unretained(this))); | 115 base::Unretained(this))); |
| 111 web_ui()->RegisterMessageCallback("requestHasProfileShortcuts", | 116 web_ui()->RegisterMessageCallback("requestHasProfileShortcuts", |
| 112 base::Bind(&ManageProfileHandler::RequestHasProfileShortcuts, | 117 base::Bind(&ManageProfileHandler::RequestHasProfileShortcuts, |
| 113 base::Unretained(this))); | 118 base::Unretained(this))); |
| 114 web_ui()->RegisterMessageCallback("profileIconSelectionChanged", | 119 web_ui()->RegisterMessageCallback("profileIconSelectionChanged", |
| 115 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged, | 120 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged, |
| 116 base::Unretained(this))); | 121 base::Unretained(this))); |
| 122 #if defined(ENABLE_SETTINGS_APP) |
| 123 web_ui()->RegisterMessageCallback("switchAppListProfile", |
| 124 base::Bind(&ManageProfileHandler::SwitchAppListProfile, |
| 125 base::Unretained(this))); |
| 126 #endif |
| 117 } | 127 } |
| 118 | 128 |
| 119 void ManageProfileHandler::Observe( | 129 void ManageProfileHandler::Observe( |
| 120 int type, | 130 int type, |
| 121 const content::NotificationSource& source, | 131 const content::NotificationSource& source, |
| 122 const content::NotificationDetails& details) { | 132 const content::NotificationDetails& details) { |
| 123 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { | 133 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { |
| 124 SendProfileNames(); | 134 SendProfileNames(); |
| 125 base::StringValue value(kManageProfileIconGridName); | 135 base::StringValue value(kManageProfileIconGridName); |
| 126 SendProfileIcons(value); | 136 SendProfileIcons(value); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 Browser* browser = | 313 Browser* browser = |
| 304 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); | 314 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
| 305 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; | 315 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 306 if (browser) | 316 if (browser) |
| 307 desktop_type = browser->host_desktop_type(); | 317 desktop_type = browser->host_desktop_type(); |
| 308 | 318 |
| 309 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 319 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
| 310 profile_file_path, desktop_type); | 320 profile_file_path, desktop_type); |
| 311 } | 321 } |
| 312 | 322 |
| 323 #if defined(ENABLE_SETTINGS_APP) |
| 324 void ManageProfileHandler::SwitchAppListProfile(const ListValue* args) { |
| 325 DCHECK(args); |
| 326 DCHECK(ProfileManager::IsMultipleProfilesEnabled()); |
| 327 |
| 328 const Value* file_path_value; |
| 329 FilePath profile_file_path; |
| 330 if (!args->Get(0, &file_path_value) || |
| 331 !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) |
| 332 return; |
| 333 |
| 334 chrome::SetAppListProfile(profile_file_path); |
| 335 // Close the settings app, since it will now be for the wrong profile. |
| 336 web_ui()->GetWebContents()->Close(); |
| 337 } |
| 338 #endif // defined(ENABLE_SETTINGS_APP) |
| 339 |
| 313 void ManageProfileHandler::ProfileIconSelectionChanged( | 340 void ManageProfileHandler::ProfileIconSelectionChanged( |
| 314 const base::ListValue* args) { | 341 const base::ListValue* args) { |
| 315 DCHECK(args); | 342 DCHECK(args); |
| 316 | 343 |
| 317 FilePath profile_file_path; | 344 FilePath profile_file_path; |
| 318 if (!GetProfilePathFromArgs(args, &profile_file_path)) | 345 if (!GetProfilePathFromArgs(args, &profile_file_path)) |
| 319 return; | 346 return; |
| 320 | 347 |
| 321 // Currently this only supports editing the current profile's info. | 348 // Currently this only supports editing the current profile's info. |
| 322 if (profile_file_path != Profile::FromWebUI(web_ui())->GetPath()) | 349 if (profile_file_path != Profile::FromWebUI(web_ui())->GetPath()) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 | 396 |
| 370 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { | 397 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { |
| 371 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 398 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 372 | 399 |
| 373 const base::FundamentalValue has_shortcuts_value(has_shortcuts); | 400 const base::FundamentalValue has_shortcuts_value(has_shortcuts); |
| 374 web_ui()->CallJavascriptFunction( | 401 web_ui()->CallJavascriptFunction( |
| 375 "ManageProfileOverlay.receiveHasProfileShortcuts", has_shortcuts_value); | 402 "ManageProfileOverlay.receiveHasProfileShortcuts", has_shortcuts_value); |
| 376 } | 403 } |
| 377 | 404 |
| 378 } // namespace options | 405 } // namespace options |
| OLD | NEW |