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