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.
5 #ifndef XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_
6 #define XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_
8 #if defined(OS_ANDROID)
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"
25 class URLRequestContextGetter;
29 class DownloadManagerDelegate;
32 namespace visitedlink {
33 class VisitedLinkMaster;
38 class RuntimeDownloadManagerDelegate;
39 class RuntimeURLRequestContextGetter;
42 : public content::BrowserContext
43 #if defined(OS_ANDROID)
44 , public visitedlink::VisitedLinkDelegate
49 virtual ~RuntimeContext();
51 // Convenience method to returns the RuntimeContext corresponding to the
53 static RuntimeContext* FromWebContents(content::WebContents* web_contents);
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,
80 const GURL& requesting_frame,
82 const MidiSysExPermissionCallback& callback) OVERRIDE { }
83 virtual void CancelMidiSysExPermissionRequest(
84 int render_process_id,
87 const GURL& requesting_frame) OVERRIDE {}
88 virtual void RequestProtectedMediaIdentifierPermission(
89 int render_process_id,
93 const GURL& requesting_frame,
94 const ProtectedMediaIdentifierPermissionCallback& callback) OVERRIDE;
95 virtual void CancelProtectedMediaIdentifierPermissionRequests(
96 int group_id) OVERRIDE;
98 net::URLRequestContextGetter* CreateRequestContext(
99 content::ProtocolHandlerMap* protocol_handlers,
100 content::ProtocolHandlerScopedVector protocol_interceptors);
101 net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
102 const base::FilePath& partition_path,
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;
117 class RuntimeResourceContext;
119 // Performs initialization of the RuntimeContext while IO is still
120 // allowed on the current thread.
121 void InitWhileIOAllowed();
123 #if defined(OS_ANDROID)
124 // Reset visitedlink master and initialize it.
125 void InitVisitedLinkMaster();
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)
135 scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
138 typedef std::map<std::string, scoped_refptr<RuntimeURLRequestContextGetter> >
139 PartitionPathContextGetterMap;
140 PartitionPathContextGetterMap context_getters_;
142 DISALLOW_COPY_AND_ASSIGN(RuntimeContext);
147 #endif // XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_