| 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_request_info.h" | 5 #include "webkit/glue/plugins/pepper_url_request_info.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 #include "net/http/http_util.h" | 10 #include "net/http/http_util.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 &Create, | 115 &Create, |
| 116 &IsURLRequestInfo, | 116 &IsURLRequestInfo, |
| 117 &SetProperty, | 117 &SetProperty, |
| 118 &AppendDataToBody, | 118 &AppendDataToBody, |
| 119 &AppendFileToBody | 119 &AppendFileToBody |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 } // namespace | 122 } // namespace |
| 123 | 123 |
| 124 URLRequestInfo::URLRequestInfo(PluginModule* module) | 124 URLRequestInfo::URLRequestInfo(PluginModule* module) |
| 125 : Resource(module) { | 125 : Resource(module), |
| 126 stream_to_file_(false) { |
| 126 } | 127 } |
| 127 | 128 |
| 128 URLRequestInfo::~URLRequestInfo() { | 129 URLRequestInfo::~URLRequestInfo() { |
| 129 } | 130 } |
| 130 | 131 |
| 131 // static | 132 // static |
| 132 const PPB_URLRequestInfo* URLRequestInfo::GetInterface() { | 133 const PPB_URLRequestInfo* URLRequestInfo::GetInterface() { |
| 133 return &ppb_urlrequestinfo; | 134 return &ppb_urlrequestinfo; |
| 134 } | 135 } |
| 135 | 136 |
| 136 bool URLRequestInfo::SetBooleanProperty(PP_URLRequestProperty property, | 137 bool URLRequestInfo::SetBooleanProperty(PP_URLRequestProperty property, |
| 137 bool value) { | 138 bool value) { |
| 138 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 139 switch (property) { |
| 139 return false; | 140 case PP_URLREQUESTPROPERTY_STREAMTOFILE: |
| 141 stream_to_file_ = value; |
| 142 return true; |
| 143 default: |
| 144 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
| 145 return false; |
| 146 } |
| 140 } | 147 } |
| 141 | 148 |
| 142 bool URLRequestInfo::SetStringProperty(PP_URLRequestProperty property, | 149 bool URLRequestInfo::SetStringProperty(PP_URLRequestProperty property, |
| 143 const std::string& value) { | 150 const std::string& value) { |
| 144 // TODO(darin): Validate input. Perhaps at a different layer? | 151 // TODO(darin): Validate input. Perhaps at a different layer? |
| 145 switch (property) { | 152 switch (property) { |
| 146 case PP_URLREQUESTPROPERTY_URL: | 153 case PP_URLREQUESTPROPERTY_URL: |
| 147 url_ = value; // NOTE: This may be a relative URL. | 154 url_ = value; // NOTE: This may be a relative URL. |
| 148 return true; | 155 return true; |
| 149 case PP_URLREQUESTPROPERTY_METHOD: | 156 case PP_URLREQUESTPROPERTY_METHOD: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 160 bool URLRequestInfo::AppendDataToBody(const std::string& data) { | 167 bool URLRequestInfo::AppendDataToBody(const std::string& data) { |
| 161 if (!data.empty()) | 168 if (!data.empty()) |
| 162 body_.push_back(BodyItem(data)); | 169 body_.push_back(BodyItem(data)); |
| 163 return true; | 170 return true; |
| 164 } | 171 } |
| 165 | 172 |
| 166 bool URLRequestInfo::AppendFileToBody(FileRef* file_ref, | 173 bool URLRequestInfo::AppendFileToBody(FileRef* file_ref, |
| 167 int64_t start_offset, | 174 int64_t start_offset, |
| 168 int64_t number_of_bytes, | 175 int64_t number_of_bytes, |
| 169 PP_Time expected_last_modified_time) { | 176 PP_Time expected_last_modified_time) { |
| 177 // Ignore a call to append nothing. |
| 178 if (number_of_bytes == 0) |
| 179 return true; |
| 180 |
| 181 // Check for bad values. (-1 means read until end of file.) |
| 182 if (start_offset < 0 || number_of_bytes < -1) |
| 183 return false; |
| 184 |
| 170 body_.push_back(BodyItem(file_ref, | 185 body_.push_back(BodyItem(file_ref, |
| 171 start_offset, | 186 start_offset, |
| 172 number_of_bytes, | 187 number_of_bytes, |
| 173 expected_last_modified_time)); | 188 expected_last_modified_time)); |
| 174 return true; | 189 return true; |
| 175 } | 190 } |
| 176 | 191 |
| 177 WebURLRequest URLRequestInfo::ToWebURLRequest(WebFrame* frame) const { | 192 WebURLRequest URLRequestInfo::ToWebURLRequest(WebFrame* frame) const { |
| 178 WebURLRequest web_request; | 193 WebURLRequest web_request; |
| 179 web_request.initialize(); | 194 web_request.initialize(); |
| 180 web_request.setURL(frame->document().completeURL(WebString::fromUTF8(url_))); | 195 web_request.setURL(frame->document().completeURL(WebString::fromUTF8(url_))); |
| 196 web_request.setDownloadToFile(stream_to_file_); |
| 181 | 197 |
| 182 if (!method_.empty()) | 198 if (!method_.empty()) |
| 183 web_request.setHTTPMethod(WebString::fromUTF8(method_)); | 199 web_request.setHTTPMethod(WebString::fromUTF8(method_)); |
| 184 | 200 |
| 185 if (!headers_.empty()) { | 201 if (!headers_.empty()) { |
| 186 net::HttpUtil::HeadersIterator it(headers_.begin(), headers_.end(), "\n"); | 202 net::HttpUtil::HeadersIterator it(headers_.begin(), headers_.end(), "\n"); |
| 187 while (it.GetNext()) { | 203 while (it.GetNext()) { |
| 188 if (!IsIgnoredRequestHeader(it.name())) { | 204 if (!IsIgnoredRequestHeader(it.name())) { |
| 189 web_request.addHTTPHeaderField( | 205 web_request.addHTTPHeaderField( |
| 190 WebString::fromUTF8(it.name()), | 206 WebString::fromUTF8(it.name()), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 211 } | 227 } |
| 212 } | 228 } |
| 213 web_request.setHTTPBody(http_body); | 229 web_request.setHTTPBody(http_body); |
| 214 } | 230 } |
| 215 | 231 |
| 216 frame->setReferrerForRequest(web_request, WebURL()); // Use default. | 232 frame->setReferrerForRequest(web_request, WebURL()); // Use default. |
| 217 return web_request; | 233 return web_request; |
| 218 } | 234 } |
| 219 | 235 |
| 220 } // namespace pepper | 236 } // namespace pepper |
| OLD | NEW |