diff options
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r-- | chrome/browser/ui/browser_window.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view.cc | 21 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/views/password_generation_bubble_view.cc | 80 | ||||
-rw-r--r-- | chrome/browser/ui/views/password_generation_bubble_view.h | 61 |
5 files changed, 168 insertions, 0 deletions
diff --git a/chrome/browser/ui/browser_window.h b/chrome/browser/ui/browser_window.h index f31a537..3d3851bb 100644 --- a/chrome/browser/ui/browser_window.h +++ b/chrome/browser/ui/browser_window.h @@ -352,6 +352,11 @@ class BrowserWindow : public BaseWindow { // Shows the avatar bubble on the window frame off of the avatar button. virtual void ShowAvatarBubbleFromAvatarButton() = 0; + // Show bubble for password generation positioned relative to |rect|. A stub + // implementation is provided since this feature is currently only available + // for Windows. + virtual void ShowPasswordGenerationBubble(const gfx::Rect& rect) {} + protected: friend class BrowserList; friend class BrowserView; diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 640babf..7f791b2 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -57,6 +57,7 @@ #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" #include "chrome/browser/ui/views/infobars/infobar_container_view.h" #include "chrome/browser/ui/views/location_bar/location_icon_view.h" +#include "chrome/browser/ui/views/password_generation_bubble_view.h" #include "chrome/browser/ui/views/status_bubble_views.h" #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h" @@ -2471,3 +2472,23 @@ void BrowserView::ShowAvatarBubbleFromAvatarButton() { if (button) button->ShowAvatarBubble(); } + +void BrowserView::ShowPasswordGenerationBubble(const gfx::Rect& rect) { + // Create a rect in the content bounds that the bubble will point to. + gfx::Point origin(rect.origin()); + views::View::ConvertPointToScreen(GetTabContentsContainerView(), &origin); + gfx::Rect bounds(origin, rect.size()); + + // Create the bubble. + WebContents* web_contents = GetSelectedWebContents(); + if (!web_contents) + return; + + PasswordGenerationBubbleView* bubble = + new PasswordGenerationBubbleView(bounds, + this, + web_contents->GetRenderViewHost()); + browser::CreateViewsBubble(bubble); + bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); + bubble->Show(); +} diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index d01e7b7..10104d4 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -324,6 +324,7 @@ class BrowserView : public BrowserWindow, virtual void ShowAvatarBubble(content::WebContents* web_contents, const gfx::Rect& rect) OVERRIDE; virtual void ShowAvatarBubbleFromAvatarButton() OVERRIDE; + virtual void ShowPasswordGenerationBubble(const gfx::Rect& rect) OVERRIDE; // Overridden from BrowserWindowTesting: virtual BookmarkBarView* GetBookmarkBarView() const OVERRIDE; diff --git a/chrome/browser/ui/views/password_generation_bubble_view.cc b/chrome/browser/ui/views/password_generation_bubble_view.cc new file mode 100644 index 0000000..46404b4 --- /dev/null +++ b/chrome/browser/ui/views/password_generation_bubble_view.cc @@ -0,0 +1,80 @@ +// 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. + +#include "chrome/browser/ui/views/password_generation_bubble_view.h" + +#include "base/utf_string_conversions.h" +#include "chrome/browser/autofill/password_generator.h" +#include "chrome/browser/ui/views/window.h" +#include "chrome/common/autofill_messages.h" +#include "content/public/browser/render_view_host.h" +#include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/textfield/textfield.h" +#include "ui/views/layout/grid_layout.h" +#include "ui/views/layout/layout_constants.h" + +using views::ColumnSet; +using views::GridLayout; + +PasswordGenerationBubbleView::PasswordGenerationBubbleView( + const gfx::Rect& anchor_rect, + views::View* anchor_view, + content::RenderViewHost* render_view_host) + : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), + accept_button_(NULL), + text_field_(NULL), + anchor_rect_(anchor_rect), + render_view_host_(render_view_host) {} + +PasswordGenerationBubbleView::~PasswordGenerationBubbleView() {} + +void PasswordGenerationBubbleView::Init() { + // TODO(gcasto): Localize text after we have finalized the UI. + // crbug.com/118062 + accept_button_ = new views::NativeTextButton(this, + ASCIIToUTF16("Try It")); + + text_field_ = new views::Textfield(); + text_field_->SetText(ASCIIToUTF16(password_generator_.Generate())); + + views::Label* title_label = new views::Label( + ASCIIToUTF16("Password Suggestion")); + + GridLayout* layout = new GridLayout(this); + SetLayoutManager(layout); + + // Title row. + ColumnSet* cs = layout->AddColumnSet(0); + cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + + // Input row + cs = layout->AddColumnSet(1); + cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 100); + cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); + cs->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + + layout->StartRow(0, 0); + layout->AddView(title_label); + + layout->StartRow(0, 1); + layout->AddView(text_field_); + layout->AddView(accept_button_); +} + +gfx::Rect PasswordGenerationBubbleView::GetAnchorRect() { + return anchor_rect_; +} + +void PasswordGenerationBubbleView::ButtonPressed(views::Button* sender, + const views::Event& event) { + if (sender == accept_button_) { + render_view_host_->Send(new AutofillMsg_GeneratedPasswordAccepted( + render_view_host_->GetRoutingID(), text_field_->text())); + StartFade(false); + } +} diff --git a/chrome/browser/ui/views/password_generation_bubble_view.h b/chrome/browser/ui/views/password_generation_bubble_view.h new file mode 100644 index 0000000..bce9aff --- /dev/null +++ b/chrome/browser/ui/views/password_generation_bubble_view.h @@ -0,0 +1,61 @@ +// 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/view.h" + +namespace content { +class RenderViewHost; +} + +namespace views { +class TextButton; +class Textfield; +} + +// 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| is informed. +class PasswordGenerationBubbleView : public views::BubbleDelegateView, + public views::ButtonListener { + public: + PasswordGenerationBubbleView(const gfx::Rect& anchor_rect, + views::View* anchor_view, + content::RenderViewHost* render_view_host); + 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; + + // Subviews + views::TextButton* accept_button_; + views::Textfield* text_field_; + + // Location that the bubble points to + gfx::Rect anchor_rect_; + + // RenderViewHost associated with the button that spawned this bubble. + content::RenderViewHost* render_view_host_; + + // Class to generate passwords + autofill::PasswordGenerator password_generator_; + + DISALLOW_COPY_AND_ASSIGN(PasswordGenerationBubbleView); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_PASSWORD_GENERATION_BUBBLE_VIEW_H_ |