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 "chrome/browser/password_manager/chrome_password_manager_client.h" | 5 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 13 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
14 #include "chrome/browser/password_manager/password_manager_util.h" | 14 #include "chrome/browser/password_manager/password_manager_util.h" |
15 #include "chrome/browser/password_manager/password_store_factory.h" | 15 #include "chrome/browser/password_manager/password_store_factory.h" |
16 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" | 16 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
17 #include "chrome/browser/password_manager/sync_metrics.h" | 17 #include "chrome/browser/password_manager/sync_metrics.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/sync/profile_sync_service.h" | 19 #include "chrome/browser/sync/profile_sync_service.h" |
20 #include "chrome/browser/sync/profile_sync_service_factory.h" | 20 #include "chrome/browser/sync/profile_sync_service_factory.h" |
21 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h " | 21 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h " |
22 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 22 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/chrome_version_info.h" | 24 #include "chrome/common/chrome_version_info.h" |
25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
26 #include "components/autofill/content/common/autofill_messages.h" | 26 #include "components/autofill/content/common/autofill_messages.h" |
27 #include "components/autofill/core/browser/password_generator.h" | 27 #include "components/autofill/core/browser/password_generator.h" |
28 #include "components/autofill/core/common/password_form.h" | 28 #include "components/autofill/core/common/password_form.h" |
29 #include "components/password_manager/content/browser/content_password_manager_d river.h" | |
29 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" | 30 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" |
30 #include "components/password_manager/content/common/credential_manager_messages .h" | 31 #include "components/password_manager/content/common/credential_manager_messages .h" |
31 #include "components/password_manager/content/common/credential_manager_types.h" | 32 #include "components/password_manager/content/common/credential_manager_types.h" |
32 #include "components/password_manager/core/browser/log_receiver.h" | 33 #include "components/password_manager/core/browser/log_receiver.h" |
33 #include "components/password_manager/core/browser/password_form_manager.h" | 34 #include "components/password_manager/core/browser/password_form_manager.h" |
34 #include "components/password_manager/core/browser/password_manager.h" | 35 #include "components/password_manager/core/browser/password_manager.h" |
35 #include "components/password_manager/core/browser/password_manager_internals_se rvice.h" | 36 #include "components/password_manager/core/browser/password_manager_internals_se rvice.h" |
36 #include "components/password_manager/core/browser/password_manager_metrics_util .h" | 37 #include "components/password_manager/core/browser/password_manager_metrics_util .h" |
37 #include "components/password_manager/core/common/password_manager_switches.h" | 38 #include "components/password_manager/core/common/password_manager_switches.h" |
38 #include "content/public/browser/navigation_entry.h" | 39 #include "content/public/browser/navigation_entry.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
66 ChromePasswordManagerClient::ChromePasswordManagerClient( | 67 ChromePasswordManagerClient::ChromePasswordManagerClient( |
67 content::WebContents* web_contents, | 68 content::WebContents* web_contents, |
68 autofill::AutofillClient* autofill_client) | 69 autofill::AutofillClient* autofill_client) |
69 : content::WebContentsObserver(web_contents), | 70 : content::WebContentsObserver(web_contents), |
70 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 71 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
71 driver_(web_contents, this, autofill_client), | 72 driver_(web_contents, this, autofill_client), |
72 credential_manager_dispatcher_(web_contents, this), | 73 credential_manager_dispatcher_(web_contents, this), |
73 observer_(NULL), | 74 observer_(NULL), |
74 can_use_log_router_(false), | 75 can_use_log_router_(false), |
75 autofill_sync_state_(ALLOW_SYNC_CREDENTIALS), | 76 autofill_sync_state_(ALLOW_SYNC_CREDENTIALS), |
76 sync_credential_was_filtered_(false) { | 77 sync_credential_was_filtered_(false), |
78 render_frame_host_source_(NULL) { | |
vabr (Chromium)
2014/11/10 14:34:38
NULL -> nullptr
("recommended for new code", http:
Evan Stade
2014/11/14 23:25:49
Done.
| |
77 PasswordManagerInternalsService* service = | 79 PasswordManagerInternalsService* service = |
78 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 80 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
79 if (service) | 81 if (service) |
80 can_use_log_router_ = service->RegisterClient(this); | 82 can_use_log_router_ = service->RegisterClient(this); |
81 SetUpAutofillSyncState(); | 83 SetUpAutofillSyncState(); |
82 } | 84 } |
83 | 85 |
84 ChromePasswordManagerClient::~ChromePasswordManagerClient() { | 86 ChromePasswordManagerClient::~ChromePasswordManagerClient() { |
85 PasswordManagerInternalsService* service = | 87 PasswordManagerInternalsService* service = |
86 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); | 88 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile_); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 ChromePasswordManagerClient::GetPasswordStore() { | 223 ChromePasswordManagerClient::GetPasswordStore() { |
222 // Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord | 224 // Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord |
223 // itself when it shouldn't access the PasswordStore. | 225 // itself when it shouldn't access the PasswordStore. |
224 // TODO(gcasto): Is is safe to change this to Profile::IMPLICIT_ACCESS? | 226 // TODO(gcasto): Is is safe to change this to Profile::IMPLICIT_ACCESS? |
225 return PasswordStoreFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS) | 227 return PasswordStoreFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS) |
226 .get(); | 228 .get(); |
227 } | 229 } |
228 | 230 |
229 password_manager::PasswordManagerDriver* | 231 password_manager::PasswordManagerDriver* |
230 ChromePasswordManagerClient::GetDriver() { | 232 ChromePasswordManagerClient::GetDriver() { |
231 return &driver_; | 233 return driver_.GetDriverForFrame(web_contents()->GetMainFrame()); |
232 } | 234 } |
233 | 235 |
234 base::FieldTrial::Probability | 236 base::FieldTrial::Probability |
235 ChromePasswordManagerClient::GetProbabilityForExperiment( | 237 ChromePasswordManagerClient::GetProbabilityForExperiment( |
236 const std::string& experiment_name) { | 238 const std::string& experiment_name) { |
237 base::FieldTrial::Probability enabled_probability = 0; | 239 base::FieldTrial::Probability enabled_probability = 0; |
238 if (experiment_name == | 240 if (experiment_name == |
239 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { | 241 password_manager::PasswordManager::kOtherPossibleUsernamesExperiment) { |
240 switch (chrome::VersionInfo::GetChannel()) { | 242 switch (chrome::VersionInfo::GetChannel()) { |
241 case chrome::VersionInfo::CHANNEL_DEV: | 243 case chrome::VersionInfo::CHANNEL_DEV: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 if (service) | 285 if (service) |
284 service->ProcessLog(text); | 286 service->ProcessLog(text); |
285 } | 287 } |
286 | 288 |
287 bool ChromePasswordManagerClient::IsLoggingActive() const { | 289 bool ChromePasswordManagerClient::IsLoggingActive() const { |
288 // WebUI tabs do not need to log password saving progress. In particular, the | 290 // WebUI tabs do not need to log password saving progress. In particular, the |
289 // internals page itself should not send any logs. | 291 // internals page itself should not send any logs. |
290 return can_use_log_router_ && !web_contents()->GetWebUI(); | 292 return can_use_log_router_ && !web_contents()->GetWebUI(); |
291 } | 293 } |
292 | 294 |
293 // static | |
294 password_manager::PasswordGenerationManager* | |
295 ChromePasswordManagerClient::GetGenerationManagerFromWebContents( | |
296 content::WebContents* contents) { | |
297 ChromePasswordManagerClient* client = | |
298 ChromePasswordManagerClient::FromWebContents(contents); | |
299 if (!client) | |
300 return NULL; | |
301 return client->GetDriver()->GetPasswordGenerationManager(); | |
302 } | |
303 | |
304 // static | |
305 password_manager::PasswordManager* | |
306 ChromePasswordManagerClient::GetManagerFromWebContents( | |
307 content::WebContents* contents) { | |
308 ChromePasswordManagerClient* client = | |
309 ChromePasswordManagerClient::FromWebContents(contents); | |
310 if (!client) | |
311 return NULL; | |
312 return client->GetDriver()->GetPasswordManager(); | |
313 } | |
314 | |
315 void ChromePasswordManagerClient::SetTestObserver( | 295 void ChromePasswordManagerClient::SetTestObserver( |
316 autofill::PasswordGenerationPopupObserver* observer) { | 296 autofill::PasswordGenerationPopupObserver* observer) { |
317 observer_ = observer; | 297 observer_ = observer; |
318 } | 298 } |
319 | 299 |
320 bool ChromePasswordManagerClient::OnMessageReceived( | 300 bool ChromePasswordManagerClient::OnMessageReceived( |
321 const IPC::Message& message) { | 301 const IPC::Message& message, |
302 content::RenderFrameHost* render_frame_host) { | |
303 render_frame_host_source_ = render_frame_host; | |
304 | |
322 bool handled = true; | 305 bool handled = true; |
323 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) | 306 IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message) |
324 // Autofill messages: | 307 // Autofill messages: |
325 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, | 308 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, |
326 ShowPasswordGenerationPopup) | 309 ShowPasswordGenerationPopup) |
327 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, | 310 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup, |
328 ShowPasswordEditingPopup) | 311 ShowPasswordEditingPopup) |
329 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, | 312 IPC_MESSAGE_HANDLER(AutofillHostMsg_HidePasswordGenerationPopup, |
330 HidePasswordGenerationPopup) | 313 HidePasswordGenerationPopup) |
331 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, | 314 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed, |
332 NotifyRendererOfLoggingAvailability) | 315 NotifyRendererOfLoggingAvailability) |
333 | 316 |
334 // Default: | 317 // Default: |
335 IPC_MESSAGE_UNHANDLED(handled = false) | 318 IPC_MESSAGE_UNHANDLED(handled = false) |
336 IPC_END_MESSAGE_MAP() | 319 IPC_END_MESSAGE_MAP() |
320 | |
321 render_frame_host_source_ = NULL; | |
vabr (Chromium)
2014/11/10 14:34:38
NULL -> nullptr
Evan Stade
2014/11/14 23:25:49
Done.
| |
337 return handled; | 322 return handled; |
338 } | 323 } |
339 | 324 |
340 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( | 325 gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace( |
341 const gfx::RectF& bounds) { | 326 const gfx::RectF& bounds) { |
342 gfx::Rect client_area = web_contents()->GetContainerBounds(); | 327 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
343 return bounds + client_area.OffsetFromOrigin(); | 328 return bounds + client_area.OffsetFromOrigin(); |
344 } | 329 } |
345 | 330 |
346 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( | 331 void ChromePasswordManagerClient::ShowPasswordGenerationPopup( |
347 const gfx::RectF& bounds, | 332 const gfx::RectF& bounds, |
348 int max_length, | 333 int max_length, |
349 const autofill::PasswordForm& form) { | 334 const autofill::PasswordForm& form) { |
350 // TODO(gcasto): Validate data in PasswordForm. | 335 // TODO(gcasto): Validate data in PasswordForm. |
351 | 336 |
352 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 337 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
353 | 338 |
354 popup_controller_ = | 339 popup_controller_ = |
355 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 340 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
356 popup_controller_, | 341 popup_controller_, element_bounds_in_screen_space, form, max_length, |
357 element_bounds_in_screen_space, | 342 driver_.GetDriverForFrame(render_frame_host_source_) |
358 form, | 343 ->GetPasswordManager(), |
359 max_length, | 344 observer_, web_contents(), web_contents()->GetNativeView()); |
360 driver_.GetPasswordManager(), | |
361 observer_, | |
362 web_contents(), | |
363 web_contents()->GetNativeView()); | |
364 popup_controller_->Show(true /* display_password */); | 345 popup_controller_->Show(true /* display_password */); |
365 } | 346 } |
366 | 347 |
367 void ChromePasswordManagerClient::ShowPasswordEditingPopup( | 348 void ChromePasswordManagerClient::ShowPasswordEditingPopup( |
368 const gfx::RectF& bounds, | 349 const gfx::RectF& bounds, |
369 const autofill::PasswordForm& form) { | 350 const autofill::PasswordForm& form) { |
370 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); | 351 gfx::RectF element_bounds_in_screen_space = GetBoundsInScreenSpace(bounds); |
371 popup_controller_ = | 352 popup_controller_ = |
372 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( | 353 autofill::PasswordGenerationPopupControllerImpl::GetOrCreate( |
373 popup_controller_, | 354 popup_controller_, element_bounds_in_screen_space, form, |
374 element_bounds_in_screen_space, | |
375 form, | |
376 0, // Unspecified max length. | 355 0, // Unspecified max length. |
377 driver_.GetPasswordManager(), | 356 driver_.GetDriverForFrame(render_frame_host_source_) |
378 observer_, | 357 ->GetPasswordManager(), |
379 web_contents(), | 358 observer_, web_contents(), web_contents()->GetNativeView()); |
380 web_contents()->GetNativeView()); | |
381 popup_controller_->Show(false /* display_password */); | 359 popup_controller_->Show(false /* display_password */); |
382 } | 360 } |
383 | 361 |
384 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { | 362 void ChromePasswordManagerClient::NotifyRendererOfLoggingAvailability() { |
385 if (!web_contents()) | 363 if (!web_contents()) |
386 return; | 364 return; |
387 | 365 |
388 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( | 366 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_SetLoggingState( |
389 web_contents()->GetRenderViewHost()->GetRoutingID(), | 367 web_contents()->GetRenderViewHost()->GetRoutingID(), |
390 can_use_log_router_)); | 368 can_use_log_router_)); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 | 467 |
490 if (group_name == "DisallowSyncCredentialsForReauth") { | 468 if (group_name == "DisallowSyncCredentialsForReauth") { |
491 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; | 469 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH; |
492 } else if (group_name == "DisallowSyncCredentials") { | 470 } else if (group_name == "DisallowSyncCredentials") { |
493 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; | 471 autofill_sync_state_ = DISALLOW_SYNC_CREDENTIALS; |
494 } else { | 472 } else { |
495 // Allow by default. | 473 // Allow by default. |
496 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; | 474 autofill_sync_state_ = ALLOW_SYNC_CREDENTIALS; |
497 } | 475 } |
498 } | 476 } |
OLD | NEW |