<commit_before>// Copyright 2014 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/user_manager_view.h"

#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/signin_promo.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/user_manager.h"
#include "chrome/browser/ui/views/auto_keep_alive.h"
#include "chrome/browser/ui/views/browser_dialogs.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/guest_view/browser/guest_view_manager.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "google_apis/gaia/gaia_urls.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"
#include "ui/views/window/dialog_delegate.h"

#if defined(OS_WIN)
#include "chrome/browser/shell_integration.h"
#include "ui/base/win/shell.h"
#include "ui/views/win/hwnd_util.h"
#endif

#if defined(USE_ASH)
#include "ash/shelf/shelf_util.h"
#include "ash/wm/window_util.h"
#include "grit/ash_resources.h"
#endif

namespace {

// An open User Manager window. There can only be one open at a time. This
// is reset to NULL when the window is closed.
UserManagerView* instance_ = NULL;
bool instance_under_construction_ = false;

class ReauthDelegate : public views::DialogDelegateView,
                       public UserManager::ReauthDialogObserver {
 public:
  ReauthDelegate(views::WebView* web_view,
                 const std::string& email_address);
  ~ReauthDelegate() override {}

 private:
  ReauthDelegate();
  // views::DialogDelegate:
  gfx::Size GetPreferredSize() const override;
  bool CanResize() const override;
  bool CanMaximize() const override;
  bool CanMinimize() const override;
  bool UseNewStyleForThisDialog() const override;
  ui::ModalType GetModalType() const override;
  void DeleteDelegate() override;
  base::string16 GetWindowTitle() const override;
  int GetDialogButtons() const override;

  // UserManager::ReauthObserver:
  void CloseReauthDialog() override;

  views::WebView* web_view_;
  const std::string email_address_;

  DISALLOW_COPY_AND_ASSIGN(ReauthDelegate);
};

ReauthDelegate::ReauthDelegate(views::WebView* web_view,
                               const std::string& email_address)
    : UserManager::ReauthDialogObserver(
          web_view->GetWebContents(), email_address),
      web_view_(web_view),
      email_address_(email_address) {
  AddChildView(web_view_);
  SetLayoutManager(new views::FillLayout());

  // Load the re-auth URL, prepopulated with the user's email address.
  // Add the index of the profile to the URL so that the inline login page
  // knows which profile to load and update the credentials.
  GURL url = signin::GetReauthURLWithEmail(email_address_);
  web_view_->LoadInitialURL(url);
}

gfx::Size ReauthDelegate::GetPreferredSize() const {
  return gfx::Size(UserManager::kReauthDialogWidth,
                   UserManager::kReauthDialogHeight);
}

bool ReauthDelegate::CanResize() const {
  return true;
}

bool ReauthDelegate::CanMaximize() const  {
  return true;
}

bool ReauthDelegate::CanMinimize() const  {
  return true;
}

bool ReauthDelegate::UseNewStyleForThisDialog() const {
  return false;
}

ui::ModalType ReauthDelegate::GetModalType() const {
  return ui::MODAL_TYPE_WINDOW;
}

void ReauthDelegate::DeleteDelegate() {
  delete this;
}

base::string16 ReauthDelegate::GetWindowTitle() const {
  return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE);
}

int ReauthDelegate::GetDialogButtons() const {
  return ui::DIALOG_BUTTON_NONE;
}

void ReauthDelegate::CloseReauthDialog() {
  GetWidget()->Close();
}

} // namespace

// UserManager -----------------------------------------------------------------

