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