- add sources.
[platform/framework/web/crosswalk.git] / src / content / renderer / fetchers / alt_error_page_resource_fetcher.h
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 WebKit {
15 class WebFrame;
16 class WebURLResponse;
17 }
18
19 namespace content {
20 class ResourceFetcherWithTimeout;
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(WebKit::WebFrame*,
30                               const WebKit::WebURLRequest&,
31                               const WebKit::WebURLError&,
32                               const std::string&)> Callback;
33
34   AltErrorPageResourceFetcher(
35       const GURL& url,
36       WebKit::WebFrame* frame,
37       const WebKit::WebURLRequest& original_request,
38       const WebKit::WebURLError& original_error,
39       const Callback& callback);
40   ~AltErrorPageResourceFetcher();
41
42   // Stop any pending loads.
43   void Cancel();
44
45  private:
46   void OnURLFetchComplete(const WebKit::WebURLResponse& response,
47                           const std::string& data);
48
49   // Does the actual fetching.
50   scoped_ptr<ResourceFetcherWithTimeout> fetcher_;
51
52   WebKit::WebFrame* frame_;
53   Callback callback_;
54
55   // The original request.  If loading the alternate error page fails, it's
56   // needed to generate the error page.
57   WebKit::WebURLRequest original_request_;
58
59   // The error associated with this load.  If there's an error talking with the
60   // alt error page server, we need this to complete the original load.
61   WebKit::WebURLError original_error_;
62
63   DISALLOW_COPY_AND_ASSIGN(AltErrorPageResourceFetcher);
64 };
65
66 }  // namespace content
67
68 #endif  // CONTENT_RENDERER_FETCHERS_ALT_ERROR_PAGE_RESOURCE_FETCHER_H_