summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-17 02:10:45 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-17 02:10:45 +0000
commitbf712f8ee12c3045ed390005887acb28e2bc7d49 (patch)
tree03769bfbfd2c85160932135dc4f06f6da9e45875 /webkit
parentdce730aba66fca3b63458a483bb60eeb716f2a79 (diff)
downloadchromium_src-bf712f8ee12c3045ed390005887acb28e2bc7d49.zip
chromium_src-bf712f8ee12c3045ed390005887acb28e2bc7d49.tar.gz
chromium_src-bf712f8ee12c3045ed390005887acb28e2bc7d49.tar.bz2
Convert the URL loading objects to the API/thunk system.
TEST=PPAPI UI tests BUG=none Review URL: http://codereview.chromium.org/7192012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89439 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc11
-rw-r--r--webkit/plugins/ppapi/ppb_url_loader_impl.cc199
-rw-r--r--webkit/plugins/ppapi/ppb_url_loader_impl.h57
-rw-r--r--webkit/plugins/ppapi/ppb_url_request_info_impl.cc314
-rw-r--r--webkit/plugins/ppapi/ppb_url_request_info_impl.h35
-rw-r--r--webkit/plugins/ppapi/ppb_url_response_info_impl.cc85
-rw-r--r--webkit/plugins/ppapi/ppb_url_response_info_impl.h23
-rw-r--r--webkit/plugins/ppapi/resource_creation_impl.cc8
-rw-r--r--webkit/plugins/ppapi/url_request_info_unittest.cc7
9 files changed, 263 insertions, 476 deletions
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index 5204a90..06e97a8 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -90,9 +90,6 @@
#include "webkit/plugins/ppapi/ppb_scrollbar_impl.h"
#include "webkit/plugins/ppapi/ppb_transport_impl.h"
#include "webkit/plugins/ppapi/ppb_uma_private_impl.h"
-#include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
-#include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
-#include "webkit/plugins/ppapi/ppb_url_response_info_impl.h"
#include "webkit/plugins/ppapi/ppb_url_util_impl.h"
#include "webkit/plugins/ppapi/ppb_video_decoder_impl.h"
#include "webkit/plugins/ppapi/ppb_video_layer_impl.h"
@@ -314,13 +311,13 @@ const void* GetInterface(const char* name) {
if (strcmp(name, PPB_UMA_PRIVATE_INTERFACE) == 0)
return PPB_UMA_Private_Impl::GetInterface();
if (strcmp(name, PPB_URLLOADER_INTERFACE) == 0)
- return PPB_URLLoader_Impl::GetInterface();
+ return ::ppapi::thunk::GetPPB_URLLoader_Thunk();
if (strcmp(name, PPB_URLLOADERTRUSTED_INTERFACE) == 0)
- return PPB_URLLoader_Impl::GetTrustedInterface();
+ return ::ppapi::thunk::GetPPB_URLLoaderTrusted_Thunk();
if (strcmp(name, PPB_URLREQUESTINFO_INTERFACE) == 0)
- return PPB_URLRequestInfo_Impl::GetInterface();
+ return ::ppapi::thunk::GetPPB_URLRequestInfo_Thunk();
if (strcmp(name, PPB_URLRESPONSEINFO_INTERFACE) == 0)
- return PPB_URLResponseInfo_Impl::GetInterface();
+ return ::ppapi::thunk::GetPPB_URLResponseInfo_Thunk();
if (strcmp(name, PPB_URLUTIL_DEV_INTERFACE) == 0)
return PPB_URLUtil_Impl::GetInterface();
if (strcmp(name, PPB_VAR_DEPRECATED_INTERFACE) == 0)
diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.cc b/webkit/plugins/ppapi/ppb_url_loader_impl.cc
index 193b461..3b57d12 100644
--- a/webkit/plugins/ppapi/ppb_url_loader_impl.cc
+++ b/webkit/plugins/ppapi/ppb_url_loader_impl.cc
@@ -10,6 +10,7 @@
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_url_loader.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
+#include "ppapi/thunk/enter.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
@@ -30,6 +31,9 @@
#include "webkit/plugins/ppapi/ppb_url_response_info_impl.h"
using appcache::WebApplicationCacheHostImpl;
+using ppapi::thunk::EnterResourceNoLock;
+using ppapi::thunk::PPB_URLLoader_API;
+using ppapi::thunk::PPB_URLRequestInfo_API;
using WebKit::WebFrame;
using WebKit::WebString;
using WebKit::WebURL;
@@ -47,157 +51,6 @@ using WebKit::WebURLResponse;
namespace webkit {
namespace ppapi {
-namespace {
-
-PP_Resource Create(PP_Instance instance_id) {
- PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
- if (!instance)
- return 0;
-
- PPB_URLLoader_Impl* loader = new PPB_URLLoader_Impl(instance, false);
- return loader->GetReference();
-}
-
-PP_Bool IsURLLoader(PP_Resource resource) {
- return BoolToPPBool(!!Resource::GetAs<PPB_URLLoader_Impl>(resource));
-}
-
-int32_t Open(PP_Resource loader_id,
- PP_Resource request_id,
- PP_CompletionCallback callback) {
- scoped_refptr<PPB_URLLoader_Impl> loader(
- Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
- if (!loader)
- return PP_ERROR_BADRESOURCE;
-
- scoped_refptr<PPB_URLRequestInfo_Impl> request(
- Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id));
- if (!request)
- return PP_ERROR_BADRESOURCE;
-
- return loader->Open(request, callback);
-}
-
-int32_t FollowRedirect(PP_Resource loader_id,
- PP_CompletionCallback callback) {
- scoped_refptr<PPB_URLLoader_Impl> loader(
- Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
- if (!loader)
- return PP_ERROR_BADRESOURCE;
-
- return loader->FollowRedirect(callback);
-}
-
-PP_Bool GetUploadProgress(PP_Resource loader_id,
- int64_t* bytes_sent,
- int64_t* total_bytes_to_be_sent) {
- scoped_refptr<PPB_URLLoader_Impl> loader(
- Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
- if (!loader)
- return PP_FALSE;
-
- return BoolToPPBool(loader->GetUploadProgress(bytes_sent,
- total_bytes_to_be_sent));
-}
-
-PP_Bool GetDownloadProgress(PP_Resource loader_id,
- int64_t* bytes_received,
- int64_t* total_bytes_to_be_received) {
- scoped_refptr<PPB_URLLoader_Impl> loader(
- Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
- if (!loader)
- return PP_FALSE;
-
- return BoolToPPBool(loader->GetDownloadProgress(bytes_received,
- total_bytes_to_be_received));
-}
-
-PP_Resource GetResponseInfo(PP_Resource loader_id) {
- scoped_refptr<PPB_URLLoader_Impl> loader(
- Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
- if (!loader)
- return 0;
-
- PPB_URLResponseInfo_Impl* response_info = loader->response_info();
- if (!response_info)
- return 0;
-
- return response_info->GetReference();
-}
-
-int32_t ReadResponseBody(PP_Resource loader_id,
- void* buffer,
- int32_t bytes_to_read,
- PP_CompletionCallback callback) {
- scoped_refptr<PPB_URLLoader_Impl> loader(
- Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
- if (!loader)
- return PP_ERROR_BADRESOURCE;
-
- return loader->ReadResponseBody(buffer, bytes_to_read, callback);
-}
-
-int32_t FinishStreamingToFile(PP_Resource loader_id,
- PP_CompletionCallback callback) {
- scoped_refptr<PPB_URLLoader_Impl> loader(
- Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
- if (!loader)
- return PP_ERROR_BADRESOURCE;
-
- return loader->FinishStreamingToFile(callback);
-}
-
-void Close(PP_Resource loader_id) {
- scoped_refptr<PPB_URLLoader_Impl> loader(
- Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
- if (!loader)
- return;
-
- loader->Close();
-}
-
-const PPB_URLLoader ppb_urlloader = {
- &Create,
- &IsURLLoader,
- &Open,
- &FollowRedirect,
- &GetUploadProgress,
- &GetDownloadProgress,
- &GetResponseInfo,
- &ReadResponseBody,
- &FinishStreamingToFile,
- &Close
-};
-
-void GrantUniversalAccess(PP_Resource loader_id) {
- scoped_refptr<PPB_URLLoader_Impl> loader(
- Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
- if (!loader)
- return;
-
- loader->GrantUniversalAccess();
-}
-
-void SetStatusCallback(PP_Resource loader_id,
- PP_URLLoaderTrusted_StatusCallback cb) {
- scoped_refptr<PPB_URLLoader_Impl> loader(
- Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
- if (!loader)
- return;
- loader->SetStatusCallback(cb);
-}
-
-const PPB_URLLoaderTrusted ppb_urlloadertrusted = {
- &GrantUniversalAccess,
- &SetStatusCallback
-};
-
-WebFrame* GetFrame(PluginInstance* instance) {
- return instance->container()->element().document().frame();
-}
-
-} // namespace
-
PPB_URLLoader_Impl::PPB_URLLoader_Impl(PluginInstance* instance,
bool main_document_loader)
: Resource(instance),
@@ -220,16 +73,16 @@ PPB_URLLoader_Impl::~PPB_URLLoader_Impl() {
}
// static
-const PPB_URLLoader* PPB_URLLoader_Impl::GetInterface() {
- return &ppb_urlloader;
-}
+PP_Resource PPB_URLLoader_Impl::Create(PP_Instance pp_instance) {
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance);
+ if (!instance)
+ return 0;
-// static
-const PPB_URLLoaderTrusted* PPB_URLLoader_Impl::GetTrustedInterface() {
- return &ppb_urlloadertrusted;
+ PPB_URLLoader_Impl* loader = new PPB_URLLoader_Impl(instance, false);
+ return loader->GetReference();
}
-PPB_URLLoader_Impl* PPB_URLLoader_Impl::AsPPB_URLLoader_Impl() {
+PPB_URLLoader_API* PPB_URLLoader_Impl::AsPPB_URLLoader_API() {
return this;
}
@@ -242,8 +95,14 @@ void PPB_URLLoader_Impl::LastPluginRefWasDeleted(bool instance_destroyed) {
}
}
-int32_t PPB_URLLoader_Impl::Open(PPB_URLRequestInfo_Impl* request,
+int32_t PPB_URLLoader_Impl::Open(PP_Resource request_id,
PP_CompletionCallback callback) {
+ EnterResourceNoLock<PPB_URLRequestInfo_API> enter_request(request_id, true);
+ if (enter_request.failed())
+ return PP_ERROR_BADARGUMENT;
+ PPB_URLRequestInfo_Impl* request = static_cast<PPB_URLRequestInfo_Impl*>(
+ enter_request.object());
+
int32_t rv = ValidateCallback(callback);
if (rv != PP_OK)
return rv;
@@ -254,7 +113,7 @@ int32_t PPB_URLLoader_Impl::Open(PPB_URLRequestInfo_Impl* request,
if (loader_.get())
return PP_ERROR_INPROGRESS;
- WebFrame* frame = GetFrame(instance());
+ WebFrame* frame = instance()->container()->element().document().frame();
if (!frame)
return PP_ERROR_FAILED;
WebURLRequest web_request(request->ToWebURLRequest(frame));
@@ -303,29 +162,35 @@ int32_t PPB_URLLoader_Impl::FollowRedirect(PP_CompletionCallback callback) {
return PP_OK_COMPLETIONPENDING;
}
-bool PPB_URLLoader_Impl::GetUploadProgress(int64_t* bytes_sent,
- int64_t* total_bytes_to_be_sent) {
+PP_Bool PPB_URLLoader_Impl::GetUploadProgress(int64_t* bytes_sent,
+ int64_t* total_bytes_to_be_sent) {
if (!RecordUploadProgress()) {
*bytes_sent = 0;
*total_bytes_to_be_sent = 0;
- return false;
+ return PP_FALSE;
}
*bytes_sent = bytes_sent_;
*total_bytes_to_be_sent = total_bytes_to_be_sent_;
- return true;
+ return PP_TRUE;
}
-bool PPB_URLLoader_Impl::GetDownloadProgress(
+PP_Bool PPB_URLLoader_Impl::GetDownloadProgress(
int64_t* bytes_received,
int64_t* total_bytes_to_be_received) {
if (!RecordDownloadProgress()) {
*bytes_received = 0;
*total_bytes_to_be_received = 0;
- return false;
+ return PP_FALSE;
}
*bytes_received = bytes_received_;
*total_bytes_to_be_received = total_bytes_to_be_received_;
- return true;
+ return PP_TRUE;
+}
+
+PP_Resource PPB_URLLoader_Impl::GetResponseInfo() {
+ if (!response_info_)
+ return 0;
+ return response_info_->GetReference();
}
int32_t PPB_URLLoader_Impl::ReadResponseBody(void* buffer,
diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.h b/webkit/plugins/ppapi/ppb_url_loader_impl.h
index 878ce65..f931406 100644
--- a/webkit/plugins/ppapi/ppb_url_loader_impl.h
+++ b/webkit/plugins/ppapi/ppb_url_loader_impl.h
@@ -11,14 +11,12 @@
#include "base/memory/scoped_ptr.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
+#include "ppapi/thunk/ppb_url_loader_api.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h"
#include "webkit/plugins/ppapi/callbacks.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/resource.h"
-struct PPB_URLLoader;
-struct PPB_URLLoaderTrusted;
-
namespace WebKit {
class WebFrame;
class WebURL;
@@ -31,39 +29,40 @@ class PluginInstance;
class PPB_URLRequestInfo_Impl;
class PPB_URLResponseInfo_Impl;
-class PPB_URLLoader_Impl : public Resource, public WebKit::WebURLLoaderClient {
+class PPB_URLLoader_Impl : public Resource,
+ public ::ppapi::thunk::PPB_URLLoader_API,
+ public WebKit::WebURLLoaderClient {
public:
PPB_URLLoader_Impl(PluginInstance* instance, bool main_document_loader);
virtual ~PPB_URLLoader_Impl();
- // Returns a pointer to the interface implementing PPB_URLLoader that is
- // exposed to the plugin.
- static const PPB_URLLoader* GetInterface();
+ static PP_Resource Create(PP_Instance instance);
- // Returns a pointer to the interface implementing PPB_URLLoaderTrusted that
- // is exposed to the plugin.
- static const PPB_URLLoaderTrusted* GetTrustedInterface();
+ // ResourceObjectBase overrides.
+ virtual ::ppapi::thunk::PPB_URLLoader_API* AsPPB_URLLoader_API() OVERRIDE;
// Resource overrides.
- virtual PPB_URLLoader_Impl* AsPPB_URLLoader_Impl();
- virtual void LastPluginRefWasDeleted(bool instance_destroyed);
-
- // PPB_URLLoader implementation.
- int32_t Open(PPB_URLRequestInfo_Impl* request,
- PP_CompletionCallback callback);
- int32_t FollowRedirect(PP_CompletionCallback callback);
- bool GetUploadProgress(int64_t* bytes_sent,
- int64_t* total_bytes_to_be_sent);
- bool GetDownloadProgress(int64_t* bytes_received,
- int64_t* total_bytes_to_be_received);
- int32_t ReadResponseBody(void* buffer, int32_t bytes_to_read,
- PP_CompletionCallback callback);
- int32_t FinishStreamingToFile(PP_CompletionCallback callback);
- void Close();
-
- // PPB_URLLoaderTrusted implementation.
- void GrantUniversalAccess();
- void SetStatusCallback(PP_URLLoaderTrusted_StatusCallback cb);
+ virtual void LastPluginRefWasDeleted(bool instance_destroyed) OVERRIDE;
+
+ // PPB_URLLoader_API implementation.
+ virtual int32_t Open(PP_Resource request_id,
+ PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t FollowRedirect(PP_CompletionCallback callback) OVERRIDE;
+ virtual PP_Bool GetUploadProgress(int64_t* bytes_sent,
+ int64_t* total_bytes_to_be_sent) OVERRIDE;
+ virtual PP_Bool GetDownloadProgress(
+ int64_t* bytes_received,
+ int64_t* total_bytes_to_be_received) OVERRIDE;
+ virtual PP_Resource GetResponseInfo() OVERRIDE;
+ virtual int32_t ReadResponseBody(void* buffer,
+ int32_t bytes_to_read,
+ PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t FinishStreamingToFile(
+ PP_CompletionCallback callback) OVERRIDE;
+ virtual void Close() OVERRIDE;
+ virtual void GrantUniversalAccess() OVERRIDE;
+ virtual void SetStatusCallback(
+ PP_URLLoaderTrusted_StatusCallback cb) OVERRIDE;
// WebKit::WebURLLoaderClient implementation.
virtual void willSendRequest(WebKit::WebURLLoader* loader,
diff --git a/webkit/plugins/ppapi/ppb_url_request_info_impl.cc b/webkit/plugins/ppapi/ppb_url_request_info_impl.cc
index 185ab2a..64c3f59 100644
--- a/webkit/plugins/ppapi/ppb_url_request_info_impl.cc
+++ b/webkit/plugins/ppapi/ppb_url_request_info_impl.cc
@@ -10,6 +10,8 @@
#include "googleurl/src/url_util.h"
#include "net/http/http_util.h"
#include "ppapi/c/pp_var.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_file_ref_api.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
@@ -23,6 +25,9 @@
#include "webkit/plugins/ppapi/var.h"
#include "webkit/glue/webkit_glue.h"
+using ppapi::thunk::EnterResourceNoLock;
+using ppapi::thunk::PPB_FileRef_API;
+using ppapi::thunk::PPB_URLRequestInfo_API;
using WebKit::WebData;
using WebKit::WebHTTPBody;
using WebKit::WebString;
@@ -85,96 +90,6 @@ bool AreValidHeaders(const std::string& headers) {
return true;
}
-PP_Resource Create(PP_Instance instance_id) {
- PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
- if (!instance)
- return 0;
-
- PPB_URLRequestInfo_Impl* request = new PPB_URLRequestInfo_Impl(instance);
-
- return request->GetReference();
-}
-
-PP_Bool IsURLRequestInfo(PP_Resource resource) {
- return BoolToPPBool(!!Resource::GetAs<PPB_URLRequestInfo_Impl>(resource));
-}
-
-PP_Bool SetProperty(PP_Resource request_id,
- PP_URLRequestProperty property,
- PP_Var var) {
- scoped_refptr<PPB_URLRequestInfo_Impl> request(
- Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id));
- if (!request)
- return PP_FALSE;
-
- PP_Bool result = PP_FALSE;
- switch (var.type) {
- case PP_VARTYPE_UNDEFINED:
- result = BoolToPPBool(request->SetUndefinedProperty(property));
- break;
- case PP_VARTYPE_BOOL:
- result = BoolToPPBool(
- request->SetBooleanProperty(property,
- PPBoolToBool(var.value.as_bool)));
- break;
- case PP_VARTYPE_INT32:
- result = BoolToPPBool(
- request->SetIntegerProperty(property, var.value.as_int));
- break;
- case PP_VARTYPE_STRING: {
- scoped_refptr<StringVar> string(StringVar::FromPPVar(var));
- if (string)
- result = BoolToPPBool(request->SetStringProperty(property,
- string->value()));
- break;
- }
- default:
- break;
- }
- return result;
-}
-
-PP_Bool AppendDataToBody(PP_Resource request_id,
- const void* data,
- uint32_t len) {
- scoped_refptr<PPB_URLRequestInfo_Impl> request(
- Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id));
- if (!request)
- return PP_FALSE;
-
- return BoolToPPBool(request->AppendDataToBody(std::string(
- static_cast<const char*>(data), len)));
-}
-
-PP_Bool AppendFileToBody(PP_Resource request_id,
- PP_Resource file_ref_id,
- int64_t start_offset,
- int64_t number_of_bytes,
- PP_Time expected_last_modified_time) {
- scoped_refptr<PPB_URLRequestInfo_Impl> request(
- Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id));
- if (!request)
- return PP_FALSE;
-
- scoped_refptr<PPB_FileRef_Impl> file_ref(
- Resource::GetAs<PPB_FileRef_Impl>(file_ref_id));
- if (!file_ref)
- return PP_FALSE;
-
- return BoolToPPBool(request->AppendFileToBody(file_ref,
- start_offset,
- number_of_bytes,
- expected_last_modified_time));
-}
-
-const PPB_URLRequestInfo ppb_urlrequestinfo = {
- &Create,
- &IsURLRequestInfo,
- &SetProperty,
- &AppendDataToBody,
- &AppendFileToBody
-};
-
} // namespace
struct PPB_URLRequestInfo_Impl::BodyItem {
@@ -220,14 +135,139 @@ PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() {
}
// static
-const PPB_URLRequestInfo* PPB_URLRequestInfo_Impl::GetInterface() {
- return &ppb_urlrequestinfo;
+PP_Resource PPB_URLRequestInfo_Impl::Create(PP_Instance pp_instance) {
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance);
+ if (!instance)
+ return 0;
+
+ PPB_URLRequestInfo_Impl* request = new PPB_URLRequestInfo_Impl(instance);
+ return request->GetReference();
}
-PPB_URLRequestInfo_Impl* PPB_URLRequestInfo_Impl::AsPPB_URLRequestInfo_Impl() {
+PPB_URLRequestInfo_API* PPB_URLRequestInfo_Impl::AsPPB_URLRequestInfo_API() {
return this;
}
+PP_Bool PPB_URLRequestInfo_Impl::SetProperty(PP_URLRequestProperty property,
+ PP_Var var) {
+ PP_Bool result = PP_FALSE;
+ switch (var.type) {
+ case PP_VARTYPE_UNDEFINED:
+ result = PP_FromBool(SetUndefinedProperty(property));
+ break;
+ case PP_VARTYPE_BOOL:
+ result = PP_FromBool(
+ SetBooleanProperty(property, PP_ToBool(var.value.as_bool)));
+ break;
+ case PP_VARTYPE_INT32:
+ result = PP_FromBool(
+ SetIntegerProperty(property, var.value.as_int));
+ break;
+ case PP_VARTYPE_STRING: {
+ scoped_refptr<StringVar> string(StringVar::FromPPVar(var));
+ if (string)
+ result = PP_FromBool(SetStringProperty(property, string->value()));
+ break;
+ }
+ default:
+ break;
+ }
+ return result;
+}
+
+PP_Bool PPB_URLRequestInfo_Impl::AppendDataToBody(const void* data,
+ uint32_t len) {
+ if (len > 0)
+ body_.push_back(BodyItem(std::string(static_cast<const char*>(data), len)));
+ return PP_TRUE;
+}
+
+PP_Bool PPB_URLRequestInfo_Impl::AppendFileToBody(
+ PP_Resource file_ref,
+ int64_t start_offset,
+ int64_t number_of_bytes,
+ PP_Time expected_last_modified_time) {
+ // Ignore a call to append nothing.
+ if (number_of_bytes == 0)
+ return PP_TRUE;
+
+ // Check for bad values. (-1 means read until end of file.)
+ if (start_offset < 0 || number_of_bytes < -1)
+ return PP_FALSE;
+
+ EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true);
+ if (enter.failed())
+ return PP_FALSE;
+
+ body_.push_back(BodyItem(static_cast<PPB_FileRef_Impl*>(enter.object()),
+ start_offset,
+ number_of_bytes,
+ expected_last_modified_time));
+ return PP_TRUE;
+}
+
+WebURLRequest PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame) const {
+ WebURLRequest web_request;
+ web_request.initialize();
+ web_request.setURL(frame->document().completeURL(WebString::fromUTF8(url_)));
+ web_request.setDownloadToFile(stream_to_file_);
+ web_request.setReportUploadProgress(record_upload_progress());
+
+ if (!method_.empty())
+ web_request.setHTTPMethod(WebString::fromUTF8(method_));
+
+ if (!headers_.empty()) {
+ net::HttpUtil::HeadersIterator it(headers_.begin(), headers_.end(), "\n");
+ while (it.GetNext()) {
+ web_request.addHTTPHeaderField(
+ WebString::fromUTF8(it.name()),
+ WebString::fromUTF8(it.values()));
+ }
+ }
+
+ if (!body_.empty()) {
+ WebHTTPBody http_body;
+ http_body.initialize();
+ for (size_t i = 0; i < body_.size(); ++i) {
+ if (body_[i].file_ref) {
+ http_body.appendFileRange(
+ webkit_glue::FilePathToWebString(
+ body_[i].file_ref->GetSystemPath()),
+ body_[i].start_offset,
+ body_[i].number_of_bytes,
+ body_[i].expected_last_modified_time);
+ } else {
+ DCHECK(!body_[i].data.empty());
+ http_body.appendData(WebData(body_[i].data));
+ }
+ }
+ web_request.setHTTPBody(http_body);
+ }
+
+ if (has_custom_referrer_url_) {
+ if (!custom_referrer_url_.empty())
+ frame->setReferrerForRequest(web_request, GURL(custom_referrer_url_));
+ } else if (!allow_cross_origin_requests_) {
+ // Use default, except for cross-origin requests, since 'referer' is not
+ // whitelisted and will cause the request to fail.
+ frame->setReferrerForRequest(web_request, WebURL());
+ }
+
+ if (has_custom_content_transfer_encoding_) {
+ if (!custom_content_transfer_encoding_.empty()) {
+ web_request.addHTTPHeaderField(
+ WebString::fromUTF8("Content-Transfer-Encoding"),
+ WebString::fromUTF8(custom_content_transfer_encoding_));
+ }
+ }
+
+ return web_request;
+}
+
+bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const {
+ return has_custom_referrer_url_ || has_custom_content_transfer_encoding_;
+}
+
bool PPB_URLRequestInfo_Impl::SetUndefinedProperty(
PP_URLRequestProperty property) {
switch (property) {
@@ -315,93 +355,5 @@ bool PPB_URLRequestInfo_Impl::SetStringProperty(PP_URLRequestProperty property,
}
}
-bool PPB_URLRequestInfo_Impl::AppendDataToBody(const std::string& data) {
- if (!data.empty())
- body_.push_back(BodyItem(data));
- return true;
-}
-
-bool PPB_URLRequestInfo_Impl::AppendFileToBody(
- PPB_FileRef_Impl* file_ref,
- int64_t start_offset,
- int64_t number_of_bytes,
- PP_Time expected_last_modified_time) {
- // Ignore a call to append nothing.
- if (number_of_bytes == 0)
- return true;
-
- // Check for bad values. (-1 means read until end of file.)
- if (start_offset < 0 || number_of_bytes < -1)
- return false;
-
- body_.push_back(BodyItem(file_ref,
- start_offset,
- number_of_bytes,
- expected_last_modified_time));
- return true;
-}
-
-WebURLRequest PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame) const {
- WebURLRequest web_request;
- web_request.initialize();
- web_request.setURL(frame->document().completeURL(WebString::fromUTF8(url_)));
- web_request.setDownloadToFile(stream_to_file_);
- web_request.setReportUploadProgress(record_upload_progress());
-
- if (!method_.empty())
- web_request.setHTTPMethod(WebString::fromUTF8(method_));
-
- if (!headers_.empty()) {
- net::HttpUtil::HeadersIterator it(headers_.begin(), headers_.end(), "\n");
- while (it.GetNext()) {
- web_request.addHTTPHeaderField(
- WebString::fromUTF8(it.name()),
- WebString::fromUTF8(it.values()));
- }
- }
-
- if (!body_.empty()) {
- WebHTTPBody http_body;
- http_body.initialize();
- for (size_t i = 0; i < body_.size(); ++i) {
- if (body_[i].file_ref) {
- http_body.appendFileRange(
- webkit_glue::FilePathToWebString(
- body_[i].file_ref->GetSystemPath()),
- body_[i].start_offset,
- body_[i].number_of_bytes,
- body_[i].expected_last_modified_time);
- } else {
- DCHECK(!body_[i].data.empty());
- http_body.appendData(WebData(body_[i].data));
- }
- }
- web_request.setHTTPBody(http_body);
- }
-
- if (has_custom_referrer_url_) {
- if (!custom_referrer_url_.empty())
- frame->setReferrerForRequest(web_request, GURL(custom_referrer_url_));
- } else if (!allow_cross_origin_requests_) {
- // Use default, except for cross-origin requests, since 'referer' is not
- // whitelisted and will cause the request to fail.
- frame->setReferrerForRequest(web_request, WebURL());
- }
-
- if (has_custom_content_transfer_encoding_) {
- if (!custom_content_transfer_encoding_.empty()) {
- web_request.addHTTPHeaderField(
- WebString::fromUTF8("Content-Transfer-Encoding"),
- WebString::fromUTF8(custom_content_transfer_encoding_));
- }
- }
-
- return web_request;
-}
-
-bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const {
- return has_custom_referrer_url_ || has_custom_content_transfer_encoding_;
-}
-
} // namespace ppapi
} // namespace webkit
diff --git a/webkit/plugins/ppapi/ppb_url_request_info_impl.h b/webkit/plugins/ppapi/ppb_url_request_info_impl.h
index 2cdf3e4..872e498 100644
--- a/webkit/plugins/ppapi/ppb_url_request_info_impl.h
+++ b/webkit/plugins/ppapi/ppb_url_request_info_impl.h
@@ -10,6 +10,7 @@
#include "base/memory/ref_counted.h"
#include "ppapi/c/ppb_url_request_info.h"
+#include "ppapi/thunk/ppb_url_request_info_api.h"
#include "webkit/plugins/ppapi/resource.h"
namespace WebKit {
@@ -22,34 +23,38 @@ namespace ppapi {
class PPB_FileRef_Impl;
-class PPB_URLRequestInfo_Impl : public Resource {
+class PPB_URLRequestInfo_Impl : public Resource,
+ public ::ppapi::thunk::PPB_URLRequestInfo_API {
public:
explicit PPB_URLRequestInfo_Impl(PluginInstance* instance);
virtual ~PPB_URLRequestInfo_Impl();
- // Returns a pointer to the interface implementing PPB_URLRequestInfo that is
- // exposed to the plugin.
- static const PPB_URLRequestInfo* GetInterface();
+ static PP_Resource Create(PP_Instance instance);
- // Resource overrides.
- virtual PPB_URLRequestInfo_Impl* AsPPB_URLRequestInfo_Impl();
+ // ResourceObjectBase overrides.
+ virtual PPB_URLRequestInfo_API* AsPPB_URLRequestInfo_API() OVERRIDE;
// PPB_URLRequestInfo implementation.
+ virtual PP_Bool SetProperty(PP_URLRequestProperty property,
+ PP_Var var) OVERRIDE;
+ virtual PP_Bool AppendDataToBody(const void* data, uint32_t len) OVERRIDE;
+ virtual PP_Bool AppendFileToBody(
+ PP_Resource file_ref,
+ int64_t start_offset,
+ int64_t number_of_bytes,
+ PP_Time expected_last_modified_time) OVERRIDE;
+
+ WebKit::WebURLRequest ToWebURLRequest(WebKit::WebFrame* frame) const;
+
+ // Whether universal access is required to use this request.
+ bool RequiresUniversalAccess() const;
+
bool SetUndefinedProperty(PP_URLRequestProperty property);
bool SetBooleanProperty(PP_URLRequestProperty property, bool value);
bool SetIntegerProperty(PP_URLRequestProperty property, int32_t value);
bool SetStringProperty(PP_URLRequestProperty property,
const std::string& value);
- bool AppendDataToBody(const std::string& data);
- bool AppendFileToBody(PPB_FileRef_Impl* file_ref,
- int64_t start_offset,
- int64_t number_of_bytes,
- PP_Time expected_last_modified_time);
-
- WebKit::WebURLRequest ToWebURLRequest(WebKit::WebFrame* frame) const;
- // Whether universal access is required to use this request.
- bool RequiresUniversalAccess() const;
bool follow_redirects() { return follow_redirects_; }
diff --git a/webkit/plugins/ppapi/ppb_url_response_info_impl.cc b/webkit/plugins/ppapi/ppb_url_response_info_impl.cc
index b097fd2..4160e6b 100644
--- a/webkit/plugins/ppapi/ppb_url_response_info_impl.cc
+++ b/webkit/plugins/ppapi/ppb_url_response_info_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -16,6 +16,7 @@
#include "webkit/plugins/ppapi/var.h"
#include "webkit/glue/webkit_glue.h"
+using ppapi::thunk::PPB_URLResponseInfo_API;
using WebKit::WebHTTPHeaderVisitor;
using WebKit::WebString;
using WebKit::WebURLResponse;
@@ -41,40 +42,6 @@ class HeaderFlattener : public WebHTTPHeaderVisitor {
std::string buffer_;
};
-PP_Bool IsURLResponseInfo(PP_Resource resource) {
- return BoolToPPBool(!!Resource::GetAs<PPB_URLResponseInfo_Impl>(resource));
-}
-
-PP_Var GetProperty(PP_Resource response_id,
- PP_URLResponseProperty property) {
- scoped_refptr<PPB_URLResponseInfo_Impl> response(
- Resource::GetAs<PPB_URLResponseInfo_Impl>(response_id));
- if (!response)
- return PP_MakeUndefined();
-
- return response->GetProperty(property);
-}
-
-PP_Resource GetBody(PP_Resource response_id) {
- scoped_refptr<PPB_URLResponseInfo_Impl> response(
- Resource::GetAs<PPB_URLResponseInfo_Impl>(response_id));
- if (!response.get())
- return 0;
-
- PPB_FileRef_Impl* body = response->body();
- if (!body)
- return 0;
- body->AddRef(); // AddRef for the caller.
-
- return body->GetReference();
-}
-
-const PPB_URLResponseInfo ppb_urlresponseinfo = {
- &IsURLResponseInfo,
- &GetProperty,
- &GetBody
-};
-
bool IsRedirect(int32_t status) {
return status >= 300 && status <= 399;
}
@@ -89,13 +56,28 @@ PPB_URLResponseInfo_Impl::PPB_URLResponseInfo_Impl(PluginInstance* instance)
PPB_URLResponseInfo_Impl::~PPB_URLResponseInfo_Impl() {
}
-// static
-const PPB_URLResponseInfo* PPB_URLResponseInfo_Impl::GetInterface() {
- return &ppb_urlresponseinfo;
+bool PPB_URLResponseInfo_Impl::Initialize(const WebURLResponse& response) {
+ url_ = response.url().spec();
+ status_code_ = response.httpStatusCode();
+ status_text_ = response.httpStatusText().utf8();
+ if (IsRedirect(status_code_)) {
+ redirect_url_ = response.httpHeaderField(
+ WebString::fromUTF8("Location")).utf8();
+ }
+
+ HeaderFlattener flattener;
+ response.visitHTTPHeaderFields(&flattener);
+ headers_ = flattener.buffer();
+
+ WebString file_path = response.downloadFilePath();
+ if (!file_path.isEmpty()) {
+ body_ = new PPB_FileRef_Impl(instance(),
+ webkit_glue::WebStringToFilePath(file_path));
+ }
+ return true;
}
-PPB_URLResponseInfo_Impl*
-PPB_URLResponseInfo_Impl::AsPPB_URLResponseInfo_Impl() {
+PPB_URLResponseInfo_API* PPB_URLResponseInfo_Impl::AsPPB_URLResponseInfo_API() {
return this;
}
@@ -122,24 +104,11 @@ PP_Var PPB_URLResponseInfo_Impl::GetProperty(PP_URLResponseProperty property) {
return PP_MakeUndefined();
}
-bool PPB_URLResponseInfo_Impl::Initialize(const WebURLResponse& response) {
- url_ = response.url().spec();
- status_code_ = response.httpStatusCode();
- status_text_ = response.httpStatusText().utf8();
- if (IsRedirect(status_code_)) {
- redirect_url_ = response.httpHeaderField(
- WebString::fromUTF8("Location")).utf8();
- }
-
- HeaderFlattener flattener;
- response.visitHTTPHeaderFields(&flattener);
- headers_ = flattener.buffer();
-
- WebString file_path = response.downloadFilePath();
- if (!file_path.isEmpty())
- body_ = new PPB_FileRef_Impl(instance(),
- webkit_glue::WebStringToFilePath(file_path));
- return true;
+PP_Resource PPB_URLResponseInfo_Impl::GetBodyAsFileRef() {
+ if (!body_.get())
+ return 0;
+ body_->AddRef(); // AddRef for the caller.
+ return body_->GetReference();
}
} // namespace ppapi
diff --git a/webkit/plugins/ppapi/ppb_url_response_info_impl.h b/webkit/plugins/ppapi/ppb_url_response_info_impl.h
index fa916d9..10f44ea 100644
--- a/webkit/plugins/ppapi/ppb_url_response_info_impl.h
+++ b/webkit/plugins/ppapi/ppb_url_response_info_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "ppapi/c/ppb_url_response_info.h"
+#include "ppapi/thunk/ppb_url_response_info_api.h"
#include "webkit/plugins/ppapi/resource.h"
namespace WebKit {
@@ -20,25 +21,23 @@ namespace ppapi {
class PPB_FileRef_Impl;
-class PPB_URLResponseInfo_Impl : public Resource {
+class PPB_URLResponseInfo_Impl
+ : public Resource,
+ public ::ppapi::thunk::PPB_URLResponseInfo_API {
public:
explicit PPB_URLResponseInfo_Impl(PluginInstance* instance);
virtual ~PPB_URLResponseInfo_Impl();
- // Returns a pointer to the interface implementing PPB_URLResponseInfo that
- // is exposed to the plugin.
- static const PPB_URLResponseInfo* GetInterface();
-
- // Resource overrides.
- virtual PPB_URLResponseInfo_Impl* AsPPB_URLResponseInfo_Impl();
+ bool Initialize(const WebKit::WebURLResponse& response);
- // PPB_URLResponseInfo implementation.
- PP_Var GetProperty(PP_URLResponseProperty property);
+ // ResourceObjectBase overrides.
+ virtual PPB_URLResponseInfo_API* AsPPB_URLResponseInfo_API() OVERRIDE;
- bool Initialize(const WebKit::WebURLResponse& response);
+ // PPB_URLResponseInfo_API implementation.
+ virtual PP_Var GetProperty(PP_URLResponseProperty property) OVERRIDE;
+ virtual PP_Resource GetBodyAsFileRef() OVERRIDE;
PPB_FileRef_Impl* body() { return body_; }
-
std::string redirect_url() { return redirect_url_; }
private:
diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc
index 8e18864..a8caf76 100644
--- a/webkit/plugins/ppapi/resource_creation_impl.cc
+++ b/webkit/plugins/ppapi/resource_creation_impl.cc
@@ -20,6 +20,8 @@
#include "webkit/plugins/ppapi/ppb_font_impl.h"
#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
+#include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
+#include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
namespace webkit {
namespace ppapi {
@@ -173,13 +175,11 @@ PP_Resource ResourceCreationImpl::CreateSurface3D(
}
PP_Resource ResourceCreationImpl::CreateURLLoader(PP_Instance instance) {
- NOTIMPLEMENTED();
- return 0;
+ return PPB_URLLoader_Impl::Create(instance);
}
PP_Resource ResourceCreationImpl::CreateURLRequestInfo(PP_Instance instance) {
- NOTIMPLEMENTED();
- return 0;
+ return PPB_URLRequestInfo_Impl::Create(instance);
}
} // namespace ppapi
diff --git a/webkit/plugins/ppapi/url_request_info_unittest.cc b/webkit/plugins/ppapi/url_request_info_unittest.cc
index e3af414..5234ff2 100644
--- a/webkit/plugins/ppapi/url_request_info_unittest.cc
+++ b/webkit/plugins/ppapi/url_request_info_unittest.cc
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "ppapi/thunk/thunk.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
-
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
#include "webkit/plugins/ppapi/ppapi_unittest.h"
@@ -95,7 +95,8 @@ WebView* URLRequestInfoTest::web_view_;
WebFrame* URLRequestInfoTest::frame_;
TEST_F(URLRequestInfoTest, GetInterface) {
- const PPB_URLRequestInfo* interface = info_->GetInterface();
+ const PPB_URLRequestInfo* interface =
+ ::ppapi::thunk::GetPPB_URLRequestInfo_Thunk();
ASSERT_TRUE(interface);
ASSERT_TRUE(interface->Create);
ASSERT_TRUE(interface->IsURLRequestInfo);
@@ -107,7 +108,7 @@ TEST_F(URLRequestInfoTest, GetInterface) {
}
TEST_F(URLRequestInfoTest, AsURLRequestInfo) {
- ASSERT_EQ(info_, info_->AsPPB_URLRequestInfo_Impl());
+ ASSERT_EQ(info_, info_->AsPPB_URLRequestInfo_API());
}
TEST_F(URLRequestInfoTest, StreamToFile) {