OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/autofill_driver_impl.h" | 5 #include "components/autofill/content/browser/autofill_driver_impl.h" |
6 | 6 |
7 #include "components/autofill/core/browser/autofill_external_delegate.h" | 7 #include "components/autofill/core/browser/autofill_external_delegate.h" |
8 #include "components/autofill/core/browser/autofill_manager.h" | 8 #include "components/autofill/core/browser/autofill_manager.h" |
9 #include "components/autofill/core/browser/autofill_manager_delegate.h" | 9 #include "components/autofill/core/browser/autofill_manager_delegate.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
11 | 11 |
12 namespace autofill { | 12 namespace autofill { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 const char kAutofillDriverImplWebContentsUserDataKey[] = | 16 const char kAutofillDriverImplWebContentsUserDataKey[] = |
17 "web_contents_autofill_driver_impl"; | 17 "web_contents_autofill_driver_impl"; |
18 | 18 |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 // static | 21 // static |
22 void AutofillDriverImpl::CreateForWebContentsAndDelegate( | 22 void AutofillDriverImpl::CreateForWebContentsAndDelegate( |
23 content::WebContents* contents, | 23 content::WebContents* contents, |
24 autofill::AutofillManagerDelegate* delegate, | 24 autofill::AutofillManagerDelegate* delegate, |
25 const std::string& app_locale, | 25 const std::string& app_locale, |
26 AutofillManager::AutofillDownloadManagerState enable_download_manager, | 26 AutofillManager::AutofillDownloadManagerState enable_download_manager) { |
27 bool enable_native_ui) { | |
28 if (FromWebContents(contents)) | 27 if (FromWebContents(contents)) |
29 return; | 28 return; |
30 | 29 |
31 contents->SetUserData(kAutofillDriverImplWebContentsUserDataKey, | 30 contents->SetUserData(kAutofillDriverImplWebContentsUserDataKey, |
32 new AutofillDriverImpl(contents, | 31 new AutofillDriverImpl(contents, |
33 delegate, | 32 delegate, |
34 app_locale, | 33 app_locale, |
35 enable_download_manager, | 34 enable_download_manager)); |
36 enable_native_ui)); | |
37 // Trigger the lazy creation of AutocheckoutWhitelistManagerService, and | 35 // Trigger the lazy creation of AutocheckoutWhitelistManagerService, and |
38 // schedule a fetch of the Autocheckout whitelist file if it's not already | 36 // schedule a fetch of the Autocheckout whitelist file if it's not already |
39 // loaded. This helps ensure that the whitelist will be available by the time | 37 // loaded. This helps ensure that the whitelist will be available by the time |
40 // the user navigates to a form on which Autocheckout should be enabled. | 38 // the user navigates to a form on which Autocheckout should be enabled. |
41 delegate->GetAutocheckoutWhitelistManager(); | 39 delegate->GetAutocheckoutWhitelistManager(); |
42 } | 40 } |
43 | 41 |
44 // static | 42 // static |
45 AutofillDriverImpl* AutofillDriverImpl::FromWebContents( | 43 AutofillDriverImpl* AutofillDriverImpl::FromWebContents( |
46 content::WebContents* contents) { | 44 content::WebContents* contents) { |
47 return static_cast<AutofillDriverImpl*>( | 45 return static_cast<AutofillDriverImpl*>( |
48 contents->GetUserData(kAutofillDriverImplWebContentsUserDataKey)); | 46 contents->GetUserData(kAutofillDriverImplWebContentsUserDataKey)); |
49 } | 47 } |
50 | 48 |
51 AutofillDriverImpl::AutofillDriverImpl( | 49 AutofillDriverImpl::AutofillDriverImpl( |
52 content::WebContents* web_contents, | 50 content::WebContents* web_contents, |
53 autofill::AutofillManagerDelegate* delegate, | 51 autofill::AutofillManagerDelegate* delegate, |
54 const std::string& app_locale, | 52 const std::string& app_locale, |
55 AutofillManager::AutofillDownloadManagerState enable_download_manager, | 53 AutofillManager::AutofillDownloadManagerState enable_download_manager) |
56 bool enable_native_ui) | |
57 : content::WebContentsObserver(web_contents), | 54 : content::WebContentsObserver(web_contents), |
58 autofill_manager_(this, delegate, app_locale, enable_download_manager) { | 55 autofill_manager_(this, delegate, app_locale, enable_download_manager) { |
59 if (enable_native_ui) { | 56 SetAutofillExternalDelegate(scoped_ptr<AutofillExternalDelegate>( |
60 SetAutofillExternalDelegate(scoped_ptr<AutofillExternalDelegate>( | 57 new AutofillExternalDelegate(web_contents, &autofill_manager_))); |
61 new AutofillExternalDelegate(web_contents, &autofill_manager_))); | |
62 } | |
63 } | 58 } |
64 | 59 |
65 AutofillDriverImpl::~AutofillDriverImpl() {} | 60 AutofillDriverImpl::~AutofillDriverImpl() {} |
66 | 61 |
67 content::WebContents* AutofillDriverImpl::GetWebContents() { | 62 content::WebContents* AutofillDriverImpl::GetWebContents() { |
68 return web_contents(); | 63 return web_contents(); |
69 } | 64 } |
70 | 65 |
71 bool AutofillDriverImpl::OnMessageReceived(const IPC::Message& message) { | 66 bool AutofillDriverImpl::OnMessageReceived(const IPC::Message& message) { |
72 // TODO(blundell): Move IPC handling into this class. | 67 // TODO(blundell): Move IPC handling into this class. |
73 return autofill_manager_.OnMessageReceived(message); | 68 return autofill_manager_.OnMessageReceived(message); |
74 } | 69 } |
75 | 70 |
76 void AutofillDriverImpl::DidNavigateMainFrame( | 71 void AutofillDriverImpl::DidNavigateMainFrame( |
77 const content::LoadCommittedDetails& details, | 72 const content::LoadCommittedDetails& details, |
78 const content::FrameNavigateParams& params) { | 73 const content::FrameNavigateParams& params) { |
79 // TODO(blundell): Move the logic of this method into this class. | 74 // TODO(blundell): Move the logic of this method into this class. |
80 autofill_manager_.DidNavigateMainFrame(details, params); | 75 autofill_manager_.DidNavigateMainFrame(details, params); |
81 } | 76 } |
82 | 77 |
83 void AutofillDriverImpl::SetAutofillExternalDelegate( | 78 void AutofillDriverImpl::SetAutofillExternalDelegate( |
84 scoped_ptr<AutofillExternalDelegate> delegate) { | 79 scoped_ptr<AutofillExternalDelegate> delegate) { |
85 autofill_external_delegate_.reset(delegate.release()); | 80 autofill_external_delegate_.reset(delegate.release()); |
86 autofill_manager_.SetExternalDelegate(autofill_external_delegate_.get()); | 81 autofill_manager_.SetExternalDelegate(autofill_external_delegate_.get()); |
87 } | 82 } |
88 | 83 |
89 } // namespace autofill | 84 } // namespace autofill |
OLD | NEW |