| Index: webkit/tools/test_shell/simple_resource_loader_bridge.cc
|
| ===================================================================
|
| --- webkit/tools/test_shell/simple_resource_loader_bridge.cc (revision 60222)
|
| +++ webkit/tools/test_shell/simple_resource_loader_bridge.cc (working copy)
|
| @@ -33,8 +33,10 @@
|
| #include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
|
|
|
| #include "base/file_path.h"
|
| +#include "base/file_util.h"
|
| #include "base/logging.h"
|
| #include "base/message_loop.h"
|
| +#include "base/message_loop_proxy.h"
|
| #if defined(OS_MACOSX) || defined(OS_WIN)
|
| #include "base/nss_util.h"
|
| #endif
|
| @@ -44,6 +46,7 @@
|
| #include "base/thread.h"
|
| #include "base/waitable_event.h"
|
| #include "net/base/cookie_store.h"
|
| +#include "net/base/file_stream.h"
|
| #include "net/base/io_buffer.h"
|
| #include "net/base/load_flags.h"
|
| #include "net/base/net_errors.h"
|
| @@ -62,6 +65,7 @@
|
| #include "webkit/appcache/appcache_interfaces.h"
|
| #include "webkit/blob/blob_storage_controller.h"
|
| #include "webkit/blob/blob_url_request_job.h"
|
| +#include "webkit/blob/deletable_file_reference.h"
|
| #include "webkit/glue/resource_loader_bridge.h"
|
| #include "webkit/tools/test_shell/simple_appcache_system.h"
|
| #include "webkit/tools/test_shell/simple_socket_stream_bridge.h"
|
| @@ -71,6 +75,7 @@
|
| using webkit_glue::ResourceLoaderBridge;
|
| using net::StaticCookiePolicy;
|
| using net::HttpResponseHeaders;
|
| +using webkit_blob::DeletableFileReference;
|
|
|
| namespace {
|
|
|
| @@ -174,6 +179,7 @@
|
| int load_flags;
|
| ResourceType::Type request_type;
|
| int appcache_host_id;
|
| + bool download_to_file;
|
| scoped_refptr<net::UploadData> upload;
|
| };
|
|
|
| @@ -188,7 +194,8 @@
|
| public:
|
| // Takes ownership of the params.
|
| RequestProxy()
|
| - : buf_(new net::IOBuffer(kDataSize)),
|
| + : download_to_file_(false),
|
| + buf_(new net::IOBuffer(kDataSize)),
|
| last_upload_position_(0) {
|
| }
|
|
|
| @@ -267,6 +274,17 @@
|
| peer_->OnReceivedData(buf_copy.get(), bytes_read);
|
| }
|
|
|
| + void NotifyDownloadedData(int bytes_read) {
|
| + if (!peer_)
|
| + return;
|
| +
|
| + // Continue reading more data, see the comment in NotifyReceivedData.
|
| + g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
|
| + this, &RequestProxy::AsyncReadData));
|
| +
|
| + peer_->OnDownloadedData(bytes_read);
|
| + }
|
| +
|
| void NotifyCompletedRequest(const URLRequestStatus& status,
|
| const std::string& security_info,
|
| const base::Time& complete_time) {
|
| @@ -306,6 +324,17 @@
|
| SimpleAppCacheSystem::SetExtraRequestInfo(
|
| request_.get(), params->appcache_host_id, params->request_type);
|
|
|
| + download_to_file_ = params->download_to_file;
|
| + if (download_to_file_) {
|
| + FilePath path;
|
| + if (file_util::CreateTemporaryFile(&path)) {
|
| + downloaded_file_ = DeletableFileReference::GetOrCreate(
|
| + path, base::MessageLoopProxy::CreateForCurrentThread());
|
| + file_stream_.Open(
|
| + path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE);
|
| + }
|
| + }
|
| +
|
| request_->Start();
|
|
|
| if (request_->has_upload() &&
|
| @@ -377,6 +406,13 @@
|
| }
|
|
|
| virtual void OnReceivedData(int bytes_read) {
|
| + if (download_to_file_) {
|
| + file_stream_.Write(buf_->data(), bytes_read, NULL);
|
| + owner_loop_->PostTask(FROM_HERE, NewRunnableMethod(
|
| + this, &RequestProxy::NotifyDownloadedData, bytes_read));
|
| + return;
|
| + }
|
| +
|
| owner_loop_->PostTask(FROM_HERE, NewRunnableMethod(
|
| this, &RequestProxy::NotifyReceivedData, bytes_read));
|
| }
|
| @@ -384,6 +420,8 @@
|
| virtual void OnCompletedRequest(const URLRequestStatus& status,
|
| const std::string& security_info,
|
| const base::Time& complete_time) {
|
| + if (download_to_file_)
|
| + file_stream_.Close();
|
| owner_loop_->PostTask(FROM_HERE, NewRunnableMethod(
|
| this,
|
| &RequestProxy::NotifyCompletedRequest,
|
| @@ -486,6 +524,8 @@
|
| request->GetMimeType(&info->mime_type);
|
| request->GetCharset(&info->charset);
|
| info->content_length = request->GetExpectedContentSize();
|
| + if (downloaded_file_)
|
| + info->download_file_path = downloaded_file_->path();
|
| SimpleAppCacheSystem::GetExtraResponseInfo(
|
| request,
|
| &info->appcache_id,
|
| @@ -494,6 +534,11 @@
|
|
|
| scoped_ptr<URLRequest> request_;
|
|
|
| + // Support for request.download_to_file behavior.
|
| + bool download_to_file_;
|
| + net::FileStream file_stream_;
|
| + scoped_refptr<DeletableFileReference> downloaded_file_;
|
| +
|
| // Size of our async IO data buffers
|
| static const int kDataSize = 16*1024;
|
|
|
| @@ -553,13 +598,18 @@
|
| }
|
|
|
| virtual void OnReceivedData(int bytes_read) {
|
| - result_->data.append(buf_->data(), bytes_read);
|
| + if (download_to_file_)
|
| + file_stream_.Write(buf_->data(), bytes_read, NULL);
|
| + else
|
| + result_->data.append(buf_->data(), bytes_read);
|
| AsyncReadData(); // read more (may recurse)
|
| }
|
|
|
| virtual void OnCompletedRequest(const URLRequestStatus& status,
|
| const std::string& security_info,
|
| const base::Time& complete_time) {
|
| + if (download_to_file_)
|
| + file_stream_.Close();
|
| result_->status = status;
|
| event_.Signal();
|
| }
|
| @@ -577,7 +627,6 @@
|
| const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info)
|
| : params_(new RequestParams),
|
| proxy_(NULL) {
|
| - DCHECK(!request_info.download_to_file); // Not implemented yet!
|
| params_->method = request_info.method;
|
| params_->url = request_info.url;
|
| params_->first_party_for_cookies = request_info.first_party_for_cookies;
|
| @@ -586,6 +635,7 @@
|
| params_->load_flags = request_info.load_flags;
|
| params_->request_type = request_info.request_type;
|
| params_->appcache_host_id = request_info.appcache_host_id;
|
| + params_->download_to_file = request_info.download_to_file;
|
| }
|
|
|
| virtual ~ResourceLoaderBridgeImpl() {
|
|
|