• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_RENDERER_FETCHERS_ALT_ERROR_PAGE_RESOURCE_FETCHER_H_
6 #define CONTENT_RENDERER_FETCHERS_ALT_ERROR_PAGE_RESOURCE_FETCHER_H_
7 
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "third_party/WebKit/public/platform/WebURLError.h"
11 #include "third_party/WebKit/public/platform/WebURLRequest.h"
12 #include "url/gurl.h"
13 
14 namespace blink {
15 class WebFrame;
16 class WebURLResponse;
17 }
18 
19 namespace content {
20 class ResourceFetcher;
21 
22 // Used for downloading alternate dns error pages. Once downloading is done
23 // (or fails), the webview delegate is notified.
24 class AltErrorPageResourceFetcher {
25  public:
26   // This will be called when the alternative error page has been fetched,
27   // successfully or not.  If there is a failure, the third parameter (the
28   // data) will be empty.
29   typedef base::Callback<void(blink::WebFrame*,
30                               const blink::WebURLRequest&,
31                               const blink::WebURLError&,
32                               const std::string&)> Callback;
33 
34   AltErrorPageResourceFetcher(
35       const GURL& url,
36       blink::WebFrame* frame,
37       const blink::WebURLRequest& original_request,
38       const blink::WebURLError& original_error,
39       const Callback& callback);
40   ~AltErrorPageResourceFetcher();
41 
42  private:
43   void OnURLFetchComplete(const blink::WebURLResponse& response,
44                           const std::string& data);
45 
46   // Does the actual fetching.
47   scoped_ptr<ResourceFetcher> fetcher_;
48 
49   blink::WebFrame* frame_;
50   Callback callback_;
51 
52   // The original request.  If loading the alternate error page fails, it's
53   // needed to generate the error page.
54   blink::WebURLRequest original_request_;
55 
56   // The error associated with this load.  If there's an error talking with the
57   // alt error page server, we need this to complete the original load.
58   blink::WebURLError original_error_;
59 
60   DISALLOW_COPY_AND_ASSIGN(AltErrorPageResourceFetcher);
61 };
62 
63 }  // namespace content
64 
65 #endif  // CONTENT_RENDERER_FETCHERS_ALT_ERROR_PAGE_RESOURCE_FETCHER_H_
66