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