OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/profiles/user_manager_view.h" | 5 #include "chrome/browser/ui/views/profiles/user_manager_view.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/lifetime/application_lifetime.h" | 8 #include "chrome/browser/lifetime/application_lifetime.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/browser/profiles/profile_metrics.h" | 10 #include "chrome/browser/profiles/profile_metrics.h" |
11 #include "chrome/browser/profiles/profile_window.h" | 11 #include "chrome/browser/profiles/profile_window.h" |
12 #include "chrome/browser/profiles/profiles_state.h" | 12 #include "chrome/browser/profiles/profiles_state.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_dialogs.h" | 14 #include "chrome/browser/ui/browser_dialogs.h" |
15 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/user_manager.h" |
17 #include "chrome/browser/ui/views/auto_keep_alive.h" | 18 #include "chrome/browser/ui/views/auto_keep_alive.h" |
18 #include "chrome/grit/chromium_strings.h" | 19 #include "chrome/grit/chromium_strings.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
22 #include "ui/views/controls/webview/webview.h" | 23 #include "ui/views/controls/webview/webview.h" |
23 #include "ui/views/layout/fill_layout.h" | 24 #include "ui/views/layout/fill_layout.h" |
24 #include "ui/views/view.h" | 25 #include "ui/views/view.h" |
25 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
26 #include "ui/views/window/dialog_client_view.h" | 27 #include "ui/views/window/dialog_client_view.h" |
27 | 28 |
28 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
29 #include "chrome/browser/shell_integration.h" | 30 #include "chrome/browser/shell_integration.h" |
30 #include "ui/base/win/shell.h" | 31 #include "ui/base/win/shell.h" |
31 #include "ui/views/win/hwnd_util.h" | 32 #include "ui/views/win/hwnd_util.h" |
32 #endif | 33 #endif |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
36 // Default window size. | 37 // Default window size. |
37 const int kWindowWidth = 900; | 38 const int kWindowWidth = 900; |
38 const int kWindowHeight = 700; | 39 const int kWindowHeight = 700; |
39 | 40 |
40 } | 41 // An open User Manager window. There can only be one open at a time. This |
| 42 // is reset to NULL when the window is closed. |
| 43 UserManagerView* instance_ = NULL; |
41 | 44 |
42 namespace chrome { | 45 } // namespace |
43 | 46 |
44 // Declared in browser_dialogs.h so others don't have to depend on this header. | 47 // UserManager ----------------------------------------------------------------- |
45 void ShowUserManager(const base::FilePath& profile_path_to_focus) { | |
46 UserManagerView::Show( | |
47 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL); | |
48 } | |
49 | 48 |
50 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) { | 49 void UserManager::Show( |
51 UserManagerView::Show(base::FilePath(), tutorial); | 50 const base::FilePath& profile_path_to_focus, |
52 } | 51 profiles::UserManagerTutorialMode tutorial_mode, |
53 | 52 profiles::UserManagerProfileSelected profile_open_action) { |
54 void HideUserManager() { | |
55 UserManagerView::Hide(); | |
56 } | |
57 | |
58 } // namespace chrome | |
59 | |
60 // static | |
61 UserManagerView* UserManagerView::instance_ = NULL; | |
62 | |
63 UserManagerView::UserManagerView() | |
64 : web_view_(NULL), | |
65 keep_alive_(new AutoKeepAlive(NULL)) { | |
66 } | |
67 | |
68 UserManagerView::~UserManagerView() { | |
69 } | |
70 | |
71 // static | |
72 void UserManagerView::Show(const base::FilePath& profile_path_to_focus, | |
73 profiles::UserManagerTutorialMode tutorial_mode) { | |
74 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::OPEN_USER_MANAGER); | 53 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::OPEN_USER_MANAGER); |
75 if (instance_) { | 54 if (instance_) { |
76 // If we are showing the User Manager after locking a profile, change the | 55 // If we are showing the User Manager after locking a profile, change the |
77 // active profile to Guest. | 56 // active profile to Guest. |
78 profiles::SetActiveProfileToGuestIfLocked(); | 57 profiles::SetActiveProfileToGuestIfLocked(); |
79 | 58 |
80 // If there's a user manager window open already, just activate it. | 59 // If there's a user manager window open already, just activate it. |
81 instance_->GetWidget()->Activate(); | 60 instance_->GetWidget()->Activate(); |
82 return; | 61 return; |
83 } | 62 } |
84 | 63 |
85 // Create the guest profile, if necessary, and open the user manager | 64 // Create the guest profile, if necessary, and open the user manager |
86 // from the guest profile. | 65 // from the guest profile. |
87 profiles::CreateGuestProfileForUserManager( | 66 profiles::CreateGuestProfileForUserManager( |
88 profile_path_to_focus, | 67 profile_path_to_focus, |
89 tutorial_mode, | 68 tutorial_mode, |
| 69 profile_open_action, |
90 base::Bind(&UserManagerView::OnGuestProfileCreated, | 70 base::Bind(&UserManagerView::OnGuestProfileCreated, |
91 base::Passed(make_scoped_ptr(new UserManagerView)), | 71 base::Passed(make_scoped_ptr(new UserManagerView)), |
92 profile_path_to_focus)); | 72 profile_path_to_focus)); |
93 } | 73 } |
94 | 74 |
95 // static | 75 void UserManager::Hide() { |
96 void UserManagerView::Hide() { | |
97 if (instance_) | 76 if (instance_) |
98 instance_->GetWidget()->Close(); | 77 instance_->GetWidget()->Close(); |
99 } | 78 } |
100 | 79 |
101 // static | 80 bool UserManager::IsShowing() { |
102 bool UserManagerView::IsShowing() { | |
103 return instance_ ? instance_->GetWidget()->IsActive() : false; | 81 return instance_ ? instance_->GetWidget()->IsActive() : false; |
104 } | 82 } |
105 | 83 |
| 84 // UserManagerView ------------------------------------------------------------- |
| 85 |
| 86 UserManagerView::UserManagerView() |
| 87 : web_view_(NULL), |
| 88 keep_alive_(new AutoKeepAlive(NULL)) { |
| 89 } |
| 90 |
| 91 UserManagerView::~UserManagerView() { |
| 92 } |
| 93 |
106 // static | 94 // static |
107 void UserManagerView::OnGuestProfileCreated( | 95 void UserManagerView::OnGuestProfileCreated( |
108 scoped_ptr<UserManagerView> instance, | 96 scoped_ptr<UserManagerView> instance, |
109 const base::FilePath& profile_path_to_focus, | 97 const base::FilePath& profile_path_to_focus, |
110 Profile* guest_profile, | 98 Profile* guest_profile, |
111 const std::string& url) { | 99 const std::string& url) { |
112 // If we are showing the User Manager after locking a profile, change the | 100 // If we are showing the User Manager after locking a profile, change the |
113 // active profile to Guest. | 101 // active profile to Guest. |
114 profiles::SetActiveProfileToGuestIfLocked(); | 102 profiles::SetActiveProfileToGuestIfLocked(); |
115 | 103 |
| 104 DCHECK(!instance_); |
116 instance_ = instance.release(); // |instance_| takes over ownership. | 105 instance_ = instance.release(); // |instance_| takes over ownership. |
117 instance_->Init(profile_path_to_focus, guest_profile, GURL(url)); | 106 instance_->Init(profile_path_to_focus, guest_profile, GURL(url)); |
118 } | 107 } |
119 | 108 |
120 void UserManagerView::Init( | 109 void UserManagerView::Init( |
121 const base::FilePath& profile_path_to_focus, | 110 const base::FilePath& profile_path_to_focus, |
122 Profile* guest_profile, | 111 Profile* guest_profile, |
123 const GURL& url) { | 112 const GURL& url) { |
124 web_view_ = new views::WebView(guest_profile); | 113 web_view_ = new views::WebView(guest_profile); |
125 web_view_->set_allow_accelerators(true); | 114 web_view_->set_allow_accelerators(true); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 // Now that the window is closed, we can allow a new one to be opened. | 200 // Now that the window is closed, we can allow a new one to be opened. |
212 // (WindowClosing comes in asynchronously from the call to Close() and we | 201 // (WindowClosing comes in asynchronously from the call to Close() and we |
213 // may have already opened a new instance). | 202 // may have already opened a new instance). |
214 if (instance_ == this) | 203 if (instance_ == this) |
215 instance_ = NULL; | 204 instance_ = NULL; |
216 } | 205 } |
217 | 206 |
218 bool UserManagerView::UseNewStyleForThisDialog() const { | 207 bool UserManagerView::UseNewStyleForThisDialog() const { |
219 return false; | 208 return false; |
220 } | 209 } |
OLD | NEW |