Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: chrome/browser/ui/webui/options/password_manager_handler.cc

Issue 7554008: Removal of Profile from content part 6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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/ui/webui/options/password_manager_handler.h" 5 #include "chrome/browser/ui/webui/options/password_manager_handler.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/google/google_util.h" 11 #include "chrome/browser/google/google_util.h"
12 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
17 #include "content/browser/tab_contents/tab_contents.h"
17 #include "content/common/notification_details.h" 18 #include "content/common/notification_details.h"
18 #include "content/common/notification_source.h" 19 #include "content/common/notification_source.h"
19 #include "grit/chromium_strings.h" 20 #include "grit/chromium_strings.h"
20 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
21 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 #include "webkit/glue/password_form.h" 24 #include "webkit/glue/password_form.h"
24 25
25 PasswordManagerHandler::PasswordManagerHandler() 26 PasswordManagerHandler::PasswordManagerHandler()
26 : ALLOW_THIS_IN_INITIALIZER_LIST(populater_(this)), 27 : ALLOW_THIS_IN_INITIALIZER_LIST(populater_(this)),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 77 }
77 78
78 void PasswordManagerHandler::Initialize() { 79 void PasswordManagerHandler::Initialize() {
79 // Due to the way that handlers are (re)initialized under certain types of 80 // Due to the way that handlers are (re)initialized under certain types of
80 // navigation, we may already be initialized. (See bugs 88986 and 86448.) 81 // navigation, we may already be initialized. (See bugs 88986 and 86448.)
81 // If this is the case, return immediately. This is a hack. 82 // If this is the case, return immediately. This is a hack.
82 // TODO(mdm): remove this hack once it is no longer necessary. 83 // TODO(mdm): remove this hack once it is no longer necessary.
83 if (!show_passwords_.GetPrefName().empty()) 84 if (!show_passwords_.GetPrefName().empty())
84 return; 85 return;
85 86
87 Profile* profile =
88 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
86 show_passwords_.Init(prefs::kPasswordManagerAllowShowPasswords, 89 show_passwords_.Init(prefs::kPasswordManagerAllowShowPasswords,
87 web_ui_->GetProfile()->GetPrefs(), this); 90 profile->GetPrefs(), this);
88 // We should not cache web_ui_->GetProfile(). See crosbug.com/6304. 91 // We should not cache web_ui_->GetProfile(). See crosbug.com/6304.
89 PasswordStore* store = GetPasswordStore(); 92 PasswordStore* store = GetPasswordStore();
90 if (store) 93 if (store)
91 store->AddObserver(this); 94 store->AddObserver(this);
92 } 95 }
93 96
94 void PasswordManagerHandler::RegisterMessages() { 97 void PasswordManagerHandler::RegisterMessages() {
95 DCHECK(web_ui_); 98 DCHECK(web_ui_);
96 99
97 web_ui_->RegisterMessageCallback("updatePasswordLists", 100 web_ui_->RegisterMessageCallback("updatePasswordLists",
98 NewCallback(this, &PasswordManagerHandler::UpdatePasswordLists)); 101 NewCallback(this, &PasswordManagerHandler::UpdatePasswordLists));
99 web_ui_->RegisterMessageCallback("removeSavedPassword", 102 web_ui_->RegisterMessageCallback("removeSavedPassword",
100 NewCallback(this, &PasswordManagerHandler::RemoveSavedPassword)); 103 NewCallback(this, &PasswordManagerHandler::RemoveSavedPassword));
101 web_ui_->RegisterMessageCallback("removePasswordException", 104 web_ui_->RegisterMessageCallback("removePasswordException",
102 NewCallback(this, &PasswordManagerHandler::RemovePasswordException)); 105 NewCallback(this, &PasswordManagerHandler::RemovePasswordException));
103 web_ui_->RegisterMessageCallback("removeAllSavedPasswords", 106 web_ui_->RegisterMessageCallback("removeAllSavedPasswords",
104 NewCallback(this, &PasswordManagerHandler::RemoveAllSavedPasswords)); 107 NewCallback(this, &PasswordManagerHandler::RemoveAllSavedPasswords));
105 web_ui_->RegisterMessageCallback("removeAllPasswordExceptions", NewCallback( 108 web_ui_->RegisterMessageCallback("removeAllPasswordExceptions", NewCallback(
106 this, &PasswordManagerHandler::RemoveAllPasswordExceptions)); 109 this, &PasswordManagerHandler::RemoveAllPasswordExceptions));
107 } 110 }
108 111
109 void PasswordManagerHandler::OnLoginsChanged() { 112 void PasswordManagerHandler::OnLoginsChanged() {
110 UpdatePasswordLists(NULL); 113 UpdatePasswordLists(NULL);
111 } 114 }
112 115
113 PasswordStore* PasswordManagerHandler::GetPasswordStore() { 116 PasswordStore* PasswordManagerHandler::GetPasswordStore() {
114 return web_ui_->GetProfile()->GetPasswordStore(Profile::EXPLICIT_ACCESS); 117 Profile* profile =
118 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
119 return profile->GetPasswordStore(Profile::EXPLICIT_ACCESS);
115 } 120 }
116 121
117 void PasswordManagerHandler::Observe(int type, 122 void PasswordManagerHandler::Observe(int type,
118 const NotificationSource& source, 123 const NotificationSource& source,
119 const NotificationDetails& details) { 124 const NotificationDetails& details) {
120 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 125 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
121 std::string* pref_name = Details<std::string>(details).ptr(); 126 std::string* pref_name = Details<std::string>(details).ptr();
122 if (*pref_name == prefs::kPasswordManagerAllowShowPasswords) { 127 if (*pref_name == prefs::kPasswordManagerAllowShowPasswords) {
123 UpdatePasswordLists(NULL); 128 UpdatePasswordLists(NULL);
124 } 129 }
125 } 130 }
126 131
127 OptionsPageUIHandler::Observe(type, source, details); 132 OptionsPageUIHandler::Observe(type, source, details);
128 } 133 }
129 134
130 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) { 135 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) {
131 // Reset the current lists. 136 // Reset the current lists.
132 password_list_.reset(); 137 password_list_.reset();
133 password_exception_list_.reset(); 138 password_exception_list_.reset();
134 139
135 languages_ = 140 Profile* profile =
136 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); 141 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
142 languages_ = profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
137 populater_.Populate(); 143 populater_.Populate();
138 exception_populater_.Populate(); 144 exception_populater_.Populate();
139 } 145 }
140 146
141 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) { 147 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) {
142 PasswordStore* store = GetPasswordStore(); 148 PasswordStore* store = GetPasswordStore();
143 if (!store) 149 if (!store)
144 return; 150 return;
145 std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); 151 std::string string_value = UTF16ToUTF8(ExtractStringValue(args));
146 int index; 152 int index;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 OnPasswordStoreRequestDone( 281 OnPasswordStoreRequestDone(
276 CancelableRequestProvider::Handle handle, 282 CancelableRequestProvider::Handle handle,
277 const std::vector<webkit_glue::PasswordForm*>& result) { 283 const std::vector<webkit_glue::PasswordForm*>& result) {
278 DCHECK_EQ(pending_login_query_, handle); 284 DCHECK_EQ(pending_login_query_, handle);
279 pending_login_query_ = 0; 285 pending_login_query_ = 0;
280 page_->password_exception_list_.reset(); 286 page_->password_exception_list_.reset();
281 page_->password_exception_list_.insert(page_->password_exception_list_.end(), 287 page_->password_exception_list_.insert(page_->password_exception_list_.end(),
282 result.begin(), result.end()); 288 result.begin(), result.end());
283 page_->SetPasswordExceptionList(); 289 page_->SetPasswordExceptionList();
284 } 290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698