Upstream version 10.38.210.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / runtime_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_RUNTIME_CONTEXT_H_
7 #define XWALK_RUNTIME_BROWSER_RUNTIME_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 RuntimeContext
42     : public content::BrowserContext
43 #if defined(OS_ANDROID)
44       , public visitedlink::VisitedLinkDelegate
45 #endif
46 {
47  public:
48   RuntimeContext();
49   virtual ~RuntimeContext();
50
51   // Convenience method to returns the RuntimeContext corresponding to the
52   // given WebContents.
53   static RuntimeContext* FromWebContents(content::WebContents* web_contents);
54
55   // BrowserContext implementation.
56   virtual base::FilePath GetPath() const OVERRIDE;
57   virtual bool IsOffTheRecord() const OVERRIDE;
58   virtual content::DownloadManagerDelegate*
59       GetDownloadManagerDelegate() OVERRIDE;
60   virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
61   virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
62       int renderer_child_id) OVERRIDE;
63   virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
64   virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
65       int renderer_child_id) OVERRIDE;
66   virtual net::URLRequestContextGetter*
67       GetMediaRequestContextForStoragePartition(
68           const base::FilePath& partition_path,
69           bool in_memory) OVERRIDE;
70   virtual content::ResourceContext* GetResourceContext() OVERRIDE;
71   virtual content::BrowserPluginGuestManager*
72       GetGuestManager() OVERRIDE;
73   virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
74   virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE;
75   virtual content::SSLHostStateDelegate* GetSSLHostStateDelegate() OVERRIDE;
76
77   RuntimeURLRequestContextGetter* GetURLRequestContextGetterById(
78       const std::string& pkg_id);
79   net::URLRequestContextGetter* CreateRequestContext(
80       content::ProtocolHandlerMap* protocol_handlers,
81       content::URLRequestInterceptorScopedVector request_interceptors);
82   net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
83       const base::FilePath& partition_path,
84       bool in_memory,
85       content::ProtocolHandlerMap* protocol_handlers,
86       content::URLRequestInterceptorScopedVector request_interceptors);
87 #if defined(OS_ANDROID)
88   void SetCSPString(const std::string& csp);
89   std::string GetCSPString() const;
90   // These methods map to Add methods in visitedlink::VisitedLinkMaster.
91   void AddVisitedURLs(const std::vector<GURL>& urls);
92   // visitedlink::VisitedLinkDelegate implementation.
93   virtual void RebuildTable(
94       const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
95 #endif
96
97  private:
98   class RuntimeResourceContext;
99
100   // Performs initialization of the RuntimeContext while IO is still
101   // allowed on the current thread.
102   void InitWhileIOAllowed();
103
104 #if defined(OS_ANDROID)
105   // Reset visitedlink master and initialize it.
106   void InitVisitedLinkMaster();
107 #endif
108
109   scoped_ptr<RuntimeResourceContext> resource_context_;
110   scoped_refptr<RuntimeDownloadManagerDelegate> download_manager_delegate_;
111   scoped_refptr<RuntimeURLRequestContextGetter> url_request_getter_;
112 #if defined(OS_ANDROID)
113   std::string csp_;
114   scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
115 #endif
116
117   typedef std::map<base::FilePath::StringType,
118       scoped_refptr<RuntimeURLRequestContextGetter> >
119       PartitionPathContextGetterMap;
120   PartitionPathContextGetterMap context_getters_;
121
122   DISALLOW_COPY_AND_ASSIGN(RuntimeContext);
123 };
124
125 }  // namespace xwalk
126
127 #endif  // XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_