Upstream version 5.34.104.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 "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 "content/public/browser/browser_context.h"
17 #include "content/public/browser/content_browser_client.h"
18 #include "content/public/browser/geolocation_permission_context.h"
19
20 namespace net {
21 class URLRequestContextGetter;
22 }
23
24 namespace content {
25 class DownloadManagerDelegate;
26 }
27
28 namespace xwalk {
29
30 class RuntimeDownloadManagerDelegate;
31 class RuntimeURLRequestContextGetter;
32
33 class RuntimeContext : public content::BrowserContext {
34  public:
35   RuntimeContext();
36   virtual ~RuntimeContext();
37
38   // Convenience method to returns the RuntimeContext corresponding to the
39   // given WebContents.
40   static RuntimeContext* FromWebContents(content::WebContents* web_contents);
41
42   // BrowserContext implementation.
43   virtual base::FilePath GetPath() const OVERRIDE;
44   virtual bool IsOffTheRecord() const OVERRIDE;
45   virtual content::DownloadManagerDelegate*
46       GetDownloadManagerDelegate() OVERRIDE;
47   virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
48   virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
49       int renderer_child_id) OVERRIDE;
50   virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
51   virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
52       int renderer_child_id) OVERRIDE;
53   virtual net::URLRequestContextGetter*
54       GetMediaRequestContextForStoragePartition(
55           const base::FilePath& partition_path,
56           bool in_memory) OVERRIDE;
57   virtual content::ResourceContext* GetResourceContext() OVERRIDE;
58   virtual content::GeolocationPermissionContext*
59       GetGeolocationPermissionContext() OVERRIDE;
60   virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
61   virtual void RequestMidiSysExPermission(
62       int render_process_id,
63       int render_view_id,
64       int bridge_id,
65       const GURL& requesting_frame,
66       const MidiSysExPermissionCallback& callback) OVERRIDE { }
67   virtual void CancelMidiSysExPermissionRequest(
68       int render_process_id,
69       int render_view_id,
70       int bridge_id,
71       const GURL& requesting_frame) OVERRIDE {}
72   virtual void RequestProtectedMediaIdentifierPermission(
73       int render_process_id,
74       int render_view_id,
75       int bridge_id,
76       int group_id,
77       const GURL& requesting_frame,
78       const ProtectedMediaIdentifierPermissionCallback& callback) OVERRIDE;
79   virtual void CancelProtectedMediaIdentifierPermissionRequests(
80       int group_id) OVERRIDE;
81
82   net::URLRequestContextGetter* CreateRequestContext(
83       content::ProtocolHandlerMap* protocol_handlers);
84   net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
85       const base::FilePath& partition_path,
86       bool in_memory,
87       content::ProtocolHandlerMap* protocol_handlers);
88 #if defined(OS_ANDROID)
89   void SetCSPString(const std::string& csp);
90   std::string GetCSPString() const;
91 #endif
92
93  private:
94   class RuntimeResourceContext;
95
96   // Performs initialization of the RuntimeContext while IO is still
97   // allowed on the current thread.
98   void InitWhileIOAllowed();
99
100   scoped_ptr<RuntimeResourceContext> resource_context_;
101   scoped_refptr<RuntimeDownloadManagerDelegate> download_manager_delegate_;
102   scoped_refptr<RuntimeURLRequestContextGetter> url_request_getter_;
103   scoped_refptr<content::GeolocationPermissionContext>
104        geolocation_permission_context_;
105 #if defined(OS_ANDROID)
106   std::string csp_;
107 #endif
108   DISALLOW_COPY_AND_ASSIGN(RuntimeContext);
109 };
110
111 }  // namespace xwalk
112
113 #endif  // XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_