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

Side by Side Diff: chrome/browser/autofill/autofill_external_delegate.cc

Issue 12217024: Use WeakPtr to simplify AutofillPopupControllerImpl memory management (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android build Created 7 years, 10 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/autofill/autocomplete_history_manager.h" 6 #include "chrome/browser/autofill/autocomplete_history_manager.h"
7 #include "chrome/browser/autofill/autofill_external_delegate.h" 7 #include "chrome/browser/autofill/autofill_external_delegate.h"
8 #include "chrome/browser/autofill/autofill_manager.h" 8 #include "chrome/browser/autofill/autofill_manager.h"
9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
10 #include "chrome/common/autofill_messages.h" 10 #include "chrome/common/autofill_messages.h"
(...skipping 28 matching lines...) Expand all
39 web_contents->SetUserData( 39 web_contents->SetUserData(
40 UserDataKey(), 40 UserDataKey(),
41 new AutofillExternalDelegate(web_contents, autofill_manager)); 41 new AutofillExternalDelegate(web_contents, autofill_manager));
42 } 42 }
43 43
44 AutofillExternalDelegate::AutofillExternalDelegate( 44 AutofillExternalDelegate::AutofillExternalDelegate(
45 content::WebContents* web_contents, 45 content::WebContents* web_contents,
46 AutofillManager* autofill_manager) 46 AutofillManager* autofill_manager)
47 : web_contents_(web_contents), 47 : web_contents_(web_contents),
48 autofill_manager_(autofill_manager), 48 autofill_manager_(autofill_manager),
49 controller_(NULL),
50 password_autofill_manager_(web_contents), 49 password_autofill_manager_(web_contents),
51 autofill_query_id_(0), 50 autofill_query_id_(0),
52 display_warning_if_disabled_(false), 51 display_warning_if_disabled_(false),
53 has_shown_autofill_popup_for_current_edit_(false) { 52 has_shown_autofill_popup_for_current_edit_(false) {
54 registrar_.Add(this, 53 registrar_.Add(this,
55 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, 54 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
56 content::Source<content::WebContents>(web_contents)); 55 content::Source<content::WebContents>(web_contents));
57 if (web_contents) { 56 if (web_contents) {
58 registrar_.Add( 57 registrar_.Add(
59 this, 58 this,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 184
186 void AutofillExternalDelegate::ApplyAutofillSuggestions( 185 void AutofillExternalDelegate::ApplyAutofillSuggestions(
187 const std::vector<string16>& autofill_values, 186 const std::vector<string16>& autofill_values,
188 const std::vector<string16>& autofill_labels, 187 const std::vector<string16>& autofill_labels,
189 const std::vector<string16>& autofill_icons, 188 const std::vector<string16>& autofill_icons,
190 const std::vector<int>& autofill_unique_ids) { 189 const std::vector<int>& autofill_unique_ids) {
191 controller_->Show(autofill_values, 190 controller_->Show(autofill_values,
192 autofill_labels, 191 autofill_labels,
193 autofill_icons, 192 autofill_icons,
194 autofill_unique_ids); 193 autofill_unique_ids);
195
196 web_contents()->GetRenderViewHost()->AddKeyboardListener(controller_);
197 } 194 }
198 195
199 void AutofillExternalDelegate::SetCurrentDataListValues( 196 void AutofillExternalDelegate::SetCurrentDataListValues(
200 const std::vector<string16>& data_list_values, 197 const std::vector<string16>& data_list_values,
201 const std::vector<string16>& data_list_labels, 198 const std::vector<string16>& data_list_labels,
202 const std::vector<string16>& data_list_icons, 199 const std::vector<string16>& data_list_icons,
203 const std::vector<int>& data_list_unique_ids) { 200 const std::vector<int>& data_list_unique_ids) {
204 data_list_values_ = data_list_values; 201 data_list_values_ = data_list_values;
205 data_list_labels_ = data_list_labels; 202 data_list_labels_ = data_list_labels;
206 data_list_icons_ = data_list_icons; 203 data_list_icons_ = data_list_icons;
207 data_list_unique_ids_ = data_list_unique_ids; 204 data_list_unique_ids_ = data_list_unique_ids;
208 } 205 }
209 206
207 void AutofillExternalDelegate::OnPopupShown(
208 content::KeyboardListener* listener) {
209 if (web_contents_)
210 web_contents_->GetRenderViewHost()->AddKeyboardListener(listener);
211 }
212
213 void AutofillExternalDelegate::OnPopupHidden(
214 content::KeyboardListener* listener) {
215 if (web_contents_)
216 web_contents_->GetRenderViewHost()->RemoveKeyboardListener(listener);
217 }
218
210 void AutofillExternalDelegate::DidSelectSuggestion(int identifier) { 219 void AutofillExternalDelegate::DidSelectSuggestion(int identifier) {
211 ClearPreviewedForm(); 220 ClearPreviewedForm();
212 221
213 // Only preview the data if it is a profile. 222 // Only preview the data if it is a profile.
214 if (identifier > 0) 223 if (identifier > 0)
215 FillAutofillFormData(identifier, true); 224 FillAutofillFormData(identifier, true);
216 } 225 }
217 226
218 void AutofillExternalDelegate::DidAcceptSuggestion(const string16& value, 227 void AutofillExternalDelegate::DidAcceptSuggestion(const string16& value,
219 int identifier) { 228 int identifier) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 270
262 void AutofillExternalDelegate::ClearPreviewedForm() { 271 void AutofillExternalDelegate::ClearPreviewedForm() {
263 if (web_contents_) { 272 if (web_contents_) {
264 RenderViewHost* host = web_contents_->GetRenderViewHost(); 273 RenderViewHost* host = web_contents_->GetRenderViewHost();
265 274
266 if (host) 275 if (host)
267 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); 276 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID()));
268 } 277 }
269 } 278 }
270 279
271 void AutofillExternalDelegate::ControllerDestroyed() {
272 web_contents()->GetRenderViewHost()->RemoveKeyboardListener(controller_);
273 controller_ = NULL;
274 }
275
276 void AutofillExternalDelegate::HideAutofillPopup() { 280 void AutofillExternalDelegate::HideAutofillPopup() {
277 if (controller_) { 281 if (controller_) {
278 controller_->Hide(); 282 controller_->Hide();
279 // Go ahead and invalidate |controller_|. After calling Hide(), it won't 283 OnPopupHidden(controller_.get());
280 // inform |this| of its destruction.
281 ControllerDestroyed();
282 } 284 }
283 } 285 }
284 286
285 void AutofillExternalDelegate::Reset() { 287 void AutofillExternalDelegate::Reset() {
286 HideAutofillPopup(); 288 HideAutofillPopup();
287 289
288 password_autofill_manager_.Reset(); 290 password_autofill_manager_.Reset();
289 } 291 }
290 292
291 void AutofillExternalDelegate::AddPasswordFormMapping( 293 void AutofillExternalDelegate::AddPasswordFormMapping(
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 const content::NotificationDetails& details) { 416 const content::NotificationDetails& details) {
415 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { 417 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) {
416 if (!*content::Details<bool>(details).ptr()) 418 if (!*content::Details<bool>(details).ptr())
417 HideAutofillPopup(); 419 HideAutofillPopup();
418 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { 420 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
419 HideAutofillPopup(); 421 HideAutofillPopup();
420 } else { 422 } else {
421 NOTREACHED(); 423 NOTREACHED();
422 } 424 }
423 } 425 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_external_delegate.h ('k') | chrome/browser/autofill/test_autofill_external_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698