| Index: webkit/plugins/ppapi/ppb_url_loader_impl.cc
|
| ===================================================================
|
| --- webkit/plugins/ppapi/ppb_url_loader_impl.cc (revision 71399)
|
| +++ webkit/plugins/ppapi/ppb_url_loader_impl.cc (working copy)
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -21,7 +21,6 @@
|
| #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
|
| #include "webkit/appcache/web_application_cache_host_impl.h"
|
| #include "webkit/plugins/ppapi/common.h"
|
| -#include "webkit/plugins/ppapi/plugin_module.h"
|
| #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
|
| #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
|
| #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h"
|
| @@ -233,19 +232,19 @@
|
|
|
| int32_t PPB_URLLoader_Impl::Open(PPB_URLRequestInfo_Impl* request,
|
| PP_CompletionCallback callback) {
|
| - int32_t rv = ValidateCallback(callback);
|
| - if (rv != PP_OK)
|
| - return rv;
|
| -
|
| if (loader_.get())
|
| return PP_ERROR_INPROGRESS;
|
|
|
| + // We only support non-blocking calls.
|
| + if (!callback.func)
|
| + return PP_ERROR_BADARGUMENT;
|
| +
|
| WebFrame* frame = GetFrame(instance_);
|
| if (!frame)
|
| return PP_ERROR_FAILED;
|
| WebURLRequest web_request(request->ToWebURLRequest(frame));
|
|
|
| - rv = CanRequest(frame, web_request.url());
|
| + int32_t rv = CanRequest(frame, web_request.url());
|
| if (rv != PP_OK)
|
| return rv;
|
|
|
| @@ -264,25 +263,28 @@
|
| loader_->loadAsynchronously(web_request, this);
|
|
|
| request_info_ = scoped_refptr<PPB_URLRequestInfo_Impl>(request);
|
| + pending_callback_ = callback;
|
|
|
| // Notify completion when we receive a redirect or response headers.
|
| - RegisterCallback(callback);
|
| return PP_ERROR_WOULDBLOCK;
|
| }
|
|
|
| int32_t PPB_URLLoader_Impl::FollowRedirect(PP_CompletionCallback callback) {
|
| - int32_t rv = ValidateCallback(callback);
|
| - if (rv != PP_OK)
|
| - return rv;
|
| + if (pending_callback_.func)
|
| + return PP_ERROR_INPROGRESS;
|
|
|
| + // We only support non-blocking calls.
|
| + if (!callback.func)
|
| + return PP_ERROR_BADARGUMENT;
|
| +
|
| WebURL redirect_url = GURL(response_info_->redirect_url());
|
|
|
| - rv = CanRequest(GetFrame(instance_), redirect_url);
|
| + int32_t rv = CanRequest(GetFrame(instance_), redirect_url);
|
| if (rv != PP_OK)
|
| return rv;
|
|
|
| + pending_callback_ = callback;
|
| loader_->setDefersLoading(false); // Allow the redirect to continue.
|
| - RegisterCallback(callback);
|
| return PP_ERROR_WOULDBLOCK;
|
| }
|
|
|
| @@ -314,14 +316,17 @@
|
| int32_t PPB_URLLoader_Impl::ReadResponseBody(char* buffer,
|
| int32_t bytes_to_read,
|
| PP_CompletionCallback callback) {
|
| - int32_t rv = ValidateCallback(callback);
|
| - if (rv != PP_OK)
|
| - return rv;
|
| if (!response_info_ || response_info_->body())
|
| return PP_ERROR_FAILED;
|
| if (bytes_to_read <= 0 || !buffer)
|
| return PP_ERROR_BADARGUMENT;
|
| + if (pending_callback_.func)
|
| + return PP_ERROR_INPROGRESS;
|
|
|
| + // We only support non-blocking calls.
|
| + if (!callback.func)
|
| + return PP_ERROR_BADARGUMENT;
|
| +
|
| user_buffer_ = buffer;
|
| user_buffer_size_ = bytes_to_read;
|
|
|
| @@ -335,24 +340,23 @@
|
| return done_status_;
|
| }
|
|
|
| - RegisterCallback(callback);
|
| + pending_callback_ = callback;
|
| return PP_ERROR_WOULDBLOCK;
|
| }
|
|
|
| int32_t PPB_URLLoader_Impl::FinishStreamingToFile(
|
| PP_CompletionCallback callback) {
|
| - int32_t rv = ValidateCallback(callback);
|
| - if (rv != PP_OK)
|
| - return rv;
|
| if (!response_info_ || !response_info_->body())
|
| return PP_ERROR_FAILED;
|
| + if (pending_callback_.func)
|
| + return PP_ERROR_INPROGRESS;
|
|
|
| // We may have already reached EOF.
|
| if (done_status_ != PP_ERROR_WOULDBLOCK)
|
| return done_status_;
|
|
|
| // Wait for didFinishLoading / didFail.
|
| - RegisterCallback(callback);
|
| + pending_callback_ = callback;
|
| return PP_ERROR_WOULDBLOCK;
|
| }
|
|
|
| @@ -363,8 +367,6 @@
|
| WebFrame* frame = instance_->container()->element().document().frame();
|
| frame->stopLoading();
|
| }
|
| - // TODO(viettrungluu): Check what happens to the callback (probably the
|
| - // wrong thing). May need to post abort here. crbug.com/69457
|
| }
|
|
|
| void PPB_URLLoader_Impl::GrantUniversalAccess() {
|
| @@ -429,7 +431,7 @@
|
| if (user_buffer_) {
|
| RunCallback(FillUserBuffer());
|
| } else {
|
| - DCHECK(!pending_callback_.get() || pending_callback_->completed());
|
| + DCHECK(!pending_callback_.func);
|
| }
|
| }
|
|
|
| @@ -480,33 +482,15 @@
|
| // goes out of scope.
|
| }
|
|
|
| -int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) {
|
| - // We only support non-blocking calls.
|
| - if (!callback.func)
|
| - return PP_ERROR_BADARGUMENT;
|
| +void PPB_URLLoader_Impl::RunCallback(int32_t result) {
|
| + if (!pending_callback_.func)
|
| + return;
|
|
|
| - if (pending_callback_.get() && !pending_callback_->completed())
|
| - return PP_ERROR_INPROGRESS;
|
| -
|
| - return PP_OK;
|
| + PP_CompletionCallback callback = {0};
|
| + std::swap(callback, pending_callback_);
|
| + PP_RunCompletionCallback(&callback, result);
|
| }
|
|
|
| -void PPB_URLLoader_Impl::RegisterCallback(PP_CompletionCallback callback) {
|
| - DCHECK(callback.func);
|
| - DCHECK(!pending_callback_.get() || pending_callback_->completed());
|
| -
|
| - PP_Resource resource_id = GetReferenceNoAddRef();
|
| - CHECK(resource_id);
|
| - pending_callback_ = new TrackedCompletionCallback(
|
| - module()->GetCallbackTracker(), resource_id, callback);
|
| -}
|
| -
|
| -void PPB_URLLoader_Impl::RunCallback(int32_t result) {
|
| - scoped_refptr<TrackedCompletionCallback> callback;
|
| - callback.swap(pending_callback_);
|
| - callback->Run(result); // Will complete abortively if necessary.
|
| -}
|
| -
|
| size_t PPB_URLLoader_Impl::FillUserBuffer() {
|
| DCHECK(user_buffer_);
|
| DCHECK(user_buffer_size_);
|
|
|