OLD | NEW |
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_pref_store.h" |
9 #include "android_webview/browser/aw_quota_manager_bridge.h" | 9 #include "android_webview/browser/aw_quota_manager_bridge.h" |
10 #include "android_webview/browser/jni_dependency_factory.h" | 10 #include "android_webview/browser/jni_dependency_factory.h" |
11 #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 "android_webview/browser/net/init_native_callback.h" | 12 #include "android_webview/browser/net/init_native_callback.h" |
13 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/prefs/pref_service_builder.h" | 15 #include "base/prefs/pref_service_builder.h" |
16 #include "components/autofill/core/common/autofill_pref_names.h" | 16 #include "components/autofill/core/common/autofill_pref_names.h" |
17 #include "components/user_prefs/user_prefs.h" | 17 #include "components/user_prefs/user_prefs.h" |
18 #include "components/visitedlink/browser/visitedlink_master.h" | 18 #include "components/visitedlink/browser/visitedlink_master.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/cookie_store_factory.h" | 20 #include "content/public/browser/cookie_store_factory.h" |
21 #include "content/public/browser/resource_context.h" | 21 #include "content/public/browser/resource_context.h" |
22 #include "content/public/browser/storage_partition.h" | 22 #include "content/public/browser/storage_partition.h" |
23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
24 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
25 | 25 |
| 26 using content::BrowserThread; |
| 27 |
26 namespace android_webview { | 28 namespace android_webview { |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 // Shows notifications which correspond to PersistentPrefStore's reading errors. | 32 // Shows notifications which correspond to PersistentPrefStore's reading errors. |
31 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 33 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
32 } | 34 } |
33 | 35 |
34 class AwResourceContext : public content::ResourceContext { | 36 class AwResourceContext : public content::ResourceContext { |
35 public: | 37 public: |
36 explicit AwResourceContext(net::URLRequestContextGetter* getter) | 38 explicit AwResourceContext(net::URLRequestContextGetter* getter) |
37 : getter_(getter) { | 39 : getter_(getter) { |
38 DCHECK(getter_); | 40 DCHECK(getter_); |
39 } | 41 } |
40 virtual ~AwResourceContext() {} | 42 virtual ~AwResourceContext() {} |
41 | 43 |
42 // content::ResourceContext implementation. | 44 // content::ResourceContext implementation. |
43 virtual net::HostResolver* GetHostResolver() OVERRIDE { | 45 virtual net::HostResolver* GetHostResolver() OVERRIDE { |
44 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
45 return getter_->GetURLRequestContext()->host_resolver(); | 47 return getter_->GetURLRequestContext()->host_resolver(); |
46 } | 48 } |
47 virtual net::URLRequestContext* GetRequestContext() OVERRIDE { | 49 virtual net::URLRequestContext* GetRequestContext() OVERRIDE { |
48 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
49 return getter_->GetURLRequestContext(); | 51 return getter_->GetURLRequestContext(); |
50 } | 52 } |
51 virtual bool AllowMicAccess(const GURL& origin) OVERRIDE { | 53 virtual bool AllowMicAccess(const GURL& origin) OVERRIDE { |
52 return false; | 54 return false; |
53 } | 55 } |
54 virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE { | 56 virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE { |
55 return false; | 57 return false; |
56 } | 58 } |
57 | 59 |
58 private: | 60 private: |
59 net::URLRequestContextGetter* getter_; | 61 net::URLRequestContextGetter* getter_; |
60 | 62 |
61 DISALLOW_COPY_AND_ASSIGN(AwResourceContext); | 63 DISALLOW_COPY_AND_ASSIGN(AwResourceContext); |
62 }; | 64 }; |
63 | 65 |
64 AwBrowserContext* g_browser_context = NULL; | 66 AwBrowserContext* g_browser_context = NULL; |
65 | 67 |
66 } // namespace | 68 } // namespace |
67 | 69 |
68 AwBrowserContext::AwBrowserContext( | 70 AwBrowserContext::AwBrowserContext( |
69 const base::FilePath path, | 71 const base::FilePath path, |
70 JniDependencyFactory* native_factory) | 72 JniDependencyFactory* native_factory) |
71 : context_storage_path_(path), | 73 : context_storage_path_(path), |
72 native_factory_(native_factory), | 74 native_factory_(native_factory), |
73 user_pref_service_ready_(false) { | 75 user_pref_service_ready_(false) { |
74 DCHECK(g_browser_context == NULL); | 76 DCHECK(g_browser_context == NULL); |
75 g_browser_context = this; | 77 g_browser_context = this; |
| 78 |
| 79 form_database_service_.reset( |
| 80 new AwFormDatabaseService(context_storage_path_)); |
76 } | 81 } |
77 | 82 |
78 AwBrowserContext::~AwBrowserContext() { | 83 AwBrowserContext::~AwBrowserContext() { |
79 DCHECK(g_browser_context == this); | 84 DCHECK(g_browser_context == this); |
80 g_browser_context = NULL; | 85 g_browser_context = NULL; |
81 } | 86 } |
82 | 87 |
83 // static | 88 // static |
84 AwBrowserContext* AwBrowserContext::GetDefault() { | 89 AwBrowserContext* AwBrowserContext::GetDefault() { |
85 // TODO(joth): rather than store in a global here, lookup this instance | 90 // TODO(joth): rather than store in a global here, lookup this instance |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 144 |
140 AwQuotaManagerBridge* AwBrowserContext::GetQuotaManagerBridge() { | 145 AwQuotaManagerBridge* AwBrowserContext::GetQuotaManagerBridge() { |
141 if (!quota_manager_bridge_) { | 146 if (!quota_manager_bridge_) { |
142 quota_manager_bridge_.reset( | 147 quota_manager_bridge_.reset( |
143 native_factory_->CreateAwQuotaManagerBridge(this)); | 148 native_factory_->CreateAwQuotaManagerBridge(this)); |
144 } | 149 } |
145 return quota_manager_bridge_.get(); | 150 return quota_manager_bridge_.get(); |
146 } | 151 } |
147 | 152 |
148 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { | 153 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { |
149 if (!form_database_service_) { | |
150 form_database_service_.reset( | |
151 new AwFormDatabaseService(context_storage_path_)); | |
152 } | |
153 return form_database_service_.get(); | 154 return form_database_service_.get(); |
154 } | 155 } |
155 | 156 |
156 // Create user pref service for autofill functionality. | 157 // Create user pref service for autofill functionality. |
157 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { | 158 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { |
158 if (user_pref_service_ready_) | 159 if (user_pref_service_ready_) |
159 return; | 160 return; |
160 | 161 |
161 user_pref_service_ready_ = true; | 162 user_pref_service_ready_ = true; |
162 PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); | 163 PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 255 |
255 void AwBrowserContext::RebuildTable( | 256 void AwBrowserContext::RebuildTable( |
256 const scoped_refptr<URLEnumerator>& enumerator) { | 257 const scoped_refptr<URLEnumerator>& enumerator) { |
257 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client | 258 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client |
258 // can change in the lifetime of this WebView and may not yet be set here. | 259 // can change in the lifetime of this WebView and may not yet be set here. |
259 // Therefore this initialization path is not used. | 260 // Therefore this initialization path is not used. |
260 enumerator->OnComplete(true); | 261 enumerator->OnComplete(true); |
261 } | 262 } |
262 | 263 |
263 } // namespace android_webview | 264 } // namespace android_webview |
OLD | NEW |