Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: ppapi/proxy/url_response_info_resource.cc

Issue 10993031: Refactor the URLResponseInfo to use new design (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/url_response_info_resource.h ('k') | ppapi/shared_impl/url_response_info_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ppapi/proxy/url_response_info_resource.h"
6
7 #include "ppapi/proxy/ppb_file_ref_proxy.h"
8 #include "ppapi/shared_impl/var.h"
9 #include "ppapi/thunk/enter.h"
10 #include "ppapi/thunk/resource_creation_api.h"
11
12 namespace ppapi {
13 namespace proxy {
14
15 namespace {
16
17 bool IsRedirect(int32_t status) {
18 return status >= 300 && status <= 399;
19 }
20
21 } // namespace
22
23 URLResponseInfoResource::URLResponseInfoResource(
24 Connection connection,
25 PP_Instance instance,
26 const URLResponseInfoData& data,
27 PP_Resource file_ref_resource)
28 : PluginResource(connection, instance),
29 data_(data),
30 body_as_file_ref_(ScopedPPResource::PassRef(), file_ref_resource) {
31 }
32
33 URLResponseInfoResource::~URLResponseInfoResource() {
34 }
35
36 thunk::PPB_URLResponseInfo_API*
37 URLResponseInfoResource::AsPPB_URLResponseInfo_API() {
38 return this;
39 }
40
41 PP_Var URLResponseInfoResource::GetProperty(PP_URLResponseProperty property) {
42 switch (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);
48 break;
49 case PP_URLRESPONSEPROPERTY_REDIRECTMETHOD:
50 if (IsRedirect(data_.status_code))
51 return StringVar::StringToPPVar(data_.status_text);
52 break;
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);
59 }
60 // The default is to return an undefined PP_Var.
61 return PP_MakeUndefined();
62 }
63
64 PP_Resource URLResponseInfoResource::GetBodyAsFileRef() {
65 if (!body_as_file_ref_.get())
66 return 0;
67 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(
68 body_as_file_ref_.get());
69 return body_as_file_ref_.get();
70 }
71
72 URLResponseInfoData URLResponseInfoResource::GetData() {
73 // One ref is passed to the caller if there's a file ref.
74 if (body_as_file_ref_.get()) {
75 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(
76 body_as_file_ref_.get());
77 }
78 return data_;
79 }
80
81 } // namespace proxy
82 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/url_response_info_resource.h ('k') | ppapi/shared_impl/url_response_info_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698