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.
5 #ifndef ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_
6 #define ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_
10 #include "android_webview/browser/aw_download_manager_delegate.h"
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "components/visitedlink/browser/visitedlink_delegate.h"
17 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/content_browser_client.h"
19 #include "content/public/browser/geolocation_permission_context.h"
20 #include "net/url_request/url_request_job_factory.h"
26 class ResourceContext;
30 namespace data_reduction_proxy {
31 class DataReductionProxySettings;
38 namespace visitedlink {
39 class VisitedLinkMaster;
42 using data_reduction_proxy::DataReductionProxySettings;
44 namespace android_webview {
46 class AwFormDatabaseService;
47 class AwQuotaManagerBridge;
48 class AwURLRequestContextGetter;
49 class JniDependencyFactory;
51 class AwBrowserContext : public content::BrowserContext,
52 public visitedlink::VisitedLinkDelegate {
55 AwBrowserContext(const base::FilePath path,
56 JniDependencyFactory* native_factory);
57 virtual ~AwBrowserContext();
59 // Currently only one instance per process is supported.
60 static AwBrowserContext* GetDefault();
62 // Convenience method to returns the AwBrowserContext corresponding to the
64 static AwBrowserContext* FromWebContents(
65 content::WebContents* web_contents);
67 static void SetDataReductionProxyEnabled(bool enabled);
69 // Maps to BrowserMainParts::PreMainMessageLoopRun.
70 void PreMainMessageLoopRun();
72 // These methods map to Add methods in visitedlink::VisitedLinkMaster.
73 void AddVisitedURLs(const std::vector<GURL>& urls);
75 net::URLRequestContextGetter* CreateRequestContext(
76 content::ProtocolHandlerMap* protocol_handlers);
77 net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
78 const base::FilePath& partition_path,
80 content::ProtocolHandlerMap* protocol_handlers);
82 AwQuotaManagerBridge* GetQuotaManagerBridge();
84 AwFormDatabaseService* GetFormDatabaseService();
86 DataReductionProxySettings* GetDataReductionProxySettings();
88 void CreateUserPrefServiceIfNecessary();
90 // content::BrowserContext implementation.
91 virtual base::FilePath GetPath() const OVERRIDE;
92 virtual bool IsOffTheRecord() const OVERRIDE;
93 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
94 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
95 int renderer_child_id) OVERRIDE;
96 virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
97 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
98 int renderer_child_id) OVERRIDE;
99 virtual net::URLRequestContextGetter*
100 GetMediaRequestContextForStoragePartition(
101 const base::FilePath& partition_path, bool in_memory) OVERRIDE;
102 virtual void RequestMidiSysExPermission(
103 int render_process_id,
106 const GURL& requesting_frame,
108 const MidiSysExPermissionCallback& callback) OVERRIDE;
109 virtual void CancelMidiSysExPermissionRequest(
110 int render_process_id,
113 const GURL& requesting_frame) OVERRIDE;
114 virtual void RequestProtectedMediaIdentifierPermission(
115 int render_process_id,
119 const GURL& requesting_frame,
120 const ProtectedMediaIdentifierPermissionCallback& callback) OVERRIDE;
121 virtual void CancelProtectedMediaIdentifierPermissionRequests(int group_id)
123 virtual content::ResourceContext* GetResourceContext() OVERRIDE;
124 virtual content::DownloadManagerDelegate*
125 GetDownloadManagerDelegate() OVERRIDE;
126 virtual content::GeolocationPermissionContext*
127 GetGeolocationPermissionContext() OVERRIDE;
128 virtual content::BrowserPluginGuestManagerDelegate*
129 GetGuestManagerDelegate() OVERRIDE;
130 virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
132 // visitedlink::VisitedLinkDelegate implementation.
133 virtual void RebuildTable(
134 const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
137 static bool data_reduction_proxy_enabled_;
139 // The file path where data for this context is persisted.
140 base::FilePath context_storage_path_;
142 JniDependencyFactory* native_factory_;
143 scoped_refptr<net::CookieStore> cookie_store_;
144 scoped_refptr<AwURLRequestContextGetter> url_request_context_getter_;
145 scoped_refptr<content::GeolocationPermissionContext>
146 geolocation_permission_context_;
147 scoped_refptr<AwQuotaManagerBridge> quota_manager_bridge_;
148 scoped_ptr<AwFormDatabaseService> form_database_service_;
150 AwDownloadManagerDelegate download_manager_delegate_;
152 scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
153 scoped_ptr<content::ResourceContext> resource_context_;
155 scoped_ptr<PrefService> user_pref_service_;
157 scoped_ptr<DataReductionProxySettings> data_reduction_proxy_settings_;
159 DISALLOW_COPY_AND_ASSIGN(AwBrowserContext);
162 } // namespace android_webview
164 #endif // ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_