summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/password_generation_bubble_view.h
blob: fb24ede894d1c4c51c138caa5280f11854d47727 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2012 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_PASSWORD_GENERATION_BUBBLE_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_PASSWORD_GENERATION_BUBBLE_VIEW_H_
#pragma once

#include "chrome/browser/autofill/password_generator.h"
#include "ui/gfx/rect.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/link_listener.h"
#include "ui/views/view.h"
#include "webkit/forms/password_form.h"

namespace content {
class PageNavigator;
class RenderViewHost;
}

namespace views {
class TextButton;
class Textfield;
}

class PasswordManager;

// PasswordGenerationBubbleView is a bubble used to show possible generated
// passwords to users. It is set in the page content, anchored at |anchor_rect|.
// If the generated password is accepted by the user, the renderer associated
// with |render_view_host| and the |password_manager| are informed.
class PasswordGenerationBubbleView : public views::BubbleDelegateView,
                                     public views::ButtonListener,
                                     public views::LinkListener {
 public:
  PasswordGenerationBubbleView(const gfx::Rect& anchor_rect,
                               const webkit::forms::PasswordForm& form,
                               views::View* anchor_view,
                               content::RenderViewHost* render_view_host,
                               content::PageNavigator* navigator,
                               PasswordManager* password_manager);
  virtual ~PasswordGenerationBubbleView();

 private:
  // views::BubbleDelegateView
  virtual void Init() OVERRIDE;
  virtual gfx::Rect GetAnchorRect() OVERRIDE;

  // views::ButtonListener
  virtual void ButtonPressed(views::Button* sender,
                             const views::Event& event) OVERRIDE;

  // views::LinkListener
  virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;

  // views::WidgetDelegate
  virtual views::View* GetInitiallyFocusedView() OVERRIDE;

  // Subviews
  views::TextButton* accept_button_;
  views::Textfield* text_field_;

  // Location that the bubble points to
  gfx::Rect anchor_rect_;

  // The form associated with the password field(s) that we are generated.
  webkit::forms::PasswordForm form_;

  // RenderViewHost associated with the button that spawned this bubble.
  content::RenderViewHost* render_view_host_;

  // An object used to handle page loads that originate from link clicks
  // within this UI.
  content::PageNavigator* navigator_;

  // PasswordManager associated with this tab.
  PasswordManager* password_manager_;

  // Class to generate passwords
  autofill::PasswordGenerator password_generator_;

  DISALLOW_COPY_AND_ASSIGN(PasswordGenerationBubbleView);
};

#endif  // CHROME_BROWSER_UI_VIEWS_PASSWORD_GENERATION_BUBBLE_VIEW_H_