| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "ppapi/cpp/url_loader.h" | 5 #include "ppapi/cpp/url_loader.h" |
| 6 | 6 |
| 7 #include "ppapi/c/ppb_url_loader.h" | 7 #include "ppapi/c/ppb_url_loader.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
| 10 #include "ppapi/cpp/file_ref.h" | 10 #include "ppapi/cpp/file_ref.h" |
| 11 #include "ppapi/cpp/instance_handle.h" | 11 #include "ppapi/cpp/instance_handle.h" |
| 12 #include "ppapi/cpp/module.h" | 12 #include "ppapi/cpp/module.h" |
| 13 #include "ppapi/cpp/module_impl.h" | 13 #include "ppapi/cpp/module_impl.h" |
| 14 #include "ppapi/cpp/url_request_info.h" | 14 #include "ppapi/cpp/url_request_info.h" |
| 15 #include "ppapi/cpp/url_response_info.h" | 15 #include "ppapi/cpp/url_response_info.h" |
| 16 | 16 |
| 17 namespace pp { | 17 namespace pp { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 template <> const char* interface_name<PPB_URLLoader>() { | 21 template <> const char* interface_name<PPB_URLLoader_1_0>() { |
| 22 return PPB_URLLOADER_INTERFACE; | 22 return PPB_URLLOADER_INTERFACE_1_0; |
| 23 } | 23 } |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 URLLoader::URLLoader(PP_Resource resource) : Resource(resource) { | 27 URLLoader::URLLoader(PP_Resource resource) : Resource(resource) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 URLLoader::URLLoader(const InstanceHandle& instance) { | 30 URLLoader::URLLoader(const InstanceHandle& instance) { |
| 31 if (!has_interface<PPB_URLLoader>()) | 31 if (!has_interface<PPB_URLLoader_1_0>()) |
| 32 return; | 32 return; |
| 33 PassRefFromConstructor(get_interface<PPB_URLLoader>()->Create( | 33 PassRefFromConstructor(get_interface<PPB_URLLoader_1_0>()->Create( |
| 34 instance.pp_instance())); | 34 instance.pp_instance())); |
| 35 } | 35 } |
| 36 | 36 |
| 37 URLLoader::URLLoader(const URLLoader& other) : Resource(other) { | 37 URLLoader::URLLoader(const URLLoader& other) : Resource(other) { |
| 38 } | 38 } |
| 39 | 39 |
| 40 int32_t URLLoader::Open(const URLRequestInfo& request_info, | 40 int32_t URLLoader::Open(const URLRequestInfo& request_info, |
| 41 const CompletionCallback& cc) { | 41 const CompletionCallback& cc) { |
| 42 if (!has_interface<PPB_URLLoader>()) | 42 if (!has_interface<PPB_URLLoader_1_0>()) |
| 43 return cc.MayForce(PP_ERROR_NOINTERFACE); | 43 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 44 return get_interface<PPB_URLLoader>()->Open(pp_resource(), | 44 return get_interface<PPB_URLLoader_1_0>()->Open(pp_resource(), |
| 45 request_info.pp_resource(), | 45 request_info.pp_resource(), |
| 46 cc.pp_completion_callback()); | 46 cc.pp_completion_callback()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 int32_t URLLoader::FollowRedirect(const CompletionCallback& cc) { | 49 int32_t URLLoader::FollowRedirect(const CompletionCallback& cc) { |
| 50 if (!has_interface<PPB_URLLoader>()) | 50 if (!has_interface<PPB_URLLoader_1_0>()) |
| 51 return cc.MayForce(PP_ERROR_NOINTERFACE); | 51 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 52 return get_interface<PPB_URLLoader>()->FollowRedirect( | 52 return get_interface<PPB_URLLoader_1_0>()->FollowRedirect( |
| 53 pp_resource(), cc.pp_completion_callback()); | 53 pp_resource(), cc.pp_completion_callback()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool URLLoader::GetUploadProgress(int64_t* bytes_sent, | 56 bool URLLoader::GetUploadProgress(int64_t* bytes_sent, |
| 57 int64_t* total_bytes_to_be_sent) const { | 57 int64_t* total_bytes_to_be_sent) const { |
| 58 if (!has_interface<PPB_URLLoader>()) | 58 if (!has_interface<PPB_URLLoader_1_0>()) |
| 59 return false; | 59 return false; |
| 60 return PP_ToBool(get_interface<PPB_URLLoader>()->GetUploadProgress( | 60 return PP_ToBool(get_interface<PPB_URLLoader_1_0>()->GetUploadProgress( |
| 61 pp_resource(), bytes_sent, total_bytes_to_be_sent)); | 61 pp_resource(), bytes_sent, total_bytes_to_be_sent)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool URLLoader::GetDownloadProgress( | 64 bool URLLoader::GetDownloadProgress( |
| 65 int64_t* bytes_received, | 65 int64_t* bytes_received, |
| 66 int64_t* total_bytes_to_be_received) const { | 66 int64_t* total_bytes_to_be_received) const { |
| 67 if (!has_interface<PPB_URLLoader>()) | 67 if (!has_interface<PPB_URLLoader_1_0>()) |
| 68 return false; | 68 return false; |
| 69 return PP_ToBool(get_interface<PPB_URLLoader>()->GetDownloadProgress( | 69 return PP_ToBool(get_interface<PPB_URLLoader_1_0>()->GetDownloadProgress( |
| 70 pp_resource(), bytes_received, total_bytes_to_be_received)); | 70 pp_resource(), bytes_received, total_bytes_to_be_received)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 URLResponseInfo URLLoader::GetResponseInfo() const { | 73 URLResponseInfo URLLoader::GetResponseInfo() const { |
| 74 if (!has_interface<PPB_URLLoader>()) | 74 if (!has_interface<PPB_URLLoader_1_0>()) |
| 75 return URLResponseInfo(); | 75 return URLResponseInfo(); |
| 76 return URLResponseInfo(PASS_REF, | 76 return URLResponseInfo(PASS_REF, |
| 77 get_interface<PPB_URLLoader>()->GetResponseInfo( | 77 get_interface<PPB_URLLoader_1_0>()->GetResponseInfo( |
| 78 pp_resource())); | 78 pp_resource())); |
| 79 } | 79 } |
| 80 | 80 |
| 81 int32_t URLLoader::ReadResponseBody(void* buffer, | 81 int32_t URLLoader::ReadResponseBody(void* buffer, |
| 82 int32_t bytes_to_read, | 82 int32_t bytes_to_read, |
| 83 const CompletionCallback& cc) { | 83 const CompletionCallback& cc) { |
| 84 if (!has_interface<PPB_URLLoader>()) | 84 if (!has_interface<PPB_URLLoader_1_0>()) |
| 85 return cc.MayForce(PP_ERROR_NOINTERFACE); | 85 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 86 return get_interface<PPB_URLLoader>()->ReadResponseBody( | 86 return get_interface<PPB_URLLoader_1_0>()->ReadResponseBody( |
| 87 pp_resource(), buffer, bytes_to_read, cc.pp_completion_callback()); | 87 pp_resource(), buffer, bytes_to_read, cc.pp_completion_callback()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 int32_t URLLoader::FinishStreamingToFile(const CompletionCallback& cc) { | 90 int32_t URLLoader::FinishStreamingToFile(const CompletionCallback& cc) { |
| 91 if (!has_interface<PPB_URLLoader>()) | 91 if (!has_interface<PPB_URLLoader_1_0>()) |
| 92 return cc.MayForce(PP_ERROR_NOINTERFACE); | 92 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 93 return get_interface<PPB_URLLoader>()->FinishStreamingToFile( | 93 return get_interface<PPB_URLLoader_1_0>()->FinishStreamingToFile( |
| 94 pp_resource(), cc.pp_completion_callback()); | 94 pp_resource(), cc.pp_completion_callback()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void URLLoader::Close() { | 97 void URLLoader::Close() { |
| 98 if (!has_interface<PPB_URLLoader>()) | 98 if (!has_interface<PPB_URLLoader_1_0>()) |
| 99 return; | 99 return; |
| 100 get_interface<PPB_URLLoader>()->Close(pp_resource()); | 100 get_interface<PPB_URLLoader_1_0>()->Close(pp_resource()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace pp | 103 } // namespace pp |
| OLD | NEW |