blob: a76ac493513a4ed16f677495078da82659e8ec71 [file] [log] [blame]
[email protected]844fecb2012-11-16 20:11:061// 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/proxy/url_response_info_resource.h"
6
avie029c4132015-12-23 06:45:227#include <stdint.h>
8
[email protected]c6420f082013-09-18 22:42:419#include "ppapi/proxy/file_ref_resource.h"
[email protected]844fecb2012-11-16 20:11:0610#include "ppapi/shared_impl/var.h"
11#include "ppapi/thunk/enter.h"
12#include "ppapi/thunk/resource_creation_api.h"
13
14namespace ppapi {
15namespace proxy {
16
17namespace {
18
19bool IsRedirect(int32_t status) {
20 return status >= 300 && status <= 399;
21}
22
23} // namespace
24
25URLResponseInfoResource::URLResponseInfoResource(
26 Connection connection,
27 PP_Instance instance,
Marijn Kruisselbrink9ebd7ba2018-06-11 23:18:0428 const URLResponseInfoData& data)
29 : PluginResource(connection, instance), data_(data) {}
[email protected]844fecb2012-11-16 20:11:0630
31URLResponseInfoResource::~URLResponseInfoResource() {
32}
33
34thunk::PPB_URLResponseInfo_API*
35URLResponseInfoResource::AsPPB_URLResponseInfo_API() {
36 return this;
37}
38
39PP_Var URLResponseInfoResource::GetProperty(PP_URLResponseProperty property) {
40 switch (property) {
41 case PP_URLRESPONSEPROPERTY_URL:
42 return StringVar::StringToPPVar(data_.url);
43 case PP_URLRESPONSEPROPERTY_REDIRECTURL:
44 if (IsRedirect(data_.status_code))
45 return StringVar::StringToPPVar(data_.redirect_url);
46 break;
47 case PP_URLRESPONSEPROPERTY_REDIRECTMETHOD:
48 if (IsRedirect(data_.status_code))
49 return StringVar::StringToPPVar(data_.status_text);
50 break;
51 case PP_URLRESPONSEPROPERTY_STATUSCODE:
52 return PP_MakeInt32(data_.status_code);
53 case PP_URLRESPONSEPROPERTY_STATUSLINE:
54 return StringVar::StringToPPVar(data_.status_text);
55 case PP_URLRESPONSEPROPERTY_HEADERS:
56 return StringVar::StringToPPVar(data_.headers);
57 }
58 // The default is to return an undefined PP_Var.
59 return PP_MakeUndefined();
60}
61
62PP_Resource URLResponseInfoResource::GetBodyAsFileRef() {
Marijn Kruisselbrink9ebd7ba2018-06-11 23:18:0463 return 0;
[email protected]844fecb2012-11-16 20:11:0664}
65
[email protected]844fecb2012-11-16 20:11:0666} // namespace proxy
67} // namespace ppapi