Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / user_manager_view.cc
blob62ee25014ce68fdd137b281a92edc102b36f81e2
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.
5 #include "chrome/browser/ui/views/user_manager_view.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/lifetime/application_lifetime.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_dialogs.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/common/url_constants.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_view.h"
17 #include "grit/generated_resources.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/views/controls/webview/webview.h"
20 #include "ui/views/layout/fill_layout.h"
21 #include "ui/views/view.h"
22 #include "ui/views/widget/widget.h"
24 #if defined(USE_ASH)
25 #include "ash/wm/window_util.h"
26 #endif
28 #if defined(OS_WIN)
29 #include "chrome/browser/shell_integration.h"
30 #include "ui/base/win/shell.h"
31 #include "ui/views/win/hwnd_util.h"
32 #include "win8/util/win8_util.h"
33 #endif
35 namespace {
37 // Default window size.
38 const int kWindowWidth = 900;
39 const int kWindowHeight = 700;
43 namespace chrome {
45 // Declared in browser_dialogs.h so others don't have to depend on this header.
46 void ShowUserManager(const base::FilePath& profile_path_to_focus) {
47 UserManagerView::Show(profile_path_to_focus);
50 void HideUserManager() {
51 UserManagerView::Hide();
54 } // namespace chrome
56 // static
57 UserManagerView* UserManagerView::instance_ = NULL;
59 UserManagerView::UserManagerView(Profile* profile)
60 : web_view_(new views::WebView(profile)) {
61 SetLayoutManager(new views::FillLayout);
62 AddChildView(web_view_);
65 UserManagerView::~UserManagerView() {
66 chrome::EndKeepAlive(); // Remove shutdown prevention.
69 // static
70 void UserManagerView::Show(const base::FilePath& profile_path_to_focus) {
71 // Prevent the browser process from shutting down while this window is open.
72 chrome::StartKeepAlive();
74 if (instance_) {
75 // If there's a user manager window open already, just activate it.
76 instance_->GetWidget()->Activate();
77 return;
80 // Create the guest profile, if necessary, and open the user manager
81 // from the guest profile.
82 ProfileManager* profile_manager = g_browser_process->profile_manager();
83 profile_manager->CreateProfileAsync(
84 ProfileManager::GetGuestProfilePath(),
85 base::Bind(&UserManagerView::OnGuestProfileCreated,
86 profile_path_to_focus),
87 base::string16(),
88 base::string16(),
89 std::string());
92 // static
93 void UserManagerView::Hide() {
94 if (instance_)
95 instance_->GetWidget()->Close();
98 // static
99 bool UserManagerView::IsShowing() {
100 return instance_ ? instance_->GetWidget()->IsActive() : false;
103 void UserManagerView::OnGuestProfileCreated(
104 const base::FilePath& profile_path_to_focus,
105 Profile* guest_profile,
106 Profile::CreateStatus status) {
107 if (status != Profile::CREATE_STATUS_INITIALIZED)
108 return;
110 instance_ = new UserManagerView(guest_profile);
111 DialogDelegate::CreateDialogWidget(instance_, NULL, NULL);
113 #if defined(OS_WIN)
114 // Set the app id for the task manager to the app id of its parent
115 ui::win::SetAppIdForWindow(
116 ShellIntegration::GetChromiumModelIdForProfile(
117 guest_profile->GetPath()),
118 views::HWNDForWidget(instance_->GetWidget()));
119 #endif
120 instance_->GetWidget()->Show();
122 // Tell the webui which user pod should be focused.
123 std::string page = chrome::kChromeUIUserManagerURL;
125 if (!profile_path_to_focus.empty()) {
126 ProfileInfoCache& cache =
127 g_browser_process->profile_manager()->GetProfileInfoCache();
128 size_t index = cache.GetIndexOfProfileWithPath(profile_path_to_focus);
129 if (index != std::string::npos) {
130 page += "#";
131 page += base::IntToString(index);
135 instance_->web_view_->LoadInitialURL(GURL(page));
136 instance_->web_view_->RequestFocus();
139 gfx::Size UserManagerView::GetPreferredSize() {
140 return gfx::Size(kWindowWidth, kWindowHeight);
143 bool UserManagerView::CanResize() const {
144 return true;
147 bool UserManagerView::CanMaximize() const {
148 return true;
151 base::string16 UserManagerView::GetWindowTitle() const {
152 return l10n_util::GetStringUTF16(IDS_USER_MANAGER_SCREEN_TITLE);
155 int UserManagerView::GetDialogButtons() const {
156 return ui::DIALOG_BUTTON_NONE;
159 void UserManagerView::WindowClosing() {
160 // Now that the window is closed, we can allow a new one to be opened.
161 // (WindowClosing comes in asynchronously from the call to Close() and we
162 // may have already opened a new instance).
163 if (instance_ == this)
164 instance_ = NULL;
167 bool UserManagerView::UseNewStyleForThisDialog() const {
168 return false;