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

Side by Side Diff: components/autofill/core/browser/autofill_external_delegate.cc

Issue 578383002: mac: Only show the access Address Book prompt a fixed number of times. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@autofill-contacts
Patch Set: Comments from isherman, round 2. Created 6 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_external_delegate.h" 5 #include "components/autofill/core/browser/autofill_external_delegate.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/metrics/sparse_histogram.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autocomplete_history_manager.h" 11 #include "components/autofill/core/browser/autocomplete_history_manager.h"
11 #include "components/autofill/core/browser/autofill_driver.h" 12 #include "components/autofill/core/browser/autofill_driver.h"
12 #include "components/autofill/core/browser/autofill_manager.h" 13 #include "components/autofill/core/browser/autofill_manager.h"
13 #include "components/autofill/core/browser/popup_item_ids.h" 14 #include "components/autofill/core/browser/popup_item_ids.h"
14 #include "grit/components_strings.h" 15 #include "grit/components_strings.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
16 17
17 #if defined(OS_MACOSX) && !defined(OS_IOS) 18 #if defined(OS_MACOSX) && !defined(OS_IOS)
18 namespace { 19 namespace {
(...skipping 23 matching lines...) Expand all
42 namespace autofill { 43 namespace autofill {
43 44
44 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, 45 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager,
45 AutofillDriver* driver) 46 AutofillDriver* driver)
46 : manager_(manager), 47 : manager_(manager),
47 driver_(driver), 48 driver_(driver),
48 query_id_(0), 49 query_id_(0),
49 display_warning_if_disabled_(false), 50 display_warning_if_disabled_(false),
50 has_suggestion_(false), 51 has_suggestion_(false),
51 has_shown_popup_for_current_edit_(false), 52 has_shown_popup_for_current_edit_(false),
52 weak_ptr_factory_(this) { 53 weak_ptr_factory_(this),
54 has_shown_address_book_prompt(false) {
53 DCHECK(manager); 55 DCHECK(manager);
54 } 56 }
55 57
56 AutofillExternalDelegate::~AutofillExternalDelegate() {} 58 AutofillExternalDelegate::~AutofillExternalDelegate() {}
57 59
58 void AutofillExternalDelegate::OnQuery(int query_id, 60 void AutofillExternalDelegate::OnQuery(int query_id,
59 const FormData& form, 61 const FormData& form,
60 const FormFieldData& field, 62 const FormFieldData& field,
61 const gfx::RectF& element_bounds, 63 const gfx::RectF& element_bounds,
62 bool display_warning_if_disabled) { 64 bool display_warning_if_disabled) {
65 if (query_form_ != form)
66 has_shown_address_book_prompt = false;
67
63 query_form_ = form; 68 query_form_ = form;
64 query_field_ = field; 69 query_field_ = field;
65 display_warning_if_disabled_ = display_warning_if_disabled; 70 display_warning_if_disabled_ = display_warning_if_disabled;
66 query_id_ = query_id; 71 query_id_ = query_id;
67 element_bounds_ = element_bounds; 72 element_bounds_ = element_bounds;
68 } 73 }
69 74
70 void AutofillExternalDelegate::OnSuggestionsReturned( 75 void AutofillExternalDelegate::OnSuggestionsReturned(
71 int query_id, 76 int query_id,
72 const std::vector<base::string16>& suggested_values, 77 const std::vector<base::string16>& suggested_values,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 labels.pop_back(); 115 labels.pop_back();
111 icons.pop_back(); 116 icons.pop_back();
112 ids.pop_back(); 117 ids.pop_back();
113 } 118 }
114 119
115 // If anything else is added to modify the values after inserting the data 120 // If anything else is added to modify the values after inserting the data
116 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be 121 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be
117 // updated to match. 122 // updated to match.
118 InsertDataListValues(&values, &labels, &icons, &ids); 123 InsertDataListValues(&values, &labels, &icons, &ids);
119 124
120 // Temporarily disabled. See http://crbug.com/408695
121 #if 0
122 #if defined(OS_MACOSX) && !defined(OS_IOS) 125 #if defined(OS_MACOSX) && !defined(OS_IOS)
123 if (values.empty() && 126 if (values.empty() &&
124 manager_->ShouldShowAccessAddressBookSuggestion(query_form_, 127 manager_->ShouldShowAccessAddressBookSuggestion(query_form_,
125 query_field_)) { 128 query_field_)) {
126 values.push_back( 129 values.push_back(
127 l10n_util::GetStringUTF16(IDS_AUTOFILL_ACCESS_MAC_CONTACTS)); 130 l10n_util::GetStringUTF16(IDS_AUTOFILL_ACCESS_MAC_CONTACTS));
128 labels.push_back(base::string16()); 131 labels.push_back(base::string16());
129 icons.push_back(base::ASCIIToUTF16("macContactsIcon")); 132 icons.push_back(base::ASCIIToUTF16("macContactsIcon"));
130 ids.push_back(POPUP_ITEM_ID_MAC_ACCESS_CONTACTS); 133 ids.push_back(POPUP_ITEM_ID_MAC_ACCESS_CONTACTS);
131 134
132 EmitHistogram(SHOWED_ACCESS_ADDRESS_BOOK_ENTRY); 135 if (!has_shown_address_book_prompt) {
136 has_shown_address_book_prompt = true;
137 EmitHistogram(SHOWED_ACCESS_ADDRESS_BOOK_ENTRY);
138 manager_->ShowedAccessAddressBookPrompt();
139 }
133 } 140 }
134 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 141 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
135 #endif
136 142
137 if (values.empty()) { 143 if (values.empty()) {
138 // No suggestions, any popup currently showing is obsolete. 144 // No suggestions, any popup currently showing is obsolete.
139 manager_->client()->HideAutofillPopup(); 145 manager_->client()->HideAutofillPopup();
140 return; 146 return;
141 } 147 }
142 148
143 // Send to display. 149 // Send to display.
144 if (query_field_.is_focusable) { 150 if (query_field_.is_focusable) {
145 manager_->client()->ShowAutofillPopup(element_bounds_, 151 manager_->client()->ShowAutofillPopup(element_bounds_,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) { 200 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) {
195 NOTREACHED(); // Should be handled elsewhere. 201 NOTREACHED(); // Should be handled elsewhere.
196 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { 202 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) {
197 driver_->RendererShouldAcceptDataListSuggestion(value); 203 driver_->RendererShouldAcceptDataListSuggestion(value);
198 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { 204 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) {
199 // User selected an Autocomplete, so we fill directly. 205 // User selected an Autocomplete, so we fill directly.
200 driver_->RendererShouldFillFieldWithValue(value); 206 driver_->RendererShouldFillFieldWithValue(value);
201 } else if (identifier == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS) { 207 } else if (identifier == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS) {
202 #if defined(OS_MACOSX) && !defined(OS_IOS) 208 #if defined(OS_MACOSX) && !defined(OS_IOS)
203 EmitHistogram(SELECTED_ACCESS_ADDRESS_BOOK_ENTRY); 209 EmitHistogram(SELECTED_ACCESS_ADDRESS_BOOK_ENTRY);
210 UMA_HISTOGRAM_SPARSE_SLOWLY(
211 "Autofill.MacAddressBook.NumShowsBeforeSelected",
212 manager_->AccessAddressBookPromptCount());
204 213
205 // User wants to give Chrome access to user's address book. 214 // User wants to give Chrome access to user's address book.
206 manager_->AccessAddressBook(); 215 manager_->AccessAddressBook();
207 216
208 // There is no deterministic method for deciding whether a blocking dialog 217 // There is no deterministic method for deciding whether a blocking dialog
209 // was presented. The following comments and code assume that a blocking 218 // was presented. The following comments and code assume that a blocking
210 // dialog was presented, but still behave correctly if no dialog was 219 // dialog was presented, but still behave correctly if no dialog was
211 // presented. 220 // presented.
212 221
213 // A blocking dialog was presented, and the user has already responded to 222 // A blocking dialog was presented, and the user has already responded to
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 POPUP_ITEM_ID_DATALIST_ENTRY); 401 POPUP_ITEM_ID_DATALIST_ENTRY);
393 } 402 }
394 403
395 #if defined(OS_MACOSX) && !defined(OS_IOS) 404 #if defined(OS_MACOSX) && !defined(OS_IOS)
396 void AutofillExternalDelegate::PingRenderer() { 405 void AutofillExternalDelegate::PingRenderer() {
397 driver_->PingRenderer(); 406 driver_->PingRenderer();
398 } 407 }
399 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 408 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
400 409
401 } // namespace autofill 410 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_external_delegate.h ('k') | components/autofill/core/browser/autofill_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698