OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/glue/plugins/pepper_url_response_info.h" | 5 #include "webkit/glue/plugins/pepper_url_response_info.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ppapi/c/pp_var.h" | 8 #include "ppapi/c/pp_var.h" |
9 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 private: | 38 private: |
39 std::string buffer_; | 39 std::string buffer_; |
40 }; | 40 }; |
41 | 41 |
42 PP_Bool IsURLResponseInfo(PP_Resource resource) { | 42 PP_Bool IsURLResponseInfo(PP_Resource resource) { |
43 return BoolToPPBool(!!Resource::GetAs<URLResponseInfo>(resource)); | 43 return BoolToPPBool(!!Resource::GetAs<URLResponseInfo>(resource)); |
44 } | 44 } |
45 | 45 |
46 PP_Var GetProperty(PP_Resource response_id, | 46 PP_Var GetProperty(PP_Resource response_id, |
47 PP_URLResponseProperty_Dev property) { | 47 PP_URLResponseProperty property) { |
48 scoped_refptr<URLResponseInfo> response( | 48 scoped_refptr<URLResponseInfo> response( |
49 Resource::GetAs<URLResponseInfo>(response_id)); | 49 Resource::GetAs<URLResponseInfo>(response_id)); |
50 if (!response) | 50 if (!response) |
51 return PP_MakeUndefined(); | 51 return PP_MakeUndefined(); |
52 | 52 |
53 return response->GetProperty(property); | 53 return response->GetProperty(property); |
54 } | 54 } |
55 | 55 |
56 PP_Resource GetBody(PP_Resource response_id) { | 56 PP_Resource GetBody(PP_Resource response_id) { |
57 scoped_refptr<URLResponseInfo> response( | 57 scoped_refptr<URLResponseInfo> response( |
58 Resource::GetAs<URLResponseInfo>(response_id)); | 58 Resource::GetAs<URLResponseInfo>(response_id)); |
59 if (!response.get()) | 59 if (!response.get()) |
60 return 0; | 60 return 0; |
61 | 61 |
62 FileRef* body = response->body(); | 62 FileRef* body = response->body(); |
63 if (!body) | 63 if (!body) |
64 return 0; | 64 return 0; |
65 body->AddRef(); // AddRef for the caller. | 65 body->AddRef(); // AddRef for the caller. |
66 | 66 |
67 return body->GetReference(); | 67 return body->GetReference(); |
68 } | 68 } |
69 | 69 |
70 const PPB_URLResponseInfo_Dev ppb_urlresponseinfo = { | 70 const PPB_URLResponseInfo ppb_urlresponseinfo = { |
71 &IsURLResponseInfo, | 71 &IsURLResponseInfo, |
72 &GetProperty, | 72 &GetProperty, |
73 &GetBody | 73 &GetBody |
74 }; | 74 }; |
75 | 75 |
76 bool IsRedirect(int32_t status) { | 76 bool IsRedirect(int32_t status) { |
77 return status >= 300 && status <= 399; | 77 return status >= 300 && status <= 399; |
78 } | 78 } |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 URLResponseInfo::URLResponseInfo(PluginModule* module) | 82 URLResponseInfo::URLResponseInfo(PluginModule* module) |
83 : Resource(module), | 83 : Resource(module), |
84 status_code_(-1) { | 84 status_code_(-1) { |
85 } | 85 } |
86 | 86 |
87 URLResponseInfo::~URLResponseInfo() { | 87 URLResponseInfo::~URLResponseInfo() { |
88 } | 88 } |
89 | 89 |
90 // static | 90 // static |
91 const PPB_URLResponseInfo_Dev* URLResponseInfo::GetInterface() { | 91 const PPB_URLResponseInfo* URLResponseInfo::GetInterface() { |
92 return &ppb_urlresponseinfo; | 92 return &ppb_urlresponseinfo; |
93 } | 93 } |
94 | 94 |
95 PP_Var URLResponseInfo::GetProperty(PP_URLResponseProperty_Dev property) { | 95 PP_Var URLResponseInfo::GetProperty(PP_URLResponseProperty property) { |
96 switch (property) { | 96 switch (property) { |
97 case PP_URLRESPONSEPROPERTY_URL: | 97 case PP_URLRESPONSEPROPERTY_URL: |
98 return StringVar::StringToPPVar(module(), url_); | 98 return StringVar::StringToPPVar(module(), url_); |
99 case PP_URLRESPONSEPROPERTY_REDIRECTURL: | 99 case PP_URLRESPONSEPROPERTY_REDIRECTURL: |
100 if (IsRedirect(status_code_)) | 100 if (IsRedirect(status_code_)) |
101 return StringVar::StringToPPVar(module(), redirect_url_); | 101 return StringVar::StringToPPVar(module(), redirect_url_); |
102 break; | 102 break; |
103 case PP_URLRESPONSEPROPERTY_REDIRECTMETHOD: | 103 case PP_URLRESPONSEPROPERTY_REDIRECTMETHOD: |
104 if (IsRedirect(status_code_)) | 104 if (IsRedirect(status_code_)) |
105 return StringVar::StringToPPVar(module(), status_text_); | 105 return StringVar::StringToPPVar(module(), status_text_); |
(...skipping 22 matching lines...) Expand all Loading... |
128 response.visitHTTPHeaderFields(&flattener); | 128 response.visitHTTPHeaderFields(&flattener); |
129 headers_ = flattener.buffer(); | 129 headers_ = flattener.buffer(); |
130 | 130 |
131 WebString file_path = response.downloadFilePath(); | 131 WebString file_path = response.downloadFilePath(); |
132 if (!file_path.isEmpty()) | 132 if (!file_path.isEmpty()) |
133 body_ = new FileRef(module(), webkit_glue::WebStringToFilePath(file_path)); | 133 body_ = new FileRef(module(), webkit_glue::WebStringToFilePath(file_path)); |
134 return true; | 134 return true; |
135 } | 135 } |
136 | 136 |
137 } // namespace pepper | 137 } // namespace pepper |
OLD | NEW |