Commit 1624e819 authored by npentrel@chromium.org's avatar npentrel@chromium.org

This CL refactors the Manage Passwords Bubble Code which previously depended...

This CL refactors the Manage Passwords Bubble Code which previously depended on TabSpecificContentSettings to directly interact with ManagePasswordsController.

BUG=261628

Review URL: https://codereview.chromium.org/87853004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238400 0039d316-1c4b-4281-b951-d872f2087c98
parent d291a2ce
......@@ -34,7 +34,6 @@
#include "net/cookies/canonical_cookie.h"
#include "webkit/common/fileapi/file_system_types.h"
using autofill::PasswordFormMap;
using content::BrowserThread;
using content::NavigationController;
using content::NavigationEntry;
......@@ -43,21 +42,6 @@ using content::WebContents;
DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings);
TabSpecificContentSettings::PasswordObserver::PasswordObserver(
TabSpecificContentSettings* tab_specific_content_settings)
: tab_specific_content_settings_(tab_specific_content_settings) {
tab_specific_content_settings_->SetPasswordObserver(this);
}
TabSpecificContentSettings::PasswordObserver::~PasswordObserver() {
if (tab_specific_content_settings_)
tab_specific_content_settings_->SetPasswordObserver(NULL);
}
void TabSpecificContentSettings::PasswordObserver::ContentSettingsDestroyed() {
tab_specific_content_settings_ = NULL;
}
TabSpecificContentSettings::SiteDataObserver::SiteDataObserver(
TabSpecificContentSettings* tab_specific_content_settings)
: tab_specific_content_settings_(tab_specific_content_settings) {
......@@ -75,7 +59,6 @@ void TabSpecificContentSettings::SiteDataObserver::ContentSettingsDestroyed() {
TabSpecificContentSettings::TabSpecificContentSettings(WebContents* tab)
: content::WebContentsObserver(tab),
password_observer_(NULL),
profile_(Profile::FromBrowserContext(tab->GetBrowserContext())),
allowed_local_shared_objects_(profile_),
blocked_local_shared_objects_(profile_),
......@@ -84,11 +67,7 @@ TabSpecificContentSettings::TabSpecificContentSettings(WebContents* tab)
pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()),
previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()),
pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT),
load_plugins_link_enabled_(true),
manage_passwords_icon_to_be_shown_(false),
password_to_be_saved_(false),
manage_passwords_bubble_needs_showing_(false),
password_submitted_(false) {
load_plugins_link_enabled_(true) {
ClearBlockedContentSettingsExceptForCookies();
ClearCookieSpecificContentSettings();
......@@ -100,8 +79,6 @@ TabSpecificContentSettings::TabSpecificContentSettings(WebContents* tab)
TabSpecificContentSettings::~TabSpecificContentSettings() {
FOR_EACH_OBSERVER(
SiteDataObserver, observer_list_, ContentSettingsDestroyed());
if (password_observer_)
password_observer_->ContentSettingsDestroyed();
}
TabSpecificContentSettings* TabSpecificContentSettings::Get(
......@@ -494,27 +471,6 @@ void TabSpecificContentSettings::OnProtectedMediaIdentifierPermissionSet(
}
#endif
void TabSpecificContentSettings::OnPasswordSubmitted(
PasswordFormManager* form_manager) {
form_manager_.reset(form_manager);
password_form_map_ = form_manager_->best_matches();
manage_passwords_icon_to_be_shown_ = true;
password_to_be_saved_ = true;
manage_passwords_bubble_needs_showing_ = true;
password_submitted_ = true;
NotifyPasswordObserver();
}
void TabSpecificContentSettings::OnPasswordAutofilled(
const PasswordFormMap& password_form_map) {
password_form_map_ = password_form_map;
manage_passwords_icon_to_be_shown_ = true;
password_to_be_saved_ = false;
manage_passwords_bubble_needs_showing_ = false;
password_submitted_ = false;
NotifyPasswordObserver();
}
TabSpecificContentSettings::MicrophoneCameraState
TabSpecificContentSettings::GetMicrophoneCameraState() const {
if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) &&
......@@ -698,12 +654,6 @@ void TabSpecificContentSettings::DidNavigateMainFrame(
ClearBlockedContentSettingsExceptForCookies();
GeolocationDidNavigate(details);
MIDIDidNavigate(details);
// Reset password states for next page.
manage_passwords_icon_to_be_shown_ = false;
password_to_be_saved_ = false;
manage_passwords_bubble_needs_showing_ = false;
NotifySiteDataObservers();
NotifyPasswordObserver();
}
}
......@@ -739,11 +689,6 @@ void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url,
}
}
void TabSpecificContentSettings::SavePassword() {
DCHECK(form_manager_.get());
form_manager_->Save();
}
void TabSpecificContentSettings::Observe(
int type,
const content::NotificationSource& source,
......@@ -769,16 +714,6 @@ void TabSpecificContentSettings::Observe(
}
}
void TabSpecificContentSettings::SetPasswordObserver(
PasswordObserver* observer) {
password_observer_ = observer;
}
void TabSpecificContentSettings::NotifyPasswordObserver() {
if (password_observer_)
password_observer_->OnPasswordAction();
}
void TabSpecificContentSettings::AddSiteDataObserver(
SiteDataObserver* observer) {
observer_list_.AddObserver(observer);
......
......@@ -15,7 +15,6 @@
#include "chrome/browser/content_settings/content_settings_usages_state.h"
#include "chrome/browser/content_settings/local_shared_objects_container.h"
#include "chrome/browser/media/media_stream_devices_controller.h"
#include "chrome/browser/password_manager/password_form_manager.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_types.h"
#include "chrome/common/custom_handlers/protocol_handler.h"
......@@ -56,31 +55,6 @@ class TabSpecificContentSettings
MICROPHONE_CAMERA_BLOCKED,
};
// A PasswordObserver is implemented in ManagePasswordsIconController which
// will be notified when a password form is submitted.
class PasswordObserver {
public:
explicit PasswordObserver(
TabSpecificContentSettings* tab_specific_content_settings);
virtual ~PasswordObserver();
// Called whenever a password form is submitted.
virtual void OnPasswordAction() = 0;
TabSpecificContentSettings* tab_specific_content_settings() {
return tab_specific_content_settings_;
}
// Called when the TabSpecificContentSettings is destroyed; nulls out
// the local reference.
void ContentSettingsDestroyed();
private:
TabSpecificContentSettings* tab_specific_content_settings_;
DISALLOW_COPY_AND_ASSIGN(PasswordObserver);
};
// Classes that want to be notified about site data events must implement
// this abstract class and add themselves as observer to the
// |TabSpecificContentSettings|.
......@@ -231,32 +205,6 @@ class TabSpecificContentSettings
// Returns the state of the camera and microphone usage.
MicrophoneCameraState GetMicrophoneCameraState() const;
void unset_manage_passwords_bubble_needs_showing() {
manage_passwords_bubble_needs_showing_ = false;
}
bool password_to_be_saved() const {
return password_to_be_saved_;
}
void unset_password_to_be_saved() {
password_to_be_saved_ = false;
}
bool manage_passwords_bubble_needs_showing() const {
return manage_passwords_bubble_needs_showing_;
}
bool manage_passwords_icon_to_be_shown() const {
return manage_passwords_icon_to_be_shown_;
}
// Returns whether there is a password to be saved.
bool GetPasswordSavingState() const;
// Returns whether the password bubble has been shown to the user.
bool GetManagePasswordsBubbleShownState() const;
const std::set<std::string>& BlockedResourcesForType(
ContentSettingsType content_type) const;
......@@ -345,33 +293,6 @@ class TabSpecificContentSettings
virtual void AppCacheAccessed(const GURL& manifest_url,
bool blocked_by_policy) OVERRIDE;
void SavePassword();
const autofill::PasswordForm pending_credentials() const {
return form_manager_->pending_credentials();
}
const autofill::PasswordFormMap best_matches() const {
return password_form_map_;
}
// TODO(npentrel) This ought to be changed. Best matches should be newly
// made when opening the ManagePasswordsBubble because there may have been
// changes to the best matches via the settings page. At the moment this also
// fails if one deletes a password when they are autofilled, as it still shows
// up after logging in and saving a password.
void remove_from_best_matches(autofill::PasswordForm password_form) {
password_form_map_.erase(password_form.username_value);
}
bool password_submitted() const {
return password_submitted_;
}
void password_submitted(bool password_submitted) {
password_submitted_ = password_submitted;
}
// Message handlers. Public for testing.
void OnContentBlocked(ContentSettingsType type,
const std::string& resource_identifier);
......@@ -415,25 +336,10 @@ class TabSpecificContentSettings
const MediaStreamDevicesController::MediaStreamTypeSettingsMap&
request_permissions);
// Called when the user submits a form containing login information, so we
// can handle later requests to save or blacklist that login information.
// This stores the provided object in form_manager_ and triggers the UI to
// prompt the user about whether they would like to save the password.
void OnPasswordSubmitted(PasswordFormManager* form_manager);
// Called when a form is autofilled with login information, so we can manage
// password credentials for the current site which are stored in
// |password_form_map|. This stores a copy of |password_form_map| and shows
// the manage password icon.
void OnPasswordAutofilled(const autofill::PasswordFormMap& password_form_map);
// There methods are called to update the status about MIDI access.
void OnMIDISysExAccessed(const GURL& reqesting_origin);
void OnMIDISysExAccessBlocked(const GURL& requesting_origin);
// Is called to set ManagePasswordsIconController as an observer.
void SetPasswordObserver(PasswordObserver* observer);
// Adds the given |SiteDataObserver|. The |observer| is notified when a
// locale shared object, like for example a cookie, is accessed.
void AddSiteDataObserver(SiteDataObserver* observer);
......@@ -453,12 +359,6 @@ class TabSpecificContentSettings
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Notifies the registered PasswordObserver of a sumitted password form.
void NotifyPasswordObserver();
// Currently the registered PasswordObserver.
PasswordObserver* password_observer_;
// Notifies all registered |SiteDataObserver|s.
void NotifySiteDataObservers();
......@@ -522,21 +422,6 @@ class TabSpecificContentSettings
std::string media_stream_requested_audio_device_;
std::string media_stream_requested_video_device_;
// Set by OnPasswordSubmitted() when the user submits a form containing login
// information. If the user responds to a subsequent "Do you want to save
// this password?" prompt, we ask this object to save or blacklist the
// associated login information in Chrome's password store.
scoped_ptr<PasswordFormManager> form_manager_;
// All previously stored credentials for a specific site. Set by
// OnPasswordSubmitted() or OnPasswordAutofilled().
autofill::PasswordFormMap password_form_map_;
bool manage_passwords_icon_to_be_shown_;
bool password_to_be_saved_;
bool manage_passwords_bubble_needs_showing_;
bool password_submitted_;
DISALLOW_COPY_AND_ASSIGN(TabSpecificContentSettings);
};
......
......@@ -11,11 +11,11 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/platform_thread.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/password_manager/password_form_manager.h"
#include "chrome/browser/password_manager/password_manager_delegate.h"
#include "chrome/browser/password_manager/password_manager_metrics_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h"
......@@ -340,10 +340,10 @@ void PasswordManager::OnPasswordFormsRendered(
if (ShouldShowSavePasswordInfoBar()) {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableSavePasswordBubble)) {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
if (content_settings) {
content_settings->OnPasswordSubmitted(
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller =
ManagePasswordsBubbleUIController::FromWebContents(web_contents());
if (manage_passwords_bubble_ui_controller) {
manage_passwords_bubble_ui_controller->OnPasswordSubmitted(
provisional_save_manager_.release());
} else {
provisional_save_manager_.reset();
......@@ -429,8 +429,8 @@ void PasswordManager::Autofill(
break;
}
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
if (content_settings)
content_settings->OnPasswordAutofilled(best_matches);
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller =
ManagePasswordsBubbleUIController::FromWebContents(web_contents());
if (manage_passwords_bubble_ui_controller)
manage_passwords_bubble_ui_controller->OnPasswordAutofilled(best_matches);
}
......@@ -39,7 +39,7 @@
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/find_bar/find_tab_helper.h"
#include "chrome/browser/ui/hung_plugin_tab_helper.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
#include "chrome/browser/ui/pdf/pdf_tab_helper.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "chrome/browser/ui/sad_tab_helper.h"
......@@ -161,7 +161,7 @@ void BrowserTabContents::AttachTabHelpers(WebContents* web_contents) {
TabSpecificContentSettings::CreateForWebContents(web_contents);
ThumbnailTabHelper::CreateForWebContents(web_contents);
TranslateTabHelper::CreateForWebContents(web_contents);
ManagePasswordsIconController::CreateForWebContents(web_contents);
ManagePasswordsBubbleUIController::CreateForWebContents(web_contents);
ZoomController::CreateForWebContents(web_contents);
#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
......
......@@ -66,7 +66,7 @@
#include "chrome/browser/ui/omnibox/location_bar_util.h"
#include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/extensions/extension_info_ui.h"
#include "chrome/browser/ui/zoom/zoom_controller.h"
......@@ -1615,10 +1615,10 @@ void LocationBarViewGtk::UpdateManagePasswordsIcon() {
if (!manage_passwords_icon_.get() || !web_contents)
return;
ManagePasswordsIconController* manage_passwords_icon_controller =
ManagePasswordsIconController::FromWebContents(web_contents);
if (!manage_passwords_icon_controller ||
!manage_passwords_icon_controller->password_to_be_saved() ||
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller =
ManagePasswordsBubbleUIController::FromWebContents(web_contents);
if (!manage_passwords_bubble_ui_controller ||
!manage_passwords_bubble_ui_controller->password_to_be_saved() ||
GetToolbarModel()->input_in_progress()) {
gtk_widget_hide(manage_passwords_icon_.get());
ManagePasswordsBubbleGtk::CloseBubble();
......@@ -1635,10 +1635,10 @@ void LocationBarViewGtk::UpdateManagePasswordsIcon() {
UTF16ToUTF8(tooltip).c_str());
gtk_widget_show(manage_passwords_icon_.get());
if (manage_passwords_icon_controller->
if (manage_passwords_bubble_ui_controller->
manage_passwords_bubble_needs_showing()) {
ShowManagePasswordsBubble();
manage_passwords_icon_controller->OnBubbleShown();
manage_passwords_bubble_ui_controller->OnBubbleShown();
}
}
......
......@@ -5,14 +5,13 @@
#include "chrome/browser/ui/gtk/manage_passwords_bubble_gtk.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/gtk/gtk_theme_service.h"
#include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
#include "grit/generated_resources.h"
#include "ui/base/gtk/gtk_hig_constants.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -122,9 +121,8 @@ void ManagePasswordsBubbleGtk::OnDestroy(GtkWidget* widget) {
}
void ManagePasswordsBubbleGtk::OnSaveButtonClicked(GtkWidget* button) {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents_);
content_settings->SavePassword();
ManagePasswordsBubbleUIController::FromWebContents(web_contents_)->
SavePassword();
Close();
}
......
......@@ -9,6 +9,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
#include "chrome/common/url_constants.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -17,15 +18,16 @@ using content::WebContents;
using autofill::PasswordFormMap;
ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
WebContents* web_contents)
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
web_contents_(web_contents) {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller =
ManagePasswordsBubbleUIController::FromWebContents(web_contents_);
password_submitted_ = content_settings->password_submitted();
password_submitted_ =
manage_passwords_bubble_ui_controller->password_submitted();
if (password_submitted_) {
if (content_settings->password_to_be_saved())
if (manage_passwords_bubble_ui_controller->password_to_be_saved())
manage_passwords_bubble_state_ = PASSWORD_TO_BE_SAVED;
else
manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING;
......@@ -36,9 +38,11 @@ ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
title_ = l10n_util::GetStringUTF16(
(manage_passwords_bubble_state_ == PASSWORD_TO_BE_SAVED) ?
IDS_SAVE_PASSWORD : IDS_MANAGE_PASSWORDS);
if (password_submitted_)
pending_credentials_ = content_settings->pending_credentials();
best_matches_ = content_settings->best_matches();
if (password_submitted_) {
pending_credentials_ =
manage_passwords_bubble_ui_controller->pending_credentials();
}
best_matches_ = manage_passwords_bubble_ui_controller->best_matches();
manage_link_ =
l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK);
}
......@@ -50,10 +54,10 @@ void ManagePasswordsBubbleModel::OnCancelClicked() {
}
void ManagePasswordsBubbleModel::OnSaveClicked() {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents_);
content_settings->SavePassword();
content_settings->unset_password_to_be_saved();
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller =
ManagePasswordsBubbleUIController::FromWebContents(web_contents_);
manage_passwords_bubble_ui_controller->SavePassword();
manage_passwords_bubble_ui_controller->unset_password_to_be_saved();
manage_passwords_bubble_state_ = MANAGE_PASSWORDS_AFTER_SAVING;
}
......@@ -62,8 +66,9 @@ void ManagePasswordsBubbleModel::OnManageLinkClicked() {
chrome::kPasswordManagerSubPage);
}
void ManagePasswordsBubbleModel::PasswordAction(
autofill::PasswordForm password_form, bool remove) {
void ManagePasswordsBubbleModel::OnPasswordAction(
autofill::PasswordForm password_form,
bool remove) {
if (!web_contents_)
return;
Profile* profile =
......@@ -78,17 +83,15 @@ void ManagePasswordsBubbleModel::PasswordAction(
// This is necessary in case the bubble is instantiated again, we thus do not
// display the pending credentials if they were deleted.
if (password_form.username_value == pending_credentials_.username_value) {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents_);
content_settings->password_submitted(!remove);
ManagePasswordsBubbleUIController::FromWebContents(web_contents_)->
set_password_submitted(!remove);
}
}
void ManagePasswordsBubbleModel::DeleteFromBestMatches(
autofill::PasswordForm password_form) {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents_);
content_settings->remove_from_best_matches(password_form);
ManagePasswordsBubbleUIController::FromWebContents(web_contents_)->
RemoveFromBestMatches(password_form);
}
void ManagePasswordsBubbleModel::WebContentsDestroyed(
......
......@@ -5,7 +5,10 @@
#ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_
#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "components/autofill/core/common/password_form.h"
#include "content/public/browser/web_contents_observer.h"
class ManagePasswordsIconController;
namespace content {
class WebContents;
......@@ -35,7 +38,7 @@ class ManagePasswordsBubbleModel : public content::WebContentsObserver {
// Called by the view code to delete or add a password form to the
// PasswordStore.
void PasswordAction(autofill::PasswordForm password_form, bool remove);
void OnPasswordAction(autofill::PasswordForm password_form, bool remove);
// Called by the view code when the ManagePasswordItemView is destroyed and
// the user chose to delete the password.
......
// Copyright 2013 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/passwords/manage_passwords_bubble_ui_controller.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "content/public/browser/notification_service.h"
using autofill::PasswordFormMap;
DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsBubbleUIController);
ManagePasswordsBubbleUIController::ManagePasswordsBubbleUIController(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
manage_passwords_icon_to_be_shown_(false),
password_to_be_saved_(false),
manage_passwords_bubble_needs_showing_(false),
password_submitted_(false) {}
ManagePasswordsBubbleUIController::~ManagePasswordsBubbleUIController() {}
void ManagePasswordsBubbleUIController::UpdateBubbleAndIconVisibility() {
#if !defined(OS_ANDROID)
Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
if (!browser)
return;
LocationBar* location_bar = browser->window()->GetLocationBar();
DCHECK(location_bar);
location_bar->UpdateManagePasswordsIconAndBubble();
#endif
}
void ManagePasswordsBubbleUIController::OnPasswordSubmitted(
PasswordFormManager* form_manager) {
form_manager_.reset(form_manager);
password_form_map_ = form_manager_->best_matches();
manage_passwords_icon_to_be_shown_ = true;
password_to_be_saved_ = true;
manage_passwords_bubble_needs_showing_ = true;
password_submitted_ = true;
UpdateBubbleAndIconVisibility();
}
void ManagePasswordsBubbleUIController::OnPasswordAutofilled(
const PasswordFormMap& password_form_map) {
password_form_map_ = password_form_map;
manage_passwords_icon_to_be_shown_ = true;
password_to_be_saved_ = false;
manage_passwords_bubble_needs_showing_ = false;
password_submitted_ = false;
UpdateBubbleAndIconVisibility();
}
void ManagePasswordsBubbleUIController::RemoveFromBestMatches(
autofill::PasswordForm password_form) {
password_form_map_.erase(password_form.username_value);
}
void ManagePasswordsBubbleUIController::OnBubbleShown() {
unset_manage_passwords_bubble_needs_showing();
}
void ManagePasswordsBubbleUIController::SavePassword() {
DCHECK(form_manager_.get());
form_manager_->Save();
}
void ManagePasswordsBubbleUIController::DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) {
if (details.is_in_page)
return;
// Reset password states for next page.
manage_passwords_icon_to_be_shown_ = false;
password_to_be_saved_ = false;
manage_passwords_bubble_needs_showing_ = false;
password_submitted_ = false;
UpdateBubbleAndIconVisibility();
}
// Copyright 2013 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_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_UI_CONTROLLER_H_
#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_UI_CONTROLLER_H_
#include "chrome/browser/password_manager/password_form_manager.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
namespace content {
class WebContents;
}
// Per-tab class to control the Omnibox password icon and bubble.
class ManagePasswordsBubbleUIController
: public content::WebContentsObserver,
public content::WebContentsUserData<ManagePasswordsBubbleUIController> {
public:
virtual ~ManagePasswordsBubbleUIController();
// Called when the user submits a form containing login information, so we
// can handle later requests to save or blacklist that login information.
// This stores the provided object in form_manager_ and triggers the UI to
// prompt the user about whether they would like to save the password.
void OnPasswordSubmitted(PasswordFormManager* form_manager);
// Called when a form is autofilled with login information, so we can manage
// password credentials for the current site which are stored in
// |password_form_map|. This stores a copy of |password_form_map| and shows
// the manage password icon.
void OnPasswordAutofilled(const autofill::PasswordFormMap& password_form_map);
// TODO(npentrel) This ought to be changed. Best matches should be newly
// made when opening the ManagePasswordsBubble because there may have been
// changes to the best matches via the settings page. At the moment this also
// fails if one deletes a password when they are autofilled, as it still shows
// up after logging in and saving a password.
void RemoveFromBestMatches(autofill::PasswordForm password_form);
void SavePassword();
// Called when the bubble is opened after the icon gets displayed. We change
// the state to know that we do not need to pop up the bubble again.
void OnBubbleShown();
bool manage_passwords_icon_to_be_shown() const {
return manage_passwords_icon_to_be_shown_;
}
bool password_to_be_saved() const {
return password_to_be_saved_;
}
bool manage_passwords_bubble_needs_showing() const {
return manage_passwords_bubble_needs_showing_;
}
void unset_manage_passwords_bubble_needs_showing() {
manage_passwords_bubble_needs_showing_ = false;
}
void unset_password_to_be_saved() {
password_to_be_saved_ = false;
}
const autofill::PasswordForm pending_credentials() const {
return form_manager_->pending_credentials();
}
const autofill::PasswordFormMap best_matches() const {
return password_form_map_;
}
bool password_submitted() const {
return password_submitted_;
}
void set_password_submitted(bool password_submitted) {
password_submitted_ = password_submitted;
}
private:
friend class content::WebContentsUserData<ManagePasswordsBubbleUIController>;
explicit ManagePasswordsBubbleUIController(
content::WebContents* web_contents);
// Called when a passwordform is autofilled, when a new passwordform is
// submitted, or when a navigation occurs to update the visibility of the
// manage passwords icon and bubble.
void UpdateBubbleAndIconVisibility();
// content::WebContentsObserver:
virtual void DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) OVERRIDE;
// Set by OnPasswordSubmitted() when the user submits a form containing login
// information. If the user responds to a subsequent "Do you want to save
// this password?" prompt, we ask this object to save or blacklist the
// associated login information in Chrome's password store.
scoped_ptr<PasswordFormManager> form_manager_;
// All previously stored credentials for a specific site. Set by
// OnPasswordSubmitted() or OnPasswordAutofilled().
autofill::PasswordFormMap password_form_map_;
bool manage_passwords_icon_to_be_shown_;
bool password_to_be_saved_;
bool manage_passwords_bubble_needs_showing_;
// Stores whether a new password has been submitted, if so we have
// |pending_credentials|.
bool password_submitted_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleUIController);
};
#endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_UI_CONTROLLER_H_
// Copyright 2013 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/passwords/manage_passwords_icon_controller.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "content/public/browser/notification_service.h"
DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsIconController);
ManagePasswordsIconController::ManagePasswordsIconController(
content::WebContents* web_contents)
: TabSpecificContentSettings::PasswordObserver(
TabSpecificContentSettings::FromWebContents(web_contents)),
content::WebContentsObserver(web_contents),
manage_passwords_icon_to_be_shown_(false),
password_to_be_saved_(false),
manage_passwords_bubble_needs_showing_(false),
browser_context_(web_contents->GetBrowserContext()) {}
ManagePasswordsIconController::~ManagePasswordsIconController() {}
void ManagePasswordsIconController::OnBubbleShown() {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
DCHECK(content_settings);
content_settings->unset_manage_passwords_bubble_needs_showing();
}
void ManagePasswordsIconController::OnPasswordAction() {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents());
DCHECK(content_settings);
manage_passwords_icon_to_be_shown_ =
content_settings->manage_passwords_icon_to_be_shown();
password_to_be_saved_ = content_settings->password_to_be_saved();
manage_passwords_bubble_needs_showing_ =
content_settings->manage_passwords_bubble_needs_showing();
Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
if (!browser)
return;
LocationBar* location_bar = browser->window()->GetLocationBar();
DCHECK(location_bar);
location_bar->UpdateManagePasswordsIconAndBubble();
}
// Copyright 2013 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_PASSWORDS_MANAGE_PASSWORDS_ICON_CONTROLLER_H_
#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_ICON_CONTROLLER_H_
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
namespace content {
class WebContents;
}
// Per-tab class to control the Omnibox password icon's visibility.
class ManagePasswordsIconController
: public TabSpecificContentSettings::PasswordObserver,
public content::WebContentsObserver,
public content::WebContentsUserData<ManagePasswordsIconController> {
public:
virtual ~ManagePasswordsIconController();
bool manage_passwords_icon_to_be_shown() const {
return manage_passwords_icon_to_be_shown_;
}
bool password_to_be_saved() const {
return password_to_be_saved_;
}
bool manage_passwords_bubble_needs_showing() const {
return manage_passwords_bubble_needs_showing_;
}
// Called when the bubble is opened after the icon gets displayed. We change
// the state to know that we do not need to pop up the bubble again.
void OnBubbleShown();
private:
friend class content::WebContentsUserData<ManagePasswordsIconController>;
explicit ManagePasswordsIconController(content::WebContents* web_contents);
// TabSpecificContentSettings::PasswordObserver:
virtual void OnPasswordAction() OVERRIDE;
bool manage_passwords_icon_to_be_shown_;
bool password_to_be_saved_;
bool manage_passwords_bubble_needs_showing_;
content::BrowserContext* browser_context_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsIconController);
};
#endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_ICON_CONTROLLER_H_
......@@ -33,7 +33,7 @@
#include "chrome/browser/ui/omnibox/location_bar_util.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h"
......@@ -1394,7 +1394,7 @@ bool LocationBarView::RefreshManagePasswordsIconView() {
return false;
const bool was_visible = manage_passwords_icon_view_->visible();
manage_passwords_icon_view_->Update(
ManagePasswordsIconController::FromWebContents(web_contents));
ManagePasswordsBubbleUIController::FromWebContents(web_contents));
return was_visible != manage_passwords_icon_view_->visible();
}
......@@ -1417,7 +1417,7 @@ void LocationBarView::ShowManagePasswordsBubbleIfNeeded() {
if (!web_contents)
return;
manage_passwords_icon_view_->ShowBubbleIfNeeded(
ManagePasswordsIconController::FromWebContents(web_contents));
ManagePasswordsBubbleUIController::FromWebContents(web_contents));
}
bool LocationBarView::HasValidSuggestText() const {
......
......@@ -87,10 +87,10 @@ ManagePasswordItemView::ManagePasswordItemView(
// static
string16 ManagePasswordItemView::GetPasswordDisplayString(
const string16& password) {
const wchar_t password_bullet = 0x2022;
const size_t max_password_char = 22;
return string16(std::min(password.length(), max_password_char),
password_bullet);
const wchar_t kPasswordBullet = 0x2022;
const size_t kMaxPasswordChar = 22;
return string16(std::min(password.length(), kMaxPasswordChar),
kPasswordBullet);
}
ManagePasswordItemView::~ManagePasswordItemView() {
......@@ -107,14 +107,14 @@ void ManagePasswordItemView::Refresh() {
delete_or_undo_button_->SetImage(
views::Button::STATE_NORMAL,
*rb->GetImageSkiaNamed(IDR_PASSWORD_UNDO_ARROW));
manage_passwords_bubble_model_->PasswordAction(password_form_, true);
manage_passwords_bubble_model_->OnPasswordAction(password_form_, true);
} else {
label_1_->SetText(password_form_.username_value);
label_2_->SetText(GetPasswordDisplayString(password_form_.password_value));
label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
delete_or_undo_button_->SetImage(views::Button::STATE_NORMAL,
*rb->GetImageSkiaNamed(IDR_CLOSE_2));
manage_passwords_bubble_model_->PasswordAction(password_form_, false);
manage_passwords_bubble_model_->OnPasswordAction(password_form_, false);
}
}
......
......@@ -8,7 +8,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/passwords/manage_password_item_view.h"
......@@ -23,8 +23,13 @@
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"
// Helpers --------------------------------------------------------------------
namespace {
// Updates either the biggest possible width for the username field in the
// manage passwords bubble or the biggest possible width for the password field.
void UpdateBiggestWidth(const autofill::PasswordForm& password_form,
bool username,
int* biggest_width) {
......@@ -40,6 +45,9 @@ void UpdateBiggestWidth(const autofill::PasswordForm& password_form,
} // namespace
// ManagePasswordsBubbleView --------------------------------------------------
// static
ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ =
NULL;
......@@ -58,7 +66,7 @@ void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents,
views::View* anchor_view = is_fullscreen ?
NULL : browser_view->GetLocationBarView()->manage_passwords_icon_view();
manage_passwords_bubble_ =
new ManagePasswordsBubbleView(anchor_view, web_contents, icon_view);
new ManagePasswordsBubbleView(web_contents, anchor_view, icon_view);
if (is_fullscreen) {
manage_passwords_bubble_->set_parent_window(
......@@ -90,8 +98,8 @@ bool ManagePasswordsBubbleView::IsShowing() {
}
ManagePasswordsBubbleView::ManagePasswordsBubbleView(
views::View* anchor_view,
content::WebContents* web_contents,
views::View* anchor_view,
ManagePasswordsIconView* icon_view)
: BubbleDelegateView(
anchor_view,
......@@ -152,19 +160,21 @@ void ManagePasswordsBubbleView::Init() {
SetLayoutManager(layout);
// This calculates the necessary widths for the list of credentials in the
// bubble.
// bubble. We do not need to clamp the password field width because
// ManagePasswordItemView::GetPasswordFisplayString() does this.
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
const int kPredefinedFieldMaxWidth =
const int predefined_username_field_max_width =
rb->GetFont(ui::ResourceBundle::BaseFont).GetAverageCharacterWidth() * 22;
const int kMaxUsernameFieldWidth = std::min(
GetMaximumUsernameOrPasswordWidth(true), kPredefinedFieldMaxWidth);
const int kFirstFieldWidth = std::max(kMaxUsernameFieldWidth,
const int max_username_or_password_width =
std::min(GetMaximumUsernameOrPasswordWidth(true),
predefined_username_field_max_width);
const int first_field_width = std::max(max_username_or_password_width,
views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)).
GetPreferredSize().width());
const int kMaxPasswordFieldWidth = GetMaximumUsernameOrPasswordWidth(false);
const int kSecondFieldWidth = std::max(kMaxPasswordFieldWidth,
const int second_field_width = std::max(
GetMaximumUsernameOrPasswordWidth(false),
views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)).
GetPreferredSize().width());
......@@ -198,8 +208,8 @@ void ManagePasswordsBubbleView::Init() {
layout->StartRow(0, kSingleColumnCredentialsId);
ManagePasswordItemView* item = new ManagePasswordItemView(
manage_passwords_bubble_model_,
manage_passwords_bubble_model_->pending_credentials(), kFirstFieldWidth,
kSecondFieldWidth);
manage_passwords_bubble_model_->pending_credentials(),
first_field_width, second_field_width);
item->set_border(views::Border::CreateSolidSidedBorder(
1, 0, 1, 0, GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor)));
......@@ -254,8 +264,8 @@ void ManagePasswordsBubbleView::Init() {
i != manage_passwords_bubble_model_->best_matches().end(); ++i) {
layout->StartRow(0, kSingleColumnCredentialsId);
ManagePasswordItemView* item = new ManagePasswordItemView(
manage_passwords_bubble_model_, *i->second, kFirstFieldWidth,
kSecondFieldWidth);
manage_passwords_bubble_model_, *i->second, first_field_width,
second_field_width);
if (i == manage_passwords_bubble_model_->best_matches().begin()) {
item->set_border(views::Border::CreateSolidSidedBorder(
1, 0, 1, 0, GetNativeTheme()->GetSystemColor(
......@@ -280,7 +290,7 @@ void ManagePasswordsBubbleView::Init() {
ManagePasswordItemView* item = new ManagePasswordItemView(
manage_passwords_bubble_model_,
manage_passwords_bubble_model_->pending_credentials(),
kFirstFieldWidth, kSecondFieldWidth);
first_field_width, second_field_width);
if (manage_passwords_bubble_model_->best_matches().empty()) {
item->set_border(views::Border::CreateSolidSidedBorder(1, 0, 1, 0,
GetNativeTheme()->GetSystemColor(
......
......@@ -38,14 +38,14 @@ class ManagePasswordsBubbleView : public views::BubbleDelegateView,
static bool IsShowing();
private:
ManagePasswordsBubbleView(views::View* anchor_view,
content::WebContents* web_contents,
ManagePasswordsBubbleView(content::WebContents* web_contents,
views::View* anchor_view,
ManagePasswordsIconView* icon_view);
virtual ~ManagePasswordsBubbleView();
// Returns the maximum width needed for the username or password field(s).
// Both can take a maximum of 22 characters. If username is set it will return
// the maximum width for the username, else the one for the password fields.
// Returns the maximum width needed for the username (if |username| is set) or
// password field, based on the actual usernames and passwords that need to be
// shown.
int GetMaximumUsernameOrPasswordWidth(bool username);
// If the bubble is not anchored to a view, places the bubble in the top
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
......@@ -22,10 +23,10 @@ ManagePasswordsIconView::ManagePasswordsIconView(
ManagePasswordsIconView::~ManagePasswordsIconView() {}
void ManagePasswordsIconView::Update(
ManagePasswordsIconController* manage_passwords_icon_controller) {
SetVisible(
manage_passwords_icon_controller &&
manage_passwords_icon_controller->manage_passwords_icon_to_be_shown() &&
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller) {
SetVisible(manage_passwords_bubble_ui_controller &&
manage_passwords_bubble_ui_controller->
manage_passwords_icon_to_be_shown() &&
!location_bar_delegate_->GetToolbarModel()->input_in_progress());
if (!visible()) {
ManagePasswordsBubbleView::CloseBubble();
......@@ -33,17 +34,18 @@ void ManagePasswordsIconView::Update(
}
SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_SAVE_PASSWORD));
SetTooltip(manage_passwords_icon_controller->password_to_be_saved());
SetTooltip(manage_passwords_bubble_ui_controller->password_to_be_saved());
}
void ManagePasswordsIconView::ShowBubbleIfNeeded(
ManagePasswordsIconController* manage_passwords_icon_controller) {
if (manage_passwords_icon_controller->
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller) {
if (manage_passwords_bubble_ui_controller->
manage_passwords_bubble_needs_showing() &&
visible() && !ManagePasswordsBubbleView::IsShowing()) {
visible() &&
!ManagePasswordsBubbleView::IsShowing()) {
ManagePasswordsBubbleView::ShowBubble(
location_bar_delegate_->GetWebContents(), this);
manage_passwords_icon_controller->OnBubbleShown();
manage_passwords_bubble_ui_controller->OnBubbleShown();
}
}
......
......@@ -6,11 +6,10 @@
#define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_ICON_VIEW_H_
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon_controller.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "ui/views/controls/image_view.h"
class ManagePasswordsIconController;
class ManagePasswordsBubbleUIController;
// View for the password icon in the Omnibox.
class ManagePasswordsIconView : public views::ImageView {
......@@ -26,11 +25,12 @@ class ManagePasswordsIconView : public views::ImageView {
// Updates the image and its tooltip appropriately, hiding or showing the icon
// as needed.
void Update(ManagePasswordsIconController* manage_passwords_icon_controller);
void Update(
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller);
// Shows a bubble from the icon if a password form was submitted.
void ShowBubbleIfNeeded(
ManagePasswordsIconController* manage_passwords_icon_controller);
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller);
void SetTooltip(bool password_to_be_saved);
......
......@@ -1470,8 +1470,8 @@
'browser/ui/panels/stacked_panel_drag_handler.h',
'browser/ui/passwords/manage_passwords_bubble_model.cc',
'browser/ui/passwords/manage_passwords_bubble_model.h',
'browser/ui/passwords/manage_passwords_icon_controller.cc',
'browser/ui/passwords/manage_passwords_icon_controller.h',
'browser/ui/passwords/manage_passwords_bubble_ui_controller.cc',
'browser/ui/passwords/manage_passwords_bubble_ui_controller.h',
'browser/ui/passwords/password_manager_presenter.cc',
'browser/ui/passwords/password_manager_presenter.h',
'browser/ui/passwords/password_ui_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