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

Side by Side Diff: android_webview/browser/aw_browser_context.cc

Issue 15097004: Enable Autocomplete feature for chromium webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@setSaveFormData2
Patch Set: address nits Created 7 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "android_webview/browser/aw_browser_context.h" 5 #include "android_webview/browser/aw_browser_context.h"
6 6
7 #include "android_webview/browser/aw_form_database_service.h" 7 #include "android_webview/browser/aw_form_database_service.h"
8 #include "android_webview/browser/aw_pref_store.h"
8 #include "android_webview/browser/aw_quota_manager_bridge.h" 9 #include "android_webview/browser/aw_quota_manager_bridge.h"
9 #include "android_webview/browser/jni_dependency_factory.h" 10 #include "android_webview/browser/jni_dependency_factory.h"
10 #include "android_webview/browser/net/aw_url_request_context_getter.h" 11 #include "android_webview/browser/net/aw_url_request_context_getter.h"
12 #include "base/prefs/pref_registry_simple.h"
13 #include "base/prefs/pref_service.h"
14 #include "base/prefs/pref_service_builder.h"
15 #include "components/autofill/core/common/autofill_pref_names.h"
16 #include "components/user_prefs/user_prefs.h"
11 #include "components/visitedlink/browser/visitedlink_master.h" 17 #include "components/visitedlink/browser/visitedlink_master.h"
12 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/resource_context.h" 19 #include "content/public/browser/resource_context.h"
14 #include "content/public/browser/storage_partition.h" 20 #include "content/public/browser/storage_partition.h"
15 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
16 #include "net/url_request/url_request_context.h" 22 #include "net/url_request/url_request_context.h"
17 23
18 namespace android_webview { 24 namespace android_webview {
19 25
20 namespace { 26 namespace {
21 27
28 // Shows notifications which correspond to PersistentPrefStore's reading errors.
29 void HandleReadError(PersistentPrefStore::PrefReadError error) {
30 }
31
22 class AwResourceContext : public content::ResourceContext { 32 class AwResourceContext : public content::ResourceContext {
23 public: 33 public:
24 explicit AwResourceContext(net::URLRequestContextGetter* getter) 34 explicit AwResourceContext(net::URLRequestContextGetter* getter)
25 : getter_(getter) {} 35 : getter_(getter) {}
26 virtual ~AwResourceContext() {} 36 virtual ~AwResourceContext() {}
27 37
28 // content::ResourceContext implementation. 38 // content::ResourceContext implementation.
29 virtual net::HostResolver* GetHostResolver() OVERRIDE { 39 virtual net::HostResolver* GetHostResolver() OVERRIDE {
30 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 40 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
31 return getter_->GetURLRequestContext()->host_resolver(); 41 return getter_->GetURLRequestContext()->host_resolver();
(...skipping 10 matching lines...) Expand all
42 }; 52 };
43 53
44 AwBrowserContext* g_browser_context = NULL; 54 AwBrowserContext* g_browser_context = NULL;
45 55
46 } // namespace 56 } // namespace
47 57
48 AwBrowserContext::AwBrowserContext( 58 AwBrowserContext::AwBrowserContext(
49 const base::FilePath path, 59 const base::FilePath path,
50 JniDependencyFactory* native_factory) 60 JniDependencyFactory* native_factory)
51 : context_storage_path_(path), 61 : context_storage_path_(path),
52 native_factory_(native_factory) { 62 native_factory_(native_factory),
63 user_pref_service_ready_(false) {
53 DCHECK(g_browser_context == NULL); 64 DCHECK(g_browser_context == NULL);
54 g_browser_context = this; 65 g_browser_context = this;
55 } 66 }
56 67
57 AwBrowserContext::~AwBrowserContext() { 68 AwBrowserContext::~AwBrowserContext() {
58 DCHECK(g_browser_context == this); 69 DCHECK(g_browser_context == this);
59 g_browser_context = NULL; 70 g_browser_context = NULL;
60 } 71 }
61 72
62 // static 73 // static
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 125 }
115 126
116 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { 127 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() {
117 if (!form_database_service_) { 128 if (!form_database_service_) {
118 form_database_service_.reset( 129 form_database_service_.reset(
119 new AwFormDatabaseService(context_storage_path_)); 130 new AwFormDatabaseService(context_storage_path_));
120 } 131 }
121 return form_database_service_.get(); 132 return form_database_service_.get();
122 } 133 }
123 134
124 AwAutofillManagerDelegate* AwBrowserContext::AutofillManagerDelegate() { 135 // Create user pref service for autofill functionality.
125 return autofill_manager_delegate_.get(); 136 void AwBrowserContext::CreateUserPrefServiceIfNecessary() {
126 } 137 if (user_pref_service_ready_)
138 return;
127 139
128 AwAutofillManagerDelegate* AwBrowserContext::CreateAutofillManagerDelegate( 140 user_pref_service_ready_ = true;
129 bool enabled) { 141 PrefRegistrySimple* pref_registry = new PrefRegistrySimple();
130 if (!autofill_manager_delegate_) { 142 pref_registry->RegisterBooleanPref(
131 autofill_manager_delegate_.reset( 143 autofill::prefs::kAutofillEnabled, false);
132 new AwAutofillManagerDelegate(enabled)); 144 pref_registry->RegisterDoublePref(
133 } 145 autofill::prefs::kAutofillPositiveUploadRate, 0.0);
134 return autofill_manager_delegate_.get(); 146 pref_registry->RegisterDoublePref(
147 autofill::prefs::kAutofillNegativeUploadRate, 0.0);
148
149 PrefServiceBuilder pref_service_builder;
150 pref_service_builder.WithUserPrefs(new AwPrefStore());
151 pref_service_builder.WithReadErrorCallback(base::Bind(&HandleReadError));
152
153 user_prefs::UserPrefs::Set(this,
154 pref_service_builder.Create(pref_registry));
135 } 155 }
136 156
137 base::FilePath AwBrowserContext::GetPath() { 157 base::FilePath AwBrowserContext::GetPath() {
138 return context_storage_path_; 158 return context_storage_path_;
139 } 159 }
140 160
141 bool AwBrowserContext::IsOffTheRecord() const { 161 bool AwBrowserContext::IsOffTheRecord() const {
142 // Android WebView does not support off the record profile yet. 162 // Android WebView does not support off the record profile yet.
143 return false; 163 return false;
144 } 164 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 227
208 void AwBrowserContext::RebuildTable( 228 void AwBrowserContext::RebuildTable(
209 const scoped_refptr<URLEnumerator>& enumerator) { 229 const scoped_refptr<URLEnumerator>& enumerator) {
210 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client 230 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client
211 // can change in the lifetime of this WebView and may not yet be set here. 231 // can change in the lifetime of this WebView and may not yet be set here.
212 // Therefore this initialization path is not used. 232 // Therefore this initialization path is not used.
213 enumerator->OnComplete(true); 233 enumerator->OnComplete(true);
214 } 234 }
215 235
216 } // namespace android_webview 236 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698