OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/content/browser/content_autofill_driver.h" | 5 #include "components/autofill/content/browser/content_autofill_driver.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
9 #include "components/autofill/content/common/autofill_messages.h" | 9 #include "components/autofill/content/common/autofill_messages.h" |
10 #include "components/autofill/core/browser/autofill_client.h" | 10 #include "components/autofill/core/browser/autofill_client.h" |
11 #include "components/autofill/core/browser/autofill_external_delegate.h" | 11 #include "components/autofill/core/browser/autofill_external_delegate.h" |
12 #include "components/autofill/core/browser/autofill_manager.h" | 12 #include "components/autofill/core/browser/autofill_manager.h" |
13 #include "components/autofill/core/browser/form_structure.h" | 13 #include "components/autofill/core/browser/form_structure.h" |
14 #include "components/autofill/core/common/autofill_switches.h" | 14 #include "components/autofill/core/common/autofill_switches.h" |
15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/navigation_details.h" | 18 #include "content/public/browser/navigation_details.h" |
| 19 #include "content/public/browser/render_frame_host.h" |
19 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/site_instance.h" |
21 #include "content/public/common/frame_navigate_params.h" | |
22 #include "ipc/ipc_message_macros.h" | 22 #include "ipc/ipc_message_macros.h" |
23 | 23 |
24 namespace autofill { | 24 namespace autofill { |
25 | 25 |
26 namespace { | |
27 | |
28 const char kContentAutofillDriverWebContentsUserDataKey[] = | |
29 "web_contents_autofill_driver_impl"; | |
30 | |
31 } // namespace | |
32 | |
33 // static | |
34 void ContentAutofillDriver::CreateForWebContentsAndDelegate( | |
35 content::WebContents* contents, | |
36 AutofillClient* client, | |
37 const std::string& app_locale, | |
38 AutofillManager::AutofillDownloadManagerState enable_download_manager) { | |
39 if (FromWebContents(contents)) | |
40 return; | |
41 | |
42 contents->SetUserData( | |
43 kContentAutofillDriverWebContentsUserDataKey, | |
44 new ContentAutofillDriver( | |
45 contents, client, app_locale, enable_download_manager)); | |
46 } | |
47 | |
48 // static | |
49 ContentAutofillDriver* ContentAutofillDriver::FromWebContents( | |
50 content::WebContents* contents) { | |
51 return static_cast<ContentAutofillDriver*>( | |
52 contents->GetUserData(kContentAutofillDriverWebContentsUserDataKey)); | |
53 } | |
54 | |
55 ContentAutofillDriver::ContentAutofillDriver( | 26 ContentAutofillDriver::ContentAutofillDriver( |
56 content::WebContents* web_contents, | 27 content::RenderFrameHost* render_frame_host, |
57 AutofillClient* client, | 28 AutofillClient* client, |
58 const std::string& app_locale, | 29 const std::string& app_locale, |
59 AutofillManager::AutofillDownloadManagerState enable_download_manager) | 30 AutofillManager::AutofillDownloadManagerState enable_download_manager) |
60 : content::WebContentsObserver(web_contents), | 31 : render_frame_host_(render_frame_host), |
| 32 client_(client), |
61 autofill_manager_(new AutofillManager(this, | 33 autofill_manager_(new AutofillManager(this, |
62 client, | 34 client, |
63 app_locale, | 35 app_locale, |
64 enable_download_manager)), | 36 enable_download_manager)), |
65 autofill_external_delegate_(autofill_manager_.get(), this), | 37 autofill_external_delegate_(autofill_manager_.get(), this), |
66 request_autocomplete_manager_(this) { | 38 request_autocomplete_manager_(this) { |
67 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_); | 39 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_); |
68 } | 40 } |
69 | 41 |
70 ContentAutofillDriver::~ContentAutofillDriver() {} | 42 ContentAutofillDriver::~ContentAutofillDriver() {} |
71 | 43 |
72 bool ContentAutofillDriver::IsOffTheRecord() const { | 44 bool ContentAutofillDriver::IsOffTheRecord() const { |
73 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 45 return render_frame_host_->GetSiteInstance() |
| 46 ->GetBrowserContext() |
| 47 ->IsOffTheRecord(); |
74 } | 48 } |
75 | 49 |
76 net::URLRequestContextGetter* ContentAutofillDriver::GetURLRequestContext() { | 50 net::URLRequestContextGetter* ContentAutofillDriver::GetURLRequestContext() { |
77 return web_contents()->GetBrowserContext()->GetRequestContext(); | 51 return render_frame_host_->GetSiteInstance() |
| 52 ->GetBrowserContext() |
| 53 ->GetRequestContext(); |
78 } | 54 } |
79 | 55 |
80 base::SequencedWorkerPool* ContentAutofillDriver::GetBlockingPool() { | 56 base::SequencedWorkerPool* ContentAutofillDriver::GetBlockingPool() { |
81 return content::BrowserThread::GetBlockingPool(); | 57 return content::BrowserThread::GetBlockingPool(); |
82 } | 58 } |
83 | 59 |
84 bool ContentAutofillDriver::RendererIsAvailable() { | 60 bool ContentAutofillDriver::RendererIsAvailable() { |
85 return (web_contents()->GetRenderViewHost() != NULL); | 61 return render_frame_host_->GetRenderViewHost() != NULL; |
86 } | 62 } |
87 | 63 |
88 void ContentAutofillDriver::SendFormDataToRenderer( | 64 void ContentAutofillDriver::SendFormDataToRenderer( |
89 int query_id, | 65 int query_id, |
90 RendererFormDataAction action, | 66 RendererFormDataAction action, |
91 const FormData& data) { | 67 const FormData& data) { |
92 if (!RendererIsAvailable()) | 68 if (!RendererIsAvailable()) |
93 return; | 69 return; |
94 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | |
95 switch (action) { | 70 switch (action) { |
96 case FORM_DATA_ACTION_FILL: | 71 case FORM_DATA_ACTION_FILL: |
97 host->Send( | 72 render_frame_host_->Send(new AutofillMsg_FillForm( |
98 new AutofillMsg_FillForm(host->GetRoutingID(), query_id, data)); | 73 render_frame_host_->GetRoutingID(), query_id, data)); |
99 break; | 74 break; |
100 case FORM_DATA_ACTION_PREVIEW: | 75 case FORM_DATA_ACTION_PREVIEW: |
101 host->Send( | 76 render_frame_host_->Send(new AutofillMsg_PreviewForm( |
102 new AutofillMsg_PreviewForm(host->GetRoutingID(), query_id, data)); | 77 render_frame_host_->GetRoutingID(), query_id, data)); |
103 break; | 78 break; |
104 } | 79 } |
105 } | 80 } |
106 | 81 |
107 void ContentAutofillDriver::PingRenderer() { | 82 void ContentAutofillDriver::PingRenderer() { |
108 if (!RendererIsAvailable()) | 83 if (!RendererIsAvailable()) |
109 return; | 84 return; |
110 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 85 render_frame_host_->Send( |
111 host->Send(new AutofillMsg_Ping(host->GetRoutingID())); | 86 new AutofillMsg_Ping(render_frame_host_->GetRoutingID())); |
| 87 } |
| 88 |
| 89 void ContentAutofillDriver::DetectAccountCreationForms( |
| 90 const std::vector<FormStructure*>& forms) { |
| 91 autofill_manager_->client()->DetectAccountCreationForms(render_frame_host_, |
| 92 forms); |
112 } | 93 } |
113 | 94 |
114 void ContentAutofillDriver::SendAutofillTypePredictionsToRenderer( | 95 void ContentAutofillDriver::SendAutofillTypePredictionsToRenderer( |
115 const std::vector<FormStructure*>& forms) { | 96 const std::vector<FormStructure*>& forms) { |
116 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 97 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
117 switches::kShowAutofillTypePredictions)) | 98 switches::kShowAutofillTypePredictions)) |
118 return; | 99 return; |
119 | 100 |
120 if (!RendererIsAvailable()) | 101 if (!RendererIsAvailable()) |
121 return; | 102 return; |
122 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | |
123 | 103 |
124 std::vector<FormDataPredictions> type_predictions; | 104 std::vector<FormDataPredictions> type_predictions; |
125 FormStructure::GetFieldTypePredictions(forms, &type_predictions); | 105 FormStructure::GetFieldTypePredictions(forms, &type_predictions); |
126 host->Send(new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(), | 106 render_frame_host_->Send(new AutofillMsg_FieldTypePredictionsAvailable( |
127 type_predictions)); | 107 render_frame_host_->GetRoutingID(), type_predictions)); |
128 } | 108 } |
129 | 109 |
130 void ContentAutofillDriver::RendererShouldAcceptDataListSuggestion( | 110 void ContentAutofillDriver::RendererShouldAcceptDataListSuggestion( |
131 const base::string16& value) { | 111 const base::string16& value) { |
132 if (!RendererIsAvailable()) | 112 if (!RendererIsAvailable()) |
133 return; | 113 return; |
134 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 114 render_frame_host_->Send(new AutofillMsg_AcceptDataListSuggestion( |
135 host->Send( | 115 render_frame_host_->GetRoutingID(), value)); |
136 new AutofillMsg_AcceptDataListSuggestion(host->GetRoutingID(), value)); | |
137 } | 116 } |
138 | 117 |
139 void ContentAutofillDriver::RendererShouldClearFilledForm() { | 118 void ContentAutofillDriver::RendererShouldClearFilledForm() { |
140 if (!RendererIsAvailable()) | 119 if (!RendererIsAvailable()) |
141 return; | 120 return; |
142 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 121 render_frame_host_->Send( |
143 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); | 122 new AutofillMsg_ClearForm(render_frame_host_->GetRoutingID())); |
144 } | 123 } |
145 | 124 |
146 void ContentAutofillDriver::RendererShouldClearPreviewedForm() { | 125 void ContentAutofillDriver::RendererShouldClearPreviewedForm() { |
147 if (!RendererIsAvailable()) | 126 if (!RendererIsAvailable()) |
148 return; | 127 return; |
149 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 128 render_frame_host_->Send( |
150 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); | 129 new AutofillMsg_ClearPreviewedForm(render_frame_host_->GetRoutingID())); |
151 } | 130 } |
152 | 131 |
153 void ContentAutofillDriver::RendererShouldFillFieldWithValue( | 132 void ContentAutofillDriver::RendererShouldFillFieldWithValue( |
154 const base::string16& value) { | 133 const base::string16& value) { |
155 if (!RendererIsAvailable()) | 134 if (!RendererIsAvailable()) |
156 return; | 135 return; |
157 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 136 render_frame_host_->Send(new AutofillMsg_FillFieldWithValue( |
158 host->Send(new AutofillMsg_FillFieldWithValue(host->GetRoutingID(), value)); | 137 render_frame_host_->GetRoutingID(), value)); |
159 } | 138 } |
| 139 |
160 void ContentAutofillDriver::RendererShouldPreviewFieldWithValue( | 140 void ContentAutofillDriver::RendererShouldPreviewFieldWithValue( |
161 const base::string16& value) { | 141 const base::string16& value) { |
162 if (!RendererIsAvailable()) | 142 if (!RendererIsAvailable()) |
163 return; | 143 return; |
164 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 144 render_frame_host_->Send(new AutofillMsg_PreviewFieldWithValue( |
165 host->Send(new AutofillMsg_PreviewFieldWithValue(host->GetRoutingID(), | 145 render_frame_host_->GetRoutingID(), value)); |
166 value)); | |
167 } | 146 } |
168 | 147 |
169 bool ContentAutofillDriver::OnMessageReceived(const IPC::Message& message) { | 148 bool ContentAutofillDriver::HandleMessage(const IPC::Message& message) { |
170 bool handled = true; | 149 bool handled = true; |
171 IPC_BEGIN_MESSAGE_MAP(ContentAutofillDriver, message) | 150 IPC_BEGIN_MESSAGE_MAP(ContentAutofillDriver, message) |
| 151 IPC_MESSAGE_FORWARD(AutofillHostMsg_FirstUserGestureObserved, |
| 152 client_, |
| 153 AutofillClient::OnFirstUserGestureObserved) |
172 IPC_MESSAGE_FORWARD(AutofillHostMsg_FormsSeen, | 154 IPC_MESSAGE_FORWARD(AutofillHostMsg_FormsSeen, |
173 autofill_manager_.get(), | 155 autofill_manager_.get(), |
174 AutofillManager::OnFormsSeen) | 156 AutofillManager::OnFormsSeen) |
175 IPC_MESSAGE_FORWARD(AutofillHostMsg_FormSubmitted, | 157 IPC_MESSAGE_FORWARD(AutofillHostMsg_FormSubmitted, |
176 autofill_manager_.get(), | 158 autofill_manager_.get(), |
177 AutofillManager::OnFormSubmitted) | 159 AutofillManager::OnFormSubmitted) |
178 IPC_MESSAGE_FORWARD(AutofillHostMsg_TextFieldDidChange, | 160 IPC_MESSAGE_FORWARD(AutofillHostMsg_TextFieldDidChange, |
179 autofill_manager_.get(), | 161 autofill_manager_.get(), |
180 AutofillManager::OnTextFieldDidChange) | 162 AutofillManager::OnTextFieldDidChange) |
181 IPC_MESSAGE_FORWARD(AutofillHostMsg_QueryFormFieldAutofill, | 163 IPC_MESSAGE_FORWARD(AutofillHostMsg_QueryFormFieldAutofill, |
(...skipping 21 matching lines...) Expand all Loading... |
203 &request_autocomplete_manager_, | 185 &request_autocomplete_manager_, |
204 RequestAutocompleteManager::OnRequestAutocomplete) | 186 RequestAutocompleteManager::OnRequestAutocomplete) |
205 IPC_MESSAGE_FORWARD(AutofillHostMsg_CancelRequestAutocomplete, | 187 IPC_MESSAGE_FORWARD(AutofillHostMsg_CancelRequestAutocomplete, |
206 &request_autocomplete_manager_, | 188 &request_autocomplete_manager_, |
207 RequestAutocompleteManager::OnCancelRequestAutocomplete) | 189 RequestAutocompleteManager::OnCancelRequestAutocomplete) |
208 IPC_MESSAGE_UNHANDLED(handled = false) | 190 IPC_MESSAGE_UNHANDLED(handled = false) |
209 IPC_END_MESSAGE_MAP() | 191 IPC_END_MESSAGE_MAP() |
210 return handled; | 192 return handled; |
211 } | 193 } |
212 | 194 |
213 void ContentAutofillDriver::DidNavigateMainFrame( | 195 void ContentAutofillDriver::DidNavigateFrame( |
214 const content::LoadCommittedDetails& details, | 196 const content::LoadCommittedDetails& details, |
215 const content::FrameNavigateParams& params) { | 197 const content::FrameNavigateParams& params) { |
216 if (details.is_navigation_to_different_page()) | 198 if (details.is_navigation_to_different_page()) |
217 autofill_manager_->Reset(); | 199 autofill_manager_->Reset(); |
218 } | 200 } |
219 | 201 |
220 void ContentAutofillDriver::SetAutofillManager( | 202 void ContentAutofillDriver::SetAutofillManager( |
221 scoped_ptr<AutofillManager> manager) { | 203 scoped_ptr<AutofillManager> manager) { |
222 autofill_manager_ = manager.Pass(); | 204 autofill_manager_ = manager.Pass(); |
223 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_); | 205 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_); |
224 } | 206 } |
225 | 207 |
226 void ContentAutofillDriver::NavigationEntryCommitted( | |
227 const content::LoadCommittedDetails& load_details) { | |
228 autofill_manager_->client()->HideAutofillPopup(); | |
229 } | |
230 | |
231 void ContentAutofillDriver::WasHidden() { | |
232 autofill_manager_->client()->HideAutofillPopup(); | |
233 } | |
234 | |
235 } // namespace autofill | 208 } // namespace autofill |
OLD | NEW |