• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RESOURCE_CONTEXT_H_
6 #define CONTENT_PUBLIC_BROWSER_RESOURCE_CONTEXT_H_
7 
8 #include <string>
9 
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/supports_user_data.h"
14 #include "build/build_config.h"
15 #include "content/common/content_export.h"
16 
17 class GURL;
18 
19 namespace appcache {
20 class AppCacheService;
21 }
22 
23 namespace net {
24 class ClientCertStore;
25 class HostResolver;
26 class KeygenHandler;
27 class URLRequestContext;
28 }
29 
30 namespace content {
31 
32 // ResourceContext contains the relevant context information required for
33 // resource loading. It lives on the IO thread, although it is constructed on
34 // the UI thread. It must be destructed on the IO thread.
35 class CONTENT_EXPORT ResourceContext : public base::SupportsUserData {
36  public:
37 #if defined(OS_IOS)
~ResourceContext()38   virtual ~ResourceContext() {}
39 #else
40   ResourceContext();
41   virtual ~ResourceContext();
42 #endif
43   virtual net::HostResolver* GetHostResolver() = 0;
44 
45   // DEPRECATED: This is no longer a valid given isolated apps/sites and
46   // storage partitioning. This getter returns the default context associated
47   // with a BrowsingContext.
48   virtual net::URLRequestContext* GetRequestContext() = 0;
49 
50   // Get platform ClientCertStore. May return NULL.
51   virtual scoped_ptr<net::ClientCertStore> CreateClientCertStore();
52 
53   // Create a platform KeygenHandler and pass it to |callback|. The |callback|
54   // may be run synchronously.
55   virtual void CreateKeygenHandler(
56       uint32 key_size_in_bits,
57       const std::string& challenge_string,
58       const GURL& url,
59       const base::Callback<void(scoped_ptr<net::KeygenHandler>)>& callback);
60 
61   // Returns true if microphone access is allowed for |origin|. Used to
62   // determine what level of authorization is given to |origin| to access
63   // resource metadata.
64   virtual bool AllowMicAccess(const GURL& origin) = 0;
65 
66   // Returns true if web camera access is allowed for |origin|. Used to
67   // determine what level of authorization is given to |origin| to access
68   // resource metadata.
69   virtual bool AllowCameraAccess(const GURL& origin) = 0;
70 
71   // Returns a callback that can be invoked to get a random salt
72   // string that is used for creating media device IDs.  The salt
73   // should be stored in the current user profile and should be reset
74   // if cookies are cleared. The default is an empty string.
75   //
76   // It is safe to hold on to the callback returned and use it without
77   // regard to the lifetime of ResourceContext, although in general
78   // you should not use it long after the profile has been destroyed.
79   //
80   // TODO(joi): We don't think it should be unnecessary to use this
81   // after ResourceContext goes away. There is likely an underying bug
82   // in the lifetime of ProfileIOData vs. ResourceProcessHost, where
83   // sometimes ProfileIOData has gone away before RPH has finished
84   // being torn down (on the IO thread). The current interface that
85   // allows using the salt object after ResourceContext has gone away
86   // was put in place to fix http://crbug.com/341211 but I intend to
87   // try to figure out how the lifetime should be fixed properly. The
88   // original interface was just a method that returns a string.
89   //
90   // TODO(perkj): Make this method pure virtual when crbug/315022 is
91   // fixed.
92   typedef base::Callback<std::string()> SaltCallback;
93   virtual SaltCallback GetMediaDeviceIDSalt();
94 };
95 
96 }  // namespace content
97 
98 #endif  // CONTENT_PUBLIC_BROWSER_RESOURCE_CONTEXT_H_
99