Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: content/renderer/pepper/url_request_info_util.cc

Issue 21966004: Pepper: Move FileRef to the "new" resource proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix bug in GetAbsolutePath (fixes FlashDRM test failure) Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/pepper/url_request_info_util.h" 5 #include "content/renderer/pepper/url_request_info_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "content/common/fileapi/file_system_messages.h" 9 #include "content/common/fileapi/file_system_messages.h"
10 #include "content/renderer/pepper/common.h" 10 #include "content/renderer/pepper/common.h"
11 #include "content/renderer/pepper/host_globals.h"
12 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
11 #include "content/renderer/pepper/plugin_module.h" 13 #include "content/renderer/pepper/plugin_module.h"
12 #include "content/renderer/pepper/ppb_file_ref_impl.h"
13 #include "content/renderer/render_thread_impl.h" 14 #include "content/renderer/render_thread_impl.h"
14 #include "net/http/http_util.h" 15 #include "net/http/http_util.h"
16 #include "ppapi/proxy/ppapi_messages.h"
17 #include "ppapi/shared_impl/file_ref_detailed_info.h"
15 #include "ppapi/shared_impl/url_request_info_data.h" 18 #include "ppapi/shared_impl/url_request_info_data.h"
16 #include "ppapi/shared_impl/var.h" 19 #include "ppapi/shared_impl/var.h"
17 #include "ppapi/thunk/enter.h" 20 #include "ppapi/thunk/enter.h"
18 #include "third_party/WebKit/public/platform/WebData.h" 21 #include "third_party/WebKit/public/platform/WebData.h"
19 #include "third_party/WebKit/public/platform/WebHTTPBody.h" 22 #include "third_party/WebKit/public/platform/WebHTTPBody.h"
20 #include "third_party/WebKit/public/platform/WebURL.h" 23 #include "third_party/WebKit/public/platform/WebURL.h"
21 #include "third_party/WebKit/public/platform/WebURLRequest.h" 24 #include "third_party/WebKit/public/platform/WebURLRequest.h"
22 #include "third_party/WebKit/public/web/WebDocument.h" 25 #include "third_party/WebKit/public/web/WebDocument.h"
23 #include "third_party/WebKit/public/web/WebFrame.h" 26 #include "third_party/WebKit/public/web/WebFrame.h"
24 #include "url/gurl.h" 27 #include "url/gurl.h"
25 #include "url/url_util.h" 28 #include "url/url_util.h"
26 #include "webkit/child/weburlrequest_extradata_impl.h" 29 #include "webkit/child/weburlrequest_extradata_impl.h"
27 30
28 using ppapi::URLRequestInfoData; 31 using ppapi::URLRequestInfoData;
29 using ppapi::Resource; 32 using ppapi::Resource;
30 using ppapi::thunk::EnterResourceNoLock; 33 using ppapi::thunk::EnterResourceNoLock;
31 using ppapi::thunk::PPB_FileRef_API;
32 using WebKit::WebData; 34 using WebKit::WebData;
33 using WebKit::WebHTTPBody; 35 using WebKit::WebHTTPBody;
34 using WebKit::WebString; 36 using WebKit::WebString;
35 using WebKit::WebFrame; 37 using WebKit::WebFrame;
36 using WebKit::WebURL; 38 using WebKit::WebURL;
37 using WebKit::WebURLRequest; 39 using WebKit::WebURLRequest;
38 40
39 namespace content { 41 namespace content {
40 42
41 namespace { 43 namespace {
42 44
43 // Appends the file ref given the Resource pointer associated with it to the 45 // Appends the file ref given the Resource pointer associated with it to the
44 // given HTTP body, returning true on success. 46 // given HTTP body, returning true on success.
45 bool AppendFileRefToBody( 47 bool AppendFileRefToBody(
46 Resource* file_ref_resource, 48 PP_Instance instance,
49 PP_Resource resource,
dmichael (off chromium) 2013/08/07 22:19:13 s/resouce/file_ref_resource
47 int64_t start_offset, 50 int64_t start_offset,
48 int64_t number_of_bytes, 51 int64_t number_of_bytes,
49 PP_Time expected_last_modified_time, 52 PP_Time expected_last_modified_time,
50 WebHTTPBody *http_body) { 53 WebHTTPBody *http_body) {
51 // Get the underlying file ref impl. 54 std::vector<PP_Resource> resources;
52 if (!file_ref_resource) 55 resources.push_back(resource);
53 return false; 56 std::vector<ppapi::FileRef_DetailedInfo> infos;
54 PPB_FileRef_API* file_ref_api = file_ref_resource->AsPPB_FileRef_API();
55 if (!file_ref_api)
56 return false;
57 const PPB_FileRef_Impl* file_ref =
58 static_cast<PPB_FileRef_Impl*>(file_ref_api);
59 57
58 // FIXME(teravest): Pull this sync operation out of the loop and only do it
59 // once for the vector of FileRefs.
60 base::FilePath platform_path; 60 base::FilePath platform_path;
61 switch (file_ref->GetFileSystemType()) { 61 PepperPluginInstanceImpl* instance_impl =
62 HostGlobals::Get()->GetInstance(instance);
63 int child_process_id = instance_impl->module()->GetPluginChildId();
64 RenderThreadImpl::current()->Send(
65 new PpapiHostMsg_FileRef_SyncGetInfoForRenderer(
66 0, child_process_id, resources, &infos));
67
68 switch (infos[0].file_system_type) {
62 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: 69 case PP_FILESYSTEMTYPE_LOCALTEMPORARY:
63 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: 70 case PP_FILESYSTEMTYPE_LOCALPERSISTENT:
64 // TODO(kinuko): remove this sync IPC when we fully support 71 // TODO(kinuko): remove this sync IPC when we fully support
65 // AppendURLRange for FileSystem URL. 72 // AppendURLRange for FileSystem URL.
66 RenderThreadImpl::current()->Send( 73 RenderThreadImpl::current()->Send(
67 new FileSystemHostMsg_SyncGetPlatformPath( 74 new FileSystemHostMsg_SyncGetPlatformPath(
68 file_ref->GetFileSystemURL(), &platform_path)); 75 GURL(infos[0].file_system_url_spec), &platform_path));
69 break; 76 break;
70 case PP_FILESYSTEMTYPE_EXTERNAL: 77 case PP_FILESYSTEMTYPE_EXTERNAL:
71 platform_path = file_ref->GetSystemPath(); 78 platform_path = infos[0].external_path;
72 break; 79 break;
73 default: 80 default:
74 NOTREACHED(); 81 NOTREACHED();
75 } 82 }
76 http_body->appendFileRange( 83 http_body->appendFileRange(
77 platform_path.AsUTF16Unsafe(), 84 platform_path.AsUTF16Unsafe(),
78 start_offset, 85 start_offset,
79 number_of_bytes, 86 number_of_bytes,
80 expected_last_modified_time); 87 expected_last_modified_time);
81 return true; 88 return true;
82 } 89 }
83 90
84 // Checks that the request data is valid. Returns false on failure. Note that 91 // Checks that the request data is valid. Returns false on failure. Note that
85 // method and header validation is done by the URL loader when the request is 92 // method and header validation is done by the URL loader when the request is
86 // opened, and any access errors are returned asynchronously. 93 // opened, and any access errors are returned asynchronously.
87 bool ValidateURLRequestData(const ::ppapi::URLRequestInfoData& data) { 94 bool ValidateURLRequestData(const ::ppapi::URLRequestInfoData& data) {
88 if (data.prefetch_buffer_lower_threshold < 0 || 95 if (data.prefetch_buffer_lower_threshold < 0 ||
89 data.prefetch_buffer_upper_threshold < 0 || 96 data.prefetch_buffer_upper_threshold < 0 ||
90 data.prefetch_buffer_upper_threshold <= 97 data.prefetch_buffer_upper_threshold <=
91 data.prefetch_buffer_lower_threshold) { 98 data.prefetch_buffer_lower_threshold) {
92 return false; 99 return false;
93 } 100 }
94 return true; 101 return true;
95 } 102 }
96 103
97 // Ensures that the file_ref members of the given request info data are
98 // populated from the resource IDs. Returns true on success.
99 bool EnsureFileRefObjectsPopulated(::ppapi::URLRequestInfoData* data) {
100 // Get the Resource objects for any file refs with only host resource (this
101 // is the state of the request as it comes off IPC).
102 for (size_t i = 0; i < data->body.size(); ++i) {
103 URLRequestInfoData::BodyItem& item = data->body[i];
104 if (item.is_file && !item.file_ref.get()) {
105 EnterResourceNoLock<PPB_FileRef_API> enter(
106 item.file_ref_host_resource.host_resource(), false);
107 if (!enter.succeeded())
108 return false;
109 item.file_ref = enter.resource();
110 }
111 }
112 return true;
113 }
114
115 } // namespace 104 } // namespace
116 105
117 bool CreateWebURLRequest(::ppapi::URLRequestInfoData* data, 106 bool CreateWebURLRequest(PP_Instance instance,
107 ::ppapi::URLRequestInfoData* data,
118 WebFrame* frame, 108 WebFrame* frame,
119 WebURLRequest* dest) { 109 WebURLRequest* dest) {
120 // In the out-of-process case, we've received the URLRequestInfoData 110 // In the out-of-process case, we've received the URLRequestInfoData
121 // from the untrusted plugin and done no validation on it. We need to be 111 // from the untrusted plugin and done no validation on it. We need to be
122 // sure it's not being malicious by checking everything for consistency. 112 // sure it's not being malicious by checking everything for consistency.
123 if (!ValidateURLRequestData(*data) || !EnsureFileRefObjectsPopulated(data)) 113 if (!ValidateURLRequestData(*data))
124 return false; 114 return false;
125 115
126 dest->initialize(); 116 dest->initialize();
127 dest->setTargetType(WebURLRequest::TargetIsObject); 117 dest->setTargetType(WebURLRequest::TargetIsObject);
128 dest->setURL(frame->document().completeURL(WebString::fromUTF8( 118 dest->setURL(frame->document().completeURL(WebString::fromUTF8(
129 data->url))); 119 data->url)));
130 dest->setDownloadToFile(data->stream_to_file); 120 dest->setDownloadToFile(data->stream_to_file);
131 dest->setReportUploadProgress(data->record_upload_progress); 121 dest->setReportUploadProgress(data->record_upload_progress);
132 122
133 if (!data->method.empty()) 123 if (!data->method.empty())
(...skipping 11 matching lines...) Expand all
145 } 135 }
146 } 136 }
147 137
148 // Append the upload data. 138 // Append the upload data.
149 if (!data->body.empty()) { 139 if (!data->body.empty()) {
150 WebHTTPBody http_body; 140 WebHTTPBody http_body;
151 http_body.initialize(); 141 http_body.initialize();
152 for (size_t i = 0; i < data->body.size(); ++i) { 142 for (size_t i = 0; i < data->body.size(); ++i) {
153 const URLRequestInfoData::BodyItem& item = data->body[i]; 143 const URLRequestInfoData::BodyItem& item = data->body[i];
154 if (item.is_file) { 144 if (item.is_file) {
155 if (!AppendFileRefToBody(item.file_ref.get(), 145 if (!AppendFileRefToBody(instance,
146 item.file_ref_pp_resource,
156 item.start_offset, 147 item.start_offset,
157 item.number_of_bytes, 148 item.number_of_bytes,
158 item.expected_last_modified_time, 149 item.expected_last_modified_time,
159 &http_body)) 150 &http_body))
160 return false; 151 return false;
161 } else { 152 } else {
162 DCHECK(!item.data.empty()); 153 DCHECK(!item.data.empty());
163 http_body.appendData(WebData(item.data)); 154 http_body.appendData(WebData(item.data));
164 } 155 }
165 } 156 }
(...skipping 27 matching lines...) Expand all
193 bool URLRequestRequiresUniversalAccess( 184 bool URLRequestRequiresUniversalAccess(
194 const ::ppapi::URLRequestInfoData& data) { 185 const ::ppapi::URLRequestInfoData& data) {
195 return 186 return
196 data.has_custom_referrer_url || 187 data.has_custom_referrer_url ||
197 data.has_custom_content_transfer_encoding || 188 data.has_custom_content_transfer_encoding ||
198 data.has_custom_user_agent || 189 data.has_custom_user_agent ||
199 url_util::FindAndCompareScheme(data.url, "javascript", NULL); 190 url_util::FindAndCompareScheme(data.url, "javascript", NULL);
200 } 191 }
201 192
202 } // namespace content 193 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/url_request_info_util.h ('k') | content/renderer/pepper/url_response_info_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698