Home | History | Annotate | Download | only in glue
      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 WEBKIT_GLUE_ALT_ERROR_PAGE_RESOURCE_FETCHER_H_
      6 #define WEBKIT_GLUE_ALT_ERROR_PAGE_RESOURCE_FETCHER_H_
      7 
      8 #include "base/callback.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "googleurl/src/gurl.h"
     11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
     12 
     13 namespace WebKit {
     14 class WebFrame;
     15 class WebURLResponse;
     16 }
     17 
     18 namespace webkit_glue {
     19 class ResourceFetcherWithTimeout;
     20 
     21 // Used for downloading alternate dns error pages. Once downloading is done
     22 // (or fails), the webview delegate is notified.
     23 class AltErrorPageResourceFetcher {
     24  public:
     25   // This will be called when the alternative error page has been fetched,
     26   // successfully or not.  If there is a failure, the third parameter (the
     27   // data) will be empty.
     28   typedef Callback3<WebKit::WebFrame*, const WebKit::WebURLError&,
     29                     const std::string&>::Type Callback;
     30 
     31   AltErrorPageResourceFetcher(const GURL& url,
     32                               WebKit::WebFrame* frame,
     33                               const WebKit::WebURLError& original_error,
     34                               Callback* callback);
     35   ~AltErrorPageResourceFetcher();
     36 
     37   // Stop any pending loads.
     38   void Cancel();
     39 
     40  private:
     41   void OnURLFetchComplete(const WebKit::WebURLResponse& response,
     42                           const std::string& data);
     43 
     44   // Does the actual fetching.
     45   scoped_ptr<ResourceFetcherWithTimeout> fetcher_;
     46 
     47   WebKit::WebFrame* frame_;
     48   scoped_ptr<Callback> callback_;
     49 
     50   // The error associated with this load.  If there's an error talking with the
     51   // alt error page server, we need this to complete the original load.
     52   WebKit::WebURLError original_error_;
     53 
     54   DISALLOW_COPY_AND_ASSIGN(AltErrorPageResourceFetcher);
     55 };
     56 
     57 }  // namespace webkit_glue
     58 
     59 #endif  // WEBKIT_GLUE_ALT_ERROR_PAGE_RESOURCE_FETCHER_H_
     60