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

Side by Side Diff: chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc

Issue 21124012: [WIP] Split AutofillDialogControllerImpl + integrate rAc on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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) 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 "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" 5 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/autofill/autocheckout_whitelist_manager_factory.h" 9 #include "chrome/browser/autofill/autocheckout_whitelist_manager_factory.h"
10 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" 10 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
11 #include "chrome/browser/autofill/personal_data_manager_factory.h" 11 #include "chrome/browser/autofill/personal_data_manager_factory.h"
12 #include "chrome/browser/infobars/infobar_service.h" 12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/autofill/autocheckout_bubble.h" 14 #include "chrome/browser/ui/autofill/autocheckout_bubble.h"
15 #include "chrome/browser/ui/autofill/autocheckout_bubble_controller.h" 15 #include "chrome/browser/ui/autofill/autocheckout_bubble_controller.h"
16 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 16 #include "chrome/browser/ui/autofill/autofill_dialog_tab_manager_delegate.h"
17 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 17 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
18 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_finder.h" 19 #include "chrome/browser/ui/browser_finder.h"
20 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/chrome_pages.h" 21 #include "chrome/browser/ui/chrome_pages.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
23 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
24 #include "components/autofill/content/browser/autofill_driver_impl.h" 24 #include "components/autofill/content/browser/autofill_driver_impl.h"
25 #include "components/autofill/core/common/autofill_pref_names.h" 25 #include "components/autofill/core/common/autofill_pref_names.h"
26 #include "content/public/browser/navigation_details.h" 26 #include "content/public/browser/navigation_details.h"
(...skipping 17 matching lines...) Expand all
44 // requires that the WebContents instance still be valid and it is not at 44 // requires that the WebContents instance still be valid and it is not at
45 // this point (in particular, the WebContentsImpl destructor has already 45 // this point (in particular, the WebContentsImpl destructor has already
46 // finished running and we are now in the base class destructor). 46 // finished running and we are now in the base class destructor).
47 DCHECK(!popup_controller_); 47 DCHECK(!popup_controller_);
48 } 48 }
49 49
50 void TabAutofillManagerDelegate::TabActivated(int reason) { 50 void TabAutofillManagerDelegate::TabActivated(int reason) {
51 if (reason != TabStripModelObserver::CHANGE_REASON_USER_GESTURE) 51 if (reason != TabStripModelObserver::CHANGE_REASON_USER_GESTURE)
52 return; 52 return;
53 53
54 if (dialog_controller_.get()) 54 if (dialog_delegate_.get())
55 dialog_controller_->TabActivated(); 55 dialog_delegate_->TabActivated();
56 } 56 }
57 57
58 PersonalDataManager* TabAutofillManagerDelegate::GetPersonalDataManager() { 58 PersonalDataManager* TabAutofillManagerDelegate::GetPersonalDataManager() {
59 Profile* profile = 59 Profile* profile =
60 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 60 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
61 return PersonalDataManagerFactory::GetForProfile( 61 return PersonalDataManagerFactory::GetForProfile(
62 profile->GetOriginalProfile()); 62 profile->GetOriginalProfile());
63 } 63 }
64 64
65 PrefService* TabAutofillManagerDelegate::GetPrefs() { 65 PrefService* TabAutofillManagerDelegate::GetPrefs() {
66 return Profile::FromBrowserContext(web_contents_->GetBrowserContext())-> 66 return Profile::FromBrowserContext(web_contents_->GetBrowserContext())->
67 GetPrefs(); 67 GetPrefs();
68 } 68 }
69 69
70 autocheckout::WhitelistManager* 70 autocheckout::WhitelistManager*
71 TabAutofillManagerDelegate::GetAutocheckoutWhitelistManager() const { 71 TabAutofillManagerDelegate::GetAutocheckoutWhitelistManager() const {
72 Profile* profile = 72 Profile* profile =
73 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 73 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
74 return autocheckout::WhitelistManagerFactory::GetForProfile( 74 return autocheckout::WhitelistManagerFactory::GetForProfile(
75 profile->GetOriginalProfile()); 75 profile->GetOriginalProfile());
76 } 76 }
77 77
78 void TabAutofillManagerDelegate::OnAutocheckoutError() { 78 void TabAutofillManagerDelegate::OnAutocheckoutError() {
79 // |dialog_controller_| is a WeakPtr, but we require it to be present when 79 // |dialog_delegate_| is a WeakPtr, but we require it to be present when
80 // |OnAutocheckoutError| is called, so we intentionally do not do NULL check. 80 // |OnAutocheckoutError| is called, so we intentionally do not do NULL check.
81 dialog_controller_->OnAutocheckoutError(); 81 dialog_delegate_->OnAutocheckoutError();
82 } 82 }
83 83
84 void TabAutofillManagerDelegate::OnAutocheckoutSuccess() { 84 void TabAutofillManagerDelegate::OnAutocheckoutSuccess() {
85 dialog_controller_->OnAutocheckoutSuccess(); 85 dialog_delegate_->OnAutocheckoutSuccess();
86 } 86 }
87 87
88 void TabAutofillManagerDelegate::ShowAutofillSettings() { 88 void TabAutofillManagerDelegate::ShowAutofillSettings() {
89 #if defined(OS_ANDROID) 89 #if defined(OS_ANDROID)
90 NOTIMPLEMENTED(); 90 NOTIMPLEMENTED();
91 #else 91 #else
92 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); 92 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
93 if (browser) 93 if (browser)
94 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); 94 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage);
95 #endif // #if defined(OS_ANDROID) 95 #endif // #if defined(OS_ANDROID)
(...skipping 18 matching lines...) Expand all
114 NOTIMPLEMENTED(); 114 NOTIMPLEMENTED();
115 #else 115 #else
116 HideAutocheckoutBubble(); 116 HideAutocheckoutBubble();
117 117
118 // Convert |bounding_box| to be in screen space. 118 // Convert |bounding_box| to be in screen space.
119 gfx::Rect container_rect; 119 gfx::Rect container_rect;
120 web_contents_->GetView()->GetContainerBounds(&container_rect); 120 web_contents_->GetView()->GetContainerBounds(&container_rect);
121 gfx::RectF anchor = bounding_box + container_rect.OffsetFromOrigin(); 121 gfx::RectF anchor = bounding_box + container_rect.OffsetFromOrigin();
122 122
123 autocheckout_bubble_ = 123 autocheckout_bubble_ =
124 AutocheckoutBubble::Create(scoped_ptr<AutocheckoutBubbleController>( 124 AutocheckoutBubble::Create(
125 new AutocheckoutBubbleController( 125 web_contents_,
126 anchor, 126 scoped_ptr<AutocheckoutBubbleController>(
127 web_contents_->GetView()->GetTopLevelNativeWindow(), 127 new AutocheckoutBubbleController(
128 is_google_user, 128 anchor,
129 callback))); 129 web_contents_->GetView()->GetTopLevelNativeWindow(),
130 is_google_user,
131 callback)));
130 autocheckout_bubble_->ShowBubble(); 132 autocheckout_bubble_->ShowBubble();
131 #endif // #if !defined(TOOLKIT_VIEWS) 133 #endif // #if !defined(TOOLKIT_VIEWS)
132 } 134 }
133 135
134 void TabAutofillManagerDelegate::HideAutocheckoutBubble() { 136 void TabAutofillManagerDelegate::HideAutocheckoutBubble() {
135 if (autocheckout_bubble_.get()) 137 if (autocheckout_bubble_.get())
136 autocheckout_bubble_->HideBubble(); 138 autocheckout_bubble_->HideBubble();
137 } 139 }
138 140
139 void TabAutofillManagerDelegate::ShowRequestAutocompleteDialog( 141 void TabAutofillManagerDelegate::ShowRequestAutocompleteDialog(
140 const FormData& form, 142 const FormData& form,
141 const GURL& source_url, 143 const GURL& source_url,
142 DialogType dialog_type, 144 DialogType dialog_type,
143 const base::Callback<void(const FormStructure*, 145 const base::Callback<void(const FormStructure*,
144 const std::string&)>& callback) { 146 const std::string&)>& callback) {
145 HideRequestAutocompleteDialog(); 147 HideRequestAutocompleteDialog();
146 148
147 dialog_controller_ = AutofillDialogControllerImpl::Create(web_contents_, 149 #if defined(ENABLE_AUTOFILL_DIALOG)
Evan Stade 2013/08/01 19:44:52 I don't think you need this ifdef. Instead do if
aruslan 2013/08/07 23:17:03 Done.
148 form, 150 dialog_delegate_ = AutofillDialogTabManagerDelegate::Create(web_contents_,
149 source_url, 151 form,
150 dialog_type, 152 source_url,
151 callback); 153 dialog_type,
152 dialog_controller_->Show(); 154 callback);
155 dialog_delegate_->Show();
156 #else
157 callback.Run(NULL, std::string());
158 NOTIMPLEMENTED();
159 #endif // #if !defined(ENABLE_AUTOFILL_DIALOG)
153 } 160 }
154 161
155 void TabAutofillManagerDelegate::ShowAutofillPopup( 162 void TabAutofillManagerDelegate::ShowAutofillPopup(
156 const gfx::RectF& element_bounds, 163 const gfx::RectF& element_bounds,
157 base::i18n::TextDirection text_direction, 164 base::i18n::TextDirection text_direction,
158 const std::vector<string16>& values, 165 const std::vector<string16>& values,
159 const std::vector<string16>& labels, 166 const std::vector<string16>& labels,
160 const std::vector<string16>& icons, 167 const std::vector<string16>& icons,
161 const std::vector<int>& identifiers, 168 const std::vector<int>& identifiers,
162 base::WeakPtr<AutofillPopupDelegate> delegate) { 169 base::WeakPtr<AutofillPopupDelegate> delegate) {
(...skipping 21 matching lines...) Expand all
184 popup_controller_->UpdateDataListValues(values, labels); 191 popup_controller_->UpdateDataListValues(values, labels);
185 } 192 }
186 193
187 void TabAutofillManagerDelegate::HideAutofillPopup() { 194 void TabAutofillManagerDelegate::HideAutofillPopup() {
188 if (popup_controller_.get()) 195 if (popup_controller_.get())
189 popup_controller_->Hide(); 196 popup_controller_->Hide();
190 } 197 }
191 198
192 void TabAutofillManagerDelegate::AddAutocheckoutStep( 199 void TabAutofillManagerDelegate::AddAutocheckoutStep(
193 AutocheckoutStepType step_type) { 200 AutocheckoutStepType step_type) {
194 dialog_controller_->AddAutocheckoutStep(step_type); 201 dialog_delegate_->AddAutocheckoutStep(step_type);
195 } 202 }
196 203
197 void TabAutofillManagerDelegate::UpdateAutocheckoutStep( 204 void TabAutofillManagerDelegate::UpdateAutocheckoutStep(
198 AutocheckoutStepType step_type, 205 AutocheckoutStepType step_type,
199 AutocheckoutStepStatus step_status) { 206 AutocheckoutStepStatus step_status) {
200 dialog_controller_->UpdateAutocheckoutStep(step_type, step_status); 207 dialog_delegate_->UpdateAutocheckoutStep(step_type, step_status);
201 } 208 }
202 209
203 bool TabAutofillManagerDelegate::IsAutocompleteEnabled() { 210 bool TabAutofillManagerDelegate::IsAutocompleteEnabled() {
204 // For browser, Autocomplete is always enabled as part of Autofill. 211 // For browser, Autocomplete is always enabled as part of Autofill.
205 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); 212 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled);
206 } 213 }
207 214
208 void TabAutofillManagerDelegate::HideRequestAutocompleteDialog() { 215 void TabAutofillManagerDelegate::HideRequestAutocompleteDialog() {
209 if (dialog_controller_.get()) 216 if (dialog_delegate_.get())
210 dialog_controller_->Hide(); 217 dialog_delegate_->Hide();
211 } 218 }
212 219
213 void TabAutofillManagerDelegate::DidNavigateMainFrame( 220 void TabAutofillManagerDelegate::DidNavigateMainFrame(
214 const content::LoadCommittedDetails& details, 221 const content::LoadCommittedDetails& details,
215 const content::FrameNavigateParams& params) { 222 const content::FrameNavigateParams& params) {
216 223
217 HideAutocheckoutBubble(); 224 HideAutocheckoutBubble();
218 225
219 if (!dialog_controller_.get()) 226 if (!dialog_delegate_.get())
220 return; 227 return;
221 228
222 // A redirect immediately after a successful Autocheckout flow shouldn't hide 229 // A redirect immediately after a successful Autocheckout flow shouldn't hide
223 // the dialog. 230 // the dialog.
224 bool preserve_dialog = AutofillDriverImpl::FromWebContents(web_contents())-> 231 bool preserve_dialog = AutofillDriverImpl::FromWebContents(web_contents())->
225 autofill_manager()->autocheckout_manager()->should_preserve_dialog(); 232 autofill_manager()->autocheckout_manager()->should_preserve_dialog();
226 bool was_redirect = details.entry && 233 bool was_redirect = details.entry &&
227 content::PageTransitionIsRedirect(details.entry->GetTransitionType()); 234 content::PageTransitionIsRedirect(details.entry->GetTransitionType());
228 235
229 if (dialog_controller_->dialog_type() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE || 236 if (dialog_delegate_->GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE ||
230 (!was_redirect && !preserve_dialog)) { 237 (!was_redirect && !preserve_dialog)) {
231 HideRequestAutocompleteDialog(); 238 HideRequestAutocompleteDialog();
232 } 239 }
233 } 240 }
234 241
235 void TabAutofillManagerDelegate::WebContentsDestroyed( 242 void TabAutofillManagerDelegate::WebContentsDestroyed(
236 content::WebContents* web_contents) { 243 content::WebContents* web_contents) {
237 HideAutofillPopup(); 244 HideAutofillPopup();
238 } 245 }
239 246
240 } // namespace autofill 247 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698