Pepper_47_C++_interfaces
url_loader.cc
Go to the documentation of this file.
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
3 // found in the LICENSE file.
4 
5 #include "ppapi/cpp/url_loader.h"
6 
7 #include "ppapi/c/ppb_url_loader.h"
8 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/cpp/file_ref.h"
12 #include "ppapi/cpp/module.h"
13 #include "ppapi/cpp/module_impl.h"
16 
17 namespace pp {
18 
19 namespace {
20 
21 template <> const char* interface_name<PPB_URLLoader_1_0>() {
22  return PPB_URLLOADER_INTERFACE_1_0;
23 }
24 
25 } // namespace
26 
27 URLLoader::URLLoader(PP_Resource resource) : Resource(resource) {
28 }
29 
31  if (!has_interface<PPB_URLLoader_1_0>())
32  return;
33  PassRefFromConstructor(get_interface<PPB_URLLoader_1_0>()->Create(
34  instance.pp_instance()));
35 }
36 
37 URLLoader::URLLoader(const URLLoader& other) : Resource(other) {
38 }
39 
41  const CompletionCallback& cc) {
42  if (!has_interface<PPB_URLLoader_1_0>())
43  return cc.MayForce(PP_ERROR_NOINTERFACE);
44  return get_interface<PPB_URLLoader_1_0>()->Open(pp_resource(),
45  request_info.pp_resource(),
47 }
48 
50  if (!has_interface<PPB_URLLoader_1_0>())
51  return cc.MayForce(PP_ERROR_NOINTERFACE);
52  return get_interface<PPB_URLLoader_1_0>()->FollowRedirect(
54 }
55 
56 bool URLLoader::GetUploadProgress(int64_t* bytes_sent,
57  int64_t* total_bytes_to_be_sent) const {
58  if (!has_interface<PPB_URLLoader_1_0>())
59  return false;
60  return PP_ToBool(get_interface<PPB_URLLoader_1_0>()->GetUploadProgress(
61  pp_resource(), bytes_sent, total_bytes_to_be_sent));
62 }
63 
65  int64_t* bytes_received,
66  int64_t* total_bytes_to_be_received) const {
67  if (!has_interface<PPB_URLLoader_1_0>())
68  return false;
69  return PP_ToBool(get_interface<PPB_URLLoader_1_0>()->GetDownloadProgress(
70  pp_resource(), bytes_received, total_bytes_to_be_received));
71 }
72 
74  if (!has_interface<PPB_URLLoader_1_0>())
75  return URLResponseInfo();
77  get_interface<PPB_URLLoader_1_0>()->GetResponseInfo(
78  pp_resource()));
79 }
80 
82  int32_t bytes_to_read,
83  const CompletionCallback& cc) {
84  if (!has_interface<PPB_URLLoader_1_0>())
85  return cc.MayForce(PP_ERROR_NOINTERFACE);
86  return get_interface<PPB_URLLoader_1_0>()->ReadResponseBody(
87  pp_resource(), buffer, bytes_to_read, cc.pp_completion_callback());
88 }
89 
91  if (!has_interface<PPB_URLLoader_1_0>())
92  return cc.MayForce(PP_ERROR_NOINTERFACE);
93  return get_interface<PPB_URLLoader_1_0>()->FinishStreamingToFile(
95 }
96 
98  if (!has_interface<PPB_URLLoader_1_0>())
99  return;
100  get_interface<PPB_URLLoader_1_0>()->Close(pp_resource());
101 }
102 
103 } // namespace pp
void PassRefFromConstructor(PP_Resource resource)
Definition: resource.cc:50
bool GetDownloadProgress(int64_t *bytes_received, int64_t *total_bytes_to_be_received) const
Definition: url_loader.cc:64
int32_t MayForce(int32_t result) const
const PP_CompletionCallback & pp_completion_callback() const
URLResponseInfo provides an API for examining URL responses.
int32_t FinishStreamingToFile(const CompletionCallback &cc)
Definition: url_loader.cc:90
URLRequestInfo provides an API for creating and manipulating URL requests.
PP_Resource pp_resource() const
Definition: resource.h:47
int32_t ReadResponseBody(void *buffer, int32_t bytes_to_read, const CompletionCallback &cc)
Definition: url_loader.cc:81
void Close()
Definition: url_loader.cc:97
bool GetUploadProgress(int64_t *bytes_sent, int64_t *total_bytes_to_be_sent) const
Definition: url_loader.cc:56
int32_t Open(const URLRequestInfo &request_info, const CompletionCallback &cc)
Definition: url_loader.cc:40
PP_Instance pp_instance() const
A reference counted module resource.
Definition: resource.h:20
URLResponseInfo GetResponseInfo() const
Definition: url_loader.cc:73
int32_t FollowRedirect(const CompletionCallback &cc)
Definition: url_loader.cc:49