diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-22 20:52:49 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-22 20:52:49 +0000 |
commit | bb55162dcf0c1100e27b1088125e3ad5175a6621 (patch) | |
tree | b3b5049237b3f5889c6a681cc4104beff8003de6 /webkit | |
parent | ad5de0edcc8f43260e23c8dc0e300133072b5c68 (diff) | |
download | chromium_src-bb55162dcf0c1100e27b1088125e3ad5175a6621.zip chromium_src-bb55162dcf0c1100e27b1088125e3ad5175a6621.tar.gz chromium_src-bb55162dcf0c1100e27b1088125e3ad5175a6621.tar.bz2 |
Pepper stream-to-file plumbing.
This just hooks up the renderer side of the IPC.
R=brettw
BUG=49789
TEST=none
Review URL: http://codereview.chromium.org/3053009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53378 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/media/buffered_data_source.h | 1 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source.cc | 4 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source.h | 4 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_file_ref.cc | 7 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_file_ref.h | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_url_loader.cc | 15 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_url_loader.h | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_url_request_info.cc | 22 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_url_request_info.h | 1 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_url_response_info.cc | 5 | ||||
-rw-r--r-- | webkit/glue/resource_loader_bridge.cc | 3 | ||||
-rw-r--r-- | webkit/glue/resource_loader_bridge.h | 18 | ||||
-rw-r--r-- | webkit/glue/weburlloader_impl.cc | 12 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_resource_loader_bridge.cc | 1 |
14 files changed, 81 insertions, 16 deletions
diff --git a/webkit/glue/media/buffered_data_source.h b/webkit/glue/media/buffered_data_source.h index 0dc2115..5ba3278 100644 --- a/webkit/glue/media/buffered_data_source.h +++ b/webkit/glue/media/buffered_data_source.h @@ -118,6 +118,7 @@ class BufferedResourceLoader : virtual void OnReceivedResponse( const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, bool content_filtered); + virtual void OnDownloadedData(int len) {} virtual void OnReceivedData(const char* data, int len); virtual void OnCompletedRequest(const URLRequestStatus& status, const std::string& security_info); diff --git a/webkit/glue/media/simple_data_source.cc b/webkit/glue/media/simple_data_source.cc index 20bf0af..a2c9725 100644 --- a/webkit/glue/media/simple_data_source.cc +++ b/webkit/glue/media/simple_data_source.cc @@ -120,10 +120,6 @@ bool SimpleDataSource::IsStreaming() { return false; } -void SimpleDataSource::OnDownloadProgress(uint64 position, uint64 size) {} - -void SimpleDataSource::OnUploadProgress(uint64 position, uint64 size) {} - bool SimpleDataSource::OnReceivedRedirect( const GURL& new_url, const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, diff --git a/webkit/glue/media/simple_data_source.h b/webkit/glue/media/simple_data_source.h index 577d973..0fea71d 100644 --- a/webkit/glue/media/simple_data_source.h +++ b/webkit/glue/media/simple_data_source.h @@ -51,8 +51,7 @@ class SimpleDataSource : public media::DataSource, virtual bool IsStreaming(); // webkit_glue::ResourceLoaderBridge::Peer implementation. - virtual void OnDownloadProgress(uint64 position, uint64 size); - virtual void OnUploadProgress(uint64 position, uint64 size); + virtual void OnUploadProgress(uint64 position, uint64 size) {} virtual bool OnReceivedRedirect( const GURL& new_url, const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, @@ -61,6 +60,7 @@ class SimpleDataSource : public media::DataSource, virtual void OnReceivedResponse( const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, bool content_filtered); + virtual void OnDownloadedData(int len) {} virtual void OnReceivedData(const char* data, int len); virtual void OnCompletedRequest(const URLRequestStatus& status, const std::string& security_info); diff --git a/webkit/glue/plugins/pepper_file_ref.cc b/webkit/glue/plugins/pepper_file_ref.cc index 9b42cff..a3181a9 100644 --- a/webkit/glue/plugins/pepper_file_ref.cc +++ b/webkit/glue/plugins/pepper_file_ref.cc @@ -130,6 +130,13 @@ FileRef::FileRef(PluginModule* module, // TODO(darin): Need to initialize system_path_. } +FileRef::FileRef(PluginModule* module, + const FilePath& external_file_path) + : Resource(module), + system_path_(external_file_path), + fs_type_(PP_FILESYSTEMTYPE_EXTERNAL) { +} + FileRef::~FileRef() { } diff --git a/webkit/glue/plugins/pepper_file_ref.h b/webkit/glue/plugins/pepper_file_ref.h index 34e4c3e..52ef8cf 100644 --- a/webkit/glue/plugins/pepper_file_ref.h +++ b/webkit/glue/plugins/pepper_file_ref.h @@ -21,6 +21,8 @@ class FileRef : public Resource { PP_FileSystemType file_system_type, const std::string& validated_path, const std::string& origin); + FileRef(PluginModule* module, + const FilePath& external_file_path); virtual ~FileRef(); // Returns a pointer to the interface implementing PPB_FileRef that is diff --git a/webkit/glue/plugins/pepper_url_loader.cc b/webkit/glue/plugins/pepper_url_loader.cc index aa09686..669ce0d 100644 --- a/webkit/glue/plugins/pepper_url_loader.cc +++ b/webkit/glue/plugins/pepper_url_loader.cc @@ -15,6 +15,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebKitClient.h" #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" +#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" #include "webkit/glue/plugins/pepper_plugin_instance.h" #include "webkit/glue/plugins/pepper_url_request_info.h" #include "webkit/glue/plugins/pepper_url_response_info.h" @@ -148,9 +149,9 @@ URLLoader::URLLoader(PluginInstance* instance) instance_(instance), pending_callback_(), bytes_sent_(0), - total_bytes_to_be_sent_(0), + total_bytes_to_be_sent_(-1), bytes_received_(0), - total_bytes_to_be_received_(0), + total_bytes_to_be_received_(-1), user_buffer_(NULL), user_buffer_size_(0), done_(false) { @@ -248,12 +249,22 @@ void URLLoader::didReceiveResponse(WebURLLoader* loader, if (response_info->Initialize(response)) response_info_ = response_info; + // Sets -1 if the content length is unknown. + total_bytes_to_be_received_ = response.expectedContentLength(); + RunCallback(PP_OK); } +void URLLoader::didDownloadData(WebURLLoader* loader, + int data_length) { + bytes_received_ += data_length; +} + void URLLoader::didReceiveData(WebURLLoader* loader, const char* data, int data_length) { + bytes_received_ += data_length; + buffer_.insert(buffer_.end(), data, data + data_length); if (user_buffer_) { RunCallback(FillUserBuffer()); diff --git a/webkit/glue/plugins/pepper_url_loader.h b/webkit/glue/plugins/pepper_url_loader.h index 088f220..d0d70f1 100644 --- a/webkit/glue/plugins/pepper_url_loader.h +++ b/webkit/glue/plugins/pepper_url_loader.h @@ -49,6 +49,8 @@ class URLLoader : public Resource, public WebKit::WebURLLoaderClient { unsigned long long total_bytes_to_be_sent); virtual void didReceiveResponse(WebKit::WebURLLoader* loader, const WebKit::WebURLResponse& response); + virtual void didDownloadData(WebKit::WebURLLoader* loader, + int data_length); virtual void didReceiveData(WebKit::WebURLLoader* loader, const char* data, int data_length); diff --git a/webkit/glue/plugins/pepper_url_request_info.cc b/webkit/glue/plugins/pepper_url_request_info.cc index d230f20..1229b51 100644 --- a/webkit/glue/plugins/pepper_url_request_info.cc +++ b/webkit/glue/plugins/pepper_url_request_info.cc @@ -122,7 +122,8 @@ const PPB_URLRequestInfo ppb_urlrequestinfo = { } // namespace URLRequestInfo::URLRequestInfo(PluginModule* module) - : Resource(module) { + : Resource(module), + stream_to_file_(false) { } URLRequestInfo::~URLRequestInfo() { @@ -135,8 +136,14 @@ const PPB_URLRequestInfo* URLRequestInfo::GetInterface() { bool URLRequestInfo::SetBooleanProperty(PP_URLRequestProperty property, bool value) { - NOTIMPLEMENTED(); // TODO(darin): Implement me! - return false; + switch (property) { + case PP_URLREQUESTPROPERTY_STREAMTOFILE: + stream_to_file_ = value; + return true; + default: + NOTIMPLEMENTED(); // TODO(darin): Implement me! + return false; + } } bool URLRequestInfo::SetStringProperty(PP_URLRequestProperty property, @@ -167,6 +174,14 @@ bool URLRequestInfo::AppendFileToBody(FileRef* file_ref, int64_t start_offset, int64_t number_of_bytes, PP_Time expected_last_modified_time) { + // Ignore a call to append nothing. + if (number_of_bytes == 0) + return true; + + // Check for bad values. (-1 means read until end of file.) + if (start_offset < 0 || number_of_bytes < -1) + return false; + body_.push_back(BodyItem(file_ref, start_offset, number_of_bytes, @@ -178,6 +193,7 @@ WebURLRequest URLRequestInfo::ToWebURLRequest(WebFrame* frame) const { WebURLRequest web_request; web_request.initialize(); web_request.setURL(frame->document().completeURL(WebString::fromUTF8(url_))); + web_request.setDownloadToFile(stream_to_file_); if (!method_.empty()) web_request.setHTTPMethod(WebString::fromUTF8(method_)); diff --git a/webkit/glue/plugins/pepper_url_request_info.h b/webkit/glue/plugins/pepper_url_request_info.h index ef1452c..a75a013 100644 --- a/webkit/glue/plugins/pepper_url_request_info.h +++ b/webkit/glue/plugins/pepper_url_request_info.h @@ -76,6 +76,7 @@ class URLRequestInfo : public Resource { std::string method_; std::string headers_; Body body_; + bool stream_to_file_; }; } // namespace pepper diff --git a/webkit/glue/plugins/pepper_url_response_info.cc b/webkit/glue/plugins/pepper_url_response_info.cc index bff92aa..fab8cae 100644 --- a/webkit/glue/plugins/pepper_url_response_info.cc +++ b/webkit/glue/plugins/pepper_url_response_info.cc @@ -12,6 +12,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" #include "webkit/glue/plugins/pepper_file_ref.h" #include "webkit/glue/plugins/pepper_var.h" +#include "webkit/glue/webkit_glue.h" using WebKit::WebHTTPHeaderVisitor; using WebKit::WebString; @@ -107,6 +108,10 @@ bool URLResponseInfo::Initialize(const WebURLResponse& response) { HeaderFlattener flattener; response.visitHTTPHeaderFields(&flattener); headers_ = flattener.buffer(); + + WebString file_path = response.downloadFilePath(); + if (!file_path.isNull()) + body_ = new FileRef(module(), webkit_glue::WebStringToFilePath(file_path)); return true; } diff --git a/webkit/glue/resource_loader_bridge.cc b/webkit/glue/resource_loader_bridge.cc index 8845256..ab19082 100644 --- a/webkit/glue/resource_loader_bridge.cc +++ b/webkit/glue/resource_loader_bridge.cc @@ -15,7 +15,8 @@ ResourceLoaderBridge::RequestInfo::RequestInfo() request_type(ResourceType::MAIN_FRAME), request_context(0), appcache_host_id(0), - routing_id(0) { + routing_id(0), + download_to_file(false) { } ResourceLoaderBridge::RequestInfo::~RequestInfo() { diff --git a/webkit/glue/resource_loader_bridge.h b/webkit/glue/resource_loader_bridge.h index e66181f5ec..7d85bd3 100644 --- a/webkit/glue/resource_loader_bridge.h +++ b/webkit/glue/resource_loader_bridge.h @@ -21,6 +21,7 @@ #if defined(OS_POSIX) #include "base/file_descriptor_posix.h" #endif +#include "base/file_path.h" #include "base/platform_file.h" #include "base/ref_counted.h" #include "base/time.h" @@ -32,8 +33,6 @@ namespace net { class HttpResponseHeaders; } -class FilePath; - namespace webkit_glue { class ResourceLoaderBridge { @@ -84,6 +83,10 @@ class ResourceLoaderBridge { // Used to associated the bridge with a frame's network context. int routing_id; + + // If true, then the response body will be downloaded to a file and the + // path to that file will be provided in ResponseInfo::download_file_path. + bool download_to_file; }; // Structure containing timing information for the request. It addresses @@ -191,6 +194,11 @@ class ResourceLoaderBridge { // Tools. LoadTimingInfo load_timing; + // The path to a file that will contain the response body. It may only + // contain a portion of the response body at the time that the ResponseInfo + // becomes available. + FilePath download_file_path; + // True if the response was delivered using SPDY. bool was_fetched_via_spdy; @@ -258,6 +266,12 @@ class ResourceLoaderBridge { virtual void OnReceivedResponse(const ResponseInfo& info, bool content_filtered) = 0; + // Called when a chunk of response data is downloaded. This method may be + // called multiple times or not at all if an error occurs. This method is + // only called if RequestInfo::download_to_file was set to true, and in + // that case, OnReceivedData will not be called. + virtual void OnDownloadedData(int len) = 0; + // Called when a chunk of response data is available. This method may // be called multiple times or not at all if an error occurs. virtual void OnReceivedData(const char* data, int len) = 0; diff --git a/webkit/glue/weburlloader_impl.cc b/webkit/glue/weburlloader_impl.cc index f235734..dcb05fa 100644 --- a/webkit/glue/weburlloader_impl.cc +++ b/webkit/glue/weburlloader_impl.cc @@ -182,6 +182,7 @@ void PopulateURLResponse( response->setWasFetchedViaProxy(info.was_fetched_via_proxy); response->setConnectionID(info.connection_id); response->setConnectionReused(info.connection_reused); + response->setDownloadFilePath(FilePathToWebString(info.download_file_path)); WebURLLoadTiming timing; timing.initialize(); @@ -213,7 +214,7 @@ void PopulateURLResponse( // pass it to GetSuggestedFilename. std::string value; if (headers->EnumerateHeader(NULL, "content-disposition", &value)) { - response->setSuggestedFileName(webkit_glue::FilePathToWebString( + response->setSuggestedFileName(FilePathToWebString( net::GetSuggestedFilename(url, value, "", FilePath()))); } @@ -260,6 +261,7 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context>, GURL* new_first_party_for_cookies); virtual void OnReceivedResponse( const ResourceLoaderBridge::ResponseInfo& info, bool content_filtered); + virtual void OnDownloadedData(int len); virtual void OnReceivedData(const char* data, int len); virtual void OnReceivedCachedMetadata(const char* data, int len); virtual void OnCompletedRequest( @@ -384,7 +386,7 @@ void WebURLLoaderImpl::Context::Start( // TODO(brettw) this should take parameter encoding into account when // creating the GURLs. - webkit_glue::ResourceLoaderBridge::RequestInfo request_info; + ResourceLoaderBridge::RequestInfo request_info; request_info.method = method; request_info.url = url; request_info.first_party_for_cookies = request.firstPartyForCookies(); @@ -397,6 +399,7 @@ void WebURLLoaderImpl::Context::Start( request_info.request_type = FromTargetType(request.targetType()); request_info.appcache_host_id = request.appCacheHostID(); request_info.routing_id = request.requestorID(); + request_info.download_to_file = request.downloadToFile(); bridge_.reset(ResourceLoaderBridge::Create(request_info)); if (!request.httpBody().isNull()) { @@ -545,6 +548,11 @@ void WebURLLoaderImpl::Context::OnReceivedResponse( response_url_ = response.url(); } +void WebURLLoaderImpl::Context::OnDownloadedData(int len) { + if (client_) + client_->didDownloadData(loader_, len); +} + void WebURLLoaderImpl::Context::OnReceivedData(const char* data, int len) { if (!client_) return; diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc index 858391a..0eb0b85 100644 --- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc +++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc @@ -540,6 +540,7 @@ class ResourceLoaderBridgeImpl : public ResourceLoaderBridge { 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; |