Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: components/autofill/content/browser/content_autofill_driver_factory.cc

Issue 2715483002: Split non-//content parts from ContentAutofillDriverFactory (Closed)
Patch Set: Add instances check Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "components/autofill/content/browser/content_autofill_driver.h" 12 #include "components/autofill/content/browser/content_autofill_driver.h"
12 #include "components/autofill/core/browser/autofill_client.h"
13 #include "components/autofill/core/browser/autofill_manager.h" 13 #include "components/autofill/core/browser/autofill_manager.h"
14 #include "components/autofill/core/browser/form_structure.h"
15 #include "components/autofill/core/common/autofill_switches.h"
16 #include "content/public/browser/navigation_handle.h" 14 #include "content/public/browser/navigation_handle.h"
17 #include "content/public/browser/render_frame_host.h" 15 #include "content/public/browser/render_frame_host.h"
18 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
19 17
20 namespace autofill { 18 namespace autofill {
21 19
20 namespace {
21
22 std::unique_ptr<AutofillDriver> CreateDriver(
23 content::RenderFrameHost* render_frame_host,
24 AutofillClient* client,
25 const std::string& app_locale,
26 AutofillManager::AutofillDownloadManagerState enable_download_manager) {
27 return base::MakeUnique<ContentAutofillDriver>(
28 render_frame_host, client, app_locale, enable_download_manager);
29 }
30
31 } // namespace
32
22 const char ContentAutofillDriverFactory:: 33 const char ContentAutofillDriverFactory::
23 kContentAutofillDriverFactoryWebContentsUserDataKey[] = 34 kContentAutofillDriverFactoryWebContentsUserDataKey[] =
24 "web_contents_autofill_driver_factory"; 35 "web_contents_autofill_driver_factory";
25 36
26 ContentAutofillDriverFactory::~ContentAutofillDriverFactory() {} 37 ContentAutofillDriverFactory::~ContentAutofillDriverFactory() {}
27 38
28 // static 39 // static
29 void ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( 40 void ContentAutofillDriverFactory::CreateForWebContentsAndDelegate(
30 content::WebContents* contents, 41 content::WebContents* contents,
31 AutofillClient* client, 42 AutofillClient* client,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 ContentAutofillDriver* driver = factory->DriverForFrame(render_frame_host); 87 ContentAutofillDriver* driver = factory->DriverForFrame(render_frame_host);
77 if (driver) 88 if (driver)
78 driver->BindRequest(std::move(request)); 89 driver->BindRequest(std::move(request));
79 } 90 }
80 91
81 ContentAutofillDriverFactory::ContentAutofillDriverFactory( 92 ContentAutofillDriverFactory::ContentAutofillDriverFactory(
82 content::WebContents* web_contents, 93 content::WebContents* web_contents,
83 AutofillClient* client, 94 AutofillClient* client,
84 const std::string& app_locale, 95 const std::string& app_locale,
85 AutofillManager::AutofillDownloadManagerState enable_download_manager) 96 AutofillManager::AutofillDownloadManagerState enable_download_manager)
86 : content::WebContentsObserver(web_contents), 97 : AutofillDriverFactory(client),
87 client_(client), 98 content::WebContentsObserver(web_contents),
88 app_locale_(app_locale), 99 app_locale_(app_locale),
89 enable_download_manager_(enable_download_manager) {} 100 enable_download_manager_(enable_download_manager) {}
90 101
91 ContentAutofillDriver* ContentAutofillDriverFactory::DriverForFrame( 102 ContentAutofillDriver* ContentAutofillDriverFactory::DriverForFrame(
92 content::RenderFrameHost* render_frame_host) { 103 content::RenderFrameHost* render_frame_host) {
93 auto mapping = frame_driver_map_.find(render_frame_host); 104 // This cast is safe because AutofillDriverFactory::AddForKey is protected
94 return mapping == frame_driver_map_.end() ? nullptr : mapping->second.get(); 105 // and always called with ContentAutofillDriver instances within
106 // ContentAutofillDriverFactory.
107 return static_cast<ContentAutofillDriver*>(DriverForKey(render_frame_host));
95 } 108 }
96 109
97 void ContentAutofillDriverFactory::RenderFrameCreated( 110 void ContentAutofillDriverFactory::RenderFrameCreated(
98 content::RenderFrameHost* render_frame_host) { 111 content::RenderFrameHost* render_frame_host) {
99 auto insertion_result = 112 AddForKey(render_frame_host,
100 frame_driver_map_.insert(std::make_pair(render_frame_host, nullptr)); 113 base::Bind(CreateDriver, render_frame_host, client(), app_locale_,
101 // This is called twice for the main frame. 114 enable_download_manager_));
102 if (insertion_result.second) { // This was the first time.
103 insertion_result.first->second = base::MakeUnique<ContentAutofillDriver>(
104 render_frame_host, client_, app_locale_, enable_download_manager_);
105 }
106 } 115 }
107 116
108 void ContentAutofillDriverFactory::RenderFrameDeleted( 117 void ContentAutofillDriverFactory::RenderFrameDeleted(
109 content::RenderFrameHost* render_frame_host) { 118 content::RenderFrameHost* render_frame_host) {
110 frame_driver_map_.erase(render_frame_host); 119 DeleteForKey(render_frame_host);
111 } 120 }
112 121
113 void ContentAutofillDriverFactory::DidFinishNavigation( 122 void ContentAutofillDriverFactory::DidFinishNavigation(
114 content::NavigationHandle* navigation_handle) { 123 content::NavigationHandle* navigation_handle) {
115 if (!navigation_handle->HasCommitted()) 124 if (!navigation_handle->HasCommitted())
116 return; 125 return;
117 126
118 client_->HideAutofillPopup(); 127 NavigationFinished();
119 frame_driver_map_[navigation_handle->GetRenderFrameHost()]-> 128 DriverForFrame(navigation_handle->GetRenderFrameHost())
120 DidNavigateFrame(navigation_handle); 129 ->DidNavigateFrame(navigation_handle);
121 } 130 }
122 131
123 void ContentAutofillDriverFactory::WasHidden() { 132 void ContentAutofillDriverFactory::WasHidden() {
124 client_->HideAutofillPopup(); 133 TabHidden();
125 } 134 }
126 135
127 } // namespace autofill 136 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/browser/content_autofill_driver_factory.h ('k') | components/autofill/core/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698