Upstream version 6.35.121.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 net {
31 class CookieStore;
32 }
33
34 namespace visitedlink {
35 class VisitedLinkMaster;
36 }
37
38 namespace android_webview {
39
40 class AwFormDatabaseService;
41 class AwQuotaManagerBridge;
42 class AwURLRequestContextGetter;
43 class JniDependencyFactory;
44
45 class AwBrowserContext : public content::BrowserContext,
46                          public visitedlink::VisitedLinkDelegate {
47  public:
48
49   AwBrowserContext(const base::FilePath path,
50                    JniDependencyFactory* native_factory);
51   virtual ~AwBrowserContext();
52
53   // Currently only one instance per process is supported.
54   static AwBrowserContext* GetDefault();
55
56   // Convenience method to returns the AwBrowserContext corresponding to the
57   // given WebContents.
58   static AwBrowserContext* FromWebContents(
59       content::WebContents* web_contents);
60
61   // Maps to BrowserMainParts::PreMainMessageLoopRun.
62   void PreMainMessageLoopRun();
63
64   // These methods map to Add methods in visitedlink::VisitedLinkMaster.
65   void AddVisitedURLs(const std::vector<GURL>& urls);
66
67   net::URLRequestContextGetter* CreateRequestContext(
68       content::ProtocolHandlerMap* protocol_handlers);
69   net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
70       const base::FilePath& partition_path,
71       bool in_memory,
72       content::ProtocolHandlerMap* protocol_handlers);
73
74   AwQuotaManagerBridge* GetQuotaManagerBridge();
75
76   AwFormDatabaseService* GetFormDatabaseService();
77   void CreateUserPrefServiceIfNecessary();
78
79   // content::BrowserContext implementation.
80   virtual base::FilePath GetPath() const OVERRIDE;
81   virtual bool IsOffTheRecord() const OVERRIDE;
82   virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
83   virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
84       int renderer_child_id) OVERRIDE;
85   virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
86   virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
87       int renderer_child_id) OVERRIDE;
88   virtual net::URLRequestContextGetter*
89       GetMediaRequestContextForStoragePartition(
90           const base::FilePath& partition_path, bool in_memory) OVERRIDE;
91   virtual void RequestMidiSysExPermission(
92       int render_process_id,
93       int render_view_id,
94       int bridge_id,
95       const GURL& requesting_frame,
96       bool user_gesture,
97       const MidiSysExPermissionCallback& callback) OVERRIDE;
98   virtual void CancelMidiSysExPermissionRequest(
99         int render_process_id,
100         int render_view_id,
101         int bridge_id,
102         const GURL& requesting_frame) OVERRIDE;
103   virtual void RequestProtectedMediaIdentifierPermission(
104       int render_process_id,
105       int render_view_id,
106       int bridge_id,
107       int group_id,
108       const GURL& requesting_frame,
109       const ProtectedMediaIdentifierPermissionCallback& callback) OVERRIDE;
110   virtual void CancelProtectedMediaIdentifierPermissionRequests(int group_id)
111       OVERRIDE;
112   virtual content::ResourceContext* GetResourceContext() OVERRIDE;
113   virtual content::DownloadManagerDelegate*
114       GetDownloadManagerDelegate() OVERRIDE;
115   virtual content::GeolocationPermissionContext*
116       GetGeolocationPermissionContext() OVERRIDE;
117   virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
118
119   // visitedlink::VisitedLinkDelegate implementation.
120   virtual void RebuildTable(
121       const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
122
123  private:
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<content::GeolocationPermissionContext>
131       geolocation_permission_context_;
132   scoped_refptr<AwQuotaManagerBridge> quota_manager_bridge_;
133   scoped_ptr<AwFormDatabaseService> form_database_service_;
134
135   AwDownloadManagerDelegate download_manager_delegate_;
136
137   scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
138   scoped_ptr<content::ResourceContext> resource_context_;
139
140   scoped_ptr<PrefService> user_pref_service_;
141
142   DISALLOW_COPY_AND_ASSIGN(AwBrowserContext);
143 };
144
145 }  // namespace android_webview
146
147 #endif  // ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_