| 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 // This constructor is entered during the creation of ContentBrowserClient, |
| 80 // before browser threads are created. Therefore any checks to enforce |
| 81 // threading (such as BrowserThread::CurrentlyOn()) will fail here. |
| 76 } | 82 } |
| 77 | 83 |
| 78 AwBrowserContext::~AwBrowserContext() { | 84 AwBrowserContext::~AwBrowserContext() { |
| 79 DCHECK(g_browser_context == this); | 85 DCHECK(g_browser_context == this); |
| 80 g_browser_context = NULL; | 86 g_browser_context = NULL; |
| 81 } | 87 } |
| 82 | 88 |
| 83 // static | 89 // static |
| 84 AwBrowserContext* AwBrowserContext::GetDefault() { | 90 AwBrowserContext* AwBrowserContext::GetDefault() { |
| 85 // TODO(joth): rather than store in a global here, lookup this instance | 91 // TODO(joth): rather than store in a global here, lookup this instance |
| (...skipping 16 matching lines...) Expand all Loading... |
| 102 NULL); | 108 NULL); |
| 103 cookie_store_->GetCookieMonster()->SetPersistSessionCookies(true); | 109 cookie_store_->GetCookieMonster()->SetPersistSessionCookies(true); |
| 104 url_request_context_getter_ = | 110 url_request_context_getter_ = |
| 105 new AwURLRequestContextGetter(GetPath(), cookie_store_.get()); | 111 new AwURLRequestContextGetter(GetPath(), cookie_store_.get()); |
| 106 | 112 |
| 107 DidCreateCookieMonster(cookie_store_->GetCookieMonster()); | 113 DidCreateCookieMonster(cookie_store_->GetCookieMonster()); |
| 108 | 114 |
| 109 visitedlink_master_.reset( | 115 visitedlink_master_.reset( |
| 110 new visitedlink::VisitedLinkMaster(this, this, false)); | 116 new visitedlink::VisitedLinkMaster(this, this, false)); |
| 111 visitedlink_master_->Init(); | 117 visitedlink_master_->Init(); |
| 118 |
| 119 form_database_service_.reset( |
| 120 new AwFormDatabaseService(context_storage_path_)); |
| 112 } | 121 } |
| 113 | 122 |
| 114 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { | 123 void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { |
| 115 DCHECK(visitedlink_master_); | 124 DCHECK(visitedlink_master_); |
| 116 visitedlink_master_->AddURLs(urls); | 125 visitedlink_master_->AddURLs(urls); |
| 117 } | 126 } |
| 118 | 127 |
| 119 net::URLRequestContextGetter* AwBrowserContext::CreateRequestContext( | 128 net::URLRequestContextGetter* AwBrowserContext::CreateRequestContext( |
| 120 content::ProtocolHandlerMap* protocol_handlers) { | 129 content::ProtocolHandlerMap* protocol_handlers) { |
| 121 // This function cannot actually create the request context because | 130 // This function cannot actually create the request context because |
| (...skipping 17 matching lines...) Expand all Loading... |
| 139 | 148 |
| 140 AwQuotaManagerBridge* AwBrowserContext::GetQuotaManagerBridge() { | 149 AwQuotaManagerBridge* AwBrowserContext::GetQuotaManagerBridge() { |
| 141 if (!quota_manager_bridge_) { | 150 if (!quota_manager_bridge_) { |
| 142 quota_manager_bridge_.reset( | 151 quota_manager_bridge_.reset( |
| 143 native_factory_->CreateAwQuotaManagerBridge(this)); | 152 native_factory_->CreateAwQuotaManagerBridge(this)); |
| 144 } | 153 } |
| 145 return quota_manager_bridge_.get(); | 154 return quota_manager_bridge_.get(); |
| 146 } | 155 } |
| 147 | 156 |
| 148 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { | 157 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(); | 158 return form_database_service_.get(); |
| 154 } | 159 } |
| 155 | 160 |
| 156 // Create user pref service for autofill functionality. | 161 // Create user pref service for autofill functionality. |
| 157 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { | 162 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { |
| 158 if (user_pref_service_ready_) | 163 if (user_pref_service_ready_) |
| 159 return; | 164 return; |
| 160 | 165 |
| 161 user_pref_service_ready_ = true; | 166 user_pref_service_ready_ = true; |
| 162 PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); | 167 PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 259 |
| 255 void AwBrowserContext::RebuildTable( | 260 void AwBrowserContext::RebuildTable( |
| 256 const scoped_refptr<URLEnumerator>& enumerator) { | 261 const scoped_refptr<URLEnumerator>& enumerator) { |
| 257 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client | 262 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client |
| 258 // can change in the lifetime of this WebView and may not yet be set here. | 263 // can change in the lifetime of this WebView and may not yet be set here. |
| 259 // Therefore this initialization path is not used. | 264 // Therefore this initialization path is not used. |
| 260 enumerator->OnComplete(true); | 265 enumerator->OnComplete(true); |
| 261 } | 266 } |
| 262 | 267 |
| 263 } // namespace android_webview | 268 } // namespace android_webview |
| OLD | NEW |