Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/autofill/content/browser/content_autofill_driver_factory.h" | |
| 6 | |
| 7 #include "components/autofill/content/browser/content_autofill_driver.h" | |
| 8 #include "components/autofill/core/browser/autofill_client.h" | |
| 9 #include "components/autofill/core/browser/autofill_manager.h" | |
| 10 #include "components/autofill/core/browser/form_structure.h" | |
| 11 #include "components/autofill/core/common/autofill_switches.h" | |
| 12 #include "content/public/browser/render_frame_host.h" | |
| 13 #include "content/public/browser/web_contents.h" | |
| 14 #include "ipc/ipc_message_macros.h" | |
| 15 | |
| 16 namespace autofill { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 const char kContentAutofillDriverFactoryWebContentsUserDataKey[] = | |
| 21 "web_contents_autofill_driver_factory"; | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 // static | |
| 26 void ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( | |
| 27 content::WebContents* contents, | |
| 28 AutofillClient* client, | |
| 29 const std::string& app_locale, | |
| 30 AutofillManager::AutofillDownloadManagerState enable_download_manager) { | |
| 31 if (FromWebContents(contents)) | |
| 32 return; | |
| 33 | |
| 34 contents->SetUserData( | |
| 35 kContentAutofillDriverFactoryWebContentsUserDataKey, | |
| 36 new ContentAutofillDriverFactory(contents, client, app_locale, | |
| 37 enable_download_manager)); | |
| 38 } | |
| 39 | |
| 40 // static | |
| 41 ContentAutofillDriverFactory* ContentAutofillDriverFactory::FromWebContents( | |
| 42 content::WebContents* contents) { | |
| 43 return static_cast<ContentAutofillDriverFactory*>(contents->GetUserData( | |
| 44 kContentAutofillDriverFactoryWebContentsUserDataKey)); | |
| 45 } | |
| 46 | |
| 47 ContentAutofillDriverFactory::ContentAutofillDriverFactory( | |
| 48 content::WebContents* web_contents, | |
| 49 AutofillClient* client, | |
| 50 const std::string& app_locale, | |
| 51 AutofillManager::AutofillDownloadManagerState enable_download_manager) | |
| 52 : content::WebContentsObserver(web_contents), | |
| 53 client_(client), | |
| 54 app_locale_(app_locale), | |
| 55 enable_download_manager_(enable_download_manager) { | |
| 56 if (web_contents->GetMainFrame()) | |
| 57 RenderFrameCreated(web_contents->GetMainFrame()); | |
|
vabr (Chromium)
2014/11/10 14:34:39
It's usually a bad idea to call virtual methods fr
Evan Stade
2014/11/14 23:25:49
Done.
| |
| 58 } | |
| 59 | |
| 60 ContentAutofillDriverFactory::~ContentAutofillDriverFactory() { | |
| 61 } | |
| 62 | |
| 63 ContentAutofillDriver* ContentAutofillDriverFactory::DriverForFrame( | |
| 64 content::RenderFrameHost* render_frame_host) { | |
| 65 return frame_driver_map_[render_frame_host]; | |
|
vabr (Chromium)
2014/11/10 14:34:39
Note that this creates a new entry in the map, if
Evan Stade
2014/11/14 23:25:49
actually it initializes with null
vabr (Chromium)
2014/11/17 15:08:48
You are right, sorry fir spreading misinformation.
| |
| 66 } | |
| 67 | |
| 68 bool ContentAutofillDriverFactory::OnMessageReceived( | |
| 69 const IPC::Message& message, | |
| 70 content::RenderFrameHost* render_frame_host) { | |
| 71 ContentAutofillDriver* driver = frame_driver_map_[render_frame_host]; | |
| 72 DCHECK(driver); | |
|
vabr (Chromium)
2014/11/10 14:34:39
Again, in addition to checking driver, the retriev
Evan Stade
2014/11/14 23:25:49
see other comments
vabr (Chromium)
2014/11/17 15:08:48
Acknowledged. Using the NULL-dereference to signal
| |
| 73 return driver->HandleMessage(message); | |
| 74 } | |
| 75 | |
| 76 void ContentAutofillDriverFactory::RenderFrameCreated( | |
| 77 content::RenderFrameHost* render_frame_host) { | |
| 78 frame_driver_map_[render_frame_host] = new ContentAutofillDriver( | |
| 79 render_frame_host, client_, app_locale_, enable_download_manager_); | |
| 80 } | |
| 81 | |
| 82 void ContentAutofillDriverFactory::RenderFrameDeleted( | |
| 83 content::RenderFrameHost* render_frame_host) { | |
| 84 ContentAutofillDriver* driver = frame_driver_map_[render_frame_host]; | |
| 85 DCHECK(driver); | |
|
vabr (Chromium)
2014/11/10 14:34:39
DCHECKing driver does not do much here -- if drive
Evan Stade
2014/11/14 23:25:49
see other comments
vabr (Chromium)
2014/11/17 15:08:48
Acknowledged.
| |
| 86 delete driver; | |
| 87 frame_driver_map_.erase(render_frame_host); | |
| 88 } | |
| 89 | |
| 90 void ContentAutofillDriverFactory::DidNavigateAnyFrame( | |
| 91 content::RenderFrameHost* render_frame_host, | |
| 92 const content::LoadCommittedDetails& details, | |
| 93 const content::FrameNavigateParams& params) { | |
| 94 ContentAutofillDriver* driver = frame_driver_map_[render_frame_host]; | |
|
vabr (Chromium)
2014/11/10 14:34:39
Please check the existence of the key, to avoid in
Evan Stade
2014/11/14 23:25:49
a) it's not inserting trash, it's inserting null
b
vabr (Chromium)
2014/11/17 15:08:49
Acknowledged.
| |
| 95 DCHECK(driver); | |
| 96 driver->DidNavigateFrame(details, params); | |
| 97 } | |
| 98 | |
| 99 void ContentAutofillDriverFactory::NavigationEntryCommitted( | |
| 100 const content::LoadCommittedDetails& load_details) { | |
| 101 client_->HideAutofillPopup(); | |
| 102 } | |
| 103 | |
| 104 void ContentAutofillDriverFactory::WasHidden() { | |
| 105 client_->HideAutofillPopup(); | |
| 106 } | |
| 107 | |
| 108 } // namespace autofill | |
| OLD | NEW |