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 CreateDriverForFrame(web_contents->GetMainFrame()); |
| 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]; |
| 66 } |
| 67 |
| 68 bool ContentAutofillDriverFactory::OnMessageReceived( |
| 69 const IPC::Message& message, |
| 70 content::RenderFrameHost* render_frame_host) { |
| 71 return frame_driver_map_[render_frame_host]->HandleMessage(message); |
| 72 } |
| 73 |
| 74 void ContentAutofillDriverFactory::RenderFrameCreated( |
| 75 content::RenderFrameHost* render_frame_host) { |
| 76 CreateDriverForFrame(render_frame_host); |
| 77 } |
| 78 |
| 79 void ContentAutofillDriverFactory::RenderFrameDeleted( |
| 80 content::RenderFrameHost* render_frame_host) { |
| 81 delete frame_driver_map_[render_frame_host]; |
| 82 frame_driver_map_.erase(render_frame_host); |
| 83 } |
| 84 |
| 85 void ContentAutofillDriverFactory::DidNavigateAnyFrame( |
| 86 content::RenderFrameHost* render_frame_host, |
| 87 const content::LoadCommittedDetails& details, |
| 88 const content::FrameNavigateParams& params) { |
| 89 frame_driver_map_[render_frame_host]->DidNavigateFrame(details, params); |
| 90 } |
| 91 |
| 92 void ContentAutofillDriverFactory::NavigationEntryCommitted( |
| 93 const content::LoadCommittedDetails& load_details) { |
| 94 client_->HideAutofillPopup(); |
| 95 } |
| 96 |
| 97 void ContentAutofillDriverFactory::WasHidden() { |
| 98 client_->HideAutofillPopup(); |
| 99 } |
| 100 |
| 101 void ContentAutofillDriverFactory::CreateDriverForFrame( |
| 102 content::RenderFrameHost* render_frame_host) { |
| 103 frame_driver_map_[render_frame_host] = new ContentAutofillDriver( |
| 104 render_frame_host, client_, app_locale_, enable_download_manager_); |
| 105 } |
| 106 |
| 107 } // namespace autofill |
OLD | NEW |