| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/password_manager_delegate_impl.h" | 5 #include "chrome/browser/password_manager_delegate_impl.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
| 11 #include "chrome/browser/password_manager/password_form_manager.h" | 11 #include "chrome/browser/password_manager/password_form_manager.h" |
| 12 #include "chrome/browser/password_manager/password_manager.h" | 12 #include "chrome/browser/password_manager/password_manager.h" |
| 13 #include "chrome/browser/renderer_host/render_view_host.h" | 13 #include "chrome/browser/renderer_host/render_view_host.h" |
| 14 #include "chrome/browser/tab_contents/infobar_delegate.h" | 14 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 15 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
| 16 #include "grit/chromium_strings.h" | 16 #include "grit/chromium_strings.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 19 #include "webkit/glue/password_form.h" | 19 #include "webkit/glue/password_form.h" |
| 20 | 20 |
| 21 // After a successful *new* login attempt, we take the PasswordFormManager in | 21 // After a successful *new* login attempt, we take the PasswordFormManager in |
| 22 // provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while | 22 // provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while |
| 23 // the user makes up their mind with the "save password" infobar. Note if the | 23 // the user makes up their mind with the "save password" infobar. Note if the |
| 24 // login is one we already know about, the end of the line is | 24 // login is one we already know about, the end of the line is |
| 25 // provisional_save_manager_ because we just update it on success and so such | 25 // provisional_save_manager_ because we just update it on success and so such |
| 26 // forms never end up in an infobar. | 26 // forms never end up in an infobar. |
| 27 class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { | 27 class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 28 public: | 28 public: |
| 29 SavePasswordInfoBarDelegate(TabContents* tab_contents, | 29 SavePasswordInfoBarDelegate(TabContents* tab_contents, |
| 30 PasswordFormManager* form_to_save) | 30 PasswordFormManager* form_to_save); |
| 31 : ConfirmInfoBarDelegate(tab_contents), | |
| 32 form_to_save_(form_to_save), | |
| 33 infobar_response_(NO_RESPONSE) {} | |
| 34 | |
| 35 virtual ~SavePasswordInfoBarDelegate() {} | |
| 36 | |
| 37 // Begin ConfirmInfoBarDelegate implementation. | |
| 38 virtual void InfoBarClosed() { | |
| 39 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", | |
| 40 infobar_response_, NUM_RESPONSE_TYPES); | |
| 41 delete this; | |
| 42 } | |
| 43 | |
| 44 virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; } | |
| 45 | |
| 46 virtual string16 GetMessageText() const { | |
| 47 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT); | |
| 48 } | |
| 49 | |
| 50 virtual SkBitmap* GetIcon() const { | |
| 51 return ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
| 52 IDR_INFOBAR_SAVE_PASSWORD); | |
| 53 } | |
| 54 | |
| 55 virtual int GetButtons() const { | |
| 56 return BUTTON_OK | BUTTON_CANCEL; | |
| 57 } | |
| 58 | |
| 59 virtual string16 GetButtonLabel(InfoBarButton button) const { | |
| 60 if (button == BUTTON_OK) | |
| 61 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON); | |
| 62 if (button == BUTTON_CANCEL) | |
| 63 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON); | |
| 64 NOTREACHED(); | |
| 65 return string16(); | |
| 66 } | |
| 67 | |
| 68 virtual bool Accept() { | |
| 69 DCHECK(form_to_save_.get()); | |
| 70 form_to_save_->Save(); | |
| 71 infobar_response_ = REMEMBER_PASSWORD; | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 virtual bool Cancel() { | |
| 76 DCHECK(form_to_save_.get()); | |
| 77 form_to_save_->PermanentlyBlacklist(); | |
| 78 infobar_response_ = DONT_REMEMBER_PASSWORD; | |
| 79 return true; | |
| 80 } | |
| 81 // End ConfirmInfoBarDelegate implementation. | |
| 82 | 31 |
| 83 private: | 32 private: |
| 84 // The PasswordFormManager managing the form we're asking the user about, | |
| 85 // and should update as per her decision. | |
| 86 scoped_ptr<PasswordFormManager> form_to_save_; | |
| 87 | |
| 88 // Used to track the results we get from the info bar. | |
| 89 enum ResponseType { | 33 enum ResponseType { |
| 90 NO_RESPONSE = 0, | 34 NO_RESPONSE = 0, |
| 91 REMEMBER_PASSWORD, | 35 REMEMBER_PASSWORD, |
| 92 DONT_REMEMBER_PASSWORD, | 36 DONT_REMEMBER_PASSWORD, |
| 93 NUM_RESPONSE_TYPES, | 37 NUM_RESPONSE_TYPES, |
| 94 }; | 38 }; |
| 39 |
| 40 virtual ~SavePasswordInfoBarDelegate(); |
| 41 |
| 42 // ConfirmInfoBarDelegate |
| 43 virtual void InfoBarClosed(); |
| 44 virtual SkBitmap* GetIcon() const; |
| 45 virtual Type GetInfoBarType() const; |
| 46 virtual string16 GetMessageText() const; |
| 47 virtual int GetButtons() const; |
| 48 virtual string16 GetButtonLabel(InfoBarButton button) const; |
| 49 virtual bool Accept(); |
| 50 virtual bool Cancel(); |
| 51 |
| 52 // The PasswordFormManager managing the form we're asking the user about, |
| 53 // and should update as per her decision. |
| 54 scoped_ptr<PasswordFormManager> form_to_save_; |
| 55 |
| 56 // Used to track the results we get from the info bar. |
| 95 ResponseType infobar_response_; | 57 ResponseType infobar_response_; |
| 96 | 58 |
| 97 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate); | 59 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate); |
| 98 }; | 60 }; |
| 99 | 61 |
| 100 //---------------------------------------------------------------------------- | 62 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( |
| 63 TabContents* tab_contents, |
| 64 PasswordFormManager* form_to_save) |
| 65 : ConfirmInfoBarDelegate(tab_contents), |
| 66 form_to_save_(form_to_save), |
| 67 infobar_response_(NO_RESPONSE) { |
| 68 } |
| 69 |
| 70 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { |
| 71 } |
| 72 |
| 73 void SavePasswordInfoBarDelegate::InfoBarClosed() { |
| 74 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", |
| 75 infobar_response_, NUM_RESPONSE_TYPES); |
| 76 delete this; |
| 77 } |
| 78 |
| 79 SkBitmap* SavePasswordInfoBarDelegate::GetIcon() const { |
| 80 return ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 81 IDR_INFOBAR_SAVE_PASSWORD); |
| 82 } |
| 83 |
| 84 InfoBarDelegate::Type SavePasswordInfoBarDelegate::GetInfoBarType() const { |
| 85 return PAGE_ACTION_TYPE; |
| 86 } |
| 87 |
| 88 string16 SavePasswordInfoBarDelegate::GetMessageText() const { |
| 89 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT); |
| 90 } |
| 91 |
| 92 int SavePasswordInfoBarDelegate::GetButtons() const { |
| 93 return BUTTON_OK | BUTTON_CANCEL; |
| 94 } |
| 95 |
| 96 string16 SavePasswordInfoBarDelegate::GetButtonLabel( |
| 97 InfoBarButton button) const { |
| 98 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 99 IDS_PASSWORD_MANAGER_SAVE_BUTTON : IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON); |
| 100 } |
| 101 |
| 102 bool SavePasswordInfoBarDelegate::Accept() { |
| 103 DCHECK(form_to_save_.get()); |
| 104 form_to_save_->Save(); |
| 105 infobar_response_ = REMEMBER_PASSWORD; |
| 106 return true; |
| 107 } |
| 108 |
| 109 bool SavePasswordInfoBarDelegate::Cancel() { |
| 110 DCHECK(form_to_save_.get()); |
| 111 form_to_save_->PermanentlyBlacklist(); |
| 112 infobar_response_ = DONT_REMEMBER_PASSWORD; |
| 113 return true; |
| 114 } |
| 115 |
| 116 |
| 117 // PasswordManagerDelegateImpl ------------------------------------------------ |
| 101 | 118 |
| 102 void PasswordManagerDelegateImpl::FillPasswordForm( | 119 void PasswordManagerDelegateImpl::FillPasswordForm( |
| 103 const webkit_glue::PasswordFormFillData& form_data) { | 120 const webkit_glue::PasswordFormFillData& form_data) { |
| 104 tab_contents_->render_view_host()->FillPasswordForm(form_data); | 121 tab_contents_->render_view_host()->FillPasswordForm(form_data); |
| 105 } | 122 } |
| 106 | 123 |
| 107 void PasswordManagerDelegateImpl::AddSavePasswordInfoBar( | 124 void PasswordManagerDelegateImpl::AddSavePasswordInfoBar( |
| 108 PasswordFormManager* form_to_save) { | 125 PasswordFormManager* form_to_save) { |
| 109 tab_contents_->AddInfoBar( | 126 tab_contents_->AddInfoBar( |
| 110 new SavePasswordInfoBarDelegate(tab_contents_, form_to_save)); | 127 new SavePasswordInfoBarDelegate(tab_contents_, form_to_save)); |
| 111 } | 128 } |
| 112 | 129 |
| 113 Profile* PasswordManagerDelegateImpl::GetProfileForPasswordManager() { | 130 Profile* PasswordManagerDelegateImpl::GetProfileForPasswordManager() { |
| 114 return tab_contents_->profile(); | 131 return tab_contents_->profile(); |
| 115 } | 132 } |
| 116 | 133 |
| 117 bool PasswordManagerDelegateImpl::DidLastPageLoadEncounterSSLErrors() { | 134 bool PasswordManagerDelegateImpl::DidLastPageLoadEncounterSSLErrors() { |
| 118 return tab_contents_->controller().ssl_manager()-> | 135 return tab_contents_->controller().ssl_manager()-> |
| 119 ProcessedSSLErrorFromRequest(); | 136 ProcessedSSLErrorFromRequest(); |
| 120 } | 137 } |
| OLD | NEW |