diff options
Diffstat (limited to 'content/renderer/pepper/url_request_info_util.cc')
-rw-r--r-- | content/renderer/pepper/url_request_info_util.cc | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/content/renderer/pepper/url_request_info_util.cc b/content/renderer/pepper/url_request_info_util.cc index e82c8a1..5b3786b 100644 --- a/content/renderer/pepper/url_request_info_util.cc +++ b/content/renderer/pepper/url_request_info_util.cc @@ -8,10 +8,13 @@ #include "base/strings/string_util.h" #include "content/common/fileapi/file_system_messages.h" #include "content/renderer/pepper/common.h" +#include "content/renderer/pepper/host_globals.h" +#include "content/renderer/pepper/pepper_plugin_instance_impl.h" #include "content/renderer/pepper/plugin_module.h" -#include "content/renderer/pepper/ppb_file_ref_impl.h" #include "content/renderer/render_thread_impl.h" #include "net/http/http_util.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/file_ref_detailed_info.h" #include "ppapi/shared_impl/url_request_info_data.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" @@ -25,10 +28,9 @@ #include "url/url_util.h" #include "webkit/child/weburlrequest_extradata_impl.h" -using ppapi::URLRequestInfoData; using ppapi::Resource; +using ppapi::URLRequestInfoData; using ppapi::thunk::EnterResourceNoLock; -using ppapi::thunk::PPB_FileRef_API; using WebKit::WebData; using WebKit::WebHTTPBody; using WebKit::WebString; @@ -43,32 +45,23 @@ namespace { // Appends the file ref given the Resource pointer associated with it to the // given HTTP body, returning true on success. bool AppendFileRefToBody( - Resource* file_ref_resource, + const ppapi::FileRefDetailedInfo& file_info, int64_t start_offset, int64_t number_of_bytes, PP_Time expected_last_modified_time, WebHTTPBody *http_body) { - // Get the underlying file ref impl. - if (!file_ref_resource) - return false; - PPB_FileRef_API* file_ref_api = file_ref_resource->AsPPB_FileRef_API(); - if (!file_ref_api) - return false; - const PPB_FileRef_Impl* file_ref = - static_cast<PPB_FileRef_Impl*>(file_ref_api); - base::FilePath platform_path; - switch (file_ref->GetFileSystemType()) { + switch (file_info.file_system_type) { case PP_FILESYSTEMTYPE_LOCALTEMPORARY: case PP_FILESYSTEMTYPE_LOCALPERSISTENT: // TODO(kinuko): remove this sync IPC when we fully support // AppendURLRange for FileSystem URL. RenderThreadImpl::current()->Send( new FileSystemHostMsg_SyncGetPlatformPath( - file_ref->GetFileSystemURL(), &platform_path)); + GURL(file_info.file_system_url_spec), &platform_path)); break; case PP_FILESYSTEMTYPE_EXTERNAL: - platform_path = file_ref->GetSystemPath(); + platform_path = file_info.external_path; break; default: NOTREACHED(); @@ -84,7 +77,7 @@ bool AppendFileRefToBody( // Checks that the request data is valid. Returns false on failure. Note that // method and header validation is done by the URL loader when the request is // opened, and any access errors are returned asynchronously. -bool ValidateURLRequestData(const ppapi::URLRequestInfoData& data) { +bool ValidateURLRequestData(const URLRequestInfoData& data) { if (data.prefetch_buffer_lower_threshold < 0 || data.prefetch_buffer_upper_threshold < 0 || data.prefetch_buffer_upper_threshold <= @@ -94,33 +87,16 @@ bool ValidateURLRequestData(const ppapi::URLRequestInfoData& data) { return true; } -// Ensures that the file_ref members of the given request info data are -// populated from the resource IDs. Returns true on success. -bool EnsureFileRefObjectsPopulated(ppapi::URLRequestInfoData* data) { - // Get the Resource objects for any file refs with only host resource (this - // is the state of the request as it comes off IPC). - for (size_t i = 0; i < data->body.size(); ++i) { - URLRequestInfoData::BodyItem& item = data->body[i]; - if (item.is_file && !item.file_ref.get()) { - EnterResourceNoLock<PPB_FileRef_API> enter( - item.file_ref_host_resource.host_resource(), false); - if (!enter.succeeded()) - return false; - item.file_ref = enter.resource(); - } - } - return true; -} - } // namespace -bool CreateWebURLRequest(ppapi::URLRequestInfoData* data, +bool CreateWebURLRequest(PP_Instance instance, + URLRequestInfoData* data, WebFrame* frame, WebURLRequest* dest) { // In the out-of-process case, we've received the URLRequestInfoData // from the untrusted plugin and done no validation on it. We need to be // sure it's not being malicious by checking everything for consistency. - if (!ValidateURLRequestData(*data) || !EnsureFileRefObjectsPopulated(data)) + if (!ValidateURLRequestData(*data)) return false; dest->initialize(); @@ -145,19 +121,44 @@ bool CreateWebURLRequest(ppapi::URLRequestInfoData* data, } } + // Get file information for FileRefs inside BodyItems. + std::vector<PP_Resource> resources; + for (size_t i = 0; i < data->body.size(); ++i) { + const URLRequestInfoData::BodyItem& item = data->body[i]; + if (item.is_file) + resources.push_back(item.file_ref_pp_resource); + } + std::vector<ppapi::FileRefDetailedInfo> infos; + + if (!resources.empty()) { + PepperPluginInstanceImpl* instance_impl = + HostGlobals::Get()->GetInstance(instance); + int child_process_id = instance_impl->module()->GetPluginChildId(); + // The routing id is automatically populated for us when set to 0. + RenderThreadImpl::current()->Send( + new PpapiHostMsg_FileRef_SyncGetInfoForRenderer( + 0, child_process_id, resources, &infos)); + if (infos.size() != resources.size()) + return false; + } + // Append the upload data. if (!data->body.empty()) { WebHTTPBody http_body; http_body.initialize(); + int file_index = 0; for (size_t i = 0; i < data->body.size(); ++i) { const URLRequestInfoData::BodyItem& item = data->body[i]; if (item.is_file) { - if (!AppendFileRefToBody(item.file_ref.get(), + if (item.file_ref_pp_resource != infos[file_index].resource) + return false; + if (!AppendFileRefToBody(infos[file_index], item.start_offset, item.number_of_bytes, item.expected_last_modified_time, &http_body)) return false; + file_index++; } else { DCHECK(!item.data.empty()); http_body.appendData(WebData(item.data)); @@ -190,7 +191,7 @@ bool CreateWebURLRequest(ppapi::URLRequestInfoData* data, return true; } -bool URLRequestRequiresUniversalAccess(const ppapi::URLRequestInfoData& data) { +bool URLRequestRequiresUniversalAccess(const URLRequestInfoData& data) { return data.has_custom_referrer_url || data.has_custom_content_transfer_encoding || |