#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h"
+#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/auto_keep_alive.h"
+#include "chrome/grit/chromium_strings.h"
#include "content/public/browser/web_contents.h"
-#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/gfx/screen.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
+#include "ui/views/window/dialog_client_view.h"
#if defined(OS_WIN)
#include "chrome/browser/shell_integration.h"
profile_path_to_focus,
tutorial_mode,
base::Bind(&UserManagerView::OnGuestProfileCreated,
- base::Passed(make_scoped_ptr(new UserManagerView))));
+ base::Passed(make_scoped_ptr(new UserManagerView)),
+ profile_path_to_focus));
}
// static
// static
void UserManagerView::OnGuestProfileCreated(
scoped_ptr<UserManagerView> instance,
+ const base::FilePath& profile_path_to_focus,
Profile* guest_profile,
const std::string& url) {
instance_ = instance.release(); // |instance_| takes over ownership.
- instance_->Init(guest_profile, GURL(url));
+ instance_->Init(profile_path_to_focus, guest_profile, GURL(url));
}
-void UserManagerView::Init(Profile* guest_profile, const GURL& url) {
+void UserManagerView::Init(
+ const base::FilePath& profile_path_to_focus,
+ Profile* guest_profile,
+ const GURL& url) {
web_view_ = new views::WebView(guest_profile);
- SetLayoutManager(new views::FillLayout);
+ web_view_->set_allow_accelerators(true);
AddChildView(web_view_);
+ SetLayoutManager(new views::FillLayout);
+ AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN));
+
+ // If the user manager is being displayed from an existing profile, use
+ // its last active browser to determine where the user manager should be
+ // placed. This is used so that we can center the dialog on the correct
+ // monitor in a multiple-monitor setup.
+ //
+ // If |profile_path_to_focus| is empty (for example, starting up chrome
+ // when all existing profiles are locked) or we can't find an active
+ // browser, bounds will remain empty and the user manager will be centered on
+ // the default monitor by default.
+ gfx::Rect bounds;
+ if (!profile_path_to_focus.empty()) {
+ ProfileManager* manager = g_browser_process->profile_manager();
+ if (manager) {
+ Profile* profile = manager->GetProfileByPath(profile_path_to_focus);
+ DCHECK(profile);
+ Browser* browser = chrome::FindLastActiveWithProfile(profile,
+ chrome::GetActiveDesktop());
+ if (browser) {
+ gfx::NativeView native_view =
+ views::Widget::GetWidgetForNativeWindow(
+ browser->window()->GetNativeWindow())->GetNativeView();
+ bounds = gfx::Screen::GetScreenFor(native_view)->
+ GetDisplayNearestWindow(native_view).work_area();
+ bounds.ClampToCenteredSize(gfx::Size(kWindowWidth, kWindowHeight));
+ }
+ }
+ }
- DialogDelegate::CreateDialogWidget(this, NULL, NULL);
+ DialogDelegate::CreateDialogWidgetWithBounds(this, NULL, NULL, bounds);
+
+ // Since the User Manager can be the only top level window, we don't
+ // want to accidentally quit all of Chrome if the user is just trying to
+ // unfocus the selected pod in the WebView.
+ GetDialogClientView()->RemoveAccelerator(
+ ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
#if defined(OS_WIN)
// Set the app id for the task manager to the app id of its parent
web_view_->RequestFocus();
}
+bool UserManagerView::AcceleratorPressed(const ui::Accelerator& accelerator) {
+ DCHECK_EQ(ui::VKEY_W, accelerator.key_code());
+ DCHECK_EQ(ui::EF_CONTROL_DOWN, accelerator.modifiers());
+ GetWidget()->Close();
+ return true;
+}
+
gfx::Size UserManagerView::GetPreferredSize() const {
return gfx::Size(kWindowWidth, kWindowHeight);
}
}
base::string16 UserManagerView::GetWindowTitle() const {
- return l10n_util::GetStringUTF16(IDS_USER_MANAGER_SCREEN_TITLE);
+ return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
}
int UserManagerView::GetDialogButtons() const {