OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/user_manager_view.h" | |
6 | |
7 #include "chrome/browser/browser_process.h" | |
8 #include "chrome/browser/lifetime/application_lifetime.h" | |
9 #include "chrome/browser/profiles/profile_manager.h" | |
10 #include "chrome/browser/profiles/profile_metrics.h" | |
11 #include "chrome/browser/profiles/profile_window.h" | |
12 #include "chrome/browser/ui/browser.h" | |
13 #include "chrome/browser/ui/browser_dialogs.h" | |
14 #include "chrome/browser/ui/browser_window.h" | |
15 #include "chrome/browser/ui/views/auto_keep_alive.h" | |
16 #include "content/public/browser/web_contents.h" | |
17 #include "content/public/browser/web_contents_view.h" | |
18 #include "grit/generated_resources.h" | |
19 #include "ui/base/l10n/l10n_util.h" | |
20 #include "ui/views/controls/webview/webview.h" | |
21 #include "ui/views/layout/fill_layout.h" | |
22 #include "ui/views/view.h" | |
23 #include "ui/views/widget/widget.h" | |
24 | |
25 #if defined(USE_ASH) | |
26 #include "ash/wm/window_util.h" | |
27 #endif | |
28 | |
29 #if defined(OS_WIN) | |
30 #include "chrome/browser/shell_integration.h" | |
31 #include "ui/base/win/shell.h" | |
32 #include "ui/views/win/hwnd_util.h" | |
33 #include "win8/util/win8_util.h" | |
34 #endif | |
35 | |
36 namespace { | |
37 | |
38 // Default window size. | |
39 const int kWindowWidth = 900; | |
40 const int kWindowHeight = 700; | |
41 | |
42 } | |
43 | |
44 namespace chrome { | |
45 | |
46 // Declared in browser_dialogs.h so others don't have to depend on this header. | |
47 void ShowUserManager(const base::FilePath& 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); | |
54 } | |
55 | |
56 void HideUserManager() { | |
57 UserManagerView::Hide(); | |
58 } | |
59 | |
60 } // namespace chrome | |
61 | |
62 // static | |
63 UserManagerView* UserManagerView::instance_ = NULL; | |
64 | |
65 UserManagerView::UserManagerView(Profile* profile) | |
66 : web_view_(new views::WebView(profile)) { | |
67 SetLayoutManager(new views::FillLayout); | |
68 AddChildView(web_view_); | |
69 } | |
70 | |
71 UserManagerView::~UserManagerView() { | |
72 } | |
73 | |
74 // static | |
75 void UserManagerView::Show(const base::FilePath& profile_path_to_focus, | |
76 profiles::UserManagerTutorialMode tutorial_mode) { | |
77 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::OPEN_USER_MANAGER); | |
78 if (instance_) { | |
79 // If there's a user manager window open already, just activate it. | |
80 instance_->GetWidget()->Activate(); | |
81 return; | |
82 } | |
83 | |
84 // Create the guest profile, if necessary, and open the user manager | |
85 // from the guest profile. | |
86 profiles::CreateGuestProfileForUserManager( | |
87 profile_path_to_focus, | |
88 tutorial_mode, | |
89 base::Bind(&UserManagerView::OnGuestProfileCreated)); | |
90 } | |
91 | |
92 // static | |
93 void UserManagerView::Hide() { | |
94 if (instance_) | |
95 instance_->GetWidget()->Close(); | |
96 } | |
97 | |
98 // static | |
99 bool UserManagerView::IsShowing() { | |
100 return instance_ ? instance_->GetWidget()->IsActive() : false; | |
101 } | |
102 | |
103 // static | |
104 void UserManagerView::OnGuestProfileCreated(Profile* guest_profile, | |
105 const std::string& url) { | |
106 instance_ = new UserManagerView(guest_profile); | |
107 DialogDelegate::CreateDialogWidget(instance_, NULL, NULL); | |
108 | |
109 gfx::NativeWindow window = instance_->GetWidget()->GetNativeWindow(); | |
110 instance_->keep_alive_.reset(new AutoKeepAlive(window)); | |
111 | |
112 #if defined(OS_WIN) | |
113 // Set the app id for the task manager to the app id of its parent | |
114 ui::win::SetAppIdForWindow( | |
115 ShellIntegration::GetChromiumModelIdForProfile( | |
116 guest_profile->GetPath()), | |
117 views::HWNDForWidget(instance_->GetWidget())); | |
118 #endif | |
119 instance_->GetWidget()->Show(); | |
120 | |
121 instance_->web_view_->LoadInitialURL(GURL(url)); | |
122 instance_->web_view_->RequestFocus(); | |
123 } | |
124 | |
125 gfx::Size UserManagerView::GetPreferredSize() { | |
126 return gfx::Size(kWindowWidth, kWindowHeight); | |
127 } | |
128 | |
129 bool UserManagerView::CanResize() const { | |
130 return true; | |
131 } | |
132 | |
133 bool UserManagerView::CanMaximize() const { | |
134 return true; | |
135 } | |
136 | |
137 base::string16 UserManagerView::GetWindowTitle() const { | |
138 return l10n_util::GetStringUTF16(IDS_USER_MANAGER_SCREEN_TITLE); | |
139 } | |
140 | |
141 int UserManagerView::GetDialogButtons() const { | |
142 return ui::DIALOG_BUTTON_NONE; | |
143 } | |
144 | |
145 void UserManagerView::WindowClosing() { | |
146 // Now that the window is closed, we can allow a new one to be opened. | |
147 // (WindowClosing comes in asynchronously from the call to Close() and we | |
148 // may have already opened a new instance). | |
149 if (instance_ == this) | |
150 instance_ = NULL; | |
151 } | |
152 | |
153 bool UserManagerView::UseNewStyleForThisDialog() const { | |
154 return false; | |
155 } | |
OLD | NEW |