Chromium Code Reviews| Index: components/password_manager/content/browser/content_password_manager_driver.cc |
| diff --git a/components/password_manager/content/browser/content_password_manager_driver.cc b/components/password_manager/content/browser/content_password_manager_driver.cc |
| index 62c20e6eed31e3ac72466c800c421635e0b00d3d..776fd5f0d5c7861f4fc23e6e8c87cb7f78f5302f 100644 |
| --- a/components/password_manager/content/browser/content_password_manager_driver.cc |
| +++ b/components/password_manager/content/browser/content_password_manager_driver.cc |
| @@ -5,14 +5,18 @@ |
| #include "components/password_manager/content/browser/content_password_manager_driver.h" |
| #include "components/autofill/content/browser/content_autofill_driver.h" |
| +#include "components/autofill/content/browser/content_autofill_driver_factory.h" |
| #include "components/autofill/content/common/autofill_messages.h" |
| #include "components/autofill/core/common/form_data.h" |
| #include "components/autofill/core/common/password_form.h" |
| +#include "components/password_manager/content/browser/content_password_manager_driver_factory.h" |
| #include "components/password_manager/core/browser/password_manager_client.h" |
| #include "content/public/browser/browser_context.h" |
| #include "content/public/browser/navigation_details.h" |
| #include "content/public/browser/navigation_entry.h" |
| +#include "content/public/browser/render_frame_host.h" |
| #include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/site_instance.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/common/ssl_status.h" |
| #include "ipc/ipc_message_macros.h" |
| @@ -21,37 +25,44 @@ |
| namespace password_manager { |
| ContentPasswordManagerDriver::ContentPasswordManagerDriver( |
| - content::WebContents* web_contents, |
| + content::RenderFrameHost* render_frame_host, |
| PasswordManagerClient* client, |
| autofill::AutofillClient* autofill_client) |
| - : WebContentsObserver(web_contents), |
| - password_manager_(client), |
| - password_generation_manager_(client), |
| - password_autofill_manager_(client, autofill_client), |
| + : render_frame_host_(render_frame_host), |
| + password_manager_(client, this), |
| + password_generation_manager_(client, this), |
| + password_autofill_manager_(client, this, autofill_client), |
| next_free_key_(0) { |
| - DCHECK(web_contents); |
| } |
| ContentPasswordManagerDriver::~ContentPasswordManagerDriver() {} |
| +// static |
| +ContentPasswordManagerDriver* |
| +ContentPasswordManagerDriver::GetForRenderFrameHost( |
| + content::RenderFrameHost* render_frame_host) { |
| + return ContentPasswordManagerDriverFactory::FromWebContents( |
| + content::WebContents::FromRenderFrameHost(render_frame_host)) |
| + ->GetDriverForFrame(render_frame_host); |
| +} |
| + |
| void ContentPasswordManagerDriver::FillPasswordForm( |
| const autofill::PasswordFormFillData& form_data) { |
| const int key = next_free_key_++; |
| password_autofill_manager_.OnAddPasswordFormMapping(key, form_data); |
| - DCHECK(web_contents()); |
| - web_contents()->GetRenderViewHost()->Send(new AutofillMsg_FillPasswordForm( |
| - web_contents()->GetRenderViewHost()->GetRoutingID(), key, form_data)); |
| + render_frame_host_->Send(new AutofillMsg_FillPasswordForm( |
| + render_frame_host_->GetRoutingID(), key, form_data)); |
| } |
| void ContentPasswordManagerDriver::AllowPasswordGenerationForForm( |
| const autofill::PasswordForm& form) { |
| - content::RenderViewHost* host = web_contents()->GetRenderViewHost(); |
| + content::RenderFrameHost* host = render_frame_host_; |
| host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), form)); |
| } |
| void ContentPasswordManagerDriver::AccountCreationFormsFound( |
| const std::vector<autofill::FormData>& forms) { |
| - content::RenderViewHost* host = web_contents()->GetRenderViewHost(); |
| + content::RenderFrameHost* host = render_frame_host_; |
| host->Send(new AutofillMsg_AccountCreationFormsDetected(host->GetRoutingID(), |
| forms)); |
| } |
| @@ -59,7 +70,7 @@ void ContentPasswordManagerDriver::AccountCreationFormsFound( |
| void ContentPasswordManagerDriver::FillSuggestion( |
| const base::string16& username, |
| const base::string16& password) { |
| - content::RenderViewHost* host = web_contents()->GetRenderViewHost(); |
| + content::RenderFrameHost* host = render_frame_host_; |
| host->Send( |
| new AutofillMsg_FillPasswordSuggestion(host->GetRoutingID(), |
| username, |
| @@ -69,7 +80,7 @@ void ContentPasswordManagerDriver::FillSuggestion( |
| void ContentPasswordManagerDriver::PreviewSuggestion( |
| const base::string16& username, |
| const base::string16& password) { |
| - content::RenderViewHost* host = web_contents()->GetRenderViewHost(); |
| + content::RenderFrameHost* host = render_frame_host_; |
| host->Send( |
| new AutofillMsg_PreviewPasswordSuggestion(host->GetRoutingID(), |
| username, |
| @@ -77,17 +88,18 @@ void ContentPasswordManagerDriver::PreviewSuggestion( |
| } |
| void ContentPasswordManagerDriver::ClearPreviewedForm() { |
| - content::RenderViewHost* host = web_contents()->GetRenderViewHost(); |
| + content::RenderFrameHost* host = render_frame_host_; |
| host->Send( |
| new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); |
| } |
| bool ContentPasswordManagerDriver::DidLastPageLoadEncounterSSLErrors() { |
| - DCHECK(web_contents()); |
| // TODO(vabr): This is a wrong entry to look at for HTTP basic auth, |
| // http://crbug.com/388246. |
| content::NavigationEntry* entry = |
| - web_contents()->GetController().GetLastCommittedEntry(); |
| + content::WebContents::FromRenderFrameHost(render_frame_host_) |
| + ->GetController() |
| + .GetLastCommittedEntry(); |
| if (!entry) { |
| return false; |
| } |
| @@ -96,8 +108,9 @@ bool ContentPasswordManagerDriver::DidLastPageLoadEncounterSSLErrors() { |
| } |
| bool ContentPasswordManagerDriver::IsOffTheRecord() { |
| - DCHECK(web_contents()); |
| - return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| + return render_frame_host_->GetSiteInstance() |
| + ->GetBrowserContext() |
| + ->IsOffTheRecord(); |
| } |
| PasswordGenerationManager* |
| @@ -114,14 +127,7 @@ ContentPasswordManagerDriver::GetPasswordAutofillManager() { |
| return &password_autofill_manager_; |
| } |
| -void ContentPasswordManagerDriver::DidNavigateMainFrame( |
| - const content::LoadCommittedDetails& details, |
| - const content::FrameNavigateParams& params) { |
| - password_manager_.DidNavigateMainFrame(details.is_in_page); |
| -} |
| - |
| -bool ContentPasswordManagerDriver::OnMessageReceived( |
| - const IPC::Message& message) { |
| +bool ContentPasswordManagerDriver::HandleMessage(const IPC::Message& message) { |
| bool handled = true; |
| IPC_BEGIN_MESSAGE_MAP(PasswordManager, message) |
| IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormsParsed, |
| @@ -145,10 +151,19 @@ bool ContentPasswordManagerDriver::OnMessageReceived( |
| return handled; |
| } |
| +void ContentPasswordManagerDriver::DidNavigateFrame( |
| + const content::LoadCommittedDetails& details, |
| + const content::FrameNavigateParams& params) { |
| + password_manager_.DidNavigateMainFrame(details.is_in_page); |
|
vabr (Chromium)
2014/11/10 14:34:40
I don't think we should call DidNavigateMainFrame
Evan Stade
2014/11/14 23:25:50
Done.
|
| +} |
| + |
| autofill::AutofillManager* ContentPasswordManagerDriver::GetAutofillManager() { |
| - autofill::ContentAutofillDriver* driver = |
| - autofill::ContentAutofillDriver::FromWebContents(web_contents()); |
| - return driver ? driver->autofill_manager() : NULL; |
| + autofill::ContentAutofillDriverFactory* factory = |
| + autofill::ContentAutofillDriverFactory::FromWebContents( |
| + content::WebContents::FromRenderFrameHost(render_frame_host_)); |
| + return factory |
| + ? factory->DriverForFrame(render_frame_host_)->autofill_manager() |
| + : NULL; |
|
vabr (Chromium)
2014/11/10 14:34:40
nit: nullptr
|
| } |
| } // namespace password_manager |