| 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 <utility> |
| 7 #include <vector> | 8 #include <vector> |
| 8 | 9 |
| 10 #include "base/bind.h" |
| 9 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 11 #include "components/autofill/content/browser/content_autofill_driver.h" | 13 #include "components/autofill/content/browser/content_autofill_driver.h" |
| 12 #include "components/autofill/core/browser/autofill_client.h" | 14 #include "components/autofill/core/browser/autofill_client.h" |
| 13 #include "components/autofill/core/browser/autofill_manager.h" | 15 #include "components/autofill/core/browser/autofill_manager.h" |
| 14 #include "components/autofill/core/browser/form_structure.h" | 16 #include "components/autofill/core/browser/form_structure.h" |
| 15 #include "components/autofill/core/common/autofill_switches.h" | 17 #include "components/autofill/core/common/autofill_switches.h" |
| 18 #include "content/public/browser/navigation_details.h" |
| 16 #include "content/public/browser/navigation_handle.h" | 19 #include "content/public/browser/navigation_handle.h" |
| 17 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 19 | 22 |
| 20 namespace autofill { | 23 namespace autofill { |
| 21 | 24 |
| 25 namespace { |
| 26 |
| 27 std::unique_ptr<AutofillDriver> CreateDriver( |
| 28 content::RenderFrameHost* host, |
| 29 AutofillClient* client, |
| 30 const std::string& app_locale, |
| 31 AutofillManager::AutofillDownloadManagerState enable_download_manager) { |
| 32 return base::MakeUnique<ContentAutofillDriver>(host, client, app_locale, |
| 33 enable_download_manager); |
| 34 } |
| 35 |
| 36 } // namespace |
| 37 |
| 22 const char ContentAutofillDriverFactory:: | 38 const char ContentAutofillDriverFactory:: |
| 23 kContentAutofillDriverFactoryWebContentsUserDataKey[] = | 39 kContentAutofillDriverFactoryWebContentsUserDataKey[] = |
| 24 "web_contents_autofill_driver_factory"; | 40 "web_contents_autofill_driver_factory"; |
| 25 | 41 |
| 26 ContentAutofillDriverFactory::~ContentAutofillDriverFactory() {} | 42 ContentAutofillDriverFactory::~ContentAutofillDriverFactory() {} |
| 27 | 43 |
| 28 // static | 44 // static |
| 29 void ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( | 45 void ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( |
| 30 content::WebContents* contents, | 46 content::WebContents* contents, |
| 31 AutofillClient* client, | 47 AutofillClient* client, |
| 32 const std::string& app_locale, | 48 const std::string& app_locale, |
| 33 AutofillManager::AutofillDownloadManagerState enable_download_manager) { | 49 AutofillManager::AutofillDownloadManagerState enable_download_manager) { |
| 34 if (FromWebContents(contents)) | 50 if (FromWebContents(contents)) |
| 35 return; | 51 return; |
| 36 | 52 |
| 37 auto new_factory = base::WrapUnique(new ContentAutofillDriverFactory( | 53 auto new_factory = base::WrapUnique(new ContentAutofillDriverFactory( |
| 38 contents, client, app_locale, enable_download_manager)); | 54 contents, client, app_locale, enable_download_manager, |
| 55 base::Bind(CreateDriver))); |
| 39 const std::vector<content::RenderFrameHost*> frames = | 56 const std::vector<content::RenderFrameHost*> frames = |
| 40 contents->GetAllFrames(); | 57 contents->GetAllFrames(); |
| 41 for (content::RenderFrameHost* frame : frames) { | 58 for (content::RenderFrameHost* frame : frames) { |
| 42 if (frame->IsRenderFrameLive()) | 59 if (frame->IsRenderFrameLive()) |
| 43 new_factory->RenderFrameCreated(frame); | 60 new_factory->RenderFrameCreated(frame); |
| 44 } | 61 } |
| 45 | 62 |
| 46 contents->SetUserData(kContentAutofillDriverFactoryWebContentsUserDataKey, | 63 contents->SetUserData(kContentAutofillDriverFactoryWebContentsUserDataKey, |
| 47 new_factory.release()); | 64 new_factory.release()); |
| 48 } | 65 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 66 // which would raise connection error to peer side. | 83 // which would raise connection error to peer side. |
| 67 // Peer side could reconnect later when needed. | 84 // Peer side could reconnect later when needed. |
| 68 if (!web_contents) | 85 if (!web_contents) |
| 69 return; | 86 return; |
| 70 | 87 |
| 71 ContentAutofillDriverFactory* factory = | 88 ContentAutofillDriverFactory* factory = |
| 72 ContentAutofillDriverFactory::FromWebContents(web_contents); | 89 ContentAutofillDriverFactory::FromWebContents(web_contents); |
| 73 if (!factory) | 90 if (!factory) |
| 74 return; | 91 return; |
| 75 | 92 |
| 76 ContentAutofillDriver* driver = factory->DriverForFrame(render_frame_host); | 93 ContentAutofillDriver* driver = static_cast<ContentAutofillDriver*>( |
| 94 factory->DriverForFrame(render_frame_host)); |
| 77 if (driver) | 95 if (driver) |
| 78 driver->BindRequest(std::move(request)); | 96 driver->BindRequest(std::move(request)); |
| 79 } | 97 } |
| 80 | 98 |
| 81 ContentAutofillDriverFactory::ContentAutofillDriverFactory( | 99 ContentAutofillDriverFactory::ContentAutofillDriverFactory( |
| 82 content::WebContents* web_contents, | 100 content::WebContents* web_contents, |
| 83 AutofillClient* client, | 101 AutofillClient* client, |
| 84 const std::string& app_locale, | 102 const std::string& app_locale, |
| 85 AutofillManager::AutofillDownloadManagerState enable_download_manager) | 103 AutofillManager::AutofillDownloadManagerState enable_download_manager, |
| 104 DriverCreator driver_creator) |
| 86 : content::WebContentsObserver(web_contents), | 105 : content::WebContentsObserver(web_contents), |
| 87 client_(client), | 106 client_(client), |
| 88 app_locale_(app_locale), | 107 app_locale_(app_locale), |
| 89 enable_download_manager_(enable_download_manager) {} | 108 enable_download_manager_(enable_download_manager), |
| 109 driver_creator_(std::move(driver_creator)) {} |
| 90 | 110 |
| 91 ContentAutofillDriver* ContentAutofillDriverFactory::DriverForFrame( | 111 AutofillDriver* ContentAutofillDriverFactory::DriverForFrame( |
| 92 content::RenderFrameHost* render_frame_host) { | 112 content::RenderFrameHost* render_frame_host) { |
| 93 auto mapping = frame_driver_map_.find(render_frame_host); | 113 auto mapping = frame_driver_map_.find(render_frame_host); |
| 94 return mapping == frame_driver_map_.end() ? nullptr : mapping->second.get(); | 114 return mapping == frame_driver_map_.end() ? nullptr : mapping->second.get(); |
| 95 } | 115 } |
| 96 | 116 |
| 97 void ContentAutofillDriverFactory::RenderFrameCreated( | 117 void ContentAutofillDriverFactory::RenderFrameCreated( |
| 98 content::RenderFrameHost* render_frame_host) { | 118 content::RenderFrameHost* render_frame_host) { |
| 99 auto insertion_result = | 119 auto insertion_result = |
| 100 frame_driver_map_.insert(std::make_pair(render_frame_host, nullptr)); | 120 frame_driver_map_.insert(std::make_pair(render_frame_host, nullptr)); |
| 101 // This is called twice for the main frame. | 121 // This is called twice for the main frame. |
| 102 if (insertion_result.second) { // This was the first time. | 122 if (insertion_result.second) { // This was the first time. |
| 103 insertion_result.first->second = base::MakeUnique<ContentAutofillDriver>( | 123 insertion_result.first->second = driver_creator_.Run( |
| 104 render_frame_host, client_, app_locale_, enable_download_manager_); | 124 render_frame_host, client_, app_locale_, enable_download_manager_); |
| 105 } | 125 } |
| 106 } | 126 } |
| 107 | 127 |
| 108 void ContentAutofillDriverFactory::RenderFrameDeleted( | 128 void ContentAutofillDriverFactory::RenderFrameDeleted( |
| 109 content::RenderFrameHost* render_frame_host) { | 129 content::RenderFrameHost* render_frame_host) { |
| 110 frame_driver_map_.erase(render_frame_host); | 130 frame_driver_map_.erase(render_frame_host); |
| 111 } | 131 } |
| 112 | 132 |
| 113 void ContentAutofillDriverFactory::DidNavigateAnyFrame( | 133 void ContentAutofillDriverFactory::DidNavigateAnyFrame( |
| 114 content::RenderFrameHost* render_frame_host, | 134 content::RenderFrameHost* render_frame_host, |
| 115 const content::LoadCommittedDetails& details, | 135 const content::LoadCommittedDetails& details, |
| 116 const content::FrameNavigateParams& params) { | 136 const content::FrameNavigateParams& params) { |
| 117 frame_driver_map_[render_frame_host]->DidNavigateFrame(details, params); | 137 if (details.is_navigation_to_different_page()) |
| 138 frame_driver_map_[render_frame_host]->NavigatedToDifferentPage(); |
| 118 } | 139 } |
| 119 | 140 |
| 120 void ContentAutofillDriverFactory::DidFinishNavigation( | 141 void ContentAutofillDriverFactory::DidFinishNavigation( |
| 121 content::NavigationHandle* navigation_handle) { | 142 content::NavigationHandle* navigation_handle) { |
| 122 if (navigation_handle->HasCommitted()) | 143 if (navigation_handle->HasCommitted()) |
| 123 client_->HideAutofillPopup(); | 144 client_->HideAutofillPopup(); |
| 124 } | 145 } |
| 125 | 146 |
| 126 void ContentAutofillDriverFactory::WasHidden() { | 147 void ContentAutofillDriverFactory::WasHidden() { |
| 127 client_->HideAutofillPopup(); | 148 client_->HideAutofillPopup(); |
| 128 } | 149 } |
| 129 | 150 |
| 130 } // namespace autofill | 151 } // namespace autofill |
| OLD | NEW |