// 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_RESPONSE_INFO_H_ #define PPAPI_CPP_URL_RESPONSE_INFO_H_ #include "ppapi/c/ppb_url_response_info.h" #include "ppapi/cpp/resource.h" #include "ppapi/cpp/var.h" /// @file /// This file defines the API for examining URL responses. namespace pp { class FileRef; /// URLResponseInfo provides an API for examaning URL responses. class URLResponseInfo : public Resource { public: /// Default constructor. This constructor creates an is_null /// resource. URLResponseInfo() {} /// A constructor used when you have received a PP_Resource as a /// return value that has already been reference counted. /// /// @param[in] resource A PP_Resource corresponding to a /// resource. URLResponseInfo(PassRef, PP_Resource resource); /// The copy constructor for URLResponseInfo. URLResponseInfo(const URLResponseInfo& other); /// This function gets a response property. /// /// @param[in] property A PP_URLResponseProperty identifying the /// type of property in the response. /// /// @return A Var containing the response property value if /// successful, is_undefined Var if an input parameter is /// invalid. Var GetProperty(PP_URLResponseProperty property) const; /// This function returns a FileRef /// pointing to the file containing the response body. This /// is only valid if PP_URLREQUESTPROPERTY_STREAMTOFILE was set /// on the URLRequestInfo used to produce this response. This /// file remains valid until the URLLoader associated with this /// URLResponseInfo is closed or destroyed. /// /// @return A FileRef corresponding to a /// FileRef if successful, an is_null object if /// PP_URLREQUESTPROPERTY_STREAMTOFILE was not requested or if /// the URLLoader has not been opened yet. FileRef GetBodyAsFileRef() const; /// This function gets the PP_URLRESPONSEPROPERTY_URL /// property for the response. /// /// @return An is_string Var containing the response property /// value if successful, is_undefined Var if an input parameter /// is invalid. Var GetURL() const { return GetProperty(PP_URLRESPONSEPROPERTY_URL); } /// This function gets the PP_URLRESPONSEPROPERTY_REDIRECTURL /// property for the response. /// /// @return An is_string Var containing the response property /// value if successful, is_undefined Var if an input parameter /// is invalid. Var GetRedirectURL() const { return GetProperty(PP_URLRESPONSEPROPERTY_REDIRECTURL); } /// This function gets the PP_URLRESPONSEPROPERTY_REDIRECTMETHOD /// property for the response. /// /// @return An is_string Var containing the response property /// value if successful, is_undefined Var if an input parameter /// is invalid. Var GetRedirectMethod() const { return GetProperty(PP_URLRESPONSEPROPERTY_REDIRECTMETHOD); } /// This function gets the PP_URLRESPONSEPROPERTY_STATUSCODE /// property for the response. /// /// @return A int32_t containing the response property value if successful, /// is_undefined Var if an input parameter is invalid. int32_t GetStatusCode() const { return GetProperty(PP_URLRESPONSEPROPERTY_STATUSCODE).AsInt(); } /// This function gets the PP_URLRESPONSEPROPERTY_STATUSLINE /// property for the response. /// /// @return An is_string Var containing the response property /// value if successful, is_undefined Var if an input parameter /// is invalid. Var GetStatusLine() const { return GetProperty(PP_URLRESPONSEPROPERTY_STATUSLINE); } /// This function gets the PP_URLRESPONSEPROPERTY_HEADERS /// property for the response. /// /// @return An is_string Var containing the response property /// value if successful, is_undefined Var if an input parameter /// is invalid. Var GetHeaders() const { return GetProperty(PP_URLRESPONSEPROPERTY_HEADERS); } }; } // namespace pp #endif // PPAPI_CPP_URL_RESPONSE_INFO_H_