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"
25 class ResourceContext;
33 namespace visitedlink {
34 class VisitedLinkMaster;
37 namespace android_webview {
39 class AwFormDatabaseService;
40 class AwQuotaManagerBridge;
41 class AwURLRequestContextGetter;
42 class JniDependencyFactory;
44 class AwBrowserContext : public content::BrowserContext,
45 public visitedlink::VisitedLinkDelegate {
48 AwBrowserContext(const base::FilePath path,
49 JniDependencyFactory* native_factory);
50 virtual ~AwBrowserContext();
52 // Currently only one instance per process is supported.
53 static AwBrowserContext* GetDefault();
55 // Convenience method to returns the AwBrowserContext corresponding to the
57 static AwBrowserContext* FromWebContents(
58 content::WebContents* web_contents);
60 // Maps to BrowserMainParts::PreMainMessageLoopRun.
61 void PreMainMessageLoopRun();
63 // These methods map to Add methods in visitedlink::VisitedLinkMaster.
64 void AddVisitedURLs(const std::vector<GURL>& urls);
66 net::URLRequestContextGetter* CreateRequestContext(
67 content::ProtocolHandlerMap* protocol_handlers);
68 net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
69 const base::FilePath& partition_path,
71 content::ProtocolHandlerMap* protocol_handlers);
73 AwQuotaManagerBridge* GetQuotaManagerBridge();
75 AwFormDatabaseService* GetFormDatabaseService();
76 void CreateUserPrefServiceIfNecessary();
78 // content::BrowserContext implementation.
79 virtual base::FilePath GetPath() const OVERRIDE;
80 virtual bool IsOffTheRecord() const OVERRIDE;
81 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
82 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
83 int renderer_child_id) OVERRIDE;
84 virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
85 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
86 int renderer_child_id) OVERRIDE;
87 virtual net::URLRequestContextGetter*
88 GetMediaRequestContextForStoragePartition(
89 const base::FilePath& partition_path, bool in_memory) OVERRIDE;
90 virtual void RequestMIDISysExPermission(
91 int render_process_id,
94 const GURL& requesting_frame,
95 const MIDISysExPermissionCallback& callback) OVERRIDE;
96 virtual void CancelMIDISysExPermissionRequest(
97 int render_process_id,
100 const GURL& requesting_frame) OVERRIDE;
101 virtual content::ResourceContext* GetResourceContext() OVERRIDE;
102 virtual content::DownloadManagerDelegate*
103 GetDownloadManagerDelegate() OVERRIDE;
104 virtual content::GeolocationPermissionContext*
105 GetGeolocationPermissionContext() OVERRIDE;
106 virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
108 // visitedlink::VisitedLinkDelegate implementation.
109 virtual void RebuildTable(
110 const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
113 // The file path where data for this context is persisted.
114 base::FilePath context_storage_path_;
116 JniDependencyFactory* native_factory_;
117 scoped_refptr<net::CookieStore> cookie_store_;
118 scoped_refptr<AwURLRequestContextGetter> url_request_context_getter_;
119 scoped_refptr<content::GeolocationPermissionContext>
120 geolocation_permission_context_;
121 scoped_refptr<AwQuotaManagerBridge> quota_manager_bridge_;
122 scoped_ptr<AwFormDatabaseService> form_database_service_;
124 AwDownloadManagerDelegate download_manager_delegate_;
126 scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
127 scoped_ptr<content::ResourceContext> resource_context_;
129 bool user_pref_service_ready_;
131 DISALLOW_COPY_AND_ASSIGN(AwBrowserContext);
134 } // namespace android_webview
136 #endif // ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_