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