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

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

Powered by Google App Engine
This is Rietveld 408576698