| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_VIEW_H__ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_VIEW_H__ |
| 6 #define CHROME_BROWSER_PASSWORD_MANAGER_VIEW_H__ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_VIEW_H__ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "chrome/browser/webdata/web_data_service.h" | 11 #include "chrome/browser/webdata/web_data_service.h" |
| 12 #include "chrome/common/stl_util-inl.h" | 12 #include "chrome/common/stl_util-inl.h" |
| 13 #include "chrome/common/gfx/text_elider.h" | 13 #include "chrome/common/gfx/text_elider.h" |
| 14 #include "chrome/views/dialog_delegate.h" | 14 #include "chrome/views/dialog_delegate.h" |
| 15 #include "chrome/views/label.h" | 15 #include "chrome/views/label.h" |
| 16 #include "chrome/views/native_button.h" | 16 #include "chrome/views/native_button.h" |
| 17 #include "chrome/views/table_view.h" | 17 #include "chrome/views/table_view.h" |
| 18 #include "chrome/views/window.h" | 18 #include "chrome/views/window.h" |
| 19 #include "webkit/glue/password_form.h" | 19 #include "webkit/glue/password_form.h" |
| 20 | 20 |
| 21 class Profile; | 21 class Profile; |
| 22 | 22 |
| 23 // An observer interface to notify change of row count in a table model. This |
| 24 // allow the container view of TableView(i.e. PasswordManagerView and |
| 25 // PasswordManagerExceptionsView), to be notified of row count changes directly |
| 26 // from the TableModel. We have two different observers in |
| 27 // PasswordManagerTableModel, namely views::TableModelObserver and |
| 28 // PasswordManagerTableModelObserver, rather than adding this event to |
| 29 // views::TableModelObserver because only container view of |
| 30 // PasswordManagerTableModel cares about this event. Because of the same reason |
| 31 // the relationship between a PasswordManagerTableModel and |
| 32 // PasswordManagerTableModelObserver is 1-to-1. |
| 33 class PasswordManagerTableModelObserver { |
| 34 public: |
| 35 virtual void OnRowCountChanged(size_t rows) = 0; |
| 36 }; |
| 37 |
| 23 class PasswordManagerTableModel : public views::TableModel, | 38 class PasswordManagerTableModel : public views::TableModel, |
| 24 public WebDataServiceConsumer { | 39 public WebDataServiceConsumer { |
| 25 public: | 40 public: |
| 26 explicit PasswordManagerTableModel(Profile* profile); | 41 explicit PasswordManagerTableModel(Profile* profile); |
| 27 virtual ~PasswordManagerTableModel(); | 42 virtual ~PasswordManagerTableModel(); |
| 28 | 43 |
| 29 // TableModel methods. | 44 // TableModel methods. |
| 30 virtual int RowCount(); | 45 virtual int RowCount(); |
| 31 virtual std::wstring GetText(int row, int column); | 46 virtual std::wstring GetText(int row, int column); |
| 32 virtual int CompareValues(int row1, int row2, int column_id); | 47 virtual int CompareValues(int row1, int row2, int column_id); |
| 33 virtual void SetObserver(views::TableModelObserver* observer); | 48 virtual void SetObserver(views::TableModelObserver* observer); |
| 34 | 49 |
| 35 // Delete the PasswordForm at specified row from the database (and remove | 50 // Delete the PasswordForm at specified row from the database (and remove |
| 36 // from view). | 51 // from view). |
| 37 void ForgetAndRemoveSignon(int row); | 52 void ForgetAndRemoveSignon(int row); |
| 38 | 53 |
| 39 // Delete all saved signons for the active profile (via web data service), | 54 // Delete all saved signons for the active profile (via web data service), |
| 40 // and clear the view. | 55 // and clear the view. |
| 41 void ForgetAndRemoveAllSignons(); | 56 void ForgetAndRemoveAllSignons(); |
| 42 | 57 |
| 43 // WebDataServiceConsumer implementation. | 58 // WebDataServiceConsumer implementation. |
| 44 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, | 59 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, |
| 45 const WDTypedResult* result); | 60 const WDTypedResult* result); |
| 46 // Request saved logins data. | 61 // Request saved logins data. |
| 47 void GetAllSavedLoginsForProfile(); | 62 void GetAllSavedLoginsForProfile(); |
| 48 | 63 |
| 49 // Return the PasswordForm at the specified index. | 64 // Return the PasswordForm at the specified index. |
| 50 PasswordForm* GetPasswordFormAt(int row); | 65 PasswordForm* GetPasswordFormAt(int row); |
| 51 | 66 |
| 67 // Set the observer who concerns about how many rows are in the table. |
| 68 void set_row_count_observer(PasswordManagerTableModelObserver* observer) { |
| 69 row_count_observer_ = observer; |
| 70 } |
| 71 |
| 52 protected: | 72 protected: |
| 53 // Wraps the PasswordForm from the database and caches the display URL for | 73 // Wraps the PasswordForm from the database and caches the display URL for |
| 54 // quick sorting. | 74 // quick sorting. |
| 55 struct PasswordRow { | 75 struct PasswordRow { |
| 56 PasswordRow(const gfx::SortedDisplayURL& url, PasswordForm* password_form) | 76 PasswordRow(const gfx::SortedDisplayURL& url, PasswordForm* password_form) |
| 57 : display_url(url), form(password_form) { | 77 : display_url(url), form(password_form) { |
| 58 } | 78 } |
| 59 | 79 |
| 60 // Contains the URL that is displayed along with the | 80 // Contains the URL that is displayed along with the |
| 61 gfx::SortedDisplayURL display_url; | 81 gfx::SortedDisplayURL display_url; |
| 62 | 82 |
| 63 // The underlying PasswordForm. We own this. | 83 // The underlying PasswordForm. We own this. |
| 64 scoped_ptr<PasswordForm> form; | 84 scoped_ptr<PasswordForm> form; |
| 65 }; | 85 }; |
| 66 | 86 |
| 67 // The web data service associated with the currently active profile. | 87 // The web data service associated with the currently active profile. |
| 68 WebDataService* web_data_service() { | 88 WebDataService* web_data_service() { |
| 69 return profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 89 return profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); |
| 70 } | 90 } |
| 71 | 91 |
| 72 // The TableView observing this model. | 92 // The TableView observing this model. |
| 73 views::TableModelObserver* observer_; | 93 views::TableModelObserver* observer_; |
| 74 | 94 |
| 95 // Dispatching row count events specific to this password manager table model |
| 96 // to this observer. |
| 97 PasswordManagerTableModelObserver* row_count_observer_; |
| 98 |
| 75 // Handle to any pending WebDataService::GetLogins query. | 99 // Handle to any pending WebDataService::GetLogins query. |
| 76 WebDataService::Handle pending_login_query_; | 100 WebDataService::Handle pending_login_query_; |
| 77 | 101 |
| 78 // The set of passwords we're showing. | 102 // The set of passwords we're showing. |
| 79 typedef std::vector<PasswordRow*> PasswordRows; | 103 typedef std::vector<PasswordRow*> PasswordRows; |
| 80 PasswordRows saved_signons_; | 104 PasswordRows saved_signons_; |
| 81 STLElementDeleter<PasswordRows> saved_signons_cleanup_; | 105 STLElementDeleter<PasswordRows> saved_signons_cleanup_; |
| 82 | 106 |
| 83 Profile* profile_; | 107 Profile* profile_; |
| 84 | 108 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 101 std::wstring label_; | 125 std::wstring label_; |
| 102 std::wstring alt_label_; | 126 std::wstring alt_label_; |
| 103 gfx::Size pref_size_; | 127 gfx::Size pref_size_; |
| 104 | 128 |
| 105 DISALLOW_EVIL_CONSTRUCTORS(MultiLabelButtons); | 129 DISALLOW_EVIL_CONSTRUCTORS(MultiLabelButtons); |
| 106 }; | 130 }; |
| 107 | 131 |
| 108 class PasswordManagerView : public views::View, | 132 class PasswordManagerView : public views::View, |
| 109 public views::DialogDelegate, | 133 public views::DialogDelegate, |
| 110 public views::TableViewObserver, | 134 public views::TableViewObserver, |
| 111 public views::NativeButton::Listener { | 135 public views::NativeButton::Listener, |
| 136 public PasswordManagerTableModelObserver { |
| 112 public: | 137 public: |
| 113 explicit PasswordManagerView(Profile* profile); | 138 explicit PasswordManagerView(Profile* profile); |
| 114 virtual ~PasswordManagerView(); | 139 virtual ~PasswordManagerView(); |
| 115 | 140 |
| 116 // Show the PasswordManagerContentView for the given profile. | 141 // Show the PasswordManagerContentView for the given profile. |
| 117 static void Show(Profile* profile); | 142 static void Show(Profile* profile); |
| 118 | 143 |
| 119 // View methods. | 144 // View methods. |
| 120 virtual void Layout(); | 145 virtual void Layout(); |
| 121 virtual gfx::Size GetPreferredSize(); | 146 virtual gfx::Size GetPreferredSize(); |
| 122 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, | 147 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, |
| 123 views::View* child); | 148 views::View* child); |
| 124 virtual void SetRemoveAllEnabled(bool enabled); | |
| 125 | |
| 126 // views::TableViewObserver implementation. | 149 // views::TableViewObserver implementation. |
| 127 virtual void OnSelectionChanged(); | 150 virtual void OnSelectionChanged(); |
| 128 | 151 |
| 129 // NativeButton::Listener implementation. | 152 // NativeButton::Listener implementation. |
| 130 virtual void ButtonPressed(views::NativeButton* sender); | 153 virtual void ButtonPressed(views::NativeButton* sender); |
| 131 | 154 |
| 132 // views::DialogDelegate methods: | 155 // views::DialogDelegate methods: |
| 133 virtual int GetDialogButtons() const; | 156 virtual int GetDialogButtons() const; |
| 134 virtual bool CanResize() const; | 157 virtual bool CanResize() const; |
| 135 virtual bool CanMaximize() const; | 158 virtual bool CanMaximize() const; |
| 136 virtual bool IsAlwaysOnTop() const; | 159 virtual bool IsAlwaysOnTop() const; |
| 137 virtual bool HasAlwaysOnTopMenu() const; | 160 virtual bool HasAlwaysOnTopMenu() const; |
| 138 virtual std::wstring GetWindowTitle() const; | 161 virtual std::wstring GetWindowTitle() const; |
| 139 virtual void WindowClosing(); | 162 virtual void WindowClosing(); |
| 140 virtual views::View* GetContentsView(); | 163 virtual views::View* GetContentsView(); |
| 141 | 164 |
| 165 // PasswordManagerTableModelObserver implementation. |
| 166 virtual void OnRowCountChanged(size_t rows); |
| 167 |
| 142 private: | 168 private: |
| 143 // Wire up buttons, the model, and the table view, and query the DB for | 169 // Wire up buttons, the model, and the table view, and query the DB for |
| 144 // saved login data tied to the given profile. | 170 // saved login data tied to the given profile. |
| 145 void Init(); | 171 void Init(); |
| 146 | 172 |
| 147 // Helper to configure our buttons and labels. | 173 // Helper to configure our buttons and labels. |
| 148 void SetupButtonsAndLabels(); | 174 void SetupButtonsAndLabels(); |
| 149 | 175 |
| 150 // Helper to configure our table view. | 176 // Helper to configure our table view. |
| 151 void SetupTable(); | 177 void SetupTable(); |
| 152 | 178 |
| 153 // Components in this view. | 179 // Components in this view. |
| 154 PasswordManagerTableModel table_model_; | 180 PasswordManagerTableModel table_model_; |
| 155 views::TableView* table_view_; | 181 views::TableView* table_view_; |
| 156 | 182 |
| 157 // The buttons and labels. | 183 // The buttons and labels. |
| 158 MultiLabelButtons show_button_; | 184 MultiLabelButtons show_button_; |
| 159 views::NativeButton remove_button_; | 185 views::NativeButton remove_button_; |
| 160 views::NativeButton remove_all_button_; | 186 views::NativeButton remove_all_button_; |
| 161 views::Label password_label_; | 187 views::Label password_label_; |
| 162 | 188 |
| 189 static PasswordManagerView* instance_; |
| 190 |
| 163 DISALLOW_EVIL_CONSTRUCTORS(PasswordManagerView); | 191 DISALLOW_EVIL_CONSTRUCTORS(PasswordManagerView); |
| 164 }; | 192 }; |
| 165 #endif // CHROME_BROWSER_PASSWORD_MANAGER_VIEW_H__ | 193 #endif // CHROME_BROWSER_PASSWORD_MANAGER_VIEW_H__ |
| 166 | 194 |
| OLD | NEW |