| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/views/user_manager_view.h" | 5 #include "chrome/browser/ui/views/user_manager_view.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | |
| 8 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/lifetime/application_lifetime.h" | 8 #include "chrome/browser/lifetime/application_lifetime.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
| 11 #include "chrome/browser/profiles/profile_metrics.h" | 10 #include "chrome/browser/profiles/profile_metrics.h" |
| 11 #include "chrome/browser/profiles/profile_window.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_dialogs.h" | 13 #include "chrome/browser/ui/browser_dialogs.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/views/auto_keep_alive.h" | 15 #include "chrome/browser/ui/views/auto_keep_alive.h" |
| 16 #include "chrome/common/url_constants.h" | |
| 17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_contents_view.h" | 17 #include "content/public/browser/web_contents_view.h" |
| 19 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/views/controls/webview/webview.h" | 20 #include "ui/views/controls/webview/webview.h" |
| 22 #include "ui/views/layout/fill_layout.h" | 21 #include "ui/views/layout/fill_layout.h" |
| 23 #include "ui/views/view.h" | 22 #include "ui/views/view.h" |
| 24 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 25 | 24 |
| 26 #if defined(USE_ASH) | 25 #if defined(USE_ASH) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 39 // Default window size. | 38 // Default window size. |
| 40 const int kWindowWidth = 900; | 39 const int kWindowWidth = 900; |
| 41 const int kWindowHeight = 700; | 40 const int kWindowHeight = 700; |
| 42 | 41 |
| 43 } | 42 } |
| 44 | 43 |
| 45 namespace chrome { | 44 namespace chrome { |
| 46 | 45 |
| 47 // Declared in browser_dialogs.h so others don't have to depend on this header. | 46 // Declared in browser_dialogs.h so others don't have to depend on this header. |
| 48 void ShowUserManager(const base::FilePath& profile_path_to_focus) { | 47 void ShowUserManager(const base::FilePath& profile_path_to_focus) { |
| 49 UserManagerView::Show(profile_path_to_focus); | 48 UserManagerView::Show( |
| 49 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL); |
| 50 } |
| 51 |
| 52 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) { |
| 53 UserManagerView::Show(base::FilePath(), tutorial); |
| 50 } | 54 } |
| 51 | 55 |
| 52 void HideUserManager() { | 56 void HideUserManager() { |
| 53 UserManagerView::Hide(); | 57 UserManagerView::Hide(); |
| 54 } | 58 } |
| 55 | 59 |
| 56 } // namespace chrome | 60 } // namespace chrome |
| 57 | 61 |
| 58 // static | 62 // static |
| 59 UserManagerView* UserManagerView::instance_ = NULL; | 63 UserManagerView* UserManagerView::instance_ = NULL; |
| 60 | 64 |
| 61 UserManagerView::UserManagerView(Profile* profile) | 65 UserManagerView::UserManagerView(Profile* profile) |
| 62 : web_view_(new views::WebView(profile)) { | 66 : web_view_(new views::WebView(profile)) { |
| 63 SetLayoutManager(new views::FillLayout); | 67 SetLayoutManager(new views::FillLayout); |
| 64 AddChildView(web_view_); | 68 AddChildView(web_view_); |
| 65 } | 69 } |
| 66 | 70 |
| 67 UserManagerView::~UserManagerView() { | 71 UserManagerView::~UserManagerView() { |
| 68 } | 72 } |
| 69 | 73 |
| 70 // static | 74 // static |
| 71 void UserManagerView::Show(const base::FilePath& profile_path_to_focus) { | 75 void UserManagerView::Show(const base::FilePath& profile_path_to_focus, |
| 76 profiles::UserManagerTutorialMode tutorial_mode) { |
| 72 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::OPEN_USER_MANAGER); | 77 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::OPEN_USER_MANAGER); |
| 73 if (instance_) { | 78 if (instance_) { |
| 74 // If there's a user manager window open already, just activate it. | 79 // If there's a user manager window open already, just activate it. |
| 75 instance_->GetWidget()->Activate(); | 80 instance_->GetWidget()->Activate(); |
| 76 return; | 81 return; |
| 77 } | 82 } |
| 78 | 83 |
| 79 // Create the guest profile, if necessary, and open the user manager | 84 // Create the guest profile, if necessary, and open the user manager |
| 80 // from the guest profile. | 85 // from the guest profile. |
| 81 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 86 profiles::CreateGuestProfileForUserManager( |
| 82 profile_manager->CreateProfileAsync( | 87 profile_path_to_focus, |
| 83 ProfileManager::GetGuestProfilePath(), | 88 tutorial_mode, |
| 84 base::Bind(&UserManagerView::OnGuestProfileCreated, | 89 base::Bind(&UserManagerView::OnGuestProfileCreated)); |
| 85 profile_path_to_focus), | |
| 86 base::string16(), | |
| 87 base::string16(), | |
| 88 std::string()); | |
| 89 } | 90 } |
| 90 | 91 |
| 91 // static | 92 // static |
| 92 void UserManagerView::Hide() { | 93 void UserManagerView::Hide() { |
| 93 if (instance_) | 94 if (instance_) |
| 94 instance_->GetWidget()->Close(); | 95 instance_->GetWidget()->Close(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 // static | 98 // static |
| 98 bool UserManagerView::IsShowing() { | 99 bool UserManagerView::IsShowing() { |
| 99 return instance_ ? instance_->GetWidget()->IsActive() : false; | 100 return instance_ ? instance_->GetWidget()->IsActive() : false; |
| 100 } | 101 } |
| 101 | 102 |
| 102 void UserManagerView::OnGuestProfileCreated( | 103 // static |
| 103 const base::FilePath& profile_path_to_focus, | 104 void UserManagerView::OnGuestProfileCreated(Profile* guest_profile, |
| 104 Profile* guest_profile, | 105 const std::string& url) { |
| 105 Profile::CreateStatus status) { | |
| 106 if (status != Profile::CREATE_STATUS_INITIALIZED) | |
| 107 return; | |
| 108 | |
| 109 instance_ = new UserManagerView(guest_profile); | 106 instance_ = new UserManagerView(guest_profile); |
| 110 DialogDelegate::CreateDialogWidget(instance_, NULL, NULL); | 107 DialogDelegate::CreateDialogWidget(instance_, NULL, NULL); |
| 111 | 108 |
| 112 gfx::NativeWindow window = instance_->GetWidget()->GetNativeWindow(); | 109 gfx::NativeWindow window = instance_->GetWidget()->GetNativeWindow(); |
| 113 instance_->keep_alive_.reset(new AutoKeepAlive(window)); | 110 instance_->keep_alive_.reset(new AutoKeepAlive(window)); |
| 114 | 111 |
| 115 #if defined(OS_WIN) | 112 #if defined(OS_WIN) |
| 116 // Set the app id for the task manager to the app id of its parent | 113 // Set the app id for the task manager to the app id of its parent |
| 117 ui::win::SetAppIdForWindow( | 114 ui::win::SetAppIdForWindow( |
| 118 ShellIntegration::GetChromiumModelIdForProfile( | 115 ShellIntegration::GetChromiumModelIdForProfile( |
| 119 guest_profile->GetPath()), | 116 guest_profile->GetPath()), |
| 120 views::HWNDForWidget(instance_->GetWidget())); | 117 views::HWNDForWidget(instance_->GetWidget())); |
| 121 #endif | 118 #endif |
| 122 instance_->GetWidget()->Show(); | 119 instance_->GetWidget()->Show(); |
| 123 | 120 |
| 124 // Tell the webui which user pod should be focused. | 121 instance_->web_view_->LoadInitialURL(GURL(url)); |
| 125 std::string page = chrome::kChromeUIUserManagerURL; | |
| 126 | |
| 127 if (!profile_path_to_focus.empty()) { | |
| 128 ProfileInfoCache& cache = | |
| 129 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 130 size_t index = cache.GetIndexOfProfileWithPath(profile_path_to_focus); | |
| 131 if (index != std::string::npos) { | |
| 132 page += "#"; | |
| 133 page += base::IntToString(index); | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 instance_->web_view_->LoadInitialURL(GURL(page)); | |
| 138 instance_->web_view_->RequestFocus(); | 122 instance_->web_view_->RequestFocus(); |
| 139 } | 123 } |
| 140 | 124 |
| 141 gfx::Size UserManagerView::GetPreferredSize() { | 125 gfx::Size UserManagerView::GetPreferredSize() { |
| 142 return gfx::Size(kWindowWidth, kWindowHeight); | 126 return gfx::Size(kWindowWidth, kWindowHeight); |
| 143 } | 127 } |
| 144 | 128 |
| 145 bool UserManagerView::CanResize() const { | 129 bool UserManagerView::CanResize() const { |
| 146 return true; | 130 return true; |
| 147 } | 131 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 162 // Now that the window is closed, we can allow a new one to be opened. | 146 // Now that the window is closed, we can allow a new one to be opened. |
| 163 // (WindowClosing comes in asynchronously from the call to Close() and we | 147 // (WindowClosing comes in asynchronously from the call to Close() and we |
| 164 // may have already opened a new instance). | 148 // may have already opened a new instance). |
| 165 if (instance_ == this) | 149 if (instance_ == this) |
| 166 instance_ = NULL; | 150 instance_ = NULL; |
| 167 } | 151 } |
| 168 | 152 |
| 169 bool UserManagerView::UseNewStyleForThisDialog() const { | 153 bool UserManagerView::UseNewStyleForThisDialog() const { |
| 170 return false; | 154 return false; |
| 171 } | 155 } |
| OLD | NEW |