| 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_factory.h" | 5 #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
| 7 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 8 #include "components/autofill/content/browser/content_autofill_driver.h" | 9 #include "components/autofill/content/browser/content_autofill_driver.h" |
| 9 #include "components/autofill/core/browser/autofill_client.h" | 10 #include "components/autofill/core/browser/autofill_client.h" |
| 10 #include "components/autofill/core/browser/autofill_manager.h" | 11 #include "components/autofill/core/browser/autofill_manager.h" |
| 11 #include "components/autofill/core/browser/form_structure.h" | 12 #include "components/autofill/core/browser/form_structure.h" |
| 12 #include "components/autofill/core/common/autofill_switches.h" | 13 #include "components/autofill/core/common/autofill_switches.h" |
| 13 #include "content/public/browser/navigation_handle.h" | 14 #include "content/public/browser/navigation_handle.h" |
| 14 #include "content/public/browser/render_frame_host.h" | 15 #include "content/public/browser/render_frame_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 16 #include "ipc/ipc_message_macros.h" | 17 #include "ipc/ipc_message_macros.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 47 content::WebContents* web_contents, | 48 content::WebContents* web_contents, |
| 48 AutofillClient* client, | 49 AutofillClient* client, |
| 49 const std::string& app_locale, | 50 const std::string& app_locale, |
| 50 AutofillManager::AutofillDownloadManagerState enable_download_manager) | 51 AutofillManager::AutofillDownloadManagerState enable_download_manager) |
| 51 : content::WebContentsObserver(web_contents), | 52 : content::WebContentsObserver(web_contents), |
| 52 client_(client), | 53 client_(client), |
| 53 app_locale_(app_locale), | 54 app_locale_(app_locale), |
| 54 enable_download_manager_(enable_download_manager) { | 55 enable_download_manager_(enable_download_manager) { |
| 55 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 56 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 56 if (main_frame->IsRenderFrameLive()) { | 57 if (main_frame->IsRenderFrameLive()) { |
| 57 frame_driver_map_[main_frame] = make_scoped_ptr(new ContentAutofillDriver( | 58 frame_driver_map_[main_frame] = base::WrapUnique(new ContentAutofillDriver( |
| 58 main_frame, client_, app_locale_, enable_download_manager_)); | 59 main_frame, client_, app_locale_, enable_download_manager_)); |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 | 62 |
| 62 ContentAutofillDriverFactory::~ContentAutofillDriverFactory() {} | 63 ContentAutofillDriverFactory::~ContentAutofillDriverFactory() {} |
| 63 | 64 |
| 64 ContentAutofillDriver* ContentAutofillDriverFactory::DriverForFrame( | 65 ContentAutofillDriver* ContentAutofillDriverFactory::DriverForFrame( |
| 65 content::RenderFrameHost* render_frame_host) { | 66 content::RenderFrameHost* render_frame_host) { |
| 66 auto mapping = frame_driver_map_.find(render_frame_host); | 67 auto mapping = frame_driver_map_.find(render_frame_host); |
| 67 return mapping == frame_driver_map_.end() ? nullptr : mapping->second.get(); | 68 return mapping == frame_driver_map_.end() ? nullptr : mapping->second.get(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 bool ContentAutofillDriverFactory::OnMessageReceived( | 71 bool ContentAutofillDriverFactory::OnMessageReceived( |
| 71 const IPC::Message& message, | 72 const IPC::Message& message, |
| 72 content::RenderFrameHost* render_frame_host) { | 73 content::RenderFrameHost* render_frame_host) { |
| 73 return frame_driver_map_[render_frame_host]->HandleMessage(message); | 74 return frame_driver_map_[render_frame_host]->HandleMessage(message); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void ContentAutofillDriverFactory::RenderFrameCreated( | 77 void ContentAutofillDriverFactory::RenderFrameCreated( |
| 77 content::RenderFrameHost* render_frame_host) { | 78 content::RenderFrameHost* render_frame_host) { |
| 78 auto insertion_result = | 79 auto insertion_result = |
| 79 frame_driver_map_.insert(std::make_pair(render_frame_host, nullptr)); | 80 frame_driver_map_.insert(std::make_pair(render_frame_host, nullptr)); |
| 80 // This is called twice for the main frame. | 81 // This is called twice for the main frame. |
| 81 if (insertion_result.second) { // This was the first time. | 82 if (insertion_result.second) { // This was the first time. |
| 82 insertion_result.first->second = make_scoped_ptr(new ContentAutofillDriver( | 83 insertion_result.first->second = base::WrapUnique(new ContentAutofillDriver( |
| 83 render_frame_host, client_, app_locale_, enable_download_manager_)); | 84 render_frame_host, client_, app_locale_, enable_download_manager_)); |
| 84 } | 85 } |
| 85 } | 86 } |
| 86 | 87 |
| 87 void ContentAutofillDriverFactory::RenderFrameDeleted( | 88 void ContentAutofillDriverFactory::RenderFrameDeleted( |
| 88 content::RenderFrameHost* render_frame_host) { | 89 content::RenderFrameHost* render_frame_host) { |
| 89 frame_driver_map_.erase(render_frame_host); | 90 frame_driver_map_.erase(render_frame_host); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void ContentAutofillDriverFactory::DidNavigateAnyFrame( | 93 void ContentAutofillDriverFactory::DidNavigateAnyFrame( |
| 93 content::RenderFrameHost* render_frame_host, | 94 content::RenderFrameHost* render_frame_host, |
| 94 const content::LoadCommittedDetails& details, | 95 const content::LoadCommittedDetails& details, |
| 95 const content::FrameNavigateParams& params) { | 96 const content::FrameNavigateParams& params) { |
| 96 frame_driver_map_[render_frame_host]->DidNavigateFrame(details, params); | 97 frame_driver_map_[render_frame_host]->DidNavigateFrame(details, params); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void ContentAutofillDriverFactory::DidFinishNavigation( | 100 void ContentAutofillDriverFactory::DidFinishNavigation( |
| 100 content::NavigationHandle* navigation_handle) { | 101 content::NavigationHandle* navigation_handle) { |
| 101 if (navigation_handle->HasCommitted()) | 102 if (navigation_handle->HasCommitted()) |
| 102 client_->HideAutofillPopup(); | 103 client_->HideAutofillPopup(); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void ContentAutofillDriverFactory::WasHidden() { | 106 void ContentAutofillDriverFactory::WasHidden() { |
| 106 client_->HideAutofillPopup(); | 107 client_->HideAutofillPopup(); |
| 107 } | 108 } |
| 108 | 109 |
| 109 } // namespace autofill | 110 } // namespace autofill |
| OLD | NEW |