summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-23 19:11:48 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-23 19:11:48 +0000
commitb086e8071269fc23c6fb9fef3785da4e41a1d82c (patch)
tree7948c405ee492caa137259e13c2f20e2ad5dedd7 /webkit
parentafa82479fced750ebee50cba4ce94c23ba064ea6 (diff)
downloadchromium_src-b086e8071269fc23c6fb9fef3785da4e41a1d82c.zip
chromium_src-b086e8071269fc23c6fb9fef3785da4e41a1d82c.tar.gz
chromium_src-b086e8071269fc23c6fb9fef3785da4e41a1d82c.tar.bz2
Alt{Error,404}PageResourceFetcher cleanup.
This change modifies AltErrorPageResourceFetcher to use Callback so that we can eliminate Alt404PageResourceFetcher. This change also eliminates dependencies from AltErrorPageResourceFetcher on WebCore. BUG=15648 TEST=none R=tony Review URL: http://codereview.chromium.org/159262 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21419 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/alt_404_page_resource_fetcher.cc55
-rw-r--r--webkit/glue/alt_404_page_resource_fetcher.h55
-rw-r--r--webkit/glue/alt_error_page_resource_fetcher.cc48
-rw-r--r--webkit/glue/alt_error_page_resource_fetcher.h54
-rw-r--r--webkit/glue/resource_fetcher.h2
-rw-r--r--webkit/glue/webframe_impl.cc14
-rw-r--r--webkit/glue/webframe_impl.h5
-rw-r--r--webkit/glue/webframeloaderclient_impl.cc26
-rw-r--r--webkit/glue/webframeloaderclient_impl.h12
-rw-r--r--webkit/webkit.gyp2
10 files changed, 87 insertions, 186 deletions
diff --git a/webkit/glue/alt_404_page_resource_fetcher.cc b/webkit/glue/alt_404_page_resource_fetcher.cc
deleted file mode 100644
index df75414..0000000
--- a/webkit/glue/alt_404_page_resource_fetcher.cc
+++ /dev/null
@@ -1,55 +0,0 @@
-// 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 "config.h"
-
-#include "base/compiler_specific.h"
-
-MSVC_PUSH_WARNING_LEVEL(0);
-#include "DocumentLoader.h"
-MSVC_POP_WARNING();
-#undef LOG
-
-#include "webkit/glue/alt_404_page_resource_fetcher.h"
-
-#include "googleurl/src/gurl.h"
-#include "webkit/glue/webframe_impl.h"
-#include "webkit/glue/webframeloaderclient_impl.h"
-
-using WebCore::DocumentLoader;
-using WebKit::WebURLResponse;
-
-namespace webkit_glue {
-
-// Number of seconds to wait for the alternate 404 page server. If it takes
-// too long, just show the original 404 page.
-static const int kDownloadTimeoutSec = 3;
-
-Alt404PageResourceFetcher::Alt404PageResourceFetcher(
- WebFrameLoaderClient* webframeloaderclient,
- WebCore::Frame* frame,
- DocumentLoader* doc_loader,
- const GURL& url)
- : webframeloaderclient_(webframeloaderclient),
- doc_loader_(doc_loader) {
-
- fetcher_.reset(new ResourceFetcherWithTimeout(
- url, WebFrameImpl::FromFrame(frame), kDownloadTimeoutSec,
- NewCallback(this, &Alt404PageResourceFetcher::OnURLFetchComplete)));
-}
-
-void Alt404PageResourceFetcher::OnURLFetchComplete(
- const WebURLResponse& response,
- const std::string& data) {
- // A null response indicates a network error.
- if (!response.isNull() && response.httpStatusCode() == 200) {
- // Only show server response if we got a 200.
- webframeloaderclient_->Alt404PageFinished(doc_loader_.get(), data);
- } else {
- webframeloaderclient_->Alt404PageFinished(doc_loader_.get(), std::string());
- }
- doc_loader_ = NULL;
-}
-
-} // namespace webkit_glue
diff --git a/webkit/glue/alt_404_page_resource_fetcher.h b/webkit/glue/alt_404_page_resource_fetcher.h
deleted file mode 100644
index 9d04e49..0000000
--- a/webkit/glue/alt_404_page_resource_fetcher.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// 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.
-
-#ifndef WEBKIT_GLUE_ALT_404_PAGE_RESOURCE_HANDLE_CLIENT_H_
-#define WEBKIT_GLUE_ALT_404_PAGE_RESOURCE_HANDLE_CLIENT_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/scoped_ptr.h"
-
-#include "webkit/glue/resource_fetcher.h"
-
-class WebFrameLoaderClient;
-
-namespace webkit_glue {
-
-// ResourceHandleClient implementation that is used for downloading alternate
-// 404 pages. Once downloading is done (or fails), the WebFrameLoaderClient is
-// notified.
-class Alt404PageResourceFetcher {
- public:
- Alt404PageResourceFetcher(WebFrameLoaderClient* webframeloaderclient,
- WebCore::Frame* frame,
- WebCore::DocumentLoader* doc_loader,
- const GURL& url);
-
- // Stop any pending loads.
- void Cancel() {
- if (fetcher_.get())
- fetcher_->Cancel();
- }
-
- private:
- void OnURLFetchComplete(const WebKit::WebURLResponse& response,
- const std::string& data);
-
- // Does the actual fetching.
- scoped_ptr<ResourceFetcherWithTimeout> fetcher_;
-
- // References to our owner which we call when finished.
- WebFrameLoaderClient* webframeloaderclient_;
-
- // The DocumentLoader associated with this load. If there's an error
- // talking with the alt 404 page server, we need this to complete the
- // original load.
- RefPtr<WebCore::DocumentLoader> doc_loader_;
-
- DISALLOW_COPY_AND_ASSIGN(Alt404PageResourceFetcher);
-};
-
-} // namespace webkit_glue
-
-#endif // WEBKIT_GLUE_ALT_404_PAGE_RESOURCE_HANDLE_CLIENT_H_
diff --git a/webkit/glue/alt_error_page_resource_fetcher.cc b/webkit/glue/alt_error_page_resource_fetcher.cc
index 6645f59..5d1a3dc 100644
--- a/webkit/glue/alt_error_page_resource_fetcher.cc
+++ b/webkit/glue/alt_error_page_resource_fetcher.cc
@@ -2,23 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "config.h"
-
-#include "base/compiler_specific.h"
-
-MSVC_PUSH_WARNING_LEVEL(0);
-#include "ResourceResponse.h"
-MSVC_POP_WARNING();
-#undef LOG
-
#include "webkit/glue/alt_error_page_resource_fetcher.h"
-#include "webkit/api/public/WebDataSource.h"
-#include "webkit/api/public/WebURLRequest.h"
-#include "webkit/glue/glue_util.h"
-#include "webkit/glue/webframe_impl.h"
-#include "webkit/glue/webview_delegate.h"
-#include "webkit/glue/webview.h"
+#include "webkit/glue/resource_fetcher.h"
using WebKit::WebURLError;
using WebKit::WebURLResponse;
@@ -30,38 +16,32 @@ namespace webkit_glue {
static const int kDownloadTimeoutSec = 3;
AltErrorPageResourceFetcher::AltErrorPageResourceFetcher(
- WebView* web_view,
- WebFrame* web_frame,
- const WebURLError& web_error,
- const GURL& url)
- : web_view_(web_view),
- web_error_(web_error),
- web_frame_(web_frame) {
- failed_request_ = web_frame_->GetProvisionalDataSource()->request();
+ const GURL& url,
+ WebFrame* frame,
+ const GURL& unreachable_url,
+ Callback* callback)
+ : callback_(callback),
+ unreachable_url_(unreachable_url) {
fetcher_.reset(new ResourceFetcherWithTimeout(
- url, web_frame, kDownloadTimeoutSec,
+ url, frame, kDownloadTimeoutSec,
NewCallback(this, &AltErrorPageResourceFetcher::OnURLFetchComplete)));
}
AltErrorPageResourceFetcher::~AltErrorPageResourceFetcher() {
}
+void AltErrorPageResourceFetcher::Cancel() {
+ fetcher_->Cancel();
+}
+
void AltErrorPageResourceFetcher::OnURLFetchComplete(
const WebURLResponse& response,
const std::string& data) {
- WebViewDelegate* delegate = web_view_->GetDelegate();
- if (!delegate)
- return;
-
// A null response indicates a network error.
if (!response.isNull() && response.httpStatusCode() == 200) {
- // We successfully got a response from the alternate error page server, so
- // load it.
- delegate->LoadNavigationErrorPage(web_frame_, failed_request_,
- web_error_, data, true);
+ callback_->Run(unreachable_url_, data);
} else {
- delegate->LoadNavigationErrorPage(web_frame_, failed_request_,
- web_error_, std::string(), true);
+ callback_->Run(unreachable_url_, std::string());
}
}
diff --git a/webkit/glue/alt_error_page_resource_fetcher.h b/webkit/glue/alt_error_page_resource_fetcher.h
index 0ca357b..3d50972 100644
--- a/webkit/glue/alt_error_page_resource_fetcher.h
+++ b/webkit/glue/alt_error_page_resource_fetcher.h
@@ -1,49 +1,59 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 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.
-#ifndef WEBKIT_GLUE_ALT_ERROR_PAGE_RESOURCE_FETCHER_H__
-#define WEBKIT_GLUE_ALT_ERROR_PAGE_RESOURCE_FETCHER_H__
-
-#include <string>
+#ifndef WEBKIT_GLUE_ALT_ERROR_PAGE_RESOURCE_FETCHER_H_
+#define WEBKIT_GLUE_ALT_ERROR_PAGE_RESOURCE_FETCHER_H_
#include "base/scoped_ptr.h"
-#include "webkit/api/public/WebURLError.h"
-#include "webkit/api/public/WebURLRequest.h"
-#include "webkit/glue/resource_fetcher.h"
+#include "base/task.h"
+#include "googleurl/src/gurl.h"
-class ResourceFetcherWithTimeout;
-class WebFrameImpl;
-class WebView;
+class WebFrame;
+
+namespace WebKit {
+class WebURLResponse;
+}
namespace webkit_glue {
+class ResourceFetcherWithTimeout;
+
// Used for downloading alternate dns error pages. Once downloading is done
// (or fails), the webview delegate is notified.
class AltErrorPageResourceFetcher {
public:
- AltErrorPageResourceFetcher(WebView* web_view,
- WebFrame* web_frame,
- const WebKit::WebURLError& web_error,
- const GURL& url);
+ // This will be called when the alternative error page has been fetched,
+ // successfully or not. If there is a failure, the second parameter (the
+ // data) will be empty.
+ typedef Callback2<const GURL&, const std::string&>::Type Callback;
+
+ AltErrorPageResourceFetcher(const GURL& url,
+ WebFrame* frame,
+ const GURL& unreachable_url,
+ Callback* callback);
~AltErrorPageResourceFetcher();
+ // Stop any pending loads.
+ void Cancel();
+
private:
void OnURLFetchComplete(const WebKit::WebURLResponse& response,
const std::string& data);
- // References to our owners
- WebView* web_view_;
- WebFrame* web_frame_;
- WebKit::WebURLError web_error_;
- WebKit::WebURLRequest failed_request_;
-
// Does the actual fetching.
scoped_ptr<ResourceFetcherWithTimeout> fetcher_;
+ scoped_ptr<Callback> callback_;
+
+ // The "unreachable url" associated with this load. If there's an error
+ // talking with the alt 404 page server, we need this to complete the
+ // original load.
+ GURL unreachable_url_;
+
DISALLOW_COPY_AND_ASSIGN(AltErrorPageResourceFetcher);
};
} // namespace webkit_glue
-#endif // WEBKIT_GLUE_ALT_ERROR_PAGE_RESOURCE_FETCHER_H__
+#endif // WEBKIT_GLUE_ALT_ERROR_PAGE_RESOURCE_FETCHER_H_
diff --git a/webkit/glue/resource_fetcher.h b/webkit/glue/resource_fetcher.h
index 338e0e1..b146e61 100644
--- a/webkit/glue/resource_fetcher.h
+++ b/webkit/glue/resource_fetcher.h
@@ -41,7 +41,7 @@ class ResourceFetcher : public WebKit::WebURLLoaderClient {
const std::string&>::Type Callback;
// We need a frame to make requests.
- ResourceFetcher(const GURL& url, WebFrame* frame, Callback* d);
+ ResourceFetcher(const GURL& url, WebFrame* frame, Callback* callback);
~ResourceFetcher();
// Stop the request and don't call the callback.
diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc
index 4087a2a..ccd08f4 100644
--- a/webkit/glue/webframe_impl.cc
+++ b/webkit/glue/webframe_impl.cc
@@ -151,6 +151,7 @@ MSVC_POP_WARNING();
#include "webkit/api/public/WebRect.h"
#include "webkit/api/public/WebScriptSource.h"
#include "webkit/api/public/WebSize.h"
+#include "webkit/api/public/WebURLError.h"
#include "webkit/glue/alt_error_page_resource_fetcher.h"
#include "webkit/glue/chrome_client_impl.h"
#include "webkit/glue/dom_operations.h"
@@ -1563,7 +1564,8 @@ void WebFrameImpl::LoadAlternateHTMLErrorPage(const WebURLRequest& request,
replace);
alt_error_page_fetcher_.reset(new AltErrorPageResourceFetcher(
- GetWebViewImpl(), this, error, error_page_url));
+ error_page_url, this, error.unreachableURL,
+ NewCallback(this, &WebFrameImpl::AltErrorPageFinished)));
}
void WebFrameImpl::DispatchWillSendRequest(WebURLRequest* request) {
@@ -1843,3 +1845,13 @@ void WebFrameImpl::LoadJavaScriptURL(const KURL& url) {
frame_->loader()->end();
}
}
+
+void WebFrameImpl::AltErrorPageFinished(const GURL& unreachable_url,
+ const std::string& html) {
+ WebViewDelegate* d = GetWebViewImpl()->delegate();
+ if (!d)
+ return;
+ WebURLError error;
+ error.unreachableURL = unreachable_url;
+ d->LoadNavigationErrorPage(this, WebURLRequest(), error, html, true);
+}
diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h
index 1795bc8..ad3d150 100644
--- a/webkit/glue/webframe_impl.h
+++ b/webkit/glue/webframe_impl.h
@@ -398,6 +398,11 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> {
void LoadJavaScriptURL(const WebCore::KURL& url);
+ // Callback function for download of alternate error pages. If the server is
+ // down or we take too long to download the page, |html| will be empty.
+ void AltErrorPageFinished(const GURL& unreachable_url,
+ const std::string& html);
+
// Valid between calls to BeginPrint() and EndPrint(). Containts the print
// information. Is used by PrintPage().
scoped_ptr<ChromePrintContext> print_context_;
diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc
index b896fab..90f059e 100644
--- a/webkit/glue/webframeloaderclient_impl.cc
+++ b/webkit/glue/webframeloaderclient_impl.cc
@@ -51,7 +51,7 @@ MSVC_POP_WARNING();
#include "webkit/api/src/WrappedResourceRequest.h"
#include "webkit/api/src/WrappedResourceResponse.h"
#include "webkit/glue/autofill_form.h"
-#include "webkit/glue/alt_404_page_resource_fetcher.h"
+#include "webkit/glue/alt_error_page_resource_fetcher.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/password_form_dom_manager.h"
#include "webkit/glue/plugins/plugin_list.h"
@@ -75,11 +75,13 @@ using WebKit::WebNavigationType;
using WebKit::WebNavigationPolicy;
using WebKit::WebString;
using WebKit::WebURL;
+using WebKit::WebURLError;
+using WebKit::WebURLRequest;
using WebKit::WebVector;
using WebKit::WrappedResourceRequest;
using WebKit::WrappedResourceResponse;
-using webkit_glue::Alt404PageResourceFetcher;
+using webkit_glue::AltErrorPageResourceFetcher;
// Domain for internal error codes.
static const char kInternalErrorDomain[] = "webkit_glue";
@@ -352,8 +354,9 @@ void WebFrameLoaderClient::dispatchDidFinishLoading(DocumentLoader* loader,
const GURL& url = GetAlt404PageUrl(loader);
DCHECK(url.is_valid()) <<
"URL changed? It was valid in dispatchDidReceiveResponse.";
- alt_404_page_fetcher_.reset(new Alt404PageResourceFetcher(this,
- webframe_->frame(), loader, url));
+ alt_404_page_fetcher_.reset(new AltErrorPageResourceFetcher(
+ url, webframe_, webkit_glue::KURLToGURL(loader->url()),
+ NewCallback(this, &WebFrameLoaderClient::Alt404PageFinished)));
}
WebViewImpl* webview = webframe_->GetWebViewImpl();
@@ -380,16 +383,21 @@ GURL WebFrameLoaderClient::GetAlt404PageUrl(DocumentLoader* loader) {
return d->GetAlternateErrorPageURL(failedURL, WebViewDelegate::HTTP_404);
}
-void WebFrameLoaderClient::Alt404PageFinished(DocumentLoader* loader,
+void WebFrameLoaderClient::Alt404PageFinished(const GURL& unreachable_url,
const std::string& html) {
- const WebURL& base_url = webkit_glue::KURLToWebURL(loader->url());
- if (html.length() > 0) {
+ // TODO(darin): Move this processing out to the embedder.
+ if (!html.empty()) {
// TODO(tc): Handle backoff on so we don't hammer the alt error page
// servers.
- webframe_->LoadHTMLString(html, base_url);
+ WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate();
+ if (!d)
+ return;
+ WebURLError error;
+ error.unreachableURL = unreachable_url;
+ d->LoadNavigationErrorPage(webframe_, WebURLRequest(), error, html, false);
} else {
// Fall back on original text
- webframe_->LoadHTMLString(postponed_data_, base_url);
+ webframe_->LoadHTMLString(postponed_data_, unreachable_url);
}
}
diff --git a/webkit/glue/webframeloaderclient_impl.h b/webkit/glue/webframeloaderclient_impl.h
index e031fae..defa4d2 100644
--- a/webkit/glue/webframeloaderclient_impl.h
+++ b/webkit/glue/webframeloaderclient_impl.h
@@ -20,7 +20,7 @@ class Widget;
}
namespace webkit_glue {
-class Alt404PageResourceFetcher;
+class AltErrorPageResourceFetcher;
}
class WebFrameImpl;
@@ -203,13 +203,11 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient {
virtual void registerForIconNotification(bool listen = true);
+ private:
// Callback function for download of alternate 404 pages. If the server is
- // down or we take more than 1s to download the page, html will be an empty
- // string.
- void Alt404PageFinished(WebCore::DocumentLoader* loader,
- const std::string& html);
+ // down or we take too long to download the page, |html| will be empty.
+ void Alt404PageFinished(const GURL& unreachable_url, const std::string& html);
- private:
void makeDocumentView();
// Given a NavigationAction, determine the associated WebNavigationPolicy.
@@ -233,7 +231,7 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient {
WebFrameImpl* webframe_;
// Resource fetcher for downloading an alternate 404 page.
- scoped_ptr<webkit_glue::Alt404PageResourceFetcher> alt_404_page_fetcher_;
+ scoped_ptr<webkit_glue::AltErrorPageResourceFetcher> alt_404_page_fetcher_;
bool postpone_loading_data_;
std::string postponed_data_;
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index c27323d..7b96e29 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -1285,8 +1285,6 @@
'glue/plugins/webplugin_delegate_impl.h',
'glue/plugins/webplugin_delegate_impl_gtk.cc',
'glue/plugins/webplugin_delegate_impl_mac.mm',
- 'glue/alt_404_page_resource_fetcher.cc',
- 'glue/alt_404_page_resource_fetcher.h',
'glue/alt_error_page_resource_fetcher.cc',
'glue/alt_error_page_resource_fetcher.h',
'glue/autofill_form.cc',