diff options
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/alt_404_page_resource_fetcher.cc | 15 | ||||
-rw-r--r-- | webkit/glue/alt_404_page_resource_fetcher.h | 20 | ||||
-rw-r--r-- | webkit/glue/alt_error_page_resource_fetcher.cc | 16 | ||||
-rw-r--r-- | webkit/glue/alt_error_page_resource_fetcher.h | 22 | ||||
-rw-r--r-- | webkit/glue/image_resource_fetcher.cc | 50 | ||||
-rw-r--r-- | webkit/glue/image_resource_fetcher.h | 35 | ||||
-rw-r--r-- | webkit/glue/resource_fetcher.cc | 123 | ||||
-rw-r--r-- | webkit/glue/resource_fetcher.h | 99 | ||||
-rw-r--r-- | webkit/glue/resource_fetcher_unittest.cc | 53 | ||||
-rw-r--r-- | webkit/glue/webframe.h | 5 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.cc | 12 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.h | 12 | ||||
-rw-r--r-- | webkit/glue/webframeloaderclient_impl.cc | 2 | ||||
-rw-r--r-- | webkit/glue/webframeloaderclient_impl.h | 6 | ||||
-rw-r--r-- | webkit/glue/webview_impl.cc | 19 | ||||
-rw-r--r-- | webkit/glue/webview_impl.h | 15 |
16 files changed, 267 insertions, 237 deletions
diff --git a/webkit/glue/alt_404_page_resource_fetcher.cc b/webkit/glue/alt_404_page_resource_fetcher.cc index 8e3c140..bc4a51d 100644 --- a/webkit/glue/alt_404_page_resource_fetcher.cc +++ b/webkit/glue/alt_404_page_resource_fetcher.cc @@ -14,13 +14,17 @@ MSVC_POP_WARNING(); #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 double kDownloadTimeoutSec = 3.0; +static const int kDownloadTimeoutSec = 3; Alt404PageResourceFetcher::Alt404PageResourceFetcher( WebFrameLoaderClient* webframeloaderclient, @@ -30,12 +34,13 @@ Alt404PageResourceFetcher::Alt404PageResourceFetcher( : webframeloaderclient_(webframeloaderclient), doc_loader_(doc_loader) { - fetcher_.reset(new ResourceFetcherWithTimeout(url, frame, - kDownloadTimeoutSec, this)); + fetcher_.reset(new ResourceFetcherWithTimeout( + url, WebFrameImpl::FromFrame(frame), kDownloadTimeoutSec, + NewCallback(this, &Alt404PageResourceFetcher::OnURLFetchComplete))); } void Alt404PageResourceFetcher::OnURLFetchComplete( - const WebCore::ResourceResponse& response, + const WebURLResponse& response, const std::string& data) { if (response.httpStatusCode() == 200) { // Only show server response if we got a 200. @@ -45,3 +50,5 @@ void Alt404PageResourceFetcher::OnURLFetchComplete( } 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 index a488ad5..9d04e49 100644 --- a/webkit/glue/alt_404_page_resource_fetcher.h +++ b/webkit/glue/alt_404_page_resource_fetcher.h @@ -2,8 +2,8 @@ // 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__ +#ifndef WEBKIT_GLUE_ALT_404_PAGE_RESOURCE_HANDLE_CLIENT_H_ +#define WEBKIT_GLUE_ALT_404_PAGE_RESOURCE_HANDLE_CLIENT_H_ #include <string> @@ -14,19 +14,18 @@ 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 ResourceFetcher::Delegate { +class Alt404PageResourceFetcher { public: Alt404PageResourceFetcher(WebFrameLoaderClient* webframeloaderclient, WebCore::Frame* frame, WebCore::DocumentLoader* doc_loader, const GURL& url); - virtual void OnURLFetchComplete(const WebCore::ResourceResponse& response, - const std::string& data); - // Stop any pending loads. void Cancel() { if (fetcher_.get()) @@ -34,6 +33,9 @@ class Alt404PageResourceFetcher : public ResourceFetcher::Delegate { } private: + void OnURLFetchComplete(const WebKit::WebURLResponse& response, + const std::string& data); + // Does the actual fetching. scoped_ptr<ResourceFetcherWithTimeout> fetcher_; @@ -45,7 +47,9 @@ class Alt404PageResourceFetcher : public ResourceFetcher::Delegate { // original load. 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_ diff --git a/webkit/glue/alt_error_page_resource_fetcher.cc b/webkit/glue/alt_error_page_resource_fetcher.cc index 139b7cd..72783da 100644 --- a/webkit/glue/alt_error_page_resource_fetcher.cc +++ b/webkit/glue/alt_error_page_resource_fetcher.cc @@ -21,29 +21,33 @@ MSVC_POP_WARNING(); #include "webkit/glue/webview.h" 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 double kDownloadTimeoutSec = 3.0; +static const int kDownloadTimeoutSec = 3; AltErrorPageResourceFetcher::AltErrorPageResourceFetcher( WebView* web_view, + WebFrame* web_frame, const WebURLError& web_error, - WebFrameImpl* web_frame, const GURL& url) : web_view_(web_view), web_error_(web_error), web_frame_(web_frame) { failed_request_ = web_frame_->GetProvisionalDataSource()->request(); - fetcher_.reset(new ResourceFetcherWithTimeout(url, web_frame->frame(), - kDownloadTimeoutSec, this)); + fetcher_.reset(new ResourceFetcherWithTimeout( + url, web_frame, kDownloadTimeoutSec, + NewCallback(this, &AltErrorPageResourceFetcher::OnURLFetchComplete))); } AltErrorPageResourceFetcher::~AltErrorPageResourceFetcher() { } void AltErrorPageResourceFetcher::OnURLFetchComplete( - const WebCore::ResourceResponse& response, + const WebURLResponse& response, const std::string& data) { WebViewDelegate* delegate = web_view_->GetDelegate(); if (!delegate) @@ -59,3 +63,5 @@ void AltErrorPageResourceFetcher::OnURLFetchComplete( web_error_, std::string(), true); } } + +} // namespace webkit_glue
\ No newline at end of file diff --git a/webkit/glue/alt_error_page_resource_fetcher.h b/webkit/glue/alt_error_page_resource_fetcher.h index 1f42892..0ca357b 100644 --- a/webkit/glue/alt_error_page_resource_fetcher.h +++ b/webkit/glue/alt_error_page_resource_fetcher.h @@ -7,12 +7,6 @@ #include <string> -#include "base/compiler_specific.h" - -MSVC_PUSH_WARNING_LEVEL(0); -#include "Timer.h" -MSVC_POP_WARNING(); - #include "base/scoped_ptr.h" #include "webkit/api/public/WebURLError.h" #include "webkit/api/public/WebURLRequest.h" @@ -22,24 +16,26 @@ class ResourceFetcherWithTimeout; class WebFrameImpl; class WebView; +namespace webkit_glue { + // Used for downloading alternate dns error pages. Once downloading is done // (or fails), the webview delegate is notified. -class AltErrorPageResourceFetcher : public ResourceFetcher::Delegate { +class AltErrorPageResourceFetcher { public: AltErrorPageResourceFetcher(WebView* web_view, + WebFrame* web_frame, const WebKit::WebURLError& web_error, - WebFrameImpl* web_frame, const GURL& url); ~AltErrorPageResourceFetcher(); - virtual void OnURLFetchComplete(const WebCore::ResourceResponse& response, - const std::string& data); - 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_; - WebFrameImpl* web_frame_; WebKit::WebURLRequest failed_request_; // Does the actual fetching. @@ -48,4 +44,6 @@ class AltErrorPageResourceFetcher : public ResourceFetcher::Delegate { DISALLOW_COPY_AND_ASSIGN(AltErrorPageResourceFetcher); }; +} // namespace webkit_glue + #endif // WEBKIT_GLUE_ALT_ERROR_PAGE_RESOURCE_FETCHER_H__ diff --git a/webkit/glue/image_resource_fetcher.cc b/webkit/glue/image_resource_fetcher.cc index 5320468c..8c63cc5 100644 --- a/webkit/glue/image_resource_fetcher.cc +++ b/webkit/glue/image_resource_fetcher.cc @@ -2,34 +2,28 @@ // 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 "ImageSourceSkia.h" -MSVC_POP_WARNING(); -#undef LOG - #include "webkit/glue/image_resource_fetcher.h" #include "base/gfx/size.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" +namespace webkit_glue { + ImageResourceFetcher::ImageResourceFetcher( - WebViewImpl* web_view, - int id, const GURL& image_url, - int image_size) - : web_view_(web_view), + WebFrame* frame, + int id, + int image_size, + Callback* callback) + : callback_(callback), id_(id), image_url_(image_url), image_size_(image_size) { - fetcher_.reset(new ResourceFetcher(image_url, - web_view->main_frame()->frame(), - this)); + fetcher_.reset(new ResourceFetcher( + image_url, frame, + NewCallback(this, &ImageResourceFetcher::OnURLFetchComplete))); } ImageResourceFetcher::~ImageResourceFetcher() { @@ -38,21 +32,19 @@ ImageResourceFetcher::~ImageResourceFetcher() { } void ImageResourceFetcher::OnURLFetchComplete( - const WebCore::ResourceResponse& response, + const WebKit::WebURLResponse& response, const std::string& data) { - SkBitmap image; - bool errored = false; - if (response.isNull()) { - errored = true; - } else if (response.httpStatusCode() == 200) { + SkBitmap bitmap; + if (!response.isNull() && response.httpStatusCode() == 200) { // Request succeeded, try to convert it to an image. - webkit_glue::ImageDecoder decoder(gfx::Size(image_size_, image_size_)); - image = decoder.Decode( + ImageDecoder decoder(gfx::Size(image_size_, image_size_)); + bitmap = decoder.Decode( reinterpret_cast<const unsigned char*>(data.data()), data.size()); } // else case: // 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 - // browser will keep trying to download favicon (when this is used to - // download the favicon). - web_view_->ImageResourceDownloadDone(this, errored, image); + // response as an image. The delegate will see a null image, indicating + // that an error occurred. + callback_->Run(this, bitmap); } + +} // namespace webkit_glue diff --git a/webkit/glue/image_resource_fetcher.h b/webkit/glue/image_resource_fetcher.h index d6d73db..1503481 100644 --- a/webkit/glue/image_resource_fetcher.h +++ b/webkit/glue/image_resource_fetcher.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H__ -#define WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H__ +#ifndef WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H_ +#define WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H_ #include "base/basictypes.h" #include "webkit/glue/resource_fetcher.h" @@ -11,34 +11,35 @@ class SkBitmap; class WebViewImpl; +namespace webkit_glue { + // ImageResourceFetcher handles downloading an image for a webview. Once // downloading is done the hosting WebViewImpl is notified. ImageResourceFetcher // is used to download the favicon and images for web apps. -class ImageResourceFetcher : public ResourceFetcher::Delegate { +class ImageResourceFetcher { public: - ImageResourceFetcher(WebViewImpl* web_view, + typedef Callback2<ImageResourceFetcher*, const SkBitmap&>::Type Callback; + + ImageResourceFetcher(const GURL& image_url, + WebFrame* frame, int id, - const GURL& image_url, - int image_size); + int image_size, + Callback* callback); 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. const GURL& image_url() const { return image_url_; } - // Hosting WebView. - WebViewImpl* web_view() const { return web_view_; } - // Unique identifier for the request. int id() const { return id_; } 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. const int id_; @@ -57,4 +58,6 @@ class ImageResourceFetcher : public ResourceFetcher::Delegate { DISALLOW_EVIL_CONSTRUCTORS(ImageResourceFetcher); }; -#endif // WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H__ +} // namespace webkit_glue + +#endif // WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H_ diff --git a/webkit/glue/resource_fetcher.cc b/webkit/glue/resource_fetcher.cc index b72ea54..1716a91 100644 --- a/webkit/glue/resource_fetcher.cc +++ b/webkit/glue/resource_fetcher.cc @@ -2,30 +2,30 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "config.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 "webkit/glue/glue_util.h" -#include "net/url_request/url_request_status.h" - -using WebCore::ResourceError; -using WebCore::ResourceHandle; -using WebCore::ResourceResponse; - -ResourceFetcher::ResourceFetcher(const GURL& url, WebCore::Frame* frame, - Delegate* d) - : url_(url), delegate_(d), completed_(false) { +#include "webkit/api/public/WebKit.h" +#include "webkit/api/public/WebKitClient.h" +#include "webkit/api/public/WebURLError.h" +#include "webkit/api/public/WebURLLoader.h" +#include "webkit/api/public/WebURLRequest.h" +#include "webkit/api/public/WebURL.h" +#include "webkit/glue/webframe.h" + +using base::TimeDelta; +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 do a http request and ignore the results). DCHECK(frame); @@ -35,7 +35,6 @@ ResourceFetcher::ResourceFetcher(const GURL& url, WebCore::Frame* frame, ResourceFetcher::~ResourceFetcher() { if (!completed_ && loader_.get()) loader_->cancel(); - loader_ = NULL; } void ResourceFetcher::Cancel() { @@ -45,68 +44,74 @@ void ResourceFetcher::Cancel() { } } -void ResourceFetcher::Start(WebCore::Frame* frame) { - WebCore::ResourceRequest request(webkit_glue::GURLToKURL(url_)); - WebCore::ResourceResponse response; - frame->loader()->client()->dispatchWillSendRequest(NULL, 0, request, - response); +void ResourceFetcher::Start(WebFrame* frame) { + WebURLRequest request(url_); + frame->DispatchWillSendRequest(&request); - loader_ = ResourceHandle::create(request, this, NULL, false, false); + loader_.reset(WebKit::webKitClient()->createURLLoader()); + loader_->loadAsynchronously(request, this); } ///////////////////////////////////////////////////////////////////////////// -// ResourceHandleClient methods -void ResourceFetcher::didReceiveResponse(ResourceHandle* resource_handle, - const ResourceResponse& response) { - ASSERT(!completed_); - // It's safe to use the ResourceResponse copy constructor - // (xmlhttprequest.cpp uses it). +// WebURLLoaderClient methods + +void ResourceFetcher::willSendRequest( + WebURLLoader* loader, WebURLRequest& new_request, + const WebURLResponse& redirect_response) { +} + +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; } -void ResourceFetcher::didReceiveData(ResourceHandle* resource_handle, - const char* data, int length, - int total_length) { - ASSERT(!completed_); - if (length <= 0) - return; +void ResourceFetcher::didReceiveData( + WebURLLoader* loader, const char* data, int data_length, + long long total_data_length) { + DCHECK(!completed_); + DCHECK(data_length > 0); - data_.append(data, length); + data_.append(data, data_length); } -void ResourceFetcher::didFinishLoading(ResourceHandle* resource_handle) { - ASSERT(!completed_); +void ResourceFetcher::didFinishLoading(WebURLLoader* loader) { + DCHECK(!completed_); completed_ = true; - if (delegate_) - delegate_->OnURLFetchComplete(response_, data_); + if (callback_) + callback_->Run(response_, data_); } -void ResourceFetcher::didFail(ResourceHandle* resource_handle, - const ResourceError& error) { - ASSERT(!completed_); +void ResourceFetcher::didFail(WebURLLoader* loader, const WebURLError& error) { + DCHECK(!completed_); completed_ = true; - // Go ahead and tell our delegate that we're done. Send an empty - // ResourceResponse and string. - if (delegate_) - delegate_->OnURLFetchComplete(ResourceResponse(), std::string()); + // Go ahead and tell our delegate that we're done. + if (callback_) + callback_->Run(WebURLResponse(), std::string()); } ///////////////////////////////////////////////////////////////////////////// // A resource fetcher with a timeout ResourceFetcherWithTimeout::ResourceFetcherWithTimeout( - const GURL& url, WebCore::Frame* frame, double timeout_secs, Delegate* d) - : ResourceFetcher(url, frame, d) { - timeout_timer_.reset(new FetchTimer(this, - &ResourceFetcherWithTimeout::TimeoutFired)); - timeout_timer_->startOneShot(timeout_secs); + const GURL& url, WebFrame* frame, int timeout_secs, Callback* c) + : ResourceFetcher(url, frame, c) { + timeout_timer_.Start(TimeDelta::FromSeconds(timeout_secs), this, + &ResourceFetcherWithTimeout::TimeoutFired); } -void ResourceFetcherWithTimeout::TimeoutFired(FetchTimer* timer) { +void ResourceFetcherWithTimeout::TimeoutFired() { if (!completed_) { loader_->cancel(); - didFail(NULL, ResourceError()); + didFail(NULL, WebURLError()); } } + +} // namespace webkit_glue 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_ diff --git a/webkit/glue/resource_fetcher_unittest.cc b/webkit/glue/resource_fetcher_unittest.cc index c742cee..a5e7022 100644 --- a/webkit/glue/resource_fetcher_unittest.cc +++ b/webkit/glue/resource_fetcher_unittest.cc @@ -2,27 +2,21 @@ // 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 - #if defined(OS_LINUX) #include <gtk/gtk.h> #endif +#include "webkit/api/public/WebURLResponse.h" #include "webkit/glue/unittest_test_server.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/tools/test_shell/simple_resource_loader_bridge.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 { @@ -39,7 +33,7 @@ class ResourceFetcherTests : public TestShellTest { static const int kMaxWaitTimeMs = 5000; static const int kWaitIntervalMs = 100; -class FetcherDelegate : public ResourceFetcher::Delegate { +class FetcherDelegate { public: FetcherDelegate() : timer_id_(0), completed_(false), time_elapsed_ms_(0) { @@ -49,8 +43,12 @@ class FetcherDelegate : public ResourceFetcher::Delegate { CreateTimer(kWaitIntervalMs); } - virtual void OnURLFetchComplete(const ResourceResponse& response, - const std::string& data) { + ResourceFetcher::Callback* NewCallback() { + return ::NewCallback(this, &FetcherDelegate::OnURLFetchComplete); + } + + void OnURLFetchComplete(const WebURLResponse& response, + const std::string& data) { response_ = response; data_ = data; completed_ = true; @@ -63,7 +61,7 @@ class FetcherDelegate : public ResourceFetcher::Delegate { int time_elapsed_ms() const { return time_elapsed_ms_; } 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 // testing infrastructure (test_shell) can generate spurious calls to the @@ -145,7 +143,7 @@ class FetcherDelegate : public ResourceFetcher::Delegate { #endif bool completed_; int time_elapsed_ms_; - ResourceResponse response_; + WebURLResponse response_; std::string data_; }; @@ -157,15 +155,12 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { UnittestTestServer::CreateServer(); ASSERT_TRUE(NULL != server.get()); - WebFrame* web_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(); + WebFrame* frame = test_shell_->webView()->GetMainFrame(); GURL url = server->TestServerPage("files/test_shell/index.html"); scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher( - url, frame, delegate.get())); + url, frame, delegate->NewCallback())); delegate->WaitForResponse(); @@ -177,7 +172,7 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { // Test 404 response. url = server->TestServerPage("files/thisfiledoesntexist.html"); delegate.reset(new FetcherDelegate); - fetcher.reset(new ResourceFetcher(url, frame, delegate.get())); + fetcher.reset(new ResourceFetcher(url, frame, delegate->NewCallback())); delegate->WaitForResponse(); @@ -191,16 +186,13 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) { UnittestTestServer::CreateServer(); ASSERT_TRUE(NULL != server.get()); - WebFrame* web_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(); + WebFrame* frame = test_shell_->webView()->GetMainFrame(); // Try to fetch a page on a site that doesn't exist. GURL url("http://localhost:1339/doesnotexist"); scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher( - url, frame, delegate.get())); + url, frame, delegate->NewCallback())); delegate->WaitForResponse(); @@ -217,17 +209,14 @@ TEST_F(ResourceFetcherTests, ResourceFetcherTimeout) { UnittestTestServer::CreateServer(); ASSERT_TRUE(NULL != server.get()); - WebFrame* web_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(); + WebFrame* frame = test_shell_->webView()->GetMainFrame(); // Grab a page that takes at least 1 sec to respond, but set the fetcher to // timeout in 0 sec. GURL url = server->TestServerPage("slow?1"); scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcherWithTimeout( - url, frame, 0, delegate.get())); + url, frame, 0, delegate->NewCallback())); delegate->WaitForResponse(); diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h index 8745362..2d624d4 100644 --- a/webkit/glue/webframe.h +++ b/webkit/glue/webframe.h @@ -128,6 +128,11 @@ class WebFrame { bool replace, 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. virtual void ExecuteScript(const WebKit::WebScriptSource& source) = 0; diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index 20f4b2a..c941f91 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -195,6 +195,7 @@ using WebCore::RenderObject; using WebCore::ResourceError; using WebCore::ResourceHandle; using WebCore::ResourceRequest; +using WebCore::ResourceResponse; using WebCore::VisibleSelection; using WebCore::ScriptValue; using WebCore::SecurityOrigin; @@ -221,6 +222,8 @@ using WebKit::WebURLError; using WebKit::WebURLRequest; using WebKit::WebURLResponse; +using webkit_glue::AltErrorPageResourceFetcher; + // Key for a StatsCounter tracking how many WebFrames are active. static const char* const kWebFrameActiveCount = "WebFrameActiveCount"; @@ -1562,7 +1565,14 @@ void WebFrameImpl::LoadAlternateHTMLErrorPage(const WebURLRequest& request, replace); 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) { diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index 4919a0b..f22f58b 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -39,7 +39,6 @@ MSVC_PUSH_WARNING_LEVEL(0); #include "PlatformString.h" MSVC_POP_WARNING(); -class AltErrorPageResourceFetcher; class ChromePrintContext; class WebDataSourceImpl; class WebPluginDelegate; @@ -48,6 +47,10 @@ class WebViewImpl; class WebTextInput; class WebTextInputImpl; +namespace gfx { +class BitmapPlatformDevice; +} + namespace WebCore { class Frame; class FrameView; @@ -59,8 +62,8 @@ class SubstituteData; struct WindowFeatures; } -namespace gfx { -class BitmapPlatformDevice; +namespace webkit_glue { +class AltErrorPageResourceFetcher; } // Implementation of WebFrame, note that this is a reference counted object. @@ -98,6 +101,7 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { const GURL& error_page_url, bool replace, const GURL& fake_url); + virtual void DispatchWillSendRequest(WebKit::WebURLRequest* request); virtual void ExecuteScript(const WebKit::WebScriptSource& source); virtual void ExecuteScriptInNewContext( const WebKit::WebScriptSource* sources, int num_sources); @@ -280,7 +284,7 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { int request_id); // 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. static int live_object_count_; diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc index d832ef2..4276160 100644 --- a/webkit/glue/webframeloaderclient_impl.cc +++ b/webkit/glue/webframeloaderclient_impl.cc @@ -79,6 +79,8 @@ using WebKit::WebVector; using WebKit::WrappedResourceRequest; using WebKit::WrappedResourceResponse; +using webkit_glue::Alt404PageResourceFetcher; + // Domain for internal error codes. static const char kInternalErrorDomain[] = "webkit_glue"; diff --git a/webkit/glue/webframeloaderclient_impl.h b/webkit/glue/webframeloaderclient_impl.h index bf49c74..01b6db4 100644 --- a/webkit/glue/webframeloaderclient_impl.h +++ b/webkit/glue/webframeloaderclient_impl.h @@ -16,13 +16,17 @@ MSVC_POP_WARNING(); #include "googleurl/src/gurl.h" #include "webkit/glue/webview_delegate.h" #include "webkit/glue/window_open_disposition.h" + namespace WebCore { class Frame; class HTMLFormElement; class Widget; } +namespace webkit_glue { class Alt404PageResourceFetcher; +} + class WebFrameImpl; class WebPluginContainer; @@ -227,7 +231,7 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient { WebFrameImpl* webframe_; // 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_; std::string postponed_data_; diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index eefe746..45ce865 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -127,6 +127,8 @@ using WebKit::WebPoint; using WebKit::WebRect; using WebKit::WebSize; +using webkit_glue::ImageResourceFetcher; + // 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 // text zoom to half and 3x the original text size. These three values match @@ -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()) return false; - image_fetchers_.insert( - new ImageResourceFetcher(this, id, image_url, image_size)); + image_fetchers_.insert(new ImageResourceFetcher( + image_url, main_frame(), id, image_size, + NewCallback(this, &WebViewImpl::OnImageFetchComplete))); return true; } @@ -1779,12 +1783,11 @@ void WebViewImpl::StartDragging(const WebDragData& drag_data) { } } -void WebViewImpl::ImageResourceDownloadDone(ImageResourceFetcher* fetcher, - bool errored, - const SkBitmap& image) { +void WebViewImpl::OnImageFetchComplete(ImageResourceFetcher* fetcher, + const SkBitmap& image) { if (delegate_) { - delegate_->DidDownloadImage(fetcher->id(), fetcher->image_url(), errored, - image); + delegate_->DidDownloadImage(fetcher->id(), fetcher->image_url(), + image.isNull(), image); } DeleteImageResourceFetcher(fetcher); } diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index c87e0ba..f5908a5 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -13,6 +13,7 @@ #include "webkit/api/public/WebPoint.h" #include "webkit/api/public/WebSize.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/webpreferences.h" #include "webkit/glue/webview.h" @@ -43,7 +44,6 @@ class WebMouseWheelEvent; } class AutocompletePopupMenuClient; -class ImageResourceFetcher; class SearchableFormData; class WebHistoryItemImpl; class WebDevToolsAgent; @@ -206,11 +206,6 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { // Start a system drag and drop operation. 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. void HideAutoCompletePopup(); @@ -222,6 +217,10 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { friend class WebView; // So WebView::Create can call our constructor friend class base::RefCounted<WebViewImpl>; + // ImageResourceFetcher::Callback. + void OnImageFetchComplete(webkit_glue::ImageResourceFetcher* fetcher, + const SkBitmap& bitmap); + WebViewImpl(); ~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. // 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 // the HitTestResult for it. @@ -277,7 +276,7 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { const WebCore::IntPoint& pos); // 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 // down. This is used by the drag client to determine what was under the |