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

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

Issue 10913257: Convert url request info to new proxy API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
6
7 #include "base/logging.h"
8 #include "base/string_util.h"
9 #include "googleurl/src/gurl.h"
10 #include "googleurl/src/url_util.h"
11 #include "net/http/http_util.h"
12 #include "ppapi/shared_impl/var.h"
13 #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/WebDocument.h"
16 #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/WebURL.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h"
20 #include "webkit/glue/webkit_glue.h"
21 #include "webkit/glue/weburlrequest_extradata_impl.h"
22 #include "webkit/plugins/ppapi/common.h"
23 #include "webkit/plugins/ppapi/plugin_module.h"
24 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
25 #include "webkit/plugins/ppapi/ppb_file_system_impl.h"
26 #include "webkit/plugins/ppapi/resource_helper.h"
27
28 using ppapi::PPB_URLRequestInfo_Data;
29 using ppapi::Resource;
30 using ppapi::thunk::EnterResourceNoLock;
31 using ppapi::thunk::PPB_FileRef_API;
32 using WebKit::WebData;
33 using WebKit::WebHTTPBody;
34 using WebKit::WebString;
35 using WebKit::WebFrame;
36 using WebKit::WebURL;
37 using WebKit::WebURLRequest;
38
39 namespace webkit {
40 namespace ppapi {
41
42 namespace {
43
44 const int32_t kDefaultPrefetchBufferUpperThreshold = 100 * 1000 * 1000;
45 const int32_t kDefaultPrefetchBufferLowerThreshold = 50 * 1000 * 1000;
46
47 } // namespace
48
49
50 PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl(
51 PP_Instance instance,
52 const PPB_URLRequestInfo_Data& data)
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
63 // sure it's not being malicious by checking everything for consistency.
64 if (!ValidateData())
65 return false;
66
67 dest->initialize();
68 dest->setTargetType(WebURLRequest::TargetIsObject);
69 dest->setURL(frame->document().completeURL(WebString::fromUTF8(
70 data().url)));
71 dest->setDownloadToFile(data().stream_to_file);
72 dest->setReportUploadProgress(data().record_upload_progress);
73
74 if (!data().method.empty())
75 dest->setHTTPMethod(WebString::fromUTF8(data().method));
76
77 dest->setFirstPartyForCookies(frame->document().firstPartyForCookies());
78
79 const std::string& headers = data().headers;
80 if (!headers.empty()) {
81 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r");
82 while (it.GetNext()) {
83 dest->addHTTPHeaderField(
84 WebString::fromUTF8(it.name()),
85 WebString::fromUTF8(it.values()));
86 }
87 }
88
89 // Append the upload data.
90 if (!data().body.empty()) {
91 WebHTTPBody http_body;
92 http_body.initialize();
93 for (size_t i = 0; i < data().body.size(); ++i) {
94 const PPB_URLRequestInfo_Data::BodyItem& item = data().body[i];
95 if (item.is_file) {
96 if (!AppendFileRefToBody(item.file_ref,
97 item.start_offset,
98 item.number_of_bytes,
99 item.expected_last_modified_time,
100 &http_body))
101 return false;
102 } else {
103 DCHECK(!item.data.empty());
104 http_body.appendData(WebData(item.data));
105 }
106 }
107 dest->setHTTPBody(http_body);
108 }
109
110 // Add the "Referer" header if there is a custom referrer. Such requests
111 // require universal access. For all other requests, "Referer" will be set
112 // after header security checks are done in AssociatedURLLoader.
113 if (data().has_custom_referrer_url && !data().custom_referrer_url.empty()) {
114 frame->setReferrerForRequest(*dest, GURL(data().custom_referrer_url));
115 }
116
117 if (data().has_custom_content_transfer_encoding &&
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(
126 WebKit::WebReferrerPolicyDefault, // Ignored.
127 WebString::fromUTF8(data().custom_user_agent)));
128 }
129
130 return true;
131 }
132
133 bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const {
134 return
135 data().has_custom_referrer_url ||
136 data().has_custom_content_transfer_encoding ||
137 data().has_custom_user_agent ||
138 url_util::FindAndCompareScheme(data().url, "javascript", NULL);
139 }
140
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
208 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_url_request_info_impl.h ('k') | webkit/plugins/ppapi/resource_creation_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698