summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp/url_request_info.h
blob: f0922a586bc388d85d0b87fc2327b3c3de90f288 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// 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.

#ifndef PPAPI_CPP_URL_REQUEST_INFO_H_
#define PPAPI_CPP_URL_REQUEST_INFO_H_

#include "ppapi/c/ppb_url_request_info.h"
#include "ppapi/cpp/resource.h"
#include "ppapi/cpp/var.h"

namespace pp {

class FileRef_Dev;
class Instance;

class URLRequestInfo : public Resource {
 public:
  // Creates an is_null resource.
  URLRequestInfo() {}

  explicit URLRequestInfo(Instance* instance);
  URLRequestInfo(const URLRequestInfo& other);

  // PPB_URLRequestInfo methods:
  bool SetProperty(PP_URLRequestProperty property, const Var& value);
  bool AppendDataToBody(const void* data, uint32_t len);
  bool AppendFileToBody(const FileRef_Dev& file_ref,
                        PP_Time expected_last_modified_time = 0);
  bool AppendFileRangeToBody(const FileRef_Dev& file_ref,
                             int64_t start_offset,
                             int64_t length,
                             PP_Time expected_last_modified_time = 0);

  // Convenient helpers for setting properties:
  bool SetURL(const Var& url_string) {
    return SetProperty(PP_URLREQUESTPROPERTY_URL, url_string);
  }
  bool SetMethod(const Var& method_string) {
    return SetProperty(PP_URLREQUESTPROPERTY_METHOD, method_string);
  }
  bool SetHeaders(const Var& headers_string) {
    return SetProperty(PP_URLREQUESTPROPERTY_HEADERS, headers_string);
  }
  bool SetStreamToFile(bool enable) {
    return SetProperty(PP_URLREQUESTPROPERTY_STREAMTOFILE, enable);
  }
  bool SetFollowRedirects(bool enable) {
    return SetProperty(PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS, enable);
  }
  bool SetRecordDownloadProgress(bool enable) {
    return SetProperty(PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS, enable);
  }
  bool SetRecordUploadProgress(bool enable) {
    return SetProperty(PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS, enable);
  }
  // To use the default referrer, set url to an Undefined Var.
  bool SetCustomReferrerURL(const Var& url) {
    return SetProperty(PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL, url);
  }
  bool SetAllowCrossOriginRequests(bool enable) {
    return SetProperty(PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS, enable);
  }
  bool SetAllowCredentials(bool enable) {
    return SetProperty(PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS, enable);
  }
  // To use the default content transfer encoding, set content_transfer_encoding
  // to an Undefined Var.
  bool SetCustomContentTransferEncoding(const Var& content_transfer_encoding) {
    return SetProperty(PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING,
                       content_transfer_encoding);
  }
  bool SetPrefetchBufferUpperThreshold(int32_t size) {
    return SetProperty(PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD,
                       size);
  }
  bool SetPrefetchBufferLowerThreshold(int32_t size) {
    return SetProperty(PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD,
                       size);
  }
};

}  // namespace pp

#endif  // PPAPI_CPP_URL_REQUEST_INFO_H_