1 // Copyright (c) 2011 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.
5 #ifndef WEBKIT_BROWSER_APPCACHE_APPCACHE_INTERCEPTOR_H_
6 #define WEBKIT_BROWSER_APPCACHE_APPCACHE_INTERCEPTOR_H_
8 #include "base/memory/singleton.h"
9 #include "net/url_request/url_request.h"
11 #include "webkit/browser/webkit_storage_browser_export.h"
12 #include "webkit/common/resource_type.h"
16 class AppCacheRequestHandler;
17 class AppCacheService;
19 // An interceptor to hijack requests and potentially service them out of
21 class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheInterceptor
22 : public net::URLRequest::Interceptor {
24 // Registers a singleton instance with the net library.
25 // Should be called early in the IO thread prior to initiating requests.
26 static void EnsureRegistered() {
30 // Must be called to make a request eligible for retrieval from an appcache.
31 static void SetExtraRequestInfo(net::URLRequest* request,
32 AppCacheService* service,
35 ResourceType::Type resource_type);
37 // May be called after response headers are complete to retrieve extra
38 // info about the response.
39 static void GetExtraResponseInfo(net::URLRequest* request,
43 // Methods to support cross site navigations.
44 static void PrepareForCrossSiteTransfer(net::URLRequest* request,
46 static void CompleteCrossSiteTransfer(net::URLRequest* request,
50 static AppCacheInterceptor* GetInstance();
53 // Override from net::URLRequest::Interceptor:
54 virtual net::URLRequestJob* MaybeIntercept(
55 net::URLRequest* request,
56 net::NetworkDelegate* network_delegate) OVERRIDE;
57 virtual net::URLRequestJob* MaybeInterceptResponse(
58 net::URLRequest* request,
59 net::NetworkDelegate* network_delegate) OVERRIDE;
60 virtual net::URLRequestJob* MaybeInterceptRedirect(
61 net::URLRequest* request,
62 net::NetworkDelegate* network_delegate,
63 const GURL& location) OVERRIDE;
66 friend struct DefaultSingletonTraits<AppCacheInterceptor>;
68 AppCacheInterceptor();
69 virtual ~AppCacheInterceptor();
71 static void SetHandler(net::URLRequest* request,
72 AppCacheRequestHandler* handler);
73 static AppCacheRequestHandler* GetHandler(net::URLRequest* request);
75 DISALLOW_COPY_AND_ASSIGN(AppCacheInterceptor);
78 } // namespace appcache
80 #endif // WEBKIT_BROWSER_APPCACHE_APPCACHE_INTERCEPTOR_H_