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 <memory> 9 #include <vector> 10 11 #include "android_webview/browser/aw_ssl_host_state_delegate.h" 12 #include "android_webview/browser/network_service/aw_proxy_config_monitor.h" 13 #include "base/compiler_specific.h" 14 #include "base/files/file_path.h" 15 #include "base/macros.h" 16 #include "base/memory/ref_counted.h" 17 #include "components/keyed_service/core/simple_factory_key.h" 18 #include "components/prefs/pref_registry_simple.h" 19 #include "components/visitedlink/browser/visitedlink_delegate.h" 20 #include "content/public/browser/browser_context.h" 21 22 class GURL; 23 class PrefService; 24 25 namespace autofill { 26 class AutocompleteHistoryManager; 27 } 28 29 namespace content { 30 class PermissionControllerDelegate; 31 class ResourceContext; 32 class SSLHostStateDelegate; 33 class WebContents; 34 } 35 36 namespace download { 37 class InProgressDownloadManager; 38 } 39 40 namespace visitedlink { 41 class VisitedLinkWriter; 42 } 43 44 namespace android_webview { 45 46 class AwFormDatabaseService; 47 class AwQuotaManagerBridge; 48 49 class AwBrowserContext : public content::BrowserContext, 50 public visitedlink::VisitedLinkDelegate { 51 public: 52 AwBrowserContext(); 53 ~AwBrowserContext() override; 54 55 // Currently only one instance per process is supported. 56 static AwBrowserContext* GetDefault(); 57 58 // Convenience method to returns the AwBrowserContext corresponding to the 59 // given WebContents. 60 static AwBrowserContext* FromWebContents( 61 content::WebContents* web_contents); 62 63 base::FilePath GetCacheDir(); 64 base::FilePath GetPrefStorePath(); 65 base::FilePath GetCookieStorePath(); 66 static base::FilePath GetContextStoragePath(); 67 68 static void RegisterPrefs(PrefRegistrySimple* registry); 69 70 // Get the list of authentication schemes to support. 71 static std::vector<std::string> GetAuthSchemes(); 72 73 // These methods map to Add methods in visitedlink::VisitedLinkWriter. 74 void AddVisitedURLs(const std::vector<GURL>& urls); 75 76 AwQuotaManagerBridge* GetQuotaManagerBridge(); 77 jlong GetQuotaManagerBridge(JNIEnv* env); 78 void SetWebLayerRunningInSameProcess(JNIEnv* env); 79 80 AwFormDatabaseService* GetFormDatabaseService(); 81 autofill::AutocompleteHistoryManager* GetAutocompleteHistoryManager(); 82 CookieManager* GetCookieManager(); 83 84 // TODO(amalova): implement for non-default browser context IsDefaultBrowserContext()85 bool IsDefaultBrowserContext() { return true; } 86 87 // content::BrowserContext implementation. 88 base::FilePath GetPath() override; 89 bool IsOffTheRecord() override; 90 content::ResourceContext* GetResourceContext() override; 91 content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; 92 content::BrowserPluginGuestManager* GetGuestManager() override; 93 storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override; 94 content::PushMessagingService* GetPushMessagingService() override; 95 content::StorageNotificationService* GetStorageNotificationService() override; 96 content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; 97 content::PermissionControllerDelegate* GetPermissionControllerDelegate() 98 override; 99 content::ClientHintsControllerDelegate* GetClientHintsControllerDelegate() 100 override; 101 content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override; 102 content::BackgroundSyncController* GetBackgroundSyncController() override; 103 content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate() 104 override; 105 download::InProgressDownloadManager* RetriveInProgressDownloadManager() 106 override; 107 108 // visitedlink::VisitedLinkDelegate implementation. 109 void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override; 110 GetPrefService()111 PrefService* GetPrefService() const { return user_pref_service_.get(); } 112 113 void SetExtendedReportingAllowed(bool allowed); 114 115 void ConfigureNetworkContextParams( 116 bool in_memory, 117 const base::FilePath& relative_partition_path, 118 network::mojom::NetworkContextParams* network_context_params, 119 network::mojom::CertVerifierCreationParams* 120 cert_verifier_creation_params); 121 122 base::android::ScopedJavaLocalRef<jobject> GetJavaBrowserContext(); 123 124 private: 125 void CreateUserPrefService(); 126 void MigrateLocalStatePrefs(); 127 128 // The file path where data for this context is persisted. 129 base::FilePath context_storage_path_; 130 131 scoped_refptr<AwQuotaManagerBridge> quota_manager_bridge_; 132 std::unique_ptr<AwFormDatabaseService> form_database_service_; 133 std::unique_ptr<autofill::AutocompleteHistoryManager> 134 autocomplete_history_manager_; 135 136 std::unique_ptr<visitedlink::VisitedLinkWriter> visitedlink_writer_; 137 std::unique_ptr<content::ResourceContext> resource_context_; 138 139 std::unique_ptr<PrefService> user_pref_service_; 140 std::unique_ptr<AwSSLHostStateDelegate> ssl_host_state_delegate_; 141 std::unique_ptr<content::PermissionControllerDelegate> permission_manager_; 142 143 SimpleFactoryKey simple_factory_key_; 144 145 base::android::ScopedJavaGlobalRef<jobject> obj_; 146 147 DISALLOW_COPY_AND_ASSIGN(AwBrowserContext); 148 }; 149 150 } // namespace android_webview 151 152 #endif // ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_ 153