Update To 11.40.268.0
[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   base::FilePath GetPath() const override;
58   bool IsOffTheRecord() const override;
59   content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
60   net::URLRequestContextGetter* GetRequestContext() override;
61   net::URLRequestContextGetter* GetRequestContextForRenderProcess(
62       int renderer_child_id) override;
63   net::URLRequestContextGetter* GetMediaRequestContext() override;
64   net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
65       int renderer_child_id) override;
66   net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition(
67           const base::FilePath& partition_path,
68           bool in_memory) override;
69   content::ResourceContext* GetResourceContext() override;
70   content::BrowserPluginGuestManager* GetGuestManager() override;
71   storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
72   content::PushMessagingService* GetPushMessagingService() override;
73   content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
74
75   RuntimeURLRequestContextGetter* GetURLRequestContextGetterById(
76       const std::string& pkg_id);
77   net::URLRequestContextGetter* CreateRequestContext(
78       content::ProtocolHandlerMap* protocol_handlers,
79       content::URLRequestInterceptorScopedVector request_interceptors);
80   net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
81       const base::FilePath& partition_path,
82       bool in_memory,
83       content::ProtocolHandlerMap* protocol_handlers,
84       content::URLRequestInterceptorScopedVector request_interceptors);
85 #if defined(OS_ANDROID)
86   void SetCSPString(const std::string& csp);
87   std::string GetCSPString() const;
88   // These methods map to Add methods in visitedlink::VisitedLinkMaster.
89   void AddVisitedURLs(const std::vector<GURL>& urls);
90   // visitedlink::VisitedLinkDelegate implementation.
91   void RebuildTable(
92       const scoped_refptr<URLEnumerator>& enumerator) override;
93 #endif
94
95  private:
96   class RuntimeResourceContext;
97
98   // Performs initialization of the XWalkBrowserContext while IO is still
99   // allowed on the current thread.
100   void InitWhileIOAllowed();
101
102 #if defined(OS_ANDROID)
103   // Reset visitedlink master and initialize it.
104   void InitVisitedLinkMaster();
105 #endif
106
107   scoped_ptr<RuntimeResourceContext> resource_context_;
108   scoped_refptr<RuntimeDownloadManagerDelegate> download_manager_delegate_;
109   scoped_refptr<RuntimeURLRequestContextGetter> url_request_getter_;
110 #if defined(OS_ANDROID)
111   std::string csp_;
112   scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
113 #endif
114
115   typedef std::map<base::FilePath::StringType,
116       scoped_refptr<RuntimeURLRequestContextGetter> >
117       PartitionPathContextGetterMap;
118   PartitionPathContextGetterMap context_getters_;
119
120   DISALLOW_COPY_AND_ASSIGN(XWalkBrowserContext);
121 };
122
123 }  // namespace xwalk
124
125 #endif  // XWALK_RUNTIME_BROWSER_XWALK_BROWSER_CONTEXT_H_