Upstream version 5.34.104.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       const MidiSysExPermissionCallback& callback) OVERRIDE;
97   virtual void CancelMidiSysExPermissionRequest(
98         int render_process_id,
99         int render_view_id,
100         int bridge_id,
101         const GURL& requesting_frame) OVERRIDE;
102   virtual void RequestProtectedMediaIdentifierPermission(
103       int render_process_id,
104       int render_view_id,
105       int bridge_id,
106       int group_id,
107       const GURL& requesting_frame,
108       const ProtectedMediaIdentifierPermissionCallback& callback) OVERRIDE;
109   virtual void CancelProtectedMediaIdentifierPermissionRequests(int group_id)
110       OVERRIDE;
111   virtual content::ResourceContext* GetResourceContext() OVERRIDE;
112   virtual content::DownloadManagerDelegate*
113       GetDownloadManagerDelegate() OVERRIDE;
114   virtual content::GeolocationPermissionContext*
115       GetGeolocationPermissionContext() OVERRIDE;
116   virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
117
118   // visitedlink::VisitedLinkDelegate implementation.
119   virtual void RebuildTable(
120       const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
121
122  private:
123   // The file path where data for this context is persisted.
124   base::FilePath context_storage_path_;
125
126   JniDependencyFactory* native_factory_;
127   scoped_refptr<net::CookieStore> cookie_store_;
128   scoped_refptr<AwURLRequestContextGetter> url_request_context_getter_;
129   scoped_refptr<content::GeolocationPermissionContext>
130       geolocation_permission_context_;
131   scoped_refptr<AwQuotaManagerBridge> quota_manager_bridge_;
132   scoped_ptr<AwFormDatabaseService> form_database_service_;
133
134   AwDownloadManagerDelegate download_manager_delegate_;
135
136   scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
137   scoped_ptr<content::ResourceContext> resource_context_;
138
139   scoped_ptr<PrefService> user_pref_service_;
140
141   DISALLOW_COPY_AND_ASSIGN(AwBrowserContext);
142 };
143
144 }  // namespace android_webview
145
146 #endif  // ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_