Commit e769a0c6 authored by Monica Basta's avatar Monica Basta Committed by Commit Bot

[ProfilePicker]: Create a new dialog view for the profile picker.

This CL creates the initial View object to show the new profile picker.  It is
currently loading the current user manager url. Next steps would be:
(1) Create the new profile picker html page (WebUI part).
(2) Load the new profile picker in ProfilePickerView

Change-Id: I1171799ce9649e4738b543f2676002f48c652c53
Bug: 1063856
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2141100
Commit-Queue: Monica Basta <msalama@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759652}
parent a6b3716d
......@@ -2247,6 +2247,7 @@ jumbo_static_library("ui") {
sources += [
"bookmarks/bookmark_bubble_sign_in_delegate.cc",
"bookmarks/bookmark_bubble_sign_in_delegate.h",
"profile_picker.h",
"startup/default_browser_infobar_delegate.cc",
"startup/default_browser_infobar_delegate.h",
"startup/default_browser_prompt.cc",
......@@ -2260,6 +2261,8 @@ jumbo_static_library("ui") {
"views/external_protocol_dialog.h",
"views/profiles/badged_profile_photo.cc",
"views/profiles/badged_profile_photo.h",
"views/profiles/profile_picker_view.cc",
"views/profiles/profile_picker_view.h",
"views/profiles/user_manager_view.cc",
"views/profiles/user_manager_view.h",
"webui/app_launcher_page_ui.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_PROFILE_PICKER_H_
#define CHROME_BROWSER_UI_PROFILE_PICKER_H_
class ProfilePicker {
public:
// Shows the Profile picker or re-activates an existing one.
static void Show();
// Hides the profile picker.
static void Hide();
private:
DISALLOW_COPY_AND_ASSIGN(ProfilePicker);
};
#endif // CHROME_BROWSER_UI_PROFILE_PICKER_H_
......@@ -81,6 +81,7 @@
#include "components/user_manager/user_manager.h"
#else
#include "chrome/browser/extensions/api/messaging/native_messaging_launch_from_native.h"
#include "chrome/browser/ui/profile_picker.h"
#include "chrome/browser/ui/user_manager.h"
#endif
......@@ -263,10 +264,12 @@ bool CanOpenProfileOnStartup(Profile* profile) {
#endif
}
#if !defined(OS_CHROMEOS)
bool ShouldShowProfilePicker() {
return !signin_util::IsForceSigninEnabled() &&
base::FeatureList::IsEnabled(features::kNewProfilePicker);
}
#endif // !defined(OS_CHROMEOS)
void ShowUserManagerOnStartup() {
#if !defined(OS_CHROMEOS)
......@@ -797,11 +800,12 @@ bool StartupBrowserCreator::LaunchBrowserForLastProfiles(
bool process_startup,
Profile* last_used_profile,
const Profiles& last_opened_profiles) {
#if !defined(OS_CHROMEOS)
if (ShouldShowProfilePicker()) {
// TODO(crbug.com/1063856): Adjust to show the profile picker.
ShowUserManagerOnStartup();
ProfilePicker::Show();
return true;
}
#endif // !defined(OS_CHROMEOS)
chrome::startup::IsProcessStartup is_process_startup = process_startup ?
chrome::startup::IS_PROCESS_STARTUP :
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/profiles/profile_picker_view.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/google_chrome_strings.h"
#include "content/public/browser/render_widget_host_view.h"
#include "ui/base/l10n/l10n_util.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"
#if defined(OS_WIN)
#include "chrome/browser/shell_integration_win.h"
#include "ui/base/win/shell.h"
#include "ui/views/win/hwnd_util.h"
#endif
namespace {
ProfilePickerView* g_profile_picker_view = nullptr;
constexpr int kWindowWidth = 800;
constexpr int kWindowHeight = 600;
} // namespace
// static
void ProfilePicker::Show() {
if (!g_profile_picker_view)
g_profile_picker_view = new ProfilePickerView();
g_profile_picker_view->Display();
}
// static
void ProfilePicker::Hide() {
if (g_profile_picker_view)
g_profile_picker_view->Clear();
}
ProfilePickerView::ProfilePickerView()
: web_view_(nullptr), initialized_(InitState::kNotInitialized) {
DialogDelegate::SetButtons(ui::DIALOG_BUTTON_NONE);
DialogDelegate::set_use_custom_frame(false);
// TODO(crbug.com/1063856): Add |RecordDialogCreation|.
}
ProfilePickerView::~ProfilePickerView() = default;
void ProfilePickerView::Display() {
if (initialized_ == kNotInitialized) {
initialized_ = kInProgress;
g_browser_process->profile_manager()->CreateProfileAsync(
ProfileManager::GetSystemProfilePath(),
base::BindRepeating(&ProfilePickerView::OnSystemProfileCreated,
weak_ptr_factory_.GetWeakPtr()),
/*name=*/base::string16(), /*icon_url=*/std::string());
return;
}
if (initialized_ == kInProgress)
return;
GetWidget()->Activate();
}
void ProfilePickerView::Clear() {
if (initialized_ == kDone) {
GetWidget()->Close();
return;
}
WindowClosing();
DeleteDelegate();
}
void ProfilePickerView::OnSystemProfileCreated(Profile* system_profile,
Profile::CreateStatus status) {
DCHECK_NE(status, Profile::CREATE_STATUS_LOCAL_FAIL);
if (status != Profile::CREATE_STATUS_INITIALIZED)
return;
Init(system_profile);
}
void ProfilePickerView::Init(Profile* system_profile) {
web_view_ = new views::WebView(system_profile);
AddChildView(web_view_);
SetLayoutManager(std::make_unique<views::FillLayout>());
DialogDelegate::CreateDialogWidget(this, nullptr, nullptr);
#if defined(OS_WIN)
// Set the app id for the user manager to the app id of its parent.
ui::win::SetAppIdForWindow(
shell_integration::win::GetChromiumModelIdForProfile(
system_profile->GetPath()),
views::HWNDForWidget(GetWidget()));
#endif
web_view_->LoadInitialURL(GURL(chrome::kChromeUIMdUserManagerUrl));
GetWidget()->Show();
web_view_->RequestFocus();
initialized_ = InitState::kDone;
}
gfx::Size ProfilePickerView::CalculatePreferredSize() const {
return gfx::Size(kWindowWidth, kWindowHeight);
}
bool ProfilePickerView::CanResize() const {
return true;
}
bool ProfilePickerView::CanMaximize() const {
return true;
}
bool ProfilePickerView::CanMinimize() const {
return true;
}
base::string16 ProfilePickerView::GetWindowTitle() const {
return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
}
void ProfilePickerView::WindowClosing() {
// Now that the window is closed, we can allow a new one to be opened.
// (WindowClosing comes in asynchronously from the call to Close() and we
// may have already opened a new instance).
if (g_profile_picker_view == this)
g_profile_picker_view = nullptr;
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_VIEW_H_
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/profile_picker.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/window/dialog_delegate.h"
// Dialog widget that contains the Desktop Profile picker webui.
class ProfilePickerView : public views::DialogDelegateView {
private:
friend class ProfilePicker;
// To display the Profile picker, use ProfilePicker::Show().
ProfilePickerView();
~ProfilePickerView() override;
enum InitState {
kNotInitialized = 0,
kInProgress = 1,
kDone = 2,
};
// Displays the profile picker.
void Display();
// Hides the profile picker.
void Clear();
// On system profile creation success, it initializes the view.
void OnSystemProfileCreated(Profile* system_profile,
Profile::CreateStatus status);
// Creates and shows the dialog.
void Init(Profile* guest_profile);
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
bool CanResize() const override;
bool CanMaximize() const override;
bool CanMinimize() const override;
base::string16 GetWindowTitle() const override;
void WindowClosing() override;
views::WebView* web_view_;
InitState initialized_;
base::WeakPtrFactory<ProfilePickerView> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ProfilePickerView);
};
#endif // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_VIEW_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment