- add sources.
[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
24 namespace content {
25 class ResourceContext;
26 class WebContents;
27 }
28
29 namespace net {
30 class CookieStore;
31 }
32
33 namespace visitedlink {
34 class VisitedLinkMaster;
35 }
36
37 namespace android_webview {
38
39 class AwFormDatabaseService;
40 class AwQuotaManagerBridge;
41 class AwURLRequestContextGetter;
42 class JniDependencyFactory;
43
44 class AwBrowserContext : public content::BrowserContext,
45                          public visitedlink::VisitedLinkDelegate {
46  public:
47
48   AwBrowserContext(const base::FilePath path,
49                    JniDependencyFactory* native_factory);
50   virtual ~AwBrowserContext();
51
52   // Currently only one instance per process is supported.
53   static AwBrowserContext* GetDefault();
54
55   // Convenience method to returns the AwBrowserContext corresponding to the
56   // given WebContents.
57   static AwBrowserContext* FromWebContents(
58       content::WebContents* web_contents);
59
60   // Maps to BrowserMainParts::PreMainMessageLoopRun.
61   void PreMainMessageLoopRun();
62
63   // These methods map to Add methods in visitedlink::VisitedLinkMaster.
64   void AddVisitedURLs(const std::vector<GURL>& urls);
65
66   net::URLRequestContextGetter* CreateRequestContext(
67       content::ProtocolHandlerMap* protocol_handlers);
68   net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
69       const base::FilePath& partition_path,
70       bool in_memory,
71       content::ProtocolHandlerMap* protocol_handlers);
72
73   AwQuotaManagerBridge* GetQuotaManagerBridge();
74
75   AwFormDatabaseService* GetFormDatabaseService();
76   void CreateUserPrefServiceIfNecessary();
77
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,
92       int render_view_id,
93       int bridge_id,
94       const GURL& requesting_frame,
95       const MIDISysExPermissionCallback& callback) OVERRIDE;
96   virtual void CancelMIDISysExPermissionRequest(
97         int render_process_id,
98         int render_view_id,
99         int bridge_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;
107
108   // visitedlink::VisitedLinkDelegate implementation.
109   virtual void RebuildTable(
110       const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
111
112  private:
113   // The file path where data for this context is persisted.
114   base::FilePath context_storage_path_;
115
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_;
123
124   AwDownloadManagerDelegate download_manager_delegate_;
125
126   scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
127   scoped_ptr<content::ResourceContext> resource_context_;
128
129   bool user_pref_service_ready_;
130
131   DISALLOW_COPY_AND_ASSIGN(AwBrowserContext);
132 };
133
134 }  // namespace android_webview
135
136 #endif  // ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_