Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / android_webview / browser / aw_browser_context.h
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 "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"
21
22 class GURL;
23 class PrefService;
24
25 namespace content {
26 class ResourceContext;
27 class WebContents;
28 }
29
30 namespace data_reduction_proxy {
31 class DataReductionProxySettings;
32 }
33
34 namespace net {
35 class CookieStore;
36 }
37
38 namespace visitedlink {
39 class VisitedLinkMaster;
40 }
41
42 using data_reduction_proxy::DataReductionProxySettings;
43
44 namespace android_webview {
45
46 class AwFormDatabaseService;
47 class AwQuotaManagerBridge;
48 class AwURLRequestContextGetter;
49 class JniDependencyFactory;
50
51 class AwBrowserContext : public content::BrowserContext,
52                          public visitedlink::VisitedLinkDelegate {
53  public:
54
55   AwBrowserContext(const base::FilePath path,
56                    JniDependencyFactory* native_factory);
57   virtual ~AwBrowserContext();
58
59   // Currently only one instance per process is supported.
60   static AwBrowserContext* GetDefault();
61
62   // Convenience method to returns the AwBrowserContext corresponding to the
63   // given WebContents.
64   static AwBrowserContext* FromWebContents(
65       content::WebContents* web_contents);
66
67   static void SetDataReductionProxyEnabled(bool enabled);
68
69   // Maps to BrowserMainParts::PreMainMessageLoopRun.
70   void PreMainMessageLoopRun();
71
72   // These methods map to Add methods in visitedlink::VisitedLinkMaster.
73   void AddVisitedURLs(const std::vector<GURL>& urls);
74
75   net::URLRequestContextGetter* CreateRequestContext(
76       content::ProtocolHandlerMap* protocol_handlers);
77   net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
78       const base::FilePath& partition_path,
79       bool in_memory,
80       content::ProtocolHandlerMap* protocol_handlers);
81
82   AwQuotaManagerBridge* GetQuotaManagerBridge();
83
84   AwFormDatabaseService* GetFormDatabaseService();
85
86   DataReductionProxySettings* GetDataReductionProxySettings();
87
88   void CreateUserPrefServiceIfNecessary();
89
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,
104       int render_view_id,
105       int bridge_id,
106       const GURL& requesting_frame,
107       bool user_gesture,
108       const MidiSysExPermissionCallback& callback) OVERRIDE;
109   virtual void CancelMidiSysExPermissionRequest(
110         int render_process_id,
111         int render_view_id,
112         int bridge_id,
113         const GURL& requesting_frame) OVERRIDE;
114   virtual void RequestProtectedMediaIdentifierPermission(
115       int render_process_id,
116       int render_view_id,
117       int bridge_id,
118       int group_id,
119       const GURL& requesting_frame,
120       const ProtectedMediaIdentifierPermissionCallback& callback) OVERRIDE;
121   virtual void CancelProtectedMediaIdentifierPermissionRequests(int group_id)
122       OVERRIDE;
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;
131
132   // visitedlink::VisitedLinkDelegate implementation.
133   virtual void RebuildTable(
134       const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
135
136  private:
137   static bool data_reduction_proxy_enabled_;
138
139   // The file path where data for this context is persisted.
140   base::FilePath context_storage_path_;
141
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_;
149
150   AwDownloadManagerDelegate download_manager_delegate_;
151
152   scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
153   scoped_ptr<content::ResourceContext> resource_context_;
154
155   scoped_ptr<PrefService> user_pref_service_;
156
157   scoped_ptr<DataReductionProxySettings> data_reduction_proxy_settings_;
158
159   DISALLOW_COPY_AND_ASSIGN(AwBrowserContext);
160 };
161
162 }  // namespace android_webview
163
164 #endif  // ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_