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