summaryrefslogtreecommitdiffstats
path: root/webkit/glue/resource_fetcher.h
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-07 16:44:39 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-07 16:44:39 +0000
commitf6134ff2597f45c240b1fc2a493d38b51aa8a884 (patch)
treebeddc103816d95a1f73a586eb523251154f84e6b /webkit/glue/resource_fetcher.h
parent62c9a8e3985009ee3503497cb4e1ab18d8cecc97 (diff)
downloadchromium_src-f6134ff2597f45c240b1fc2a493d38b51aa8a884.zip
chromium_src-f6134ff2597f45c240b1fc2a493d38b51aa8a884.tar.gz
chromium_src-f6134ff2597f45c240b1fc2a493d38b51aa8a884.tar.bz2
Modify ResourceFetcher to use WebURLLoader instead of ResourceHandle.
This is step 1 of moving ResourceFetcher usage out of WebFrame. This CL adds a new method to WebFrame, named DispatchWillSendRequest, which may be used to associate a WebURLRequest with the WebFrame. This triggers the WebViewDelegate's WillSendRequest method among other things. ResourceFetcher and friends have been modified to use callbacks instead of delegates. I just find this approach a bit cleaner and easier to work with. BUG=15648 TEST=none R=brettw Review URL: http://codereview.chromium.org/149172 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20031 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/resource_fetcher.h')
-rw-r--r--webkit/glue/resource_fetcher.h99
1 files changed, 49 insertions, 50 deletions
diff --git a/webkit/glue/resource_fetcher.h b/webkit/glue/resource_fetcher.h
index 8b00239..bc75f63 100644
--- a/webkit/glue/resource_fetcher.h
+++ b/webkit/glue/resource_fetcher.h
@@ -9,40 +9,39 @@
// ResourceFetcher::Delegate::OnURLFetchComplete will be called async after
// the ResourceFetcher object is created.
-#ifndef WEBKIT_GLUE_RESOURCE_FETCHER_H__
-#define WEBKIT_GLUE_RESOURCE_FETCHER_H__
+#ifndef WEBKIT_GLUE_RESOURCE_FETCHER_H_
+#define WEBKIT_GLUE_RESOURCE_FETCHER_H_
#include <string>
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
+#include "base/timer.h"
#include "googleurl/src/gurl.h"
+#include "webkit/api/public/WebURLLoaderClient.h"
+#include "webkit/api/public/WebURLResponse.h"
-#include "base/compiler_specific.h"
+class GURL;
+class WebFrame;
-MSVC_PUSH_WARNING_LEVEL(0);
-#include "Frame.h"
-#include "Timer.h"
-#include "ResourceHandleClient.h"
-#include "ResourceResponse.h"
-MSVC_POP_WARNING();
+namespace WebKit {
+class WebURLLoader;
+class WebURLRequest;
+struct WebURLError;
+}
-class GURL;
+namespace webkit_glue {
-class ResourceFetcher : public WebCore::ResourceHandleClient {
+class ResourceFetcher : public WebKit::WebURLLoaderClient {
public:
- class Delegate {
- public:
- // This will be called when the URL has been fetched, successfully or not.
- // If there is a failure, response and data will both be empty.
- // |response| and |data| are both valid until the URLFetcher instance is
- // destroyed.
- virtual void OnURLFetchComplete(const WebCore::ResourceResponse& response,
- const std::string& data) = 0;
- };
-
- // We need a frame and frame loader to make requests.
- ResourceFetcher(const GURL& url, WebCore::Frame* frame, Delegate* d);
+ // This will be called when the URL has been fetched, successfully or not.
+ // If there is a failure, response and data will both be empty. |response|
+ // and |data| are both valid until the URLFetcher instance is destroyed.
+ typedef Callback2<const WebKit::WebURLResponse&,
+ const std::string&>::Type Callback;
+
+ // We need a frame to make requests.
+ ResourceFetcher(const GURL& url, WebFrame* frame, Callback* d);
~ResourceFetcher();
// Stop the request and don't call the callback.
@@ -50,40 +49,40 @@ class ResourceFetcher : public WebCore::ResourceHandleClient {
bool completed() const { return completed_; }
- // ResourceHandleClient methods
- virtual void didReceiveResponse(WebCore::ResourceHandle* resource_handle,
- const WebCore::ResourceResponse& response);
-
- virtual void didReceiveData(WebCore::ResourceHandle* resource_handle,
- const char* data, int length, int total_length);
-
- virtual void didFinishLoading(WebCore::ResourceHandle* resource_handle);
-
- virtual void didFail(WebCore::ResourceHandle* resource_handle,
- const WebCore::ResourceError& error);
-
protected:
- // The parent ResourceHandle
- RefPtr<WebCore::ResourceHandle> loader_;
+ // WebURLLoaderClient methods:
+ virtual void willSendRequest(
+ WebKit::WebURLLoader* loader, WebKit::WebURLRequest& new_request,
+ const WebKit::WebURLResponse& redirect_response);
+ virtual void didSendData(
+ WebKit::WebURLLoader* loader, unsigned long long bytes_sent,
+ unsigned long long total_bytes_to_be_sent);
+ virtual void didReceiveResponse(
+ WebKit::WebURLLoader* loader, const WebKit::WebURLResponse& response);
+ virtual void didReceiveData(
+ WebKit::WebURLLoader* loader, const char* data, int data_length,
+ long long total_data_length);
+ virtual void didFinishLoading(WebKit::WebURLLoader* loader);
+ virtual void didFail(
+ WebKit::WebURLLoader* loader, const WebKit::WebURLError& error);
+
+ scoped_ptr<WebKit::WebURLLoader> loader_;
// URL we're fetching
GURL url_;
// Callback when we're done
- Delegate* delegate_;
+ Callback* callback_;
// A copy of the original resource response
- WebCore::ResourceResponse response_;
+ WebKit::WebURLResponse response_;
// Set to true once the request is compelte.
bool completed_;
private:
- // If we fail to start the request, we still want to finish async.
- typedef WebCore::Timer<ResourceFetcher> StartFailedTimer;
-
// Start the actual download.
- void Start(WebCore::Frame* frame);
+ void Start(WebFrame* frame);
// Buffer to hold the content from the server.
std::string data_;
@@ -93,20 +92,20 @@ class ResourceFetcher : public WebCore::ResourceHandleClient {
// A resource fetcher with a timeout
class ResourceFetcherWithTimeout : public ResourceFetcher {
public:
- ResourceFetcherWithTimeout(const GURL& url, WebCore::Frame* frame, double
- timeout_secs, Delegate* d);
+ ResourceFetcherWithTimeout(const GURL& url, WebFrame* frame,
+ int timeout_secs, Callback* c);
virtual ~ResourceFetcherWithTimeout() {}
private:
- typedef WebCore::Timer<ResourceFetcherWithTimeout> FetchTimer;
-
// Callback for timer that limits how long we wait for the alternate error
// page server. If this timer fires and the request hasn't completed, we
// kill the request.
- void TimeoutFired(FetchTimer* timer);
+ void TimeoutFired();
// Limit how long we wait for the alternate error page server.
- scoped_ptr<FetchTimer> timeout_timer_;
+ base::OneShotTimer<ResourceFetcherWithTimeout> timeout_timer_;
};
-#endif // WEBKIT_GLUE_RESOURCE_FETCHER_H__
+} // namespace webkit_glue
+
+#endif // WEBKIT_GLUE_RESOURCE_FETCHER_H_