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 #include "webkit/glue/alt_error_page_resource_fetcher.h" 6 7 #include "base/callback.h" 8 #include "webkit/glue/resource_fetcher.h" 9 10 using WebKit::WebFrame; 11 using WebKit::WebURLError; 12 using WebKit::WebURLRequest; 13 using WebKit::WebURLResponse; 14 15 namespace webkit_glue { 16 17 // Number of seconds to wait for the alternate error page server. If it takes 18 // too long, just use the local error page. 19 static const int kDownloadTimeoutSec = 3; 20 21 AltErrorPageResourceFetcher::AltErrorPageResourceFetcher( 22 const GURL& url, 23 WebFrame* frame, 24 const WebURLError& original_error, 25 Callback* callback) 26 : frame_(frame), 27 callback_(callback), 28 original_error_(original_error) { 29 fetcher_.reset(new ResourceFetcherWithTimeout( 30 url, frame, WebURLRequest::TargetIsMainFrame, kDownloadTimeoutSec, 31 NewCallback(this, &AltErrorPageResourceFetcher::OnURLFetchComplete))); 32 } 33 34 AltErrorPageResourceFetcher::~AltErrorPageResourceFetcher() { 35 } 36 37 void AltErrorPageResourceFetcher::Cancel() { 38 fetcher_->Cancel(); 39 } 40 41 void AltErrorPageResourceFetcher::OnURLFetchComplete( 42 const WebURLResponse& response, 43 const std::string& data) { 44 // A null response indicates a network error. 45 if (!response.isNull() && response.httpStatusCode() == 200) { 46 callback_->Run(frame_, original_error_, data); 47 } else { 48 callback_->Run(frame_, original_error_, std::string()); 49 } 50 } 51 52 } // namespace webkit_glue 53