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

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 Ben's comments Created 7 years, 7 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/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();
32 } 42 }
33 virtual net::URLRequestContext* GetRequestContext() OVERRIDE { 43 virtual net::URLRequestContext* GetRequestContext() OVERRIDE {
34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 44 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
35 return getter_->GetURLRequestContext(); 45 return getter_->GetURLRequestContext();
36 } 46 }
37 47
38 private: 48 private:
39 net::URLRequestContextGetter* getter_; 49 net::URLRequestContextGetter* getter_;
40 50
41 DISALLOW_COPY_AND_ASSIGN(AwResourceContext); 51 DISALLOW_COPY_AND_ASSIGN(AwResourceContext);
42 }; 52 };
43 53
44 } // namespace 54 } // namespace
45 55
46 AwBrowserContext::AwBrowserContext( 56 AwBrowserContext::AwBrowserContext(
47 const base::FilePath path, 57 const base::FilePath path,
48 JniDependencyFactory* native_factory) 58 JniDependencyFactory* native_factory)
49 : context_storage_path_(path), 59 : context_storage_path_(path),
50 native_factory_(native_factory) { 60 native_factory_(native_factory),
61 user_pref_service_ready_(false) {
51 } 62 }
52 63
53 AwBrowserContext::~AwBrowserContext() { 64 AwBrowserContext::~AwBrowserContext() {
54 } 65 }
55 66
56 // static 67 // static
57 AwBrowserContext* AwBrowserContext::FromWebContents( 68 AwBrowserContext* AwBrowserContext::FromWebContents(
58 content::WebContents* web_contents) { 69 content::WebContents* web_contents) {
59 // This is safe; this is the only implementation of the browser context. 70 // This is safe; this is the only implementation of the browser context.
60 return static_cast<AwBrowserContext*>(web_contents->GetBrowserContext()); 71 return static_cast<AwBrowserContext*>(web_contents->GetBrowserContext());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 112 }
102 113
103 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { 114 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() {
104 if (!form_database_service_) { 115 if (!form_database_service_) {
105 form_database_service_.reset( 116 form_database_service_.reset(
106 new AwFormDatabaseService(context_storage_path_)); 117 new AwFormDatabaseService(context_storage_path_));
107 } 118 }
108 return form_database_service_.get(); 119 return form_database_service_.get();
109 } 120 }
110 121
111 AwAutofillManagerDelegate* AwBrowserContext::AutofillManagerDelegate() { 122 // Create user pref service for autofill functionality.
112 return autofill_manager_delegate_.get(); 123 void AwBrowserContext::CreateUserPrefServiceIfNecessary() {
113 } 124 if (user_pref_service_ready_)
125 return;
114 126
115 AwAutofillManagerDelegate* AwBrowserContext::CreateAutofillManagerDelegate( 127 user_pref_service_ready_ = true;
116 bool enabled) { 128 PrefRegistrySimple* pref_registry = new PrefRegistrySimple();
117 if (!autofill_manager_delegate_) { 129 pref_registry->RegisterBooleanPref(
118 autofill_manager_delegate_.reset( 130 autofill::prefs::kAutofillEnabled, true);
119 new AwAutofillManagerDelegate(enabled)); 131 pref_registry->RegisterDoublePref(
120 } 132 autofill::prefs::kAutofillPositiveUploadRate, 0.0);
121 return autofill_manager_delegate_.get(); 133 pref_registry->RegisterDoublePref(
134 autofill::prefs::kAutofillNegativeUploadRate, 0.0);
135
136 PrefServiceBuilder pref_service_builder;
137 pref_service_builder.WithUserPrefs(new AwPrefStore());
138 pref_service_builder.WithReadErrorCallback(base::Bind(&HandleReadError));
139
140 components::UserPrefs::Set(this,
141 pref_service_builder.Create(pref_registry));
122 } 142 }
123 143
124 base::FilePath AwBrowserContext::GetPath() { 144 base::FilePath AwBrowserContext::GetPath() {
125 return context_storage_path_; 145 return context_storage_path_;
126 } 146 }
127 147
128 bool AwBrowserContext::IsOffTheRecord() const { 148 bool AwBrowserContext::IsOffTheRecord() const {
129 // Android WebView does not support off the record profile yet. 149 // Android WebView does not support off the record profile yet.
130 return false; 150 return false;
131 } 151 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 214
195 void AwBrowserContext::RebuildTable( 215 void AwBrowserContext::RebuildTable(
196 const scoped_refptr<URLEnumerator>& enumerator) { 216 const scoped_refptr<URLEnumerator>& enumerator) {
197 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client 217 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client
198 // can change in the lifetime of this WebView and may not yet be set here. 218 // can change in the lifetime of this WebView and may not yet be set here.
199 // Therefore this initialization path is not used. 219 // Therefore this initialization path is not used.
200 enumerator->OnComplete(true); 220 enumerator->OnComplete(true);
201 } 221 }
202 222
203 } // namespace android_webview 223 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698