1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/glue/alt_error_page_resource_fetcher.h"
#include "base/callback.h"
#include "webkit/glue/resource_fetcher.h"
using WebKit::WebFrame;
using WebKit::WebURLError;
using WebKit::WebURLResponse;
namespace webkit_glue {
// Number of seconds to wait for the alternate error page server. If it takes
// too long, just use the local error page.
static const int kDownloadTimeoutSec = 3;
AltErrorPageResourceFetcher::AltErrorPageResourceFetcher(
const GURL& url,
WebFrame* frame,
const WebURLError& original_error,
Callback* callback)
: frame_(frame),
callback_(callback),
original_error_(original_error) {
fetcher_.reset(new ResourceFetcherWithTimeout(
url, frame, kDownloadTimeoutSec,
NewCallback(this, &AltErrorPageResourceFetcher::OnURLFetchComplete)));
}
AltErrorPageResourceFetcher::~AltErrorPageResourceFetcher() {
}
void AltErrorPageResourceFetcher::Cancel() {
fetcher_->Cancel();
}
void AltErrorPageResourceFetcher::OnURLFetchComplete(
const WebURLResponse& response,
const std::string& data) {
// A null response indicates a network error.
if (!response.isNull() && response.httpStatusCode() == 200) {
callback_->Run(frame_, original_error_, data);
} else {
callback_->Run(frame_, original_error_, std::string());
}
}
} // namespace webkit_glue
|