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 "content/public/common/content_constants.h" |
| 25 #include "content/public/common/url_constants.h" |
| 26 #include "net/cookies/cookie_monster.h" |
24 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
25 | 28 |
26 namespace android_webview { | 29 namespace android_webview { |
27 | 30 |
28 namespace { | 31 namespace { |
29 | 32 |
30 // Shows notifications which correspond to PersistentPrefStore's reading errors. | 33 // Shows notifications which correspond to PersistentPrefStore's reading errors. |
31 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 34 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
32 } | 35 } |
33 | 36 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 91 } |
89 | 92 |
90 // static | 93 // static |
91 AwBrowserContext* AwBrowserContext::FromWebContents( | 94 AwBrowserContext* AwBrowserContext::FromWebContents( |
92 content::WebContents* web_contents) { | 95 content::WebContents* web_contents) { |
93 // This is safe; this is the only implementation of the browser context. | 96 // This is safe; this is the only implementation of the browser context. |
94 return static_cast<AwBrowserContext*>(web_contents->GetBrowserContext()); | 97 return static_cast<AwBrowserContext*>(web_contents->GetBrowserContext()); |
95 } | 98 } |
96 | 99 |
97 void AwBrowserContext::PreMainMessageLoopRun() { | 100 void AwBrowserContext::PreMainMessageLoopRun() { |
98 cookie_store_ = content::CreatePersistentCookieStore( | 101 url_request_context_getter_ = new AwURLRequestContextGetter(GetPath()); |
99 GetPath().Append(FILE_PATH_LITERAL("Cookies")), | |
100 true, | |
101 NULL, | |
102 NULL); | |
103 cookie_store_->GetCookieMonster()->SetPersistSessionCookies(true); | |
104 url_request_context_getter_ = | |
105 new AwURLRequestContextGetter(GetPath(), cookie_store_.get()); | |
106 | 102 |
107 DidCreateCookieMonster(cookie_store_->GetCookieMonster()); | 103 DidCreateCookieMonster( |
| 104 GetDefaultStoragePartition(this)->GetCookieStoreForScheme( |
| 105 chrome::kHttpScheme)->GetCookieMonster()); |
108 | 106 |
109 visitedlink_master_.reset( | 107 visitedlink_master_.reset( |
110 new visitedlink::VisitedLinkMaster(this, this, false)); | 108 new visitedlink::VisitedLinkMaster(this, this, false)); |
111 visitedlink_master_->Init(); | 109 visitedlink_master_->Init(); |
112 } | 110 } |
113 | 111 |
114 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { | 112 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { |
115 DCHECK(visitedlink_master_); | 113 DCHECK(visitedlink_master_); |
116 visitedlink_master_->AddURLs(urls); | 114 visitedlink_master_->AddURLs(urls); |
117 } | 115 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 pref_service_builder.WithReadErrorCallback(base::Bind(&HandleReadError)); | 173 pref_service_builder.WithReadErrorCallback(base::Bind(&HandleReadError)); |
176 | 174 |
177 user_prefs::UserPrefs::Set(this, | 175 user_prefs::UserPrefs::Set(this, |
178 pref_service_builder.Create(pref_registry)); | 176 pref_service_builder.Create(pref_registry)); |
179 } | 177 } |
180 | 178 |
181 base::FilePath AwBrowserContext::GetPath() const { | 179 base::FilePath AwBrowserContext::GetPath() const { |
182 return context_storage_path_; | 180 return context_storage_path_; |
183 } | 181 } |
184 | 182 |
| 183 void AwBrowserContext::OverrideCookieStoreConfigs( |
| 184 const base::FilePath& partition_path, |
| 185 bool in_memory_partition, |
| 186 bool is_default_partition, |
| 187 CookieSchemeMap* configs) { |
| 188 using content::CookieStoreConfig; |
| 189 configs->clear(); |
| 190 // By default session cookies are always restored. An Android application can |
| 191 // control this policy by calling CookieManager.removeSessionCookie() when |
| 192 // Activity.onCreate() is called with savedInstanceState == null. |
| 193 (*configs)[content::BrowserContext::kDefaultCookieScheme] = |
| 194 CookieStoreConfig(partition_path.Append(content::kCookieFilename), |
| 195 CookieStoreConfig::RESTORED_SESSION_COOKIES, |
| 196 NULL, NULL); |
| 197 } |
| 198 |
185 bool AwBrowserContext::IsOffTheRecord() const { | 199 bool AwBrowserContext::IsOffTheRecord() const { |
186 // Android WebView does not support off the record profile yet. | 200 // Android WebView does not support off the record profile yet. |
187 return false; | 201 return false; |
188 } | 202 } |
189 | 203 |
190 net::URLRequestContextGetter* AwBrowserContext::GetRequestContext() { | 204 net::URLRequestContextGetter* AwBrowserContext::GetRequestContext() { |
191 return GetDefaultStoragePartition(this)->GetURLRequestContext(); | 205 return GetDefaultStoragePartition(this)->GetURLRequestContext(); |
192 } | 206 } |
193 | 207 |
194 net::URLRequestContextGetter* | 208 net::URLRequestContextGetter* |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 268 |
255 void AwBrowserContext::RebuildTable( | 269 void AwBrowserContext::RebuildTable( |
256 const scoped_refptr<URLEnumerator>& enumerator) { | 270 const scoped_refptr<URLEnumerator>& enumerator) { |
257 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client | 271 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client |
258 // can change in the lifetime of this WebView and may not yet be set here. | 272 // can change in the lifetime of this WebView and may not yet be set here. |
259 // Therefore this initialization path is not used. | 273 // Therefore this initialization path is not used. |
260 enumerator->OnComplete(true); | 274 enumerator->OnComplete(true); |
261 } | 275 } |
262 | 276 |
263 } // namespace android_webview | 277 } // namespace android_webview |
OLD | NEW |