• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 #ifndef PPAPI_CPP_URL_RESPONSE_INFO_H_
6 #define PPAPI_CPP_URL_RESPONSE_INFO_H_
7 
8 #include "ppapi/c/ppb_url_response_info.h"
9 #include "ppapi/cpp/resource.h"
10 #include "ppapi/cpp/var.h"
11 
12 /// @file
13 /// This file defines the API for examining URL responses.
14 namespace pp {
15 
16 class FileRef;
17 
18 /// URLResponseInfo provides an API for examining URL responses.
19 class URLResponseInfo : public Resource {
20  public:
21   /// Default constructor. This constructor creates an <code>is_null</code>
22   /// resource.
URLResponseInfo()23   URLResponseInfo() {}
24 
25   /// A constructor used when you have received a <code>PP_Resource</code> as a
26   /// return value that has already been reference counted.
27   ///
28   /// @param[in] resource A <code>PP_Resource</code> corresponding to a
29   /// resource.
30   URLResponseInfo(PassRef, PP_Resource resource);
31 
32   /// The copy constructor for <code>URLResponseInfo</code>.
33   URLResponseInfo(const URLResponseInfo& other);
34 
35   /// This function gets a response property.
36   ///
37   /// @param[in] property A <code>PP_URLResponseProperty</code> identifying the
38   /// type of property in the response.
39   ///
40   /// @return A <code>Var</code> containing the response property value if
41   /// successful, <code>is_undefined Var</code> if an input parameter is
42   /// invalid.
43   Var GetProperty(PP_URLResponseProperty property) const;
44 
45   /// This function returns a <code>FileRef</code>
46   /// pointing to the file containing the response body.  This
47   /// is only valid if <code>PP_URLREQUESTPROPERTY_STREAMTOFILE</code> was set
48   /// on the <code>URLRequestInfo</code> used to produce this response.  This
49   /// file remains valid until the <code>URLLoader</code> associated with this
50   /// <code>URLResponseInfo</code> is closed or destroyed.
51   ///
52   /// @return A <code>FileRef</code> corresponding to a
53   /// <code>FileRef</code> if successful, an <code>is_null</code> object if
54   /// <code>PP_URLREQUESTPROPERTY_STREAMTOFILE</code> was not requested or if
55   /// the <code>URLLoader</code> has not been opened yet.
56   FileRef GetBodyAsFileRef() const;
57 
58   /// This function gets the <code>PP_URLRESPONSEPROPERTY_URL</code>
59   /// property for the response.
60   ///
61   /// @return An <code>is_string Var</code> containing the response property
62   /// value if successful, <code>is_undefined Var</code> if an input parameter
63   /// is invalid.
GetURL()64   Var GetURL() const {
65     return GetProperty(PP_URLRESPONSEPROPERTY_URL);
66   }
67 
68   /// This function gets the <code>PP_URLRESPONSEPROPERTY_REDIRECTURL</code>
69   /// property for the response.
70   ///
71   /// @return An <code>is_string Var</code> containing the response property
72   /// value if successful, <code>is_undefined Var</code> if an input parameter
73   /// is invalid.
GetRedirectURL()74   Var GetRedirectURL() const {
75     return GetProperty(PP_URLRESPONSEPROPERTY_REDIRECTURL);
76   }
77 
78   /// This function gets the <code>PP_URLRESPONSEPROPERTY_REDIRECTMETHOD</code>
79   /// property for the response.
80   ///
81   /// @return An <code>is_string Var</code> containing the response property
82   /// value if successful, <code>is_undefined Var</code> if an input parameter
83   /// is invalid.
GetRedirectMethod()84   Var GetRedirectMethod() const {
85     return GetProperty(PP_URLRESPONSEPROPERTY_REDIRECTMETHOD);
86   }
87 
88   /// This function gets the <code>PP_URLRESPONSEPROPERTY_STATUSCODE</code>
89   /// property for the response.
90   ///
91   /// @return A int32_t containing the response property value if successful,
92   /// <code>is_undefined Var</code> if an input parameter is invalid.
GetStatusCode()93   int32_t GetStatusCode() const {
94     return GetProperty(PP_URLRESPONSEPROPERTY_STATUSCODE).AsInt();
95   }
96 
97   /// This function gets the <code>PP_URLRESPONSEPROPERTY_STATUSLINE</code>
98   /// property for the response.
99   ///
100   /// @return An <code>is_string Var</code> containing the response property
101   /// value if successful, <code>is_undefined Var</code> if an input parameter
102   /// is invalid.
GetStatusLine()103   Var GetStatusLine() const {
104     return GetProperty(PP_URLRESPONSEPROPERTY_STATUSLINE);
105   }
106 
107   /// This function gets the <code>PP_URLRESPONSEPROPERTY_HEADERS</code>
108   /// property for the response.
109   ///
110   /// @return An <code>is_string Var</code> containing the response property
111   /// value if successful, <code>is_undefined Var</code> if an input parameter
112   /// is invalid.
GetHeaders()113   Var GetHeaders() const {
114     return GetProperty(PP_URLRESPONSEPROPERTY_HEADERS);
115   }
116 };
117 
118 }  // namespace pp
119 
120 #endif  // PPAPI_CPP_URL_RESPONSE_INFO_H_
121