Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / public / browser / browser_context.h
1 // Copyright (c) 2012 The Chromium Authors. 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 CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_
6 #define CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_
7
8 #include "base/callback_forward.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/supports_user_data.h"
12 #include "content/common/content_export.h"
13
14 class GURL;
15
16 namespace base {
17 class FilePath;
18 }
19
20 namespace fileapi {
21 class ExternalMountPoints;
22 }
23
24 namespace net {
25 class URLRequestContextGetter;
26 }
27
28 namespace quota {
29 class SpecialStoragePolicy;
30 }
31
32 namespace content {
33
34 class BrowserPluginGuestManagerDelegate;
35 class DownloadManager;
36 class DownloadManagerDelegate;
37 class GeolocationPermissionContext;
38 class IndexedDBContext;
39 class ResourceContext;
40 class SiteInstance;
41 class StoragePartition;
42
43 // This class holds the context needed for a browsing session.
44 // It lives on the UI thread. All these methods must only be called on the UI
45 // thread.
46 class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
47  public:
48   static DownloadManager* GetDownloadManager(BrowserContext* browser_context);
49
50   // Returns BrowserContext specific external mount points. It may return NULL
51   // if the context doesn't have any BrowserContext specific external mount
52   // points. Currenty, non-NULL value is returned only on ChromeOS.
53   static fileapi::ExternalMountPoints* GetMountPoints(BrowserContext* context);
54
55   static content::StoragePartition* GetStoragePartition(
56       BrowserContext* browser_context, SiteInstance* site_instance);
57   static content::StoragePartition* GetStoragePartitionForSite(
58       BrowserContext* browser_context, const GURL& site);
59   typedef base::Callback<void(StoragePartition*)> StoragePartitionCallback;
60   static void ForEachStoragePartition(
61       BrowserContext* browser_context,
62       const StoragePartitionCallback& callback);
63   static void AsyncObliterateStoragePartition(
64       BrowserContext* browser_context,
65       const GURL& site,
66       const base::Closure& on_gc_required);
67
68   // This function clears the contents of |active_paths| but does not take
69   // ownership of the pointer.
70   static void GarbageCollectStoragePartitions(
71       BrowserContext* browser_context,
72       scoped_ptr<base::hash_set<base::FilePath> > active_paths,
73       const base::Closure& done);
74
75   // DON'T USE THIS. GetDefaultStoragePartition() is going away.
76   // Use GetStoragePartition() instead. Ask ajwong@ if you have problems.
77   static content::StoragePartition* GetDefaultStoragePartition(
78       BrowserContext* browser_context);
79
80   // Ensures that the corresponding ResourceContext is initialized. Normally the
81   // BrowserContext initializs the corresponding getters when its objects are
82   // created, but if the embedder wants to pass the ResourceContext to another
83   // thread before they use BrowserContext, they should call this to make sure
84   // that the ResourceContext is ready.
85   static void EnsureResourceContextInitialized(BrowserContext* browser_context);
86
87   // Tells the HTML5 objects on this context to persist their session state
88   // across the next restart.
89   static void SaveSessionState(BrowserContext* browser_context);
90
91   virtual ~BrowserContext();
92
93   // Returns the path of the directory where this context's data is stored.
94   virtual base::FilePath GetPath() const = 0;
95
96   // Return whether this context is incognito. Default is false.
97   virtual bool IsOffTheRecord() const = 0;
98
99   // Returns the request context information associated with this context.  Call
100   // this only on the UI thread, since it can send notifications that should
101   // happen on the UI thread.
102   // TODO(creis): Remove this version in favor of the one below.
103   virtual net::URLRequestContextGetter* GetRequestContext() = 0;
104
105   // Returns the request context appropriate for the given renderer. If the
106   // renderer process doesn't have an associated installed app, or if the
107   // installed app doesn't have isolated storage, this is equivalent to calling
108   // GetRequestContext().
109   virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
110       int renderer_child_id) = 0;
111
112   // Returns the default request context for media resources associated with
113   // this context.
114   // TODO(creis): Remove this version in favor of the one below.
115   virtual net::URLRequestContextGetter* GetMediaRequestContext() = 0;
116
117   // Returns the request context for media resources associated with this
118   // context and renderer process.
119   virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
120       int renderer_child_id) = 0;
121   virtual net::URLRequestContextGetter*
122       GetMediaRequestContextForStoragePartition(
123           const base::FilePath& partition_path,
124           bool in_memory) = 0;
125
126   typedef base::Callback<void(bool)> MidiSysExPermissionCallback;
127
128   // Requests a permission to use system exclusive messages in MIDI events.
129   // |callback| will be invoked when the request is resolved.
130   virtual void RequestMidiSysExPermission(
131       int render_process_id,
132       int render_view_id,
133       int bridge_id,
134       const GURL& requesting_frame,
135       bool user_gesture,
136       const MidiSysExPermissionCallback& callback) = 0;
137
138   // Cancels a pending MIDI permission request.
139   virtual void CancelMidiSysExPermissionRequest(
140       int render_process_id,
141       int render_view_id,
142       int bridge_id,
143       const GURL& requesting_frame) = 0;
144
145   typedef base::Callback<void(bool)> ProtectedMediaIdentifierPermissionCallback;
146
147   // Request permission to access protected media identifier. The callback will
148   // tell whether it's permitted.
149   virtual void RequestProtectedMediaIdentifierPermission(
150       int render_process_id,
151       int render_view_id,
152       int bridge_id,
153       int group_id,
154       const GURL& requesting_frame,
155       const ProtectedMediaIdentifierPermissionCallback& callback) = 0;
156
157   // Cancels pending protected media identifier permission requests.
158   virtual void CancelProtectedMediaIdentifierPermissionRequests(
159       int group_id) = 0;
160
161   // Returns the resource context.
162   virtual ResourceContext* GetResourceContext() = 0;
163
164   // Returns the DownloadManagerDelegate for this context. This will be called
165   // once per context. The embedder owns the delegate and is responsible for
166   // ensuring that it outlives DownloadManager. It's valid to return NULL.
167   virtual DownloadManagerDelegate* GetDownloadManagerDelegate() = 0;
168
169   // Returns the geolocation permission context for this context. It's valid to
170   // return NULL, in which case geolocation requests will always be allowed.
171   virtual GeolocationPermissionContext* GetGeolocationPermissionContext() = 0;
172
173   // Returns the guest manager delegate for this context.
174   virtual content::BrowserPluginGuestManagerDelegate*
175       GetGuestManagerDelegate() = 0;
176
177   // Returns a special storage policy implementation, or NULL.
178   virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0;
179 };
180
181 }  // namespace content
182
183 #if defined(COMPILER_GCC)
184 namespace BASE_HASH_NAMESPACE {
185
186 template<>
187 struct hash<content::BrowserContext*> {
188   std::size_t operator()(content::BrowserContext* const& p) const {
189     return reinterpret_cast<std::size_t>(p);
190   }
191 };
192
193 }  // namespace BASE_HASH_NAMESPACE
194 #endif
195
196 #endif  // CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_