Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / runtime_context.h
1 // Copyright (c) 2013 Intel Corporation. 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 XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_
6 #define XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_
7
8 #if defined(OS_ANDROID)
9 #include <string>
10 #endif
11
12 #include <map>
13 #include <vector>
14
15 #include "base/compiler_specific.h"
16 #include "base/files/file_path.h"
17 #include "base/memory/ref_counted.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "components/visitedlink/browser/visitedlink_delegate.h"
20 #include "content/public/browser/browser_context.h"
21 #include "content/public/browser/content_browser_client.h"
22 #include "content/public/browser/geolocation_permission_context.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::GeolocationPermissionContext*
72       GetGeolocationPermissionContext() OVERRIDE;
73   virtual content::BrowserPluginGuestManagerDelegate*
74       GetGuestManagerDelegate() OVERRIDE;
75   virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
76   virtual void RequestMidiSysExPermission(
77       int render_process_id,
78       int render_view_id,
79       int bridge_id,
80       const GURL& requesting_frame,
81       bool user_gesture,
82       const MidiSysExPermissionCallback& callback) OVERRIDE { }
83   virtual void CancelMidiSysExPermissionRequest(
84       int render_process_id,
85       int render_view_id,
86       int bridge_id,
87       const GURL& requesting_frame) OVERRIDE {}
88   virtual void RequestProtectedMediaIdentifierPermission(
89       int render_process_id,
90       int render_view_id,
91       int bridge_id,
92       int group_id,
93       const GURL& requesting_frame,
94       const ProtectedMediaIdentifierPermissionCallback& callback) OVERRIDE;
95   virtual void CancelProtectedMediaIdentifierPermissionRequests(
96       int group_id) OVERRIDE;
97
98   net::URLRequestContextGetter* CreateRequestContext(
99       content::ProtocolHandlerMap* protocol_handlers,
100       content::ProtocolHandlerScopedVector protocol_interceptors);
101   net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
102       const base::FilePath& partition_path,
103       bool in_memory,
104       content::ProtocolHandlerMap* protocol_handlers,
105       content::ProtocolHandlerScopedVector protocol_interceptors);
106 #if defined(OS_ANDROID)
107   void SetCSPString(const std::string& csp);
108   std::string GetCSPString() const;
109   // These methods map to Add methods in visitedlink::VisitedLinkMaster.
110   void AddVisitedURLs(const std::vector<GURL>& urls);
111   // visitedlink::VisitedLinkDelegate implementation.
112   virtual void RebuildTable(
113       const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
114 #endif
115
116  private:
117   class RuntimeResourceContext;
118
119   // Performs initialization of the RuntimeContext while IO is still
120   // allowed on the current thread.
121   void InitWhileIOAllowed();
122
123 #if defined(OS_ANDROID)
124   // Reset visitedlink master and initialize it.
125   void InitVisitedLinkMaster();
126 #endif
127
128   scoped_ptr<RuntimeResourceContext> resource_context_;
129   scoped_refptr<RuntimeDownloadManagerDelegate> download_manager_delegate_;
130   scoped_refptr<RuntimeURLRequestContextGetter> url_request_getter_;
131   scoped_refptr<content::GeolocationPermissionContext>
132        geolocation_permission_context_;
133 #if defined(OS_ANDROID)
134   std::string csp_;
135   scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
136 #endif
137
138   typedef std::map<std::string, scoped_refptr<RuntimeURLRequestContextGetter> >
139       PartitionPathContextGetterMap;
140   PartitionPathContextGetterMap context_getters_;
141
142   DISALLOW_COPY_AND_ASSIGN(RuntimeContext);
143 };
144
145 }  // namespace xwalk
146
147 #endif  // XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_