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 3 // found in the LICENSE file. 4 5 #ifndef ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_ 6 #define ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_ 7 8 #include <vector> 9 10 #include "android_webview/browser/aw_download_manager_delegate.h" 11 #include "android_webview/browser/aw_ssl_host_state_delegate.h" 12 #include "base/basictypes.h" 13 #include "base/compiler_specific.h" 14 #include "base/files/file_path.h" 15 #include "base/memory/ref_counted.h" 16 #include "base/memory/scoped_ptr.h" 17 #include "components/visitedlink/browser/visitedlink_delegate.h" 18 #include "content/public/browser/browser_context.h" 19 #include "content/public/browser/content_browser_client.h" 20 #include "net/url_request/url_request_job_factory.h" 21 22 class GURL; 23 class PrefService; 24 25 namespace content { 26 class ResourceContext; 27 class SSLHostStateDelegate; 28 class WebContents; 29 } 30 31 namespace data_reduction_proxy { 32 class DataReductionProxyConfigurator; 33 class DataReductionProxySettings; 34 class DataReductionProxyStatisticsPrefs; 35 } 36 37 namespace net { 38 class CookieStore; 39 } 40 41 namespace visitedlink { 42 class VisitedLinkMaster; 43 } 44 45 namespace android_webview { 46 47 class AwFormDatabaseService; 48 class AwQuotaManagerBridge; 49 class AwURLRequestContextGetter; 50 class JniDependencyFactory; 51 52 class AwBrowserContext : public content::BrowserContext, 53 public visitedlink::VisitedLinkDelegate { 54 public: 55 56 AwBrowserContext(const base::FilePath path, 57 JniDependencyFactory* native_factory); 58 virtual ~AwBrowserContext(); 59 60 // Currently only one instance per process is supported. 61 static AwBrowserContext* GetDefault(); 62 63 // Convenience method to returns the AwBrowserContext corresponding to the 64 // given WebContents. 65 static AwBrowserContext* FromWebContents( 66 content::WebContents* web_contents); 67 68 static void SetDataReductionProxyEnabled(bool enabled); 69 70 // Maps to BrowserMainParts::PreMainMessageLoopRun. 71 void PreMainMessageLoopRun(); 72 73 // These methods map to Add methods in visitedlink::VisitedLinkMaster. 74 void AddVisitedURLs(const std::vector<GURL>& urls); 75 76 net::URLRequestContextGetter* CreateRequestContext( 77 content::ProtocolHandlerMap* protocol_handlers, 78 content::URLRequestInterceptorScopedVector request_interceptors); 79 net::URLRequestContextGetter* CreateRequestContextForStoragePartition( 80 const base::FilePath& partition_path, 81 bool in_memory, 82 content::ProtocolHandlerMap* protocol_handlers, 83 content::URLRequestInterceptorScopedVector request_interceptors); 84 85 AwQuotaManagerBridge* GetQuotaManagerBridge(); 86 87 AwFormDatabaseService* GetFormDatabaseService(); 88 89 data_reduction_proxy::DataReductionProxySettings* 90 GetDataReductionProxySettings(); 91 92 AwURLRequestContextGetter* GetAwURLRequestContext(); 93 94 void CreateUserPrefServiceIfNecessary(); 95 96 // content::BrowserContext implementation. 97 virtual base::FilePath GetPath() const OVERRIDE; 98 virtual bool IsOffTheRecord() const OVERRIDE; 99 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; 100 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( 101 int renderer_child_id) OVERRIDE; 102 virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE; 103 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( 104 int renderer_child_id) OVERRIDE; 105 virtual net::URLRequestContextGetter* 106 GetMediaRequestContextForStoragePartition( 107 const base::FilePath& partition_path, bool in_memory) OVERRIDE; 108 virtual content::ResourceContext* GetResourceContext() OVERRIDE; 109 virtual content::DownloadManagerDelegate* 110 GetDownloadManagerDelegate() OVERRIDE; 111 virtual content::BrowserPluginGuestManager* GetGuestManager() OVERRIDE; 112 virtual storage::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; 113 virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE; 114 virtual content::SSLHostStateDelegate* GetSSLHostStateDelegate() OVERRIDE; 115 116 // visitedlink::VisitedLinkDelegate implementation. 117 virtual void RebuildTable( 118 const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE; 119 120 private: 121 void CreateDataReductionProxyStatisticsIfNecessary(); 122 static bool data_reduction_proxy_enabled_; 123 124 // The file path where data for this context is persisted. 125 base::FilePath context_storage_path_; 126 127 JniDependencyFactory* native_factory_; 128 scoped_refptr<net::CookieStore> cookie_store_; 129 scoped_refptr<AwURLRequestContextGetter> url_request_context_getter_; 130 scoped_refptr<AwQuotaManagerBridge> quota_manager_bridge_; 131 scoped_ptr<AwFormDatabaseService> form_database_service_; 132 133 AwDownloadManagerDelegate download_manager_delegate_; 134 135 scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_; 136 scoped_ptr<content::ResourceContext> resource_context_; 137 138 scoped_ptr<PrefService> user_pref_service_; 139 140 scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator> 141 data_reduction_proxy_configurator_; 142 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs> 143 data_reduction_proxy_statistics_; 144 scoped_ptr<data_reduction_proxy::DataReductionProxySettings> 145 data_reduction_proxy_settings_; 146 scoped_ptr<AwSSLHostStateDelegate> ssl_host_state_delegate_; 147 148 DISALLOW_COPY_AND_ASSIGN(AwBrowserContext); 149 }; 150 151 } // namespace android_webview 152 153 #endif // ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_ 154