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

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

Issue 5828003: Move the Pepper implementation from webkit/glue/plugins/pepper_* to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/glue/plugins/pepper_url_request_info.h" 5 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.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 "net/http/http_util.h" 10 #include "net/http/http_util.h"
11 #include "ppapi/c/pp_var.h" 11 #include "ppapi/c/pp_var.h"
12 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" 12 #include "third_party/WebKit/WebKit/chromium/public/WebData.h"
13 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" 13 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
14 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" 14 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
15 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPBody.h" 15 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPBody.h"
16 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" 16 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
17 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" 17 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
18 #include "webkit/glue/plugins/pepper_common.h" 18 #include "webkit/plugins/ppapi/common.h"
19 #include "webkit/glue/plugins/pepper_file_ref.h" 19 #include "webkit/plugins/ppapi/plugin_module.h"
20 #include "webkit/glue/plugins/pepper_plugin_module.h" 20 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
21 #include "webkit/glue/plugins/pepper_string.h" 21 #include "webkit/plugins/ppapi/string.h"
22 #include "webkit/glue/plugins/pepper_var.h" 22 #include "webkit/plugins/ppapi/var.h"
23 #include "webkit/glue/webkit_glue.h" 23 #include "webkit/glue/webkit_glue.h"
24 24
25 using WebKit::WebData; 25 using WebKit::WebData;
26 using WebKit::WebHTTPBody; 26 using WebKit::WebHTTPBody;
27 using WebKit::WebString; 27 using WebKit::WebString;
28 using WebKit::WebFrame; 28 using WebKit::WebFrame;
29 using WebKit::WebURL; 29 using WebKit::WebURL;
30 using WebKit::WebURLRequest; 30 using WebKit::WebURLRequest;
31 31
32 namespace pepper { 32 namespace webkit {
33 namespace plugins {
34 namespace ppapi {
33 35
34 namespace { 36 namespace {
35 37
36 // If any of these request headers are specified, they will not be sent. 38 // If any of these request headers are specified, they will not be sent.
37 // TODO(darin): Add more based on security considerations? 39 // TODO(darin): Add more based on security considerations?
38 const char* const kIgnoredRequestHeaders[] = { 40 const char* const kIgnoredRequestHeaders[] = {
39 "content-length" 41 "content-length"
40 }; 42 };
41 43
42 PP_Bool IsIgnoredRequestHeader(const std::string& name) { 44 PP_Bool IsIgnoredRequestHeader(const std::string& name) {
43 for (size_t i = 0; i < arraysize(kIgnoredRequestHeaders); ++i) { 45 for (size_t i = 0; i < arraysize(kIgnoredRequestHeaders); ++i) {
44 if (LowerCaseEqualsASCII(name, kIgnoredRequestHeaders[i])) 46 if (LowerCaseEqualsASCII(name, kIgnoredRequestHeaders[i]))
45 return PP_TRUE; 47 return PP_TRUE;
46 } 48 }
47 return PP_FALSE; 49 return PP_FALSE;
48 } 50 }
49 51
50 PP_Resource Create(PP_Module module_id) { 52 PP_Resource Create(PP_Module module_id) {
51 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); 53 PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
52 if (!module) 54 if (!module)
53 return 0; 55 return 0;
54 56
55 URLRequestInfo* request = new URLRequestInfo(module); 57 PPB_URLRequestInfo_Impl* request = new PPB_URLRequestInfo_Impl(module);
56 58
57 return request->GetReference(); 59 return request->GetReference();
58 } 60 }
59 61
60 PP_Bool IsURLRequestInfo(PP_Resource resource) { 62 PP_Bool IsURLRequestInfo(PP_Resource resource) {
61 return BoolToPPBool(!!Resource::GetAs<URLRequestInfo>(resource)); 63 return BoolToPPBool(!!Resource::GetAs<PPB_URLRequestInfo_Impl>(resource));
62 } 64 }
63 65
64 PP_Bool SetProperty(PP_Resource request_id, 66 PP_Bool SetProperty(PP_Resource request_id,
65 PP_URLRequestProperty property, 67 PP_URLRequestProperty property,
66 PP_Var var) { 68 PP_Var var) {
67 scoped_refptr<URLRequestInfo> request( 69 scoped_refptr<PPB_URLRequestInfo_Impl> request(
68 Resource::GetAs<URLRequestInfo>(request_id)); 70 Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id));
69 if (!request) 71 if (!request)
70 return PP_FALSE; 72 return PP_FALSE;
71 73
72 if (var.type == PP_VARTYPE_BOOL) { 74 if (var.type == PP_VARTYPE_BOOL) {
73 return BoolToPPBool( 75 return BoolToPPBool(
74 request->SetBooleanProperty(property, 76 request->SetBooleanProperty(property,
75 PPBoolToBool(var.value.as_bool))); 77 PPBoolToBool(var.value.as_bool)));
76 } 78 }
77 79
78 if (var.type == PP_VARTYPE_STRING) { 80 if (var.type == PP_VARTYPE_STRING) {
79 scoped_refptr<StringVar> string(StringVar::FromPPVar(var)); 81 scoped_refptr<StringVar> string(StringVar::FromPPVar(var));
80 if (string) { 82 if (string) {
81 return BoolToPPBool(request->SetStringProperty(property, 83 return BoolToPPBool(request->SetStringProperty(property,
82 string->value())); 84 string->value()));
83 } 85 }
84 } 86 }
85 87
86 return PP_FALSE; 88 return PP_FALSE;
87 } 89 }
88 90
89 PP_Bool AppendDataToBody(PP_Resource request_id, 91 PP_Bool AppendDataToBody(PP_Resource request_id,
90 const char* data, 92 const char* data,
91 uint32_t len) { 93 uint32_t len) {
92 scoped_refptr<URLRequestInfo> request( 94 scoped_refptr<PPB_URLRequestInfo_Impl> request(
93 Resource::GetAs<URLRequestInfo>(request_id)); 95 Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id));
94 if (!request) 96 if (!request)
95 return PP_FALSE; 97 return PP_FALSE;
96 98
97 return BoolToPPBool(request->AppendDataToBody(std::string(data, len))); 99 return BoolToPPBool(request->AppendDataToBody(std::string(data, len)));
98 } 100 }
99 101
100 PP_Bool AppendFileToBody(PP_Resource request_id, 102 PP_Bool AppendFileToBody(PP_Resource request_id,
101 PP_Resource file_ref_id, 103 PP_Resource file_ref_id,
102 int64_t start_offset, 104 int64_t start_offset,
103 int64_t number_of_bytes, 105 int64_t number_of_bytes,
104 PP_Time expected_last_modified_time) { 106 PP_Time expected_last_modified_time) {
105 scoped_refptr<URLRequestInfo> request( 107 scoped_refptr<PPB_URLRequestInfo_Impl> request(
106 Resource::GetAs<URLRequestInfo>(request_id)); 108 Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id));
107 if (!request) 109 if (!request)
108 return PP_FALSE; 110 return PP_FALSE;
109 111
110 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); 112 scoped_refptr<PPB_FileRef_Impl> file_ref(
113 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id));
111 if (!file_ref) 114 if (!file_ref)
112 return PP_FALSE; 115 return PP_FALSE;
113 116
114 return BoolToPPBool(request->AppendFileToBody(file_ref, 117 return BoolToPPBool(request->AppendFileToBody(file_ref,
115 start_offset, 118 start_offset,
116 number_of_bytes, 119 number_of_bytes,
117 expected_last_modified_time)); 120 expected_last_modified_time));
118 } 121 }
119 122
120 const PPB_URLRequestInfo ppb_urlrequestinfo = { 123 const PPB_URLRequestInfo ppb_urlrequestinfo = {
121 &Create, 124 &Create,
122 &IsURLRequestInfo, 125 &IsURLRequestInfo,
123 &SetProperty, 126 &SetProperty,
124 &AppendDataToBody, 127 &AppendDataToBody,
125 &AppendFileToBody 128 &AppendFileToBody
126 }; 129 };
127 130
128 } // namespace 131 } // namespace
129 132
130 struct URLRequestInfo::BodyItem { 133 struct PPB_URLRequestInfo_Impl::BodyItem {
131 BodyItem(const std::string& data) 134 BodyItem(const std::string& data)
132 : data(data), 135 : data(data),
133 start_offset(0), 136 start_offset(0),
134 number_of_bytes(-1), 137 number_of_bytes(-1),
135 expected_last_modified_time(0.0) { 138 expected_last_modified_time(0.0) {
136 } 139 }
137 140
138 BodyItem(FileRef* file_ref, 141 BodyItem(PPB_FileRef_Impl* file_ref,
139 int64_t start_offset, 142 int64_t start_offset,
140 int64_t number_of_bytes, 143 int64_t number_of_bytes,
141 PP_Time expected_last_modified_time) 144 PP_Time expected_last_modified_time)
142 : file_ref(file_ref), 145 : file_ref(file_ref),
143 start_offset(start_offset), 146 start_offset(start_offset),
144 number_of_bytes(number_of_bytes), 147 number_of_bytes(number_of_bytes),
145 expected_last_modified_time(expected_last_modified_time) { 148 expected_last_modified_time(expected_last_modified_time) {
146 } 149 }
147 150
148 std::string data; 151 std::string data;
149 scoped_refptr<FileRef> file_ref; 152 scoped_refptr<PPB_FileRef_Impl> file_ref;
150 int64_t start_offset; 153 int64_t start_offset;
151 int64_t number_of_bytes; 154 int64_t number_of_bytes;
152 PP_Time expected_last_modified_time; 155 PP_Time expected_last_modified_time;
153 }; 156 };
154 157
155 URLRequestInfo::URLRequestInfo(PluginModule* module) 158 PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl(PluginModule* module)
156 : Resource(module), 159 : Resource(module),
157 stream_to_file_(false), 160 stream_to_file_(false),
158 follow_redirects_(true), 161 follow_redirects_(true),
159 record_download_progress_(false), 162 record_download_progress_(false),
160 record_upload_progress_(false) { 163 record_upload_progress_(false) {
161 } 164 }
162 165
163 URLRequestInfo::~URLRequestInfo() { 166 PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() {
164 } 167 }
165 168
166 // static 169 // static
167 const PPB_URLRequestInfo* URLRequestInfo::GetInterface() { 170 const PPB_URLRequestInfo* PPB_URLRequestInfo_Impl::GetInterface() {
168 return &ppb_urlrequestinfo; 171 return &ppb_urlrequestinfo;
169 } 172 }
170 173
171 URLRequestInfo* URLRequestInfo::AsURLRequestInfo() { 174 PPB_URLRequestInfo_Impl* PPB_URLRequestInfo_Impl::AsURLRequestInfo() {
172 return this; 175 return this;
173 } 176 }
174 177
175 bool URLRequestInfo::SetBooleanProperty(PP_URLRequestProperty property, 178 bool PPB_URLRequestInfo_Impl::SetBooleanProperty(PP_URLRequestProperty property,
176 bool value) { 179 bool value) {
177 switch (property) { 180 switch (property) {
178 case PP_URLREQUESTPROPERTY_STREAMTOFILE: 181 case PP_URLREQUESTPROPERTY_STREAMTOFILE:
179 stream_to_file_ = value; 182 stream_to_file_ = value;
180 return true; 183 return true;
181 case PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS: 184 case PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS:
182 follow_redirects_ = value; 185 follow_redirects_ = value;
183 return true; 186 return true;
184 case PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS: 187 case PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS:
185 record_download_progress_ = value; 188 record_download_progress_ = value;
186 return true; 189 return true;
187 case PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS: 190 case PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS:
188 record_upload_progress_ = value; 191 record_upload_progress_ = value;
189 return true; 192 return true;
190 default: 193 default:
191 //NOTIMPLEMENTED(); // TODO(darin): Implement me! 194 //NOTIMPLEMENTED(); // TODO(darin): Implement me!
192 return false; 195 return false;
193 } 196 }
194 } 197 }
195 198
196 bool URLRequestInfo::SetStringProperty(PP_URLRequestProperty property, 199 bool PPB_URLRequestInfo_Impl::SetStringProperty(PP_URLRequestProperty property,
197 const std::string& value) { 200 const std::string& value) {
198 // TODO(darin): Validate input. Perhaps at a different layer? 201 // TODO(darin): Validate input. Perhaps at a different layer?
199 switch (property) { 202 switch (property) {
200 case PP_URLREQUESTPROPERTY_URL: 203 case PP_URLREQUESTPROPERTY_URL:
201 url_ = value; // NOTE: This may be a relative URL. 204 url_ = value; // NOTE: This may be a relative URL.
202 return true; 205 return true;
203 case PP_URLREQUESTPROPERTY_METHOD: 206 case PP_URLREQUESTPROPERTY_METHOD:
204 method_ = value; 207 method_ = value;
205 return true; 208 return true;
206 case PP_URLREQUESTPROPERTY_HEADERS: 209 case PP_URLREQUESTPROPERTY_HEADERS:
207 headers_ = value; 210 headers_ = value;
208 return true; 211 return true;
209 default: 212 default:
210 return false; 213 return false;
211 } 214 }
212 } 215 }
213 216
214 bool URLRequestInfo::AppendDataToBody(const std::string& data) { 217 bool PPB_URLRequestInfo_Impl::AppendDataToBody(const std::string& data) {
215 if (!data.empty()) 218 if (!data.empty())
216 body_.push_back(BodyItem(data)); 219 body_.push_back(BodyItem(data));
217 return true; 220 return true;
218 } 221 }
219 222
220 bool URLRequestInfo::AppendFileToBody(FileRef* file_ref, 223 bool PPB_URLRequestInfo_Impl::AppendFileToBody(
221 int64_t start_offset, 224 PPB_FileRef_Impl* file_ref,
222 int64_t number_of_bytes, 225 int64_t start_offset,
223 PP_Time expected_last_modified_time) { 226 int64_t number_of_bytes,
227 PP_Time expected_last_modified_time) {
224 // Ignore a call to append nothing. 228 // Ignore a call to append nothing.
225 if (number_of_bytes == 0) 229 if (number_of_bytes == 0)
226 return true; 230 return true;
227 231
228 // Check for bad values. (-1 means read until end of file.) 232 // Check for bad values. (-1 means read until end of file.)
229 if (start_offset < 0 || number_of_bytes < -1) 233 if (start_offset < 0 || number_of_bytes < -1)
230 return false; 234 return false;
231 235
232 body_.push_back(BodyItem(file_ref, 236 body_.push_back(BodyItem(file_ref,
233 start_offset, 237 start_offset,
234 number_of_bytes, 238 number_of_bytes,
235 expected_last_modified_time)); 239 expected_last_modified_time));
236 return true; 240 return true;
237 } 241 }
238 242
239 WebURLRequest URLRequestInfo::ToWebURLRequest(WebFrame* frame) const { 243 WebURLRequest PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame) const {
240 WebURLRequest web_request; 244 WebURLRequest web_request;
241 web_request.initialize(); 245 web_request.initialize();
242 web_request.setURL(frame->document().completeURL(WebString::fromUTF8(url_))); 246 web_request.setURL(frame->document().completeURL(WebString::fromUTF8(url_)));
243 web_request.setDownloadToFile(stream_to_file_); 247 web_request.setDownloadToFile(stream_to_file_);
244 248
245 if (!method_.empty()) 249 if (!method_.empty())
246 web_request.setHTTPMethod(WebString::fromUTF8(method_)); 250 web_request.setHTTPMethod(WebString::fromUTF8(method_));
247 251
248 if (!headers_.empty()) { 252 if (!headers_.empty()) {
249 net::HttpUtil::HeadersIterator it(headers_.begin(), headers_.end(), "\n"); 253 net::HttpUtil::HeadersIterator it(headers_.begin(), headers_.end(), "\n");
(...skipping 22 matching lines...) Expand all
272 http_body.appendData(WebData(body_[i].data)); 276 http_body.appendData(WebData(body_[i].data));
273 } 277 }
274 } 278 }
275 web_request.setHTTPBody(http_body); 279 web_request.setHTTPBody(http_body);
276 } 280 }
277 281
278 frame->setReferrerForRequest(web_request, WebURL()); // Use default. 282 frame->setReferrerForRequest(web_request, WebURL()); // Use default.
279 return web_request; 283 return web_request;
280 } 284 }
281 285
282 } // namespace pepper 286 } // namespace ppapi
287 } // namespace plugins
288 } // namespace webkit
289
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698