Commit f6134ff2 authored by darin@chromium.org's avatar darin@chromium.org

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
parent 62c9a8e3
...@@ -14,13 +14,17 @@ MSVC_POP_WARNING(); ...@@ -14,13 +14,17 @@ MSVC_POP_WARNING();
#include "webkit/glue/alt_404_page_resource_fetcher.h" #include "webkit/glue/alt_404_page_resource_fetcher.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "webkit/glue/webframe_impl.h"
#include "webkit/glue/webframeloaderclient_impl.h" #include "webkit/glue/webframeloaderclient_impl.h"
using WebCore::DocumentLoader; using WebCore::DocumentLoader;
using WebKit::WebURLResponse;
namespace webkit_glue {
// Number of seconds to wait for the alternate 404 page server. If it takes // Number of seconds to wait for the alternate 404 page server. If it takes
// too long, just show the original 404 page. // too long, just show the original 404 page.
static const double kDownloadTimeoutSec = 3.0; static const int kDownloadTimeoutSec = 3;
Alt404PageResourceFetcher::Alt404PageResourceFetcher( Alt404PageResourceFetcher::Alt404PageResourceFetcher(
WebFrameLoaderClient* webframeloaderclient, WebFrameLoaderClient* webframeloaderclient,
...@@ -30,12 +34,13 @@ Alt404PageResourceFetcher::Alt404PageResourceFetcher( ...@@ -30,12 +34,13 @@ Alt404PageResourceFetcher::Alt404PageResourceFetcher(
: webframeloaderclient_(webframeloaderclient), : webframeloaderclient_(webframeloaderclient),
doc_loader_(doc_loader) { doc_loader_(doc_loader) {
fetcher_.reset(new ResourceFetcherWithTimeout(url, frame, fetcher_.reset(new ResourceFetcherWithTimeout(
kDownloadTimeoutSec, this)); url, WebFrameImpl::FromFrame(frame), kDownloadTimeoutSec,
NewCallback(this, &Alt404PageResourceFetcher::OnURLFetchComplete)));
} }
void Alt404PageResourceFetcher::OnURLFetchComplete( void Alt404PageResourceFetcher::OnURLFetchComplete(
const WebCore::ResourceResponse& response, const WebURLResponse& response,
const std::string& data) { const std::string& data) {
if (response.httpStatusCode() == 200) { if (response.httpStatusCode() == 200) {
// Only show server response if we got a 200. // Only show server response if we got a 200.
...@@ -45,3 +50,5 @@ void Alt404PageResourceFetcher::OnURLFetchComplete( ...@@ -45,3 +50,5 @@ void Alt404PageResourceFetcher::OnURLFetchComplete(
} }
doc_loader_ = NULL; doc_loader_ = NULL;
} }
} // namespace webkit_glue
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef WEBKIT_GLUE_ALT_404_PAGE_RESOURCE_HANDLE_CLIENT_H__ #ifndef WEBKIT_GLUE_ALT_404_PAGE_RESOURCE_HANDLE_CLIENT_H_
#define WEBKIT_GLUE_ALT_404_PAGE_RESOURCE_HANDLE_CLIENT_H__ #define WEBKIT_GLUE_ALT_404_PAGE_RESOURCE_HANDLE_CLIENT_H_
#include <string> #include <string>
...@@ -14,19 +14,18 @@ ...@@ -14,19 +14,18 @@
class WebFrameLoaderClient; class WebFrameLoaderClient;
namespace webkit_glue {
// ResourceHandleClient implementation that is used for downloading alternate // ResourceHandleClient implementation that is used for downloading alternate
// 404 pages. Once downloading is done (or fails), the WebFrameLoaderClient is // 404 pages. Once downloading is done (or fails), the WebFrameLoaderClient is
// notified. // notified.
class Alt404PageResourceFetcher : public ResourceFetcher::Delegate { class Alt404PageResourceFetcher {
public: public:
Alt404PageResourceFetcher(WebFrameLoaderClient* webframeloaderclient, Alt404PageResourceFetcher(WebFrameLoaderClient* webframeloaderclient,
WebCore::Frame* frame, WebCore::Frame* frame,
WebCore::DocumentLoader* doc_loader, WebCore::DocumentLoader* doc_loader,
const GURL& url); const GURL& url);
virtual void OnURLFetchComplete(const WebCore::ResourceResponse& response,
const std::string& data);
// Stop any pending loads. // Stop any pending loads.
void Cancel() { void Cancel() {
if (fetcher_.get()) if (fetcher_.get())
...@@ -34,6 +33,9 @@ class Alt404PageResourceFetcher : public ResourceFetcher::Delegate { ...@@ -34,6 +33,9 @@ class Alt404PageResourceFetcher : public ResourceFetcher::Delegate {
} }
private: private:
void OnURLFetchComplete(const WebKit::WebURLResponse& response,
const std::string& data);
// Does the actual fetching. // Does the actual fetching.
scoped_ptr<ResourceFetcherWithTimeout> fetcher_; scoped_ptr<ResourceFetcherWithTimeout> fetcher_;
...@@ -45,7 +47,9 @@ class Alt404PageResourceFetcher : public ResourceFetcher::Delegate { ...@@ -45,7 +47,9 @@ class Alt404PageResourceFetcher : public ResourceFetcher::Delegate {
// original load. // original load.
RefPtr<WebCore::DocumentLoader> doc_loader_; RefPtr<WebCore::DocumentLoader> doc_loader_;
DISALLOW_EVIL_CONSTRUCTORS(Alt404PageResourceFetcher); DISALLOW_COPY_AND_ASSIGN(Alt404PageResourceFetcher);
}; };
#endif // WEBKIT_GLUE_ALT_404_PAGE_RESOURCE_HANDLE_CLIENT_H__ } // namespace webkit_glue
#endif // WEBKIT_GLUE_ALT_404_PAGE_RESOURCE_HANDLE_CLIENT_H_
...@@ -21,29 +21,33 @@ MSVC_POP_WARNING(); ...@@ -21,29 +21,33 @@ MSVC_POP_WARNING();
#include "webkit/glue/webview.h" #include "webkit/glue/webview.h"
using WebKit::WebURLError; using WebKit::WebURLError;
using WebKit::WebURLResponse;
namespace webkit_glue {
// Number of seconds to wait for the alternate error page server. If it takes // Number of seconds to wait for the alternate error page server. If it takes
// too long, just use the local error page. // too long, just use the local error page.
static const double kDownloadTimeoutSec = 3.0; static const int kDownloadTimeoutSec = 3;
AltErrorPageResourceFetcher::AltErrorPageResourceFetcher( AltErrorPageResourceFetcher::AltErrorPageResourceFetcher(
WebView* web_view, WebView* web_view,
WebFrame* web_frame,
const WebURLError& web_error, const WebURLError& web_error,
WebFrameImpl* web_frame,
const GURL& url) const GURL& url)
: web_view_(web_view), : web_view_(web_view),
web_error_(web_error), web_error_(web_error),
web_frame_(web_frame) { web_frame_(web_frame) {
failed_request_ = web_frame_->GetProvisionalDataSource()->request(); failed_request_ = web_frame_->GetProvisionalDataSource()->request();
fetcher_.reset(new ResourceFetcherWithTimeout(url, web_frame->frame(), fetcher_.reset(new ResourceFetcherWithTimeout(
kDownloadTimeoutSec, this)); url, web_frame, kDownloadTimeoutSec,
NewCallback(this, &AltErrorPageResourceFetcher::OnURLFetchComplete)));
} }
AltErrorPageResourceFetcher::~AltErrorPageResourceFetcher() { AltErrorPageResourceFetcher::~AltErrorPageResourceFetcher() {
} }
void AltErrorPageResourceFetcher::OnURLFetchComplete( void AltErrorPageResourceFetcher::OnURLFetchComplete(
const WebCore::ResourceResponse& response, const WebURLResponse& response,
const std::string& data) { const std::string& data) {
WebViewDelegate* delegate = web_view_->GetDelegate(); WebViewDelegate* delegate = web_view_->GetDelegate();
if (!delegate) if (!delegate)
...@@ -59,3 +63,5 @@ void AltErrorPageResourceFetcher::OnURLFetchComplete( ...@@ -59,3 +63,5 @@ void AltErrorPageResourceFetcher::OnURLFetchComplete(
web_error_, std::string(), true); web_error_, std::string(), true);
} }
} }
} // namespace webkit_glue
\ No newline at end of file
...@@ -7,12 +7,6 @@ ...@@ -7,12 +7,6 @@
#include <string> #include <string>
#include "base/compiler_specific.h"
MSVC_PUSH_WARNING_LEVEL(0);
#include "Timer.h"
MSVC_POP_WARNING();
#include "base/scoped_ptr.h" #include "base/scoped_ptr.h"
#include "webkit/api/public/WebURLError.h" #include "webkit/api/public/WebURLError.h"
#include "webkit/api/public/WebURLRequest.h" #include "webkit/api/public/WebURLRequest.h"
...@@ -22,24 +16,26 @@ class ResourceFetcherWithTimeout; ...@@ -22,24 +16,26 @@ class ResourceFetcherWithTimeout;
class WebFrameImpl; class WebFrameImpl;
class WebView; class WebView;
namespace webkit_glue {
// Used for downloading alternate dns error pages. Once downloading is done // Used for downloading alternate dns error pages. Once downloading is done
// (or fails), the webview delegate is notified. // (or fails), the webview delegate is notified.
class AltErrorPageResourceFetcher : public ResourceFetcher::Delegate { class AltErrorPageResourceFetcher {
public: public:
AltErrorPageResourceFetcher(WebView* web_view, AltErrorPageResourceFetcher(WebView* web_view,
WebFrame* web_frame,
const WebKit::WebURLError& web_error, const WebKit::WebURLError& web_error,
WebFrameImpl* web_frame,
const GURL& url); const GURL& url);
~AltErrorPageResourceFetcher(); ~AltErrorPageResourceFetcher();
virtual void OnURLFetchComplete(const WebCore::ResourceResponse& response,
const std::string& data);
private: private:
void OnURLFetchComplete(const WebKit::WebURLResponse& response,
const std::string& data);
// References to our owners // References to our owners
WebView* web_view_; WebView* web_view_;
WebFrame* web_frame_;
WebKit::WebURLError web_error_; WebKit::WebURLError web_error_;
WebFrameImpl* web_frame_;
WebKit::WebURLRequest failed_request_; WebKit::WebURLRequest failed_request_;
// Does the actual fetching. // Does the actual fetching.
...@@ -48,4 +44,6 @@ class AltErrorPageResourceFetcher : public ResourceFetcher::Delegate { ...@@ -48,4 +44,6 @@ class AltErrorPageResourceFetcher : public ResourceFetcher::Delegate {
DISALLOW_COPY_AND_ASSIGN(AltErrorPageResourceFetcher); 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__
...@@ -2,34 +2,28 @@ ...@@ -2,34 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "config.h"
#include "base/compiler_specific.h"
MSVC_PUSH_WARNING_LEVEL(0);
#include "ImageSourceSkia.h"
MSVC_POP_WARNING();
#undef LOG
#include "webkit/glue/image_resource_fetcher.h" #include "webkit/glue/image_resource_fetcher.h"
#include "base/gfx/size.h" #include "base/gfx/size.h"
#include "webkit/glue/image_decoder.h" #include "webkit/glue/image_decoder.h"
#include "webkit/glue/webview_impl.h" #include "webkit/glue/webframe.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
namespace webkit_glue {
ImageResourceFetcher::ImageResourceFetcher( ImageResourceFetcher::ImageResourceFetcher(
WebViewImpl* web_view,
int id,
const GURL& image_url, const GURL& image_url,
int image_size) WebFrame* frame,
: web_view_(web_view), int id,
int image_size,
Callback* callback)
: callback_(callback),
id_(id), id_(id),
image_url_(image_url), image_url_(image_url),
image_size_(image_size) { image_size_(image_size) {
fetcher_.reset(new ResourceFetcher(image_url, fetcher_.reset(new ResourceFetcher(
web_view->main_frame()->frame(), image_url, frame,
this)); NewCallback(this, &ImageResourceFetcher::OnURLFetchComplete)));
} }
ImageResourceFetcher::~ImageResourceFetcher() { ImageResourceFetcher::~ImageResourceFetcher() {
...@@ -38,21 +32,19 @@ ImageResourceFetcher::~ImageResourceFetcher() { ...@@ -38,21 +32,19 @@ ImageResourceFetcher::~ImageResourceFetcher() {
} }
void ImageResourceFetcher::OnURLFetchComplete( void ImageResourceFetcher::OnURLFetchComplete(
const WebCore::ResourceResponse& response, const WebKit::WebURLResponse& response,
const std::string& data) { const std::string& data) {
SkBitmap image; SkBitmap bitmap;
bool errored = false; if (!response.isNull() && response.httpStatusCode() == 200) {
if (response.isNull()) {
errored = true;
} else if (response.httpStatusCode() == 200) {
// Request succeeded, try to convert it to an image. // Request succeeded, try to convert it to an image.
webkit_glue::ImageDecoder decoder(gfx::Size(image_size_, image_size_)); ImageDecoder decoder(gfx::Size(image_size_, image_size_));
image = decoder.Decode( bitmap = decoder.Decode(
reinterpret_cast<const unsigned char*>(data.data()), data.size()); reinterpret_cast<const unsigned char*>(data.data()), data.size());
} // else case: } // else case:
// If we get here, it means no image from server or couldn't decode the // If we get here, it means no image from server or couldn't decode the
// response as an image. Need to notify the webview though, otherwise the // response as an image. The delegate will see a null image, indicating
// browser will keep trying to download favicon (when this is used to // that an error occurred.
// download the favicon). callback_->Run(this, bitmap);
web_view_->ImageResourceDownloadDone(this, errored, image);
} }
} // namespace webkit_glue
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H__ #ifndef WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H_
#define WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H__ #define WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H_
#include "base/basictypes.h" #include "base/basictypes.h"
#include "webkit/glue/resource_fetcher.h" #include "webkit/glue/resource_fetcher.h"
...@@ -11,34 +11,35 @@ ...@@ -11,34 +11,35 @@
class SkBitmap; class SkBitmap;
class WebViewImpl; class WebViewImpl;
namespace webkit_glue {
// ImageResourceFetcher handles downloading an image for a webview. Once // ImageResourceFetcher handles downloading an image for a webview. Once
// downloading is done the hosting WebViewImpl is notified. ImageResourceFetcher // downloading is done the hosting WebViewImpl is notified. ImageResourceFetcher
// is used to download the favicon and images for web apps. // is used to download the favicon and images for web apps.
class ImageResourceFetcher : public ResourceFetcher::Delegate { class ImageResourceFetcher {
public: public:
ImageResourceFetcher(WebViewImpl* web_view, typedef Callback2<ImageResourceFetcher*, const SkBitmap&>::Type Callback;
ImageResourceFetcher(const GURL& image_url,
WebFrame* frame,
int id, int id,
const GURL& image_url, int image_size,
int image_size); Callback* callback);
virtual ~ImageResourceFetcher(); virtual ~ImageResourceFetcher();
// ResourceFetcher::Delegate method. Decodes the image and invokes one of
// DownloadFailed or DownloadedImage.
virtual void OnURLFetchComplete(const WebCore::ResourceResponse& response,
const std::string& data);
// URL of the image we're downloading. // URL of the image we're downloading.
const GURL& image_url() const { return image_url_; } const GURL& image_url() const { return image_url_; }
// Hosting WebView.
WebViewImpl* web_view() const { return web_view_; }
// Unique identifier for the request. // Unique identifier for the request.
int id() const { return id_; } int id() const { return id_; }
private: private:
WebViewImpl* web_view_; // ResourceFetcher::Callback. Decodes the image and invokes callback_.
void OnURLFetchComplete(const WebKit::WebURLResponse& response,
const std::string& data);
Callback* callback_;
// Unique identifier for the request. // Unique identifier for the request.
const int id_; const int id_;
...@@ -57,4 +58,6 @@ class ImageResourceFetcher : public ResourceFetcher::Delegate { ...@@ -57,4 +58,6 @@ class ImageResourceFetcher : public ResourceFetcher::Delegate {
DISALLOW_EVIL_CONSTRUCTORS(ImageResourceFetcher); DISALLOW_EVIL_CONSTRUCTORS(ImageResourceFetcher);
}; };
#endif // WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H__ } // namespace webkit_glue
#endif // WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H_
...@@ -2,30 +2,30 @@ ...@@ -2,30 +2,30 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "config.h"
#include "webkit/glue/resource_fetcher.h" #include "webkit/glue/resource_fetcher.h"
#include "base/compiler_specific.h"
MSVC_PUSH_WARNING_LEVEL(0);
#include "FrameLoader.h"
#include "FrameLoaderClient.h"
#include "ResourceHandle.h"
#include "ResourceRequest.h"
MSVC_POP_WARNING();
#undef LOG
#include "base/logging.h" #include "base/logging.h"
#include "webkit/glue/glue_util.h" #include "webkit/api/public/WebKit.h"
#include "net/url_request/url_request_status.h" #include "webkit/api/public/WebKitClient.h"
#include "webkit/api/public/WebURLError.h"
using WebCore::ResourceError; #include "webkit/api/public/WebURLLoader.h"
using WebCore::ResourceHandle; #include "webkit/api/public/WebURLRequest.h"
using WebCore::ResourceResponse; #include "webkit/api/public/WebURL.h"
#include "webkit/glue/webframe.h"
ResourceFetcher::ResourceFetcher(const GURL& url, WebCore::Frame* frame,
Delegate* d) using base::TimeDelta;
: url_(url), delegate_(d), completed_(false) { using WebKit::WebURLError;
using WebKit::WebURLLoader;
using WebKit::WebURLRequest;
using WebKit::WebURLResponse;
namespace webkit_glue {
ResourceFetcher::ResourceFetcher(const GURL& url, WebFrame* frame,
Callback* c)
: url_(url),
callback_(c),
completed_(false) {
// Can't do anything without a frame. However, delegate can be NULL (so we // Can't do anything without a frame. However, delegate can be NULL (so we
// can do a http request and ignore the results). // can do a http request and ignore the results).
DCHECK(frame); DCHECK(frame);
...@@ -35,7 +35,6 @@ ResourceFetcher::ResourceFetcher(const GURL& url, WebCore::Frame* frame, ...@@ -35,7 +35,6 @@ ResourceFetcher::ResourceFetcher(const GURL& url, WebCore::Frame* frame,
ResourceFetcher::~ResourceFetcher() { ResourceFetcher::~ResourceFetcher() {
if (!completed_ && loader_.get()) if (!completed_ && loader_.get())
loader_->cancel(); loader_->cancel();
loader_ = NULL;
} }
void ResourceFetcher::Cancel() { void ResourceFetcher::Cancel() {
...@@ -45,68 +44,74 @@ void ResourceFetcher::Cancel() { ...@@ -45,68 +44,74 @@ void ResourceFetcher::Cancel() {
} }
} }
void ResourceFetcher::Start(WebCore::Frame* frame) { void ResourceFetcher::Start(WebFrame* frame) {
WebCore::ResourceRequest request(webkit_glue::GURLToKURL(url_)); WebURLRequest request(url_);
WebCore::ResourceResponse response; frame->DispatchWillSendRequest(&request);
frame->loader()->client()->dispatchWillSendRequest(NULL, 0, request,
response);
loader_ = ResourceHandle::create(request, this, NULL, false, false); loader_.reset(WebKit::webKitClient()->createURLLoader());
loader_->loadAsynchronously(request, this);
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ResourceHandleClient methods // WebURLLoaderClient methods
void ResourceFetcher::didReceiveResponse(ResourceHandle* resource_handle,
const ResourceResponse& response) { void ResourceFetcher::willSendRequest(
ASSERT(!completed_); WebURLLoader* loader, WebURLRequest& new_request,
// It's safe to use the ResourceResponse copy constructor const WebURLResponse& redirect_response) {
// (xmlhttprequest.cpp uses it). }
void ResourceFetcher::didSendData(
WebURLLoader* loader, unsigned long long bytes_sent,
unsigned long long total_bytes_to_be_sent) {
}
void ResourceFetcher::didReceiveResponse(
WebURLLoader* loader, const WebURLResponse& response) {
DCHECK(!completed_);
response_ = response; response_ = response;
} }
void ResourceFetcher::didReceiveData(ResourceHandle* resource_handle, void ResourceFetcher::didReceiveData(
const char* data, int length, WebURLLoader* loader, const char* data, int data_length,
int total_length) { long long total_data_length) {
ASSERT(!completed_); DCHECK(!completed_);
if (length <= 0) DCHECK(data_length > 0);
return;
data_.append(data, length); data_.append(data, data_length);
} }
void ResourceFetcher::didFinishLoading(ResourceHandle* resource_handle) { void ResourceFetcher::didFinishLoading(WebURLLoader* loader) {
ASSERT(!completed_); DCHECK(!completed_);
completed_ = true; completed_ = true;
if (delegate_) if (callback_)
delegate_->OnURLFetchComplete(response_, data_); callback_->Run(response_, data_);
} }
void ResourceFetcher::didFail(ResourceHandle* resource_handle, void ResourceFetcher::didFail(WebURLLoader* loader, const WebURLError& error) {
const ResourceError& error) { DCHECK(!completed_);
ASSERT(!completed_);
completed_ = true; completed_ = true;
// Go ahead and tell our delegate that we're done. Send an empty // Go ahead and tell our delegate that we're done.
// ResourceResponse and string. if (callback_)
if (delegate_) callback_->Run(WebURLResponse(), std::string());
delegate_->OnURLFetchComplete(ResourceResponse(), std::string());
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// A resource fetcher with a timeout // A resource fetcher with a timeout
ResourceFetcherWithTimeout::ResourceFetcherWithTimeout( ResourceFetcherWithTimeout::ResourceFetcherWithTimeout(
const GURL& url, WebCore::Frame* frame, double timeout_secs, Delegate* d) const GURL& url, WebFrame* frame, int timeout_secs, Callback* c)
: ResourceFetcher(url, frame, d) { : ResourceFetcher(url, frame, c) {
timeout_timer_.reset(new FetchTimer(this, timeout_timer_.Start(TimeDelta::FromSeconds(timeout_secs), this,
&ResourceFetcherWithTimeout::TimeoutFired)); &ResourceFetcherWithTimeout::TimeoutFired);
timeout_timer_->startOneShot(timeout_secs);
} }
void ResourceFetcherWithTimeout::TimeoutFired(FetchTimer* timer) { void ResourceFetcherWithTimeout::TimeoutFired() {
if (!completed_) { if (!completed_) {
loader_->cancel(); loader_->cancel();
didFail(NULL, ResourceError()); didFail(NULL, WebURLError());
} }
} }
} // namespace webkit_glue
...@@ -9,40 +9,39 @@ ...@@ -9,40 +9,39 @@
// ResourceFetcher::Delegate::OnURLFetchComplete will be called async after // ResourceFetcher::Delegate::OnURLFetchComplete will be called async after
// the ResourceFetcher object is created. // the ResourceFetcher object is created.
#ifndef WEBKIT_GLUE_RESOURCE_FETCHER_H__ #ifndef WEBKIT_GLUE_RESOURCE_FETCHER_H_
#define WEBKIT_GLUE_RESOURCE_FETCHER_H__ #define WEBKIT_GLUE_RESOURCE_FETCHER_H_
#include <string> #include <string>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/scoped_ptr.h" #include "base/scoped_ptr.h"
#include "base/timer.h"
#include "googleurl/src/gurl.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); namespace WebKit {
#include "Frame.h" class WebURLLoader;
#include "Timer.h" class WebURLRequest;
#include "ResourceHandleClient.h" struct WebURLError;
#include "ResourceResponse.h" }
MSVC_POP_WARNING();
class GURL; namespace webkit_glue {
class ResourceFetcher : public WebCore::ResourceHandleClient { class ResourceFetcher : public WebKit::WebURLLoaderClient {
public: public:
class Delegate { // This will be called when the URL has been fetched, successfully or not.
public: // If there is a failure, response and data will both be empty. |response|
// This will be called when the URL has been fetched, successfully or not. // and |data| are both valid until the URLFetcher instance is destroyed.
// If there is a failure, response and data will both be empty. typedef Callback2<const WebKit::WebURLResponse&,
// |response| and |data| are both valid until the URLFetcher instance is const std::string&>::Type Callback;
// destroyed.
virtual void OnURLFetchComplete(const WebCore::ResourceResponse& response, // We need a frame to make requests.
const std::string& data) = 0; ResourceFetcher(const GURL& url, WebFrame* frame, Callback* d);
};
// We need a frame and frame loader to make requests.
ResourceFetcher(const GURL& url, WebCore::Frame* frame, Delegate* d);
~ResourceFetcher(); ~ResourceFetcher();
// Stop the request and don't call the callback. // Stop the request and don't call the callback.
...@@ -50,40 +49,40 @@ class ResourceFetcher : public WebCore::ResourceHandleClient { ...@@ -50,40 +49,40 @@ class ResourceFetcher : public WebCore::ResourceHandleClient {
bool completed() const { return completed_; } 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: protected:
// The parent ResourceHandle // WebURLLoaderClient methods:
RefPtr<WebCore::ResourceHandle> loader_; 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 // URL we're fetching
GURL url_; GURL url_;
// Callback when we're done // Callback when we're done
Delegate* delegate_; Callback* callback_;
// A copy of the original resource response // A copy of the original resource response
WebCore::ResourceResponse response_; WebKit::WebURLResponse response_;
// Set to true once the request is compelte. // Set to true once the request is compelte.
bool completed_; bool completed_;
private: private:
// If we fail to start the request, we still want to finish async.
typedef WebCore::Timer<ResourceFetcher> StartFailedTimer;
// Start the actual download. // Start the actual download.
void Start(WebCore::Frame* frame); void Start(WebFrame* frame);
// Buffer to hold the content from the server. // Buffer to hold the content from the server.
std::string data_; std::string data_;
...@@ -93,20 +92,20 @@ class ResourceFetcher : public WebCore::ResourceHandleClient { ...@@ -93,20 +92,20 @@ class ResourceFetcher : public WebCore::ResourceHandleClient {
// A resource fetcher with a timeout // A resource fetcher with a timeout
class ResourceFetcherWithTimeout : public ResourceFetcher { class ResourceFetcherWithTimeout : public ResourceFetcher {
public: public:
ResourceFetcherWithTimeout(const GURL& url, WebCore::Frame* frame, double ResourceFetcherWithTimeout(const GURL& url, WebFrame* frame,
timeout_secs, Delegate* d); int timeout_secs, Callback* c);
virtual ~ResourceFetcherWithTimeout() {} virtual ~ResourceFetcherWithTimeout() {}
private: private:
typedef WebCore::Timer<ResourceFetcherWithTimeout> FetchTimer;
// Callback for timer that limits how long we wait for the alternate error // 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 // page server. If this timer fires and the request hasn't completed, we
// kill the request. // kill the request.
void TimeoutFired(FetchTimer* timer); void TimeoutFired();
// Limit how long we wait for the alternate error page server. // 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_
...@@ -2,27 +2,21 @@ ...@@ -2,27 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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
#if defined(OS_LINUX) #if defined(OS_LINUX)
#include <gtk/gtk.h> #include <gtk/gtk.h>
#endif #endif
#include "webkit/api/public/WebURLResponse.h"
#include "webkit/glue/unittest_test_server.h" #include "webkit/glue/unittest_test_server.h"
#include "webkit/glue/webview.h" #include "webkit/glue/webview.h"
#include "webkit/glue/webframe_impl.h" #include "webkit/glue/webframe.h"
#include "webkit/glue/resource_fetcher.h" #include "webkit/glue/resource_fetcher.h"
#include "webkit/tools/test_shell/simple_resource_loader_bridge.h" #include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
#include "webkit/tools/test_shell/test_shell_test.h" #include "webkit/tools/test_shell/test_shell_test.h"
using WebCore::ResourceResponse; using WebKit::WebURLResponse;
using webkit_glue::ResourceFetcher;
using webkit_glue::ResourceFetcherWithTimeout;
namespace { namespace {
...@@ -39,7 +33,7 @@ class ResourceFetcherTests : public TestShellTest { ...@@ -39,7 +33,7 @@ class ResourceFetcherTests : public TestShellTest {
static const int kMaxWaitTimeMs = 5000; static const int kMaxWaitTimeMs = 5000;
static const int kWaitIntervalMs = 100; static const int kWaitIntervalMs = 100;
class FetcherDelegate : public ResourceFetcher::Delegate { class FetcherDelegate {
public: public:
FetcherDelegate() FetcherDelegate()
: timer_id_(0), completed_(false), time_elapsed_ms_(0) { : timer_id_(0), completed_(false), time_elapsed_ms_(0) {
...@@ -49,8 +43,12 @@ class FetcherDelegate : public ResourceFetcher::Delegate { ...@@ -49,8 +43,12 @@ class FetcherDelegate : public ResourceFetcher::Delegate {
CreateTimer(kWaitIntervalMs); CreateTimer(kWaitIntervalMs);
} }
virtual void OnURLFetchComplete(const ResourceResponse& response, ResourceFetcher::Callback* NewCallback() {
const std::string& data) { return ::NewCallback(this, &FetcherDelegate::OnURLFetchComplete);
}
void OnURLFetchComplete(const WebURLResponse& response,
const std::string& data) {
response_ = response; response_ = response;
data_ = data; data_ = data;
completed_ = true; completed_ = true;
...@@ -63,7 +61,7 @@ class FetcherDelegate : public ResourceFetcher::Delegate { ...@@ -63,7 +61,7 @@ class FetcherDelegate : public ResourceFetcher::Delegate {
int time_elapsed_ms() const { return time_elapsed_ms_; } int time_elapsed_ms() const { return time_elapsed_ms_; }
std::string data() const { return data_; } std::string data() const { return data_; }
ResourceResponse response() const { return response_; } const WebURLResponse& response() const { return response_; }
// Wait for the request to complete or timeout. We use a loop here b/c the // Wait for the request to complete or timeout. We use a loop here b/c the
// testing infrastructure (test_shell) can generate spurious calls to the // testing infrastructure (test_shell) can generate spurious calls to the
...@@ -145,7 +143,7 @@ class FetcherDelegate : public ResourceFetcher::Delegate { ...@@ -145,7 +143,7 @@ class FetcherDelegate : public ResourceFetcher::Delegate {
#endif #endif
bool completed_; bool completed_;
int time_elapsed_ms_; int time_elapsed_ms_;
ResourceResponse response_; WebURLResponse response_;
std::string data_; std::string data_;
}; };
...@@ -157,15 +155,12 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { ...@@ -157,15 +155,12 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDownload) {
UnittestTestServer::CreateServer(); UnittestTestServer::CreateServer();
ASSERT_TRUE(NULL != server.get()); ASSERT_TRUE(NULL != server.get());
WebFrame* web_frame = test_shell_->webView()->GetMainFrame(); WebFrame* frame = test_shell_->webView()->GetMainFrame();
// Not safe, but this is a unittest, so whatever.
WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame);
WebCore::Frame* frame = web_frame_impl->frame();
GURL url = server->TestServerPage("files/test_shell/index.html"); GURL url = server->TestServerPage("files/test_shell/index.html");
scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate);
scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher( scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher(
url, frame, delegate.get())); url, frame, delegate->NewCallback()));
delegate->WaitForResponse(); delegate->WaitForResponse();
...@@ -177,7 +172,7 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { ...@@ -177,7 +172,7 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDownload) {
// Test 404 response. // Test 404 response.
url = server->TestServerPage("files/thisfiledoesntexist.html"); url = server->TestServerPage("files/thisfiledoesntexist.html");
delegate.reset(new FetcherDelegate); delegate.reset(new FetcherDelegate);
fetcher.reset(new ResourceFetcher(url, frame, delegate.get())); fetcher.reset(new ResourceFetcher(url, frame, delegate->NewCallback()));
delegate->WaitForResponse(); delegate->WaitForResponse();
...@@ -191,16 +186,13 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) { ...@@ -191,16 +186,13 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) {
UnittestTestServer::CreateServer(); UnittestTestServer::CreateServer();
ASSERT_TRUE(NULL != server.get()); ASSERT_TRUE(NULL != server.get());
WebFrame* web_frame = test_shell_->webView()->GetMainFrame(); WebFrame* frame = test_shell_->webView()->GetMainFrame();
// Not safe, but this is a unittest, so whatever.
WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame);
WebCore::Frame* frame = web_frame_impl->frame();
// Try to fetch a page on a site that doesn't exist. // Try to fetch a page on a site that doesn't exist.
GURL url("http://localhost:1339/doesnotexist"); GURL url("http://localhost:1339/doesnotexist");
scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate);
scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher( scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher(
url, frame, delegate.get())); url, frame, delegate->NewCallback()));
delegate->WaitForResponse(); delegate->WaitForResponse();
...@@ -217,17 +209,14 @@ TEST_F(ResourceFetcherTests, ResourceFetcherTimeout) { ...@@ -217,17 +209,14 @@ TEST_F(ResourceFetcherTests, ResourceFetcherTimeout) {
UnittestTestServer::CreateServer(); UnittestTestServer::CreateServer();
ASSERT_TRUE(NULL != server.get()); ASSERT_TRUE(NULL != server.get());
WebFrame* web_frame = test_shell_->webView()->GetMainFrame(); WebFrame* frame = test_shell_->webView()->GetMainFrame();
// Not safe, but this is a unittest, so whatever.
WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame);
WebCore::Frame* frame = web_frame_impl->frame();
// Grab a page that takes at least 1 sec to respond, but set the fetcher to // Grab a page that takes at least 1 sec to respond, but set the fetcher to
// timeout in 0 sec. // timeout in 0 sec.
GURL url = server->TestServerPage("slow?1"); GURL url = server->TestServerPage("slow?1");
scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate);
scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcherWithTimeout( scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcherWithTimeout(
url, frame, 0, delegate.get())); url, frame, 0, delegate->NewCallback()));
delegate->WaitForResponse(); delegate->WaitForResponse();
......
...@@ -128,6 +128,11 @@ class WebFrame { ...@@ -128,6 +128,11 @@ class WebFrame {
bool replace, bool replace,
const GURL& fake_url) = 0; const GURL& fake_url) = 0;
// Called to associate the WebURLRequest with this frame. The request will
// be modified to inherit parameters that allow it to be loaded. This method
// ends up triggering WebViewDelegate::WillSendRequest.
virtual void DispatchWillSendRequest(WebKit::WebURLRequest* request) = 0;
// Executes JavaScript in the web frame. // Executes JavaScript in the web frame.
virtual void ExecuteScript(const WebKit::WebScriptSource& source) = 0; virtual void ExecuteScript(const WebKit::WebScriptSource& source) = 0;
......
...@@ -195,6 +195,7 @@ using WebCore::RenderObject; ...@@ -195,6 +195,7 @@ using WebCore::RenderObject;
using WebCore::ResourceError; using WebCore::ResourceError;
using WebCore::ResourceHandle; using WebCore::ResourceHandle;
using WebCore::ResourceRequest; using WebCore::ResourceRequest;
using WebCore::ResourceResponse;
using WebCore::VisibleSelection; using WebCore::VisibleSelection;
using WebCore::ScriptValue; using WebCore::ScriptValue;
using WebCore::SecurityOrigin; using WebCore::SecurityOrigin;
...@@ -221,6 +222,8 @@ using WebKit::WebURLError; ...@@ -221,6 +222,8 @@ using WebKit::WebURLError;
using WebKit::WebURLRequest; using WebKit::WebURLRequest;
using WebKit::WebURLResponse; using WebKit::WebURLResponse;
using webkit_glue::AltErrorPageResourceFetcher;
// Key for a StatsCounter tracking how many WebFrames are active. // Key for a StatsCounter tracking how many WebFrames are active.
static const char* const kWebFrameActiveCount = "WebFrameActiveCount"; static const char* const kWebFrameActiveCount = "WebFrameActiveCount";
...@@ -1562,7 +1565,14 @@ void WebFrameImpl::LoadAlternateHTMLErrorPage(const WebURLRequest& request, ...@@ -1562,7 +1565,14 @@ void WebFrameImpl::LoadAlternateHTMLErrorPage(const WebURLRequest& request,
replace); replace);
alt_error_page_fetcher_.reset(new AltErrorPageResourceFetcher( alt_error_page_fetcher_.reset(new AltErrorPageResourceFetcher(
GetWebViewImpl(), error, this, error_page_url)); GetWebViewImpl(), this, error, error_page_url));
}
void WebFrameImpl::DispatchWillSendRequest(WebURLRequest* request) {
ResourceResponse response;
frame_->loader()->client()->dispatchWillSendRequest(NULL, 0,
*webkit_glue::WebURLRequestToMutableResourceRequest(request),
response);
} }
void WebFrameImpl::ExecuteScript(const WebScriptSource& source) { void WebFrameImpl::ExecuteScript(const WebScriptSource& source) {
......
...@@ -39,7 +39,6 @@ MSVC_PUSH_WARNING_LEVEL(0); ...@@ -39,7 +39,6 @@ MSVC_PUSH_WARNING_LEVEL(0);
#include "PlatformString.h" #include "PlatformString.h"
MSVC_POP_WARNING(); MSVC_POP_WARNING();
class AltErrorPageResourceFetcher;
class ChromePrintContext; class ChromePrintContext;
class WebDataSourceImpl; class WebDataSourceImpl;
class WebPluginDelegate; class WebPluginDelegate;
...@@ -48,6 +47,10 @@ class WebViewImpl; ...@@ -48,6 +47,10 @@ class WebViewImpl;
class WebTextInput; class WebTextInput;
class WebTextInputImpl; class WebTextInputImpl;
namespace gfx {
class BitmapPlatformDevice;
}
namespace WebCore { namespace WebCore {
class Frame; class Frame;
class FrameView; class FrameView;
...@@ -59,8 +62,8 @@ class SubstituteData; ...@@ -59,8 +62,8 @@ class SubstituteData;
struct WindowFeatures; struct WindowFeatures;
} }
namespace gfx { namespace webkit_glue {
class BitmapPlatformDevice; class AltErrorPageResourceFetcher;
} }
// Implementation of WebFrame, note that this is a reference counted object. // Implementation of WebFrame, note that this is a reference counted object.
...@@ -98,6 +101,7 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { ...@@ -98,6 +101,7 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> {
const GURL& error_page_url, const GURL& error_page_url,
bool replace, bool replace,
const GURL& fake_url); const GURL& fake_url);
virtual void DispatchWillSendRequest(WebKit::WebURLRequest* request);
virtual void ExecuteScript(const WebKit::WebScriptSource& source); virtual void ExecuteScript(const WebKit::WebScriptSource& source);
virtual void ExecuteScriptInNewContext( virtual void ExecuteScriptInNewContext(
const WebKit::WebScriptSource* sources, int num_sources); const WebKit::WebScriptSource* sources, int num_sources);
...@@ -280,7 +284,7 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { ...@@ -280,7 +284,7 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> {
int request_id); int request_id);
// Resource fetcher for downloading an alternate DNS error page. // Resource fetcher for downloading an alternate DNS error page.
scoped_ptr<AltErrorPageResourceFetcher> alt_error_page_fetcher_; scoped_ptr<webkit_glue::AltErrorPageResourceFetcher> alt_error_page_fetcher_;
// Used to check for leaks of this object. // Used to check for leaks of this object.
static int live_object_count_; static int live_object_count_;
......
...@@ -79,6 +79,8 @@ using WebKit::WebVector; ...@@ -79,6 +79,8 @@ using WebKit::WebVector;
using WebKit::WrappedResourceRequest; using WebKit::WrappedResourceRequest;
using WebKit::WrappedResourceResponse; using WebKit::WrappedResourceResponse;
using webkit_glue::Alt404PageResourceFetcher;
// Domain for internal error codes. // Domain for internal error codes.
static const char kInternalErrorDomain[] = "webkit_glue"; static const char kInternalErrorDomain[] = "webkit_glue";
......
...@@ -16,13 +16,17 @@ MSVC_POP_WARNING(); ...@@ -16,13 +16,17 @@ MSVC_POP_WARNING();
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "webkit/glue/webview_delegate.h" #include "webkit/glue/webview_delegate.h"
#include "webkit/glue/window_open_disposition.h" #include "webkit/glue/window_open_disposition.h"
namespace WebCore { namespace WebCore {
class Frame; class Frame;
class HTMLFormElement; class HTMLFormElement;
class Widget; class Widget;
} }
namespace webkit_glue {
class Alt404PageResourceFetcher; class Alt404PageResourceFetcher;
}
class WebFrameImpl; class WebFrameImpl;
class WebPluginContainer; class WebPluginContainer;
...@@ -227,7 +231,7 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient { ...@@ -227,7 +231,7 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient {
WebFrameImpl* webframe_; WebFrameImpl* webframe_;
// Resource fetcher for downloading an alternate 404 page. // Resource fetcher for downloading an alternate 404 page.
scoped_ptr<Alt404PageResourceFetcher> alt_404_page_fetcher_; scoped_ptr<webkit_glue::Alt404PageResourceFetcher> alt_404_page_fetcher_;
bool postpone_loading_data_; bool postpone_loading_data_;
std::string postponed_data_; std::string postponed_data_;
......
...@@ -127,6 +127,8 @@ using WebKit::WebPoint; ...@@ -127,6 +127,8 @@ using WebKit::WebPoint;
using WebKit::WebRect; using WebKit::WebRect;
using WebKit::WebSize; using WebKit::WebSize;
using webkit_glue::ImageResourceFetcher;
// Change the text zoom level by kTextSizeMultiplierRatio each time the user // Change the text zoom level by kTextSizeMultiplierRatio each time the user
// zooms text in or out (ie., change by 20%). The min and max values limit // zooms text in or out (ie., change by 20%). The min and max values limit
// text zoom to half and 3x the original text size. These three values match // text zoom to half and 3x the original text size. These three values match
...@@ -1343,11 +1345,13 @@ void WebViewImpl::SetInitialFocus(bool reverse) { ...@@ -1343,11 +1345,13 @@ void WebViewImpl::SetInitialFocus(bool reverse) {
} }
} }
bool WebViewImpl::DownloadImage(int id, const GURL& image_url, int image_size) { bool WebViewImpl::DownloadImage(int id, const GURL& image_url,
int image_size) {
if (!page_.get()) if (!page_.get())
return false; return false;
image_fetchers_.insert( image_fetchers_.insert(new ImageResourceFetcher(
new ImageResourceFetcher(this, id, image_url, image_size)); image_url, main_frame(), id, image_size,
NewCallback(this, &WebViewImpl::OnImageFetchComplete)));
return true; return true;
} }
...@@ -1779,12 +1783,11 @@ void WebViewImpl::StartDragging(const WebDragData& drag_data) { ...@@ -1779,12 +1783,11 @@ void WebViewImpl::StartDragging(const WebDragData& drag_data) {
} }
} }
void WebViewImpl::ImageResourceDownloadDone(ImageResourceFetcher* fetcher, void WebViewImpl::OnImageFetchComplete(ImageResourceFetcher* fetcher,
bool errored, const SkBitmap& image) {
const SkBitmap& image) {
if (delegate_) { if (delegate_) {
delegate_->DidDownloadImage(fetcher->id(), fetcher->image_url(), errored, delegate_->DidDownloadImage(fetcher->id(), fetcher->image_url(),
image); image.isNull(), image);
} }
DeleteImageResourceFetcher(fetcher); DeleteImageResourceFetcher(fetcher);
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "webkit/api/public/WebPoint.h" #include "webkit/api/public/WebPoint.h"
#include "webkit/api/public/WebSize.h" #include "webkit/api/public/WebSize.h"
#include "webkit/glue/back_forward_list_client_impl.h" #include "webkit/glue/back_forward_list_client_impl.h"
#include "webkit/glue/image_resource_fetcher.h"
#include "webkit/glue/webframe_impl.h" #include "webkit/glue/webframe_impl.h"
#include "webkit/glue/webpreferences.h" #include "webkit/glue/webpreferences.h"
#include "webkit/glue/webview.h" #include "webkit/glue/webview.h"
...@@ -43,7 +44,6 @@ class WebMouseWheelEvent; ...@@ -43,7 +44,6 @@ class WebMouseWheelEvent;
} }
class AutocompletePopupMenuClient; class AutocompletePopupMenuClient;
class ImageResourceFetcher;
class SearchableFormData; class SearchableFormData;
class WebHistoryItemImpl; class WebHistoryItemImpl;
class WebDevToolsAgent; class WebDevToolsAgent;
...@@ -206,11 +206,6 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { ...@@ -206,11 +206,6 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> {
// Start a system drag and drop operation. // Start a system drag and drop operation.
void StartDragging(const WebKit::WebDragData& drag_data); void StartDragging(const WebKit::WebDragData& drag_data);
// ImageResourceFetcher callback.
void ImageResourceDownloadDone(ImageResourceFetcher* fetcher,
bool errored,
const SkBitmap& image);
// Hides the autocomplete popup if it is showing. // Hides the autocomplete popup if it is showing.
void HideAutoCompletePopup(); void HideAutoCompletePopup();
...@@ -222,6 +217,10 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { ...@@ -222,6 +217,10 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> {
friend class WebView; // So WebView::Create can call our constructor friend class WebView; // So WebView::Create can call our constructor
friend class base::RefCounted<WebViewImpl>; friend class base::RefCounted<WebViewImpl>;
// ImageResourceFetcher::Callback.
void OnImageFetchComplete(webkit_glue::ImageResourceFetcher* fetcher,
const SkBitmap& bitmap);
WebViewImpl(); WebViewImpl();
~WebViewImpl(); ~WebViewImpl();
...@@ -269,7 +268,7 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { ...@@ -269,7 +268,7 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> {
// Removes fetcher from the set of pending image fetchers and deletes it. // Removes fetcher from the set of pending image fetchers and deletes it.
// This is invoked after the download is completed (or fails). // This is invoked after the download is completed (or fails).
void DeleteImageResourceFetcher(ImageResourceFetcher* fetcher); void DeleteImageResourceFetcher(webkit_glue::ImageResourceFetcher* fetcher);
// Converts |pos| from window coordinates to contents coordinates and gets // Converts |pos| from window coordinates to contents coordinates and gets
// the HitTestResult for it. // the HitTestResult for it.
...@@ -277,7 +276,7 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { ...@@ -277,7 +276,7 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> {
const WebCore::IntPoint& pos); const WebCore::IntPoint& pos);
// ImageResourceFetchers schedule via DownloadImage. // ImageResourceFetchers schedule via DownloadImage.
std::set<ImageResourceFetcher*> image_fetchers_; std::set<webkit_glue::ImageResourceFetcher*> image_fetchers_;
// The point relative to the client area where the mouse was last pressed // The point relative to the client area where the mouse was last pressed
// down. This is used by the drag client to determine what was under the // down. This is used by the drag client to determine what was under the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment