6bf775b906674baade74311c78c4bcbfc222140e
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / xwalk_browser_context.h
1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #ifndef XWALK_RUNTIME_BROWSER_XWALK_BROWSER_CONTEXT_H_
7 #define XWALK_RUNTIME_BROWSER_XWALK_BROWSER_CONTEXT_H_
8
9 #if defined(OS_ANDROID)
10 #include <string>
11 #endif
12
13 #include <map>
14 #include <vector>
15
16 #include "base/compiler_specific.h"
17 #include "base/files/file_path.h"
18 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "components/visitedlink/browser/visitedlink_delegate.h"
21 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/content_browser_client.h"
23
24 namespace net {
25 class URLRequestContextGetter;
26 }
27
28 namespace content {
29 class DownloadManagerDelegate;
30 }
31
32 namespace visitedlink {
33 class VisitedLinkMaster;
34 }
35
36 namespace xwalk {
37
38 class RuntimeDownloadManagerDelegate;
39 class RuntimeURLRequestContextGetter;
40
41 class XWalkBrowserContext
42     : public content::BrowserContext
43 #if defined(OS_ANDROID)
44       , public visitedlink::VisitedLinkDelegate
45 #endif
46 {
47  public:
48   XWalkBrowserContext();
49   virtual ~XWalkBrowserContext();
50
51   // Convenience method to returns the XWalkBrowserContext corresponding to the
52   // given WebContents.
53   static XWalkBrowserContext* FromWebContents(
54       content::WebContents* web_contents);
55
56   // BrowserContext implementation.
57   virtual base::FilePath GetPath() const OVERRIDE;
58   virtual bool IsOffTheRecord() const OVERRIDE;
59   virtual content::DownloadManagerDelegate*
60       GetDownloadManagerDelegate() OVERRIDE;
61   virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
62   virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
63       int renderer_child_id) OVERRIDE;
64   virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
65   virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
66       int renderer_child_id) OVERRIDE;
67   virtual net::URLRequestContextGetter*
68       GetMediaRequestContextForStoragePartition(
69           const base::FilePath& partition_path,
70           bool in_memory) OVERRIDE;
71   virtual content::ResourceContext* GetResourceContext() OVERRIDE;
72   virtual content::BrowserPluginGuestManager*
73       GetGuestManager() OVERRIDE;
74   virtual storage::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
75   virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE;
76   virtual content::SSLHostStateDelegate* GetSSLHostStateDelegate() OVERRIDE;
77
78   RuntimeURLRequestContextGetter* GetURLRequestContextGetterById(
79       const std::string& pkg_id);
80   net::URLRequestContextGetter* CreateRequestContext(
81       content::ProtocolHandlerMap* protocol_handlers,
82       content::URLRequestInterceptorScopedVector request_interceptors);
83   net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
84       const base::FilePath& partition_path,
85       bool in_memory,
86       content::ProtocolHandlerMap* protocol_handlers,
87       content::URLRequestInterceptorScopedVector request_interceptors);
88 #if defined(OS_ANDROID)
89   void SetCSPString(const std::string& csp);
90   std::string GetCSPString() const;
91   // These methods map to Add methods in visitedlink::VisitedLinkMaster.
92   void AddVisitedURLs(const std::vector<GURL>& urls);
93   // visitedlink::VisitedLinkDelegate implementation.
94   virtual void RebuildTable(
95       const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
96 #endif
97
98  private:
99   class RuntimeResourceContext;
100
101   // Performs initialization of the XWalkBrowserContext while IO is still
102   // allowed on the current thread.
103   void InitWhileIOAllowed();
104
105 #if defined(OS_ANDROID)
106   // Reset visitedlink master and initialize it.
107   void InitVisitedLinkMaster();
108 #endif
109
110   scoped_ptr<RuntimeResourceContext> resource_context_;
111   scoped_refptr<RuntimeDownloadManagerDelegate> download_manager_delegate_;
112   scoped_refptr<RuntimeURLRequestContextGetter> url_request_getter_;
113 #if defined(OS_ANDROID)
114   std::string csp_;
115   scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
116 #endif
117
118   typedef std::map<base::FilePath::StringType,
119       scoped_refptr<RuntimeURLRequestContextGetter> >
120       PartitionPathContextGetterMap;
121   PartitionPathContextGetterMap context_getters_;
122
123   DISALLOW_COPY_AND_ASSIGN(XWalkBrowserContext);
124 };
125
126 }  // namespace xwalk
127
128 #endif  // XWALK_RUNTIME_BROWSER_XWALK_BROWSER_CONTEXT_H_