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

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

Issue 22903002: Revert 216744 "Pepper: Move FileRef to the "new" resource proxy." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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"
13 #include "content/renderer/pepper/plugin_module.h" 11 #include "content/renderer/pepper/plugin_module.h"
12 #include "content/renderer/pepper/ppb_file_ref_impl.h"
14 #include "content/renderer/render_thread_impl.h" 13 #include "content/renderer/render_thread_impl.h"
15 #include "net/http/http_util.h" 14 #include "net/http/http_util.h"
16 #include "ppapi/proxy/ppapi_messages.h"
17 #include "ppapi/shared_impl/file_ref_detailed_info.h"
18 #include "ppapi/shared_impl/url_request_info_data.h" 15 #include "ppapi/shared_impl/url_request_info_data.h"
19 #include "ppapi/shared_impl/var.h" 16 #include "ppapi/shared_impl/var.h"
20 #include "ppapi/thunk/enter.h" 17 #include "ppapi/thunk/enter.h"
21 #include "third_party/WebKit/public/platform/WebData.h" 18 #include "third_party/WebKit/public/platform/WebData.h"
22 #include "third_party/WebKit/public/platform/WebHTTPBody.h" 19 #include "third_party/WebKit/public/platform/WebHTTPBody.h"
23 #include "third_party/WebKit/public/platform/WebURL.h" 20 #include "third_party/WebKit/public/platform/WebURL.h"
24 #include "third_party/WebKit/public/platform/WebURLRequest.h" 21 #include "third_party/WebKit/public/platform/WebURLRequest.h"
25 #include "third_party/WebKit/public/web/WebDocument.h" 22 #include "third_party/WebKit/public/web/WebDocument.h"
26 #include "third_party/WebKit/public/web/WebFrame.h" 23 #include "third_party/WebKit/public/web/WebFrame.h"
27 #include "url/gurl.h" 24 #include "url/gurl.h"
28 #include "url/url_util.h" 25 #include "url/url_util.h"
29 #include "webkit/child/weburlrequest_extradata_impl.h" 26 #include "webkit/child/weburlrequest_extradata_impl.h"
30 27
28 using ppapi::URLRequestInfoData;
31 using ppapi::Resource; 29 using ppapi::Resource;
32 using ppapi::URLRequestInfoData;
33 using ppapi::thunk::EnterResourceNoLock; 30 using ppapi::thunk::EnterResourceNoLock;
31 using ppapi::thunk::PPB_FileRef_API;
34 using WebKit::WebData; 32 using WebKit::WebData;
35 using WebKit::WebHTTPBody; 33 using WebKit::WebHTTPBody;
36 using WebKit::WebString; 34 using WebKit::WebString;
37 using WebKit::WebFrame; 35 using WebKit::WebFrame;
38 using WebKit::WebURL; 36 using WebKit::WebURL;
39 using WebKit::WebURLRequest; 37 using WebKit::WebURLRequest;
40 38
41 namespace content { 39 namespace content {
42 40
43 namespace { 41 namespace {
44 42
45 // Appends the file ref given the Resource pointer associated with it to the 43 // Appends the file ref given the Resource pointer associated with it to the
46 // given HTTP body, returning true on success. 44 // given HTTP body, returning true on success.
47 bool AppendFileRefToBody( 45 bool AppendFileRefToBody(
48 const ppapi::FileRefDetailedInfo& file_info, 46 Resource* file_ref_resource,
49 int64_t start_offset, 47 int64_t start_offset,
50 int64_t number_of_bytes, 48 int64_t number_of_bytes,
51 PP_Time expected_last_modified_time, 49 PP_Time expected_last_modified_time,
52 WebHTTPBody *http_body) { 50 WebHTTPBody *http_body) {
51 // Get the underlying file ref impl.
52 if (!file_ref_resource)
53 return false;
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
53 base::FilePath platform_path; 60 base::FilePath platform_path;
54 switch (file_info.file_system_type) { 61 switch (file_ref->GetFileSystemType()) {
55 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: 62 case PP_FILESYSTEMTYPE_LOCALTEMPORARY:
56 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: 63 case PP_FILESYSTEMTYPE_LOCALPERSISTENT:
57 // TODO(kinuko): remove this sync IPC when we fully support 64 // TODO(kinuko): remove this sync IPC when we fully support
58 // AppendURLRange for FileSystem URL. 65 // AppendURLRange for FileSystem URL.
59 RenderThreadImpl::current()->Send( 66 RenderThreadImpl::current()->Send(
60 new FileSystemHostMsg_SyncGetPlatformPath( 67 new FileSystemHostMsg_SyncGetPlatformPath(
61 GURL(file_info.file_system_url_spec), &platform_path)); 68 file_ref->GetFileSystemURL(), &platform_path));
62 break; 69 break;
63 case PP_FILESYSTEMTYPE_EXTERNAL: 70 case PP_FILESYSTEMTYPE_EXTERNAL:
64 platform_path = file_info.external_path; 71 platform_path = file_ref->GetSystemPath();
65 break; 72 break;
66 default: 73 default:
67 NOTREACHED(); 74 NOTREACHED();
68 } 75 }
69 http_body->appendFileRange( 76 http_body->appendFileRange(
70 platform_path.AsUTF16Unsafe(), 77 platform_path.AsUTF16Unsafe(),
71 start_offset, 78 start_offset,
72 number_of_bytes, 79 number_of_bytes,
73 expected_last_modified_time); 80 expected_last_modified_time);
74 return true; 81 return true;
75 } 82 }
76 83
77 // Checks that the request data is valid. Returns false on failure. Note that 84 // Checks that the request data is valid. Returns false on failure. Note that
78 // method and header validation is done by the URL loader when the request is 85 // method and header validation is done by the URL loader when the request is
79 // opened, and any access errors are returned asynchronously. 86 // opened, and any access errors are returned asynchronously.
80 bool ValidateURLRequestData(const URLRequestInfoData& data) { 87 bool ValidateURLRequestData(const ppapi::URLRequestInfoData& data) {
81 if (data.prefetch_buffer_lower_threshold < 0 || 88 if (data.prefetch_buffer_lower_threshold < 0 ||
82 data.prefetch_buffer_upper_threshold < 0 || 89 data.prefetch_buffer_upper_threshold < 0 ||
83 data.prefetch_buffer_upper_threshold <= 90 data.prefetch_buffer_upper_threshold <=
84 data.prefetch_buffer_lower_threshold) { 91 data.prefetch_buffer_lower_threshold) {
85 return false; 92 return false;
86 } 93 }
87 return true; 94 return true;
88 } 95 }
89 96
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
90 } // namespace 115 } // namespace
91 116
92 bool CreateWebURLRequest(PP_Instance instance, 117 bool CreateWebURLRequest(ppapi::URLRequestInfoData* data,
93 URLRequestInfoData* data,
94 WebFrame* frame, 118 WebFrame* frame,
95 WebURLRequest* dest) { 119 WebURLRequest* dest) {
96 // In the out-of-process case, we've received the URLRequestInfoData 120 // In the out-of-process case, we've received the URLRequestInfoData
97 // from the untrusted plugin and done no validation on it. We need to be 121 // from the untrusted plugin and done no validation on it. We need to be
98 // sure it's not being malicious by checking everything for consistency. 122 // sure it's not being malicious by checking everything for consistency.
99 if (!ValidateURLRequestData(*data)) 123 if (!ValidateURLRequestData(*data) || !EnsureFileRefObjectsPopulated(data))
100 return false; 124 return false;
101 125
102 dest->initialize(); 126 dest->initialize();
103 dest->setTargetType(WebURLRequest::TargetIsObject); 127 dest->setTargetType(WebURLRequest::TargetIsObject);
104 dest->setURL(frame->document().completeURL(WebString::fromUTF8( 128 dest->setURL(frame->document().completeURL(WebString::fromUTF8(
105 data->url))); 129 data->url)));
106 dest->setDownloadToFile(data->stream_to_file); 130 dest->setDownloadToFile(data->stream_to_file);
107 dest->setReportUploadProgress(data->record_upload_progress); 131 dest->setReportUploadProgress(data->record_upload_progress);
108 132
109 if (!data->method.empty()) 133 if (!data->method.empty())
110 dest->setHTTPMethod(WebString::fromUTF8(data->method)); 134 dest->setHTTPMethod(WebString::fromUTF8(data->method));
111 135
112 dest->setFirstPartyForCookies(frame->document().firstPartyForCookies()); 136 dest->setFirstPartyForCookies(frame->document().firstPartyForCookies());
113 137
114 const std::string& headers = data->headers; 138 const std::string& headers = data->headers;
115 if (!headers.empty()) { 139 if (!headers.empty()) {
116 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r"); 140 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r");
117 while (it.GetNext()) { 141 while (it.GetNext()) {
118 dest->addHTTPHeaderField( 142 dest->addHTTPHeaderField(
119 WebString::fromUTF8(it.name()), 143 WebString::fromUTF8(it.name()),
120 WebString::fromUTF8(it.values())); 144 WebString::fromUTF8(it.values()));
121 } 145 }
122 } 146 }
123 147
124 // Get file information for FileRefs inside BodyItems.
125 std::vector<PP_Resource> resources;
126 for (size_t i = 0; i < data->body.size(); ++i) {
127 const URLRequestInfoData::BodyItem& item = data->body[i];
128 if (item.is_file)
129 resources.push_back(item.file_ref_pp_resource);
130 }
131 std::vector<ppapi::FileRefDetailedInfo> infos;
132
133 if (!resources.empty()) {
134 PepperPluginInstanceImpl* instance_impl =
135 HostGlobals::Get()->GetInstance(instance);
136 int child_process_id = instance_impl->module()->GetPluginChildId();
137 // The routing id is automatically populated for us when set to 0.
138 RenderThreadImpl::current()->Send(
139 new PpapiHostMsg_FileRef_SyncGetInfoForRenderer(
140 0, child_process_id, resources, &infos));
141 if (infos.size() != resources.size())
142 return false;
143 }
144
145 // Append the upload data. 148 // Append the upload data.
146 if (!data->body.empty()) { 149 if (!data->body.empty()) {
147 WebHTTPBody http_body; 150 WebHTTPBody http_body;
148 http_body.initialize(); 151 http_body.initialize();
149 int file_index = 0;
150 for (size_t i = 0; i < data->body.size(); ++i) { 152 for (size_t i = 0; i < data->body.size(); ++i) {
151 const URLRequestInfoData::BodyItem& item = data->body[i]; 153 const URLRequestInfoData::BodyItem& item = data->body[i];
152 if (item.is_file) { 154 if (item.is_file) {
153 if (item.file_ref_pp_resource != infos[file_index].resource) 155 if (!AppendFileRefToBody(item.file_ref.get(),
154 return false;
155 if (!AppendFileRefToBody(infos[file_index],
156 item.start_offset, 156 item.start_offset,
157 item.number_of_bytes, 157 item.number_of_bytes,
158 item.expected_last_modified_time, 158 item.expected_last_modified_time,
159 &http_body)) 159 &http_body))
160 return false; 160 return false;
161 file_index++;
162 } else { 161 } else {
163 DCHECK(!item.data.empty()); 162 DCHECK(!item.data.empty());
164 http_body.appendData(WebData(item.data)); 163 http_body.appendData(WebData(item.data));
165 } 164 }
166 } 165 }
167 dest->setHTTPBody(http_body); 166 dest->setHTTPBody(http_body);
168 } 167 }
169 168
170 // Add the "Referer" header if there is a custom referrer. Such requests 169 // Add the "Referer" header if there is a custom referrer. Such requests
171 // require universal access. For all other requests, "Referer" will be set 170 // require universal access. For all other requests, "Referer" will be set
(...skipping 12 matching lines...) Expand all
184 bool was_after_preconnect_request = false; 183 bool was_after_preconnect_request = false;
185 dest->setExtraData(new webkit_glue::WebURLRequestExtraDataImpl( 184 dest->setExtraData(new webkit_glue::WebURLRequestExtraDataImpl(
186 WebKit::WebReferrerPolicyDefault, // Ignored. 185 WebKit::WebReferrerPolicyDefault, // Ignored.
187 WebString::fromUTF8(data->custom_user_agent), 186 WebString::fromUTF8(data->custom_user_agent),
188 was_after_preconnect_request)); 187 was_after_preconnect_request));
189 } 188 }
190 189
191 return true; 190 return true;
192 } 191 }
193 192
194 bool URLRequestRequiresUniversalAccess(const URLRequestInfoData& data) { 193 bool URLRequestRequiresUniversalAccess(const ppapi::URLRequestInfoData& data) {
195 return 194 return
196 data.has_custom_referrer_url || 195 data.has_custom_referrer_url ||
197 data.has_custom_content_transfer_encoding || 196 data.has_custom_content_transfer_encoding ||
198 data.has_custom_user_agent || 197 data.has_custom_user_agent ||
199 url_util::FindAndCompareScheme(data.url, "javascript", NULL); 198 url_util::FindAndCompareScheme(data.url, "javascript", NULL);
200 } 199 }
201 200
202 } // namespace content 201 } // namespace content
OLDNEW
« no previous file with comments | « trunk/src/content/renderer/pepper/url_request_info_util.h ('k') | trunk/src/content/renderer/pepper/url_response_info_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698