// static
void UserManager::Show(
    const base::FilePath& profile_path_to_focus,
    profiles::UserManagerTutorialMode tutorial_mode,
    profiles::UserManagerProfileSelected profile_open_action) {
  DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath());

  ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::OPEN_USER_MANAGER);
  if (instance_) {
    // If we are showing the User Manager after locking a profile, change the
    // active profile to Guest.
    profiles::SetActiveProfileToGuestIfLocked();

    // Note the time we started opening the User Manager.
    instance_->set_user_manager_started_showing(base::Time::Now());

    // If there's a user manager window open already, just activate it.<commit_msg>Request focus for re-auth webview.<commit_after>// Copyright 2014 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/user_manager_view.h"

#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/signin_promo.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/user_manager.h"
#include "chrome/browser/ui/views/auto_keep_alive.h"
#include "chrome/browser/ui/views/browser_dialogs.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/guest_view/browser/guest_view_manager.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "google_apis/gaia/gaia_urls.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"
#include "ui/views/window/dialog_delegate.h"

#if defined(OS_WIN)
#include "chrome/browser/shell_integration.h"
#include "ui/base/win/shell.h"
#include "ui/views/win/hwnd_util.h"
#endif

#if defined(USE_ASH)
#include "ash/shelf/shelf_util.h"
#include "ash/wm/window_util.h"
#include "grit/ash_resources.h"
#endif

namespace {

// An open User Manager window. There can only be one open at a time. This
// is reset to NULL when the window is closed.
UserManagerView* instance_ = NULL;
bool instance_under_construction_ = false;

class ReauthDelegate : public views::DialogDelegateView,
                       public UserManager::ReauthDialogObserver {
 public:
  ReauthDelegate(views::WebView* web_view,
                 const std::string& email_address);
  ~ReauthDelegate() override {}

 private:
  ReauthDelegate();
  // views::DialogDelegate:
  gfx::Size GetPreferredSize() const override;
  bool CanResize() const override;
  bool CanMaximize() const override;
  bool CanMinimize() const override;
  bool UseNewStyleForThisDialog() const override;
  ui::ModalType GetModalType() const override;
  void DeleteDelegate() override;
  base::string16 GetWindowTitle() const override;
  int GetDialogButtons() const override;
  views::View* GetInitiallyFocusedView() override;

  // UserManager::ReauthObserver:
  void CloseReauthDialog() override;

  views::WebView* web_view_;
  const std::string email_address_;

  DISALLOW_COPY_AND_ASSIGN(ReauthDelegate);
};

ReauthDelegate::ReauthDelegate(views::WebView* web_view,
                               const std::string& email_address)
    : UserManager::ReauthDialogObserver(
          web_view->GetWebContents(), email_address),
      web_view_(web_view),
      email_address_(email_address) {
  AddChildView(web_view_);
  SetLayoutManager(new views::FillLayout());

  // Load the re-auth URL, prepopulated with the user's email address.
  // Add the index of the profile to the URL so that the inline login page
  // knows which profile to load and update the credentials.
  GURL url = signin::GetReauthURLWithEmail(email_address_);
  web_view_->LoadInitialURL(url);
}

gfx::Size ReauthDelegate::GetPreferredSize() const {
  return gfx::Size(UserManager::kReauthDialogWidth,
                   UserManager::kReauthDialogHeight);
}

bool ReauthDelegate::CanResize() const {
  return true;
}

bool ReauthDelegate::CanMaximize() const  {
  return true;
}

bool ReauthDelegate::CanMinimize() const  {
  return true;
}

bool ReauthDelegate::UseNewStyleForThisDialog() const {
  return false;
}

ui::ModalType ReauthDelegate::GetModalType() const {
  return ui::MODAL_TYPE_WINDOW;
}

void ReauthDelegate::DeleteDelegate() {
  delete this;
}

base::string16 ReauthDelegate::GetWindowTitle() const {
  return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE);
}

int ReauthDelegate::GetDialogButtons() const {
  return ui::DIALOG_BUTTON_NONE;
}

views::View* ReauthDelegate::GetInitiallyFocusedView() {
  return static_cast<views::View*>(web_view_);
}

void ReauthDelegate::CloseReauthDialog() {
  GetWidget()->Close();
}

} // namespace

// UserManager -----------------------------------------------------------------

// static
void UserManager::Show(
    const base::FilePath& profile_path_to_focus,
    profiles::UserManagerTutorialMode tutorial_mode,
    profiles::UserManagerProfileSelected profile_open_action) {
  DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath());

  ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::OPEN_USER_MANAGER);
  if (instance_) {
    // If we are showing the User Manager after locking a profile, change the
    // active profile to Guest.
    profiles::SetActiveProfileToGuestIfLocked();

    // Note the time we started opening the User Manager.
    instance_->set_user_manager_started_showing(base::Time::Now());

    // If there's a user manager window open already, just activate it.
{'fraction_non_alphanumeric': 0.12532850022655187, 'fraction_numerical': 0.002899864068871772, 'mean_word_length': 4.8298996302165875, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5320686', 'n_tokens_mistral': 3493, 'n_tokens_neox': 3448, 'n_words': 730}