resource_dispatcher_host_delegate.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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_DISPATCHER_HOST_DELEGATE_H_ 6#define CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "content/common/content_export.h" 12#include "ipc/ipc_message.h" 13#include "webkit/glue/resource_type.h" 14 15class GURL; 16template <class T> class ScopedVector; 17 18namespace appcache { 19class AppCacheService; 20} 21 22namespace content { 23class ResourceContext; 24class ResourceThrottle; 25struct Referrer; 26struct ResourceResponse; 27} 28 29namespace net { 30class AuthChallengeInfo; 31class SSLCertRequestInfo; 32class URLRequest; 33} 34 35namespace content { 36 37class ResourceDispatcherHostLoginDelegate; 38 39// Interface that the embedder provides to ResourceDispatcherHost to allow 40// observing and modifying requests. 41class CONTENT_EXPORT ResourceDispatcherHostDelegate { 42 public: 43 // Called when a request begins. Return false to abort the request. 44 virtual bool ShouldBeginRequest( 45 int child_id, 46 int route_id, 47 const std::string& method, 48 const GURL& url, 49 ResourceType::Type resource_type, 50 ResourceContext* resource_context, 51 const Referrer& referrer); 52 53 // Called after ShouldBeginRequest to allow the embedder to add resource 54 // throttles. 55 virtual void RequestBeginning( 56 net::URLRequest* request, 57 ResourceContext* resource_context, 58 appcache::AppCacheService* appcache_service, 59 ResourceType::Type resource_type, 60 int child_id, 61 int route_id, 62 bool is_continuation_of_transferred_request, 63 ScopedVector<ResourceThrottle>* throttles); 64 65 // Allows an embedder to add additional resource handlers for a download. 66 // |is_new_request| is true if this is a request that is just starting, i.e. 67 // the content layer has just added its own resource handlers; it's false if 68 // this was originally a non-download request that had some resource handlers 69 // applied already and now we found out it's a download. 70 // |in_complete| is true if this is invoked from |OnResponseCompleted|. 71 virtual void DownloadStarting( 72 net::URLRequest* request, 73 ResourceContext* resource_context, 74 int child_id, 75 int route_id, 76 int request_id, 77 bool is_content_initiated, 78 ScopedVector<ResourceThrottle>* throttles); 79 80 // Called when an SSL Client Certificate is requested. If false is returned, 81 // the request is canceled. Otherwise, the certificate is chosen. 82 virtual bool AcceptSSLClientCertificateRequest( 83 net::URLRequest* request, 84 net::SSLCertRequestInfo* cert_request_info); 85 86 // Called when authentication is required and credentials are needed. If 87 // false is returned, CancelAuth() is called on the URLRequest and the error 88 // page is shown. If true is returned, the user will be prompted for 89 // authentication credentials. 90 virtual bool AcceptAuthRequest(net::URLRequest* request, 91 net::AuthChallengeInfo* auth_info); 92 93 // Creates a ResourceDispatcherHostLoginDelegate that asks the user for a 94 // username and password. 95 virtual ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( 96 net::AuthChallengeInfo* auth_info, net::URLRequest* request); 97 98 // Launches the url for the given tab. Returns true if an attempt to handle 99 // the url was made, e.g. by launching an app. Note that this does not 100 // guarantee that the app successfully handled it. 101 virtual bool HandleExternalProtocol(const GURL& url, 102 int child_id, 103 int route_id); 104 105 // Returns true if we should force the given resource to be downloaded. 106 // Otherwise, the content layer decides. 107 virtual bool ShouldForceDownloadResource( 108 const GURL& url, const std::string& mime_type); 109 110 // Informs the delegate that a response has started. 111 virtual void OnResponseStarted( 112 net::URLRequest* request, 113 ResourceContext* resource_context, 114 ResourceResponse* response, 115 IPC::Sender* sender); 116 117 // Informs the delegate that a request has been redirected. 118 virtual void OnRequestRedirected( 119 const GURL& redirect_url, 120 net::URLRequest* request, 121 ResourceContext* resource_context, 122 ResourceResponse* response); 123 124 protected: 125 ResourceDispatcherHostDelegate(); 126 virtual ~ResourceDispatcherHostDelegate(); 127}; 128 129} // namespace content 130 131#endif // CONTENT_PUBLIC_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ 132