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

Side by Side Diff: webkit/glue/plugins/pepper_url_loader.cc

Issue 2925007: Update Chrome to pull latest PPAPI with new uses of point and size.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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) 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_loader.h" 5 #include "webkit/glue/plugins/pepper_url_loader.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "third_party/ppapi/c/pp_completion_callback.h" 8 #include "third_party/ppapi/c/pp_completion_callback.h"
9 #include "third_party/ppapi/c/pp_errors.h" 9 #include "third_party/ppapi/c/pp_errors.h"
10 #include "third_party/ppapi/c/ppb_url_loader.h" 10 #include "third_party/ppapi/c/ppb_url_loader.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 bool IsURLLoader(PP_Resource resource) { 49 bool IsURLLoader(PP_Resource resource) {
50 return !!Resource::GetAs<URLLoader>(resource).get(); 50 return !!Resource::GetAs<URLLoader>(resource).get();
51 } 51 }
52 52
53 int32_t Open(PP_Resource loader_id, 53 int32_t Open(PP_Resource loader_id,
54 PP_Resource request_id, 54 PP_Resource request_id,
55 PP_CompletionCallback callback) { 55 PP_CompletionCallback callback) {
56 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); 56 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id));
57 if (!loader.get()) 57 if (!loader.get())
58 return PP_Error_BadResource; 58 return PP_ERROR_BADRESOURCE;
59 59
60 scoped_refptr<URLRequestInfo> request( 60 scoped_refptr<URLRequestInfo> request(
61 Resource::GetAs<URLRequestInfo>(request_id)); 61 Resource::GetAs<URLRequestInfo>(request_id));
62 if (!request.get()) 62 if (!request.get())
63 return PP_Error_BadResource; 63 return PP_ERROR_BADRESOURCE;
64 64
65 return loader->Open(request, callback); 65 return loader->Open(request, callback);
66 } 66 }
67 67
68 int32_t FollowRedirect(PP_Resource loader_id, 68 int32_t FollowRedirect(PP_Resource loader_id,
69 PP_CompletionCallback callback) { 69 PP_CompletionCallback callback) {
70 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); 70 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id));
71 if (!loader.get()) 71 if (!loader.get())
72 return PP_Error_BadResource; 72 return PP_ERROR_BADRESOURCE;
73 73
74 return loader->FollowRedirect(callback); 74 return loader->FollowRedirect(callback);
75 } 75 }
76 76
77 bool GetUploadProgress(PP_Resource loader_id, 77 bool GetUploadProgress(PP_Resource loader_id,
78 int64_t* bytes_sent, 78 int64_t* bytes_sent,
79 int64_t* total_bytes_to_be_sent) { 79 int64_t* total_bytes_to_be_sent) {
80 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); 80 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id));
81 if (!loader.get()) 81 if (!loader.get())
82 return false; 82 return false;
(...skipping 27 matching lines...) Expand all
110 110
111 return response_info->GetResource(); 111 return response_info->GetResource();
112 } 112 }
113 113
114 int32_t ReadResponseBody(PP_Resource loader_id, 114 int32_t ReadResponseBody(PP_Resource loader_id,
115 char* buffer, 115 char* buffer,
116 int32_t bytes_to_read, 116 int32_t bytes_to_read,
117 PP_CompletionCallback callback) { 117 PP_CompletionCallback callback) {
118 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); 118 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id));
119 if (!loader.get()) 119 if (!loader.get())
120 return PP_Error_BadResource; 120 return PP_ERROR_BADRESOURCE;
121 121
122 return loader->ReadResponseBody(buffer, bytes_to_read, callback); 122 return loader->ReadResponseBody(buffer, bytes_to_read, callback);
123 } 123 }
124 124
125 void Close(PP_Resource loader_id) { 125 void Close(PP_Resource loader_id) {
126 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); 126 scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id));
127 if (!loader.get()) 127 if (!loader.get())
128 return; 128 return;
129 129
130 loader->Close(); 130 loader->Close();
(...skipping 27 matching lines...) Expand all
158 } 158 }
159 159
160 // static 160 // static
161 const PPB_URLLoader* URLLoader::GetInterface() { 161 const PPB_URLLoader* URLLoader::GetInterface() {
162 return &ppb_urlloader; 162 return &ppb_urlloader;
163 } 163 }
164 164
165 int32_t URLLoader::Open(URLRequestInfo* request, 165 int32_t URLLoader::Open(URLRequestInfo* request,
166 PP_CompletionCallback callback) { 166 PP_CompletionCallback callback) {
167 if (loader_.get()) 167 if (loader_.get())
168 return PP_Error_InProgress; 168 return PP_ERROR_INPROGRESS;
169 169
170 // We only support non-blocking calls. 170 // We only support non-blocking calls.
171 if (!callback.func) 171 if (!callback.func)
172 return PP_Error_BadArgument; 172 return PP_ERROR_BADARGUMENT;
173 173
174 WebURLRequest web_request(request->web_request()); 174 WebURLRequest web_request(request->web_request());
175 175
176 WebFrame* frame = instance_->container()->element().document().frame(); 176 WebFrame* frame = instance_->container()->element().document().frame();
177 if (!frame) 177 if (!frame)
178 return PP_Error_Failed; 178 return PP_ERROR_FAILED;
179 web_request.setURL( 179 web_request.setURL(
180 frame->document().completeURL(WebString::fromUTF8(request->url()))); 180 frame->document().completeURL(WebString::fromUTF8(request->url())));
181 frame->setReferrerForRequest(web_request, WebURL()); // Use default. 181 frame->setReferrerForRequest(web_request, WebURL()); // Use default.
182 frame->dispatchWillSendRequest(web_request); 182 frame->dispatchWillSendRequest(web_request);
183 183
184 loader_.reset(WebKit::webKitClient()->createURLLoader()); 184 loader_.reset(WebKit::webKitClient()->createURLLoader());
185 if (!loader_.get()) { 185 if (!loader_.get()) {
186 loader_.reset(); 186 loader_.reset();
187 return PP_Error_Failed; 187 return PP_ERROR_FAILED;
188 } 188 }
189 loader_->loadAsynchronously(web_request, this); 189 loader_->loadAsynchronously(web_request, this);
190 190
191 pending_callback_ = callback; 191 pending_callback_ = callback;
192 192
193 // Notify completion when we receive a redirect or response headers. 193 // Notify completion when we receive a redirect or response headers.
194 return PP_Error_WouldBlock; 194 return PP_ERROR_WOULDBLOCK;
195 } 195 }
196 196
197 int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) { 197 int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) {
198 NOTIMPLEMENTED(); // TODO(darin): Implement me. 198 NOTIMPLEMENTED(); // TODO(darin): Implement me.
199 return PP_Error_Failed; 199 return PP_ERROR_FAILED;
200 } 200 }
201 201
202 int32_t URLLoader::ReadResponseBody(char* buffer, int32_t bytes_to_read, 202 int32_t URLLoader::ReadResponseBody(char* buffer, int32_t bytes_to_read,
203 PP_CompletionCallback callback) { 203 PP_CompletionCallback callback) {
204 if (bytes_to_read <= 0 || !buffer) 204 if (bytes_to_read <= 0 || !buffer)
205 return PP_Error_BadArgument; 205 return PP_ERROR_BADARGUMENT;
206 if (pending_callback_.func) 206 if (pending_callback_.func)
207 return PP_Error_InProgress; 207 return PP_ERROR_INPROGRESS;
208 208
209 // We only support non-blocking calls. 209 // We only support non-blocking calls.
210 if (!callback.func) 210 if (!callback.func)
211 return PP_Error_BadArgument; 211 return PP_ERROR_BADARGUMENT;
212 212
213 user_buffer_ = buffer; 213 user_buffer_ = buffer;
214 user_buffer_size_ = bytes_to_read; 214 user_buffer_size_ = bytes_to_read;
215 215
216 if (!buffer_.empty()) 216 if (!buffer_.empty())
217 return FillUserBuffer(); 217 return FillUserBuffer();
218 218
219 pending_callback_ = callback; 219 pending_callback_ = callback;
220 return PP_Error_WouldBlock; 220 return PP_ERROR_WOULDBLOCK;
221 } 221 }
222 222
223 void URLLoader::Close() { 223 void URLLoader::Close() {
224 NOTIMPLEMENTED(); // TODO(darin): Implement me. 224 NOTIMPLEMENTED(); // TODO(darin): Implement me.
225 } 225 }
226 226
227 void URLLoader::willSendRequest(WebURLLoader* loader, 227 void URLLoader::willSendRequest(WebURLLoader* loader,
228 WebURLRequest& new_request, 228 WebURLRequest& new_request,
229 const WebURLResponse& redirect_response) { 229 const WebURLResponse& redirect_response) {
230 NOTIMPLEMENTED(); // TODO(darin): Allow the plugin to inspect redirects. 230 NOTIMPLEMENTED(); // TODO(darin): Allow the plugin to inspect redirects.
(...skipping 23 matching lines...) Expand all
254 DCHECK(!pending_callback_.func); 254 DCHECK(!pending_callback_.func);
255 } 255 }
256 } 256 }
257 257
258 void URLLoader::didFinishLoading(WebURLLoader* loader) { 258 void URLLoader::didFinishLoading(WebURLLoader* loader) {
259 RunCallback(PP_OK); 259 RunCallback(PP_OK);
260 } 260 }
261 261
262 void URLLoader::didFail(WebURLLoader* loader, const WebURLError& error) { 262 void URLLoader::didFail(WebURLLoader* loader, const WebURLError& error) {
263 // TODO(darin): Provide more detailed error information. 263 // TODO(darin): Provide more detailed error information.
264 RunCallback(PP_Error_Failed); 264 RunCallback(PP_ERROR_FAILED);
265 } 265 }
266 266
267 void URLLoader::RunCallback(int32_t result) { 267 void URLLoader::RunCallback(int32_t result) {
268 if (!pending_callback_.func) 268 if (!pending_callback_.func)
269 return; 269 return;
270 270
271 PP_CompletionCallback callback = {0}; 271 PP_CompletionCallback callback = {0};
272 std::swap(callback, pending_callback_); 272 std::swap(callback, pending_callback_);
273 PP_RunCompletionCallback(&callback, result); 273 PP_RunCompletionCallback(&callback, result);
274 } 274 }
275 275
276 size_t URLLoader::FillUserBuffer() { 276 size_t URLLoader::FillUserBuffer() {
277 DCHECK(user_buffer_); 277 DCHECK(user_buffer_);
278 DCHECK(user_buffer_size_); 278 DCHECK(user_buffer_size_);
279 279
280 size_t bytes_to_copy = std::min(buffer_.size(), user_buffer_size_); 280 size_t bytes_to_copy = std::min(buffer_.size(), user_buffer_size_);
281 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_); 281 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_);
282 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy); 282 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy);
283 283
284 // Reset for next time. 284 // Reset for next time.
285 user_buffer_ = NULL; 285 user_buffer_ = NULL;
286 user_buffer_size_ = 0; 286 user_buffer_size_ = 0;
287 return bytes_to_copy; 287 return bytes_to_copy;
288 } 288 }
289 289
290 } // namespace pepper 290 } // namespace pepper
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_plugin_module.cc ('k') | webkit/glue/plugins/pepper_url_request_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698