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

Side by Side Diff: webkit/plugins/ppapi/url_request_info_util.cc

Issue 10913257: Convert url request info to new proxy API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 "webkit/plugins/ppapi/ppb_url_request_info_impl.h" 5 #include "webkit/plugins/ppapi/url_request_info_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "googleurl/src/url_util.h" 10 #include "googleurl/src/url_util.h"
11 #include "net/http/http_util.h" 11 #include "net/http/http_util.h"
12 #include "ppapi/shared_impl/url_request_info_data.h"
12 #include "ppapi/shared_impl/var.h" 13 #include "ppapi/shared_impl/var.h"
13 #include "ppapi/thunk/enter.h" 14 #include "ppapi/thunk/enter.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody. h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody. h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h"
20 #include "webkit/glue/webkit_glue.h" 21 #include "webkit/glue/webkit_glue.h"
21 #include "webkit/glue/weburlrequest_extradata_impl.h" 22 #include "webkit/glue/weburlrequest_extradata_impl.h"
22 #include "webkit/plugins/ppapi/common.h" 23 #include "webkit/plugins/ppapi/common.h"
23 #include "webkit/plugins/ppapi/plugin_module.h" 24 #include "webkit/plugins/ppapi/plugin_module.h"
24 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" 25 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
25 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" 26 #include "webkit/plugins/ppapi/ppb_file_system_impl.h"
26 #include "webkit/plugins/ppapi/resource_helper.h" 27 #include "webkit/plugins/ppapi/resource_helper.h"
27 28
28 using ppapi::PPB_URLRequestInfo_Data; 29 using ppapi::URLRequestInfoData;
29 using ppapi::Resource; 30 using ppapi::Resource;
30 using ppapi::thunk::EnterResourceNoLock; 31 using ppapi::thunk::EnterResourceNoLock;
31 using ppapi::thunk::PPB_FileRef_API; 32 using ppapi::thunk::PPB_FileRef_API;
32 using WebKit::WebData; 33 using WebKit::WebData;
33 using WebKit::WebHTTPBody; 34 using WebKit::WebHTTPBody;
34 using WebKit::WebString; 35 using WebKit::WebString;
35 using WebKit::WebFrame; 36 using WebKit::WebFrame;
36 using WebKit::WebURL; 37 using WebKit::WebURL;
37 using WebKit::WebURLRequest; 38 using WebKit::WebURLRequest;
38 39
39 namespace webkit { 40 namespace webkit {
40 namespace ppapi { 41 namespace ppapi {
41 42
42 namespace { 43 namespace {
43 44
44 const int32_t kDefaultPrefetchBufferUpperThreshold = 100 * 1000 * 1000; 45 // Appends the file ref given the Resource pointer associated with it to the
45 const int32_t kDefaultPrefetchBufferLowerThreshold = 50 * 1000 * 1000; 46 // given HTTP body, returning true on success.
brettw 2012/09/13 23:23:59 This stuff was moved from below (no longer exposed
47 bool AppendFileRefToBody(
48 Resource* file_ref_resource,
49 int64_t start_offset,
50 int64_t number_of_bytes,
51 PP_Time expected_last_modified_time,
52 WebHTTPBody *http_body) {
53 // Get the underlying file ref impl.
54 if (!file_ref_resource)
55 return false;
56 PPB_FileRef_API* file_ref_api = file_ref_resource->AsPPB_FileRef_API();
57 if (!file_ref_api)
58 return false;
59 const PPB_FileRef_Impl* file_ref =
60 static_cast<PPB_FileRef_Impl*>(file_ref_api);
61
62 PluginDelegate* plugin_delegate =
63 ResourceHelper::GetPluginDelegate(file_ref_resource);
64 if (!plugin_delegate)
65 return false;
66
67 FilePath platform_path;
68 switch (file_ref->GetFileSystemType()) {
69 case PP_FILESYSTEMTYPE_LOCALTEMPORARY:
70 case PP_FILESYSTEMTYPE_LOCALPERSISTENT:
71 // TODO(kinuko): remove this sync IPC when we fully support
72 // AppendURLRange for FileSystem URL.
73 plugin_delegate->SyncGetFileSystemPlatformPath(
74 file_ref->GetFileSystemURL(), &platform_path);
75 break;
76 case PP_FILESYSTEMTYPE_EXTERNAL:
77 platform_path = file_ref->GetSystemPath();
78 break;
79 default:
80 NOTREACHED();
81 }
82 http_body->appendFileRange(
83 webkit_glue::FilePathToWebString(platform_path),
84 start_offset,
85 number_of_bytes,
86 expected_last_modified_time);
87 return true;
88 }
89
90 // Checks that the request data is valid. Returns false on failure. Note that
91 // method and header validation is done by the URL loader when the request is
92 // opened, and any access errors are returned asynchronously.
93 bool ValidateURLRequestData(const ::ppapi::URLRequestInfoData& data) {
94 if (data.prefetch_buffer_lower_threshold < 0 ||
95 data.prefetch_buffer_upper_threshold < 0 ||
96 data.prefetch_buffer_upper_threshold <=
97 data.prefetch_buffer_lower_threshold) {
98 return false;
99 }
100 return true;
101 }
102
103 // Ensures that the file_ref members of the given request info data are
104 // populated from the resource IDs. Returns true on success.
105 bool EnsureFileRefObjectsPopulated(::ppapi::URLRequestInfoData* data) {
106 // Get the Resource objects for any file refs with only host resource (this
107 // is the state of the request as it comes off IPC).
108 for (size_t i = 0; i < data->body.size(); ++i) {
109 URLRequestInfoData::BodyItem& item = data->body[i];
110 if (item.is_file && !item.file_ref) {
111 EnterResourceNoLock<PPB_FileRef_API> enter(
112 item.file_ref_host_resource.host_resource(), false);
113 if (!enter.succeeded())
114 return false;
115 item.file_ref = enter.resource();
116 }
117 }
118 return true;
119 }
46 120
47 } // namespace 121 } // namespace
48 122
49 123 bool CreateWebURLRequest(::ppapi::URLRequestInfoData* data,
50 PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl( 124 WebFrame* frame,
51 PP_Instance instance, 125 WebURLRequest* dest) {
52 const PPB_URLRequestInfo_Data& data) 126 // In the out-of-process case, we've received the URLRequestInfoData
53 : PPB_URLRequestInfo_Shared(::ppapi::OBJECT_IS_IMPL, instance, data) {
54 }
55
56 PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() {
57 }
58
59 bool PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame,
60 WebURLRequest* dest) {
61 // In the out-of-process case, we've received the PPB_URLRequestInfo_Data
62 // from the untrusted plugin and done no validation on it. We need to be 127 // from the untrusted plugin and done no validation on it. We need to be
63 // sure it's not being malicious by checking everything for consistency. 128 // sure it's not being malicious by checking everything for consistency.
64 if (!ValidateData()) 129 if (!ValidateURLRequestData(*data) || !EnsureFileRefObjectsPopulated(data))
65 return false; 130 return false;
66 131
67 dest->initialize(); 132 dest->initialize();
68 dest->setTargetType(WebURLRequest::TargetIsObject); 133 dest->setTargetType(WebURLRequest::TargetIsObject);
69 dest->setURL(frame->document().completeURL(WebString::fromUTF8( 134 dest->setURL(frame->document().completeURL(WebString::fromUTF8(
70 data().url))); 135 data->url)));
71 dest->setDownloadToFile(data().stream_to_file); 136 dest->setDownloadToFile(data->stream_to_file);
72 dest->setReportUploadProgress(data().record_upload_progress); 137 dest->setReportUploadProgress(data->record_upload_progress);
73 138
74 if (!data().method.empty()) 139 if (!data->method.empty())
75 dest->setHTTPMethod(WebString::fromUTF8(data().method)); 140 dest->setHTTPMethod(WebString::fromUTF8(data->method));
76 141
77 dest->setFirstPartyForCookies(frame->document().firstPartyForCookies()); 142 dest->setFirstPartyForCookies(frame->document().firstPartyForCookies());
78 143
79 const std::string& headers = data().headers; 144 const std::string& headers = data->headers;
80 if (!headers.empty()) { 145 if (!headers.empty()) {
81 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r"); 146 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r");
82 while (it.GetNext()) { 147 while (it.GetNext()) {
83 dest->addHTTPHeaderField( 148 dest->addHTTPHeaderField(
84 WebString::fromUTF8(it.name()), 149 WebString::fromUTF8(it.name()),
85 WebString::fromUTF8(it.values())); 150 WebString::fromUTF8(it.values()));
86 } 151 }
87 } 152 }
88 153
89 // Append the upload data. 154 // Append the upload data.
90 if (!data().body.empty()) { 155 if (!data->body.empty()) {
91 WebHTTPBody http_body; 156 WebHTTPBody http_body;
92 http_body.initialize(); 157 http_body.initialize();
93 for (size_t i = 0; i < data().body.size(); ++i) { 158 for (size_t i = 0; i < data->body.size(); ++i) {
94 const PPB_URLRequestInfo_Data::BodyItem& item = data().body[i]; 159 const URLRequestInfoData::BodyItem& item = data->body[i];
95 if (item.is_file) { 160 if (item.is_file) {
96 if (!AppendFileRefToBody(item.file_ref, 161 if (!AppendFileRefToBody(item.file_ref,
97 item.start_offset, 162 item.start_offset,
98 item.number_of_bytes, 163 item.number_of_bytes,
99 item.expected_last_modified_time, 164 item.expected_last_modified_time,
100 &http_body)) 165 &http_body))
101 return false; 166 return false;
102 } else { 167 } else {
103 DCHECK(!item.data.empty()); 168 DCHECK(!item.data.empty());
104 http_body.appendData(WebData(item.data)); 169 http_body.appendData(WebData(item.data));
105 } 170 }
106 } 171 }
107 dest->setHTTPBody(http_body); 172 dest->setHTTPBody(http_body);
108 } 173 }
109 174
110 // Add the "Referer" header if there is a custom referrer. Such requests 175 // Add the "Referer" header if there is a custom referrer. Such requests
111 // require universal access. For all other requests, "Referer" will be set 176 // require universal access. For all other requests, "Referer" will be set
112 // after header security checks are done in AssociatedURLLoader. 177 // after header security checks are done in AssociatedURLLoader.
113 if (data().has_custom_referrer_url && !data().custom_referrer_url.empty()) { 178 if (data->has_custom_referrer_url && !data->custom_referrer_url.empty())
114 frame->setReferrerForRequest(*dest, GURL(data().custom_referrer_url)); 179 frame->setReferrerForRequest(*dest, GURL(data->custom_referrer_url));
180
181 if (data->has_custom_content_transfer_encoding &&
182 !data->custom_content_transfer_encoding.empty()) {
183 dest->addHTTPHeaderField(
184 WebString::fromUTF8("Content-Transfer-Encoding"),
185 WebString::fromUTF8(data->custom_content_transfer_encoding));
115 } 186 }
116 187
117 if (data().has_custom_content_transfer_encoding && 188 if (data->has_custom_user_agent) {
118 !data().custom_content_transfer_encoding.empty()) {
119 dest->addHTTPHeaderField(
120 WebString::fromUTF8("Content-Transfer-Encoding"),
121 WebString::fromUTF8(data().custom_content_transfer_encoding));
122 }
123
124 if (data().has_custom_user_agent) {
125 dest->setExtraData(new webkit_glue::WebURLRequestExtraDataImpl( 189 dest->setExtraData(new webkit_glue::WebURLRequestExtraDataImpl(
126 WebKit::WebReferrerPolicyDefault, // Ignored. 190 WebKit::WebReferrerPolicyDefault, // Ignored.
127 WebString::fromUTF8(data().custom_user_agent))); 191 WebString::fromUTF8(data->custom_user_agent)));
128 } 192 }
129 193
130 return true; 194 return true;
131 } 195 }
132 196
133 bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const { 197 bool URLRequestRequiresUniversalAccess(
198 const ::ppapi::URLRequestInfoData& data) {
134 return 199 return
135 data().has_custom_referrer_url || 200 data.has_custom_referrer_url ||
136 data().has_custom_content_transfer_encoding || 201 data.has_custom_content_transfer_encoding ||
137 data().has_custom_user_agent || 202 data.has_custom_user_agent ||
138 url_util::FindAndCompareScheme(data().url, "javascript", NULL); 203 url_util::FindAndCompareScheme(data.url, "javascript", NULL);
139 } 204 }
140 205
141 bool PPB_URLRequestInfo_Impl::ValidateData() {
142 if (data().prefetch_buffer_lower_threshold < 0 ||
143 data().prefetch_buffer_upper_threshold < 0 ||
144 data().prefetch_buffer_upper_threshold <=
145 data().prefetch_buffer_lower_threshold) {
146 return false;
147 }
148
149 // Get the Resource objects for any file refs with only host resource (this
150 // is the state of the request as it comes off IPC).
151 for (size_t i = 0; i < data().body.size(); ++i) {
152 PPB_URLRequestInfo_Data::BodyItem& item = data().body[i];
153 if (item.is_file && !item.file_ref) {
154 EnterResourceNoLock<PPB_FileRef_API> enter(
155 item.file_ref_host_resource.host_resource(), false);
156 if (!enter.succeeded())
157 return false;
158 item.file_ref = enter.resource();
159 }
160 }
161 return true;
162 }
163
164 bool PPB_URLRequestInfo_Impl::AppendFileRefToBody(
165 Resource* file_ref_resource,
166 int64_t start_offset,
167 int64_t number_of_bytes,
168 PP_Time expected_last_modified_time,
169 WebHTTPBody *http_body) {
170 // Get the underlying file ref impl.
171 if (!file_ref_resource)
172 return false;
173 PPB_FileRef_API* file_ref_api = file_ref_resource->AsPPB_FileRef_API();
174 if (!file_ref_api)
175 return false;
176 const PPB_FileRef_Impl* file_ref =
177 static_cast<PPB_FileRef_Impl*>(file_ref_api);
178
179 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
180 if (!plugin_delegate)
181 return false;
182
183 FilePath platform_path;
184 switch (file_ref->GetFileSystemType()) {
185 case PP_FILESYSTEMTYPE_LOCALTEMPORARY:
186 case PP_FILESYSTEMTYPE_LOCALPERSISTENT:
187 // TODO(kinuko): remove this sync IPC when we fully support
188 // AppendURLRange for FileSystem URL.
189 plugin_delegate->SyncGetFileSystemPlatformPath(
190 file_ref->GetFileSystemURL(), &platform_path);
191 break;
192 case PP_FILESYSTEMTYPE_EXTERNAL:
193 platform_path = file_ref->GetSystemPath();
194 break;
195 default:
196 NOTREACHED();
197 }
198 http_body->appendFileRange(
199 webkit_glue::FilePathToWebString(platform_path),
200 start_offset,
201 number_of_bytes,
202 expected_last_modified_time);
203 return true;
204 }
205
206
207 } // namespace ppapi 206 } // namespace ppapi
208 } // namespace webkit 207 } // namespace webkit
OLDNEW
« webkit/plugins/ppapi/ppb_url_loader_impl.cc ('K') | « webkit/plugins/ppapi/url_request_info_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698