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.
5 #include "ppapi/proxy/url_response_info_resource.h"
7 #include "ppapi/proxy/file_ref_resource.h"
8 #include "ppapi/shared_impl/var.h"
9 #include "ppapi/thunk/enter.h"
10 #include "ppapi/thunk/resource_creation_api.h"
17 bool IsRedirect(int32_t status
) {
18 return status
>= 300 && status
<= 399;
23 URLResponseInfoResource::URLResponseInfoResource(
24 Connection connection
,
26 const URLResponseInfoData
& data
,
27 PP_Resource file_ref_resource
)
28 : PluginResource(connection
, instance
),
30 body_as_file_ref_(ScopedPPResource::PassRef(), file_ref_resource
) {
33 URLResponseInfoResource::~URLResponseInfoResource() {
36 thunk::PPB_URLResponseInfo_API
*
37 URLResponseInfoResource::AsPPB_URLResponseInfo_API() {
41 PP_Var
URLResponseInfoResource::GetProperty(PP_URLResponseProperty property
) {
43 case PP_URLRESPONSEPROPERTY_URL
:
44 return StringVar::StringToPPVar(data_
.url
);
45 case PP_URLRESPONSEPROPERTY_REDIRECTURL
:
46 if (IsRedirect(data_
.status_code
))
47 return StringVar::StringToPPVar(data_
.redirect_url
);
49 case PP_URLRESPONSEPROPERTY_REDIRECTMETHOD
:
50 if (IsRedirect(data_
.status_code
))
51 return StringVar::StringToPPVar(data_
.status_text
);
53 case PP_URLRESPONSEPROPERTY_STATUSCODE
:
54 return PP_MakeInt32(data_
.status_code
);
55 case PP_URLRESPONSEPROPERTY_STATUSLINE
:
56 return StringVar::StringToPPVar(data_
.status_text
);
57 case PP_URLRESPONSEPROPERTY_HEADERS
:
58 return StringVar::StringToPPVar(data_
.headers
);
60 // The default is to return an undefined PP_Var.
61 return PP_MakeUndefined();
64 PP_Resource
URLResponseInfoResource::GetBodyAsFileRef() {
65 if (!body_as_file_ref_
.get())
67 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(
68 body_as_file_ref_
.get());
69 return body_as_file_ref_
.get();