OLD | NEW |
(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 "webkit/plugins/ppapi/url_response_info_util.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPHeade
rVisitor.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" |
| 12 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
| 13 #include "webkit/glue/webkit_glue.h" |
| 14 |
| 15 using WebKit::WebHTTPHeaderVisitor; |
| 16 using WebKit::WebString; |
| 17 using WebKit::WebURLResponse; |
| 18 |
| 19 namespace webkit { |
| 20 namespace ppapi { |
| 21 |
| 22 namespace { |
| 23 |
| 24 class HeaderFlattener : public WebHTTPHeaderVisitor { |
| 25 public: |
| 26 const std::string& buffer() const { return buffer_; } |
| 27 |
| 28 virtual void visitHeader(const WebString& name, const WebString& value) { |
| 29 if (!buffer_.empty()) |
| 30 buffer_.append("\n"); |
| 31 buffer_.append(name.utf8()); |
| 32 buffer_.append(": "); |
| 33 buffer_.append(value.utf8()); |
| 34 } |
| 35 |
| 36 private: |
| 37 std::string buffer_; |
| 38 }; |
| 39 |
| 40 bool IsRedirect(int32_t status) { |
| 41 return status >= 300 && status <= 399; |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
| 46 ::ppapi::URLResponseInfoData DataFromWebURLResponse( |
| 47 PP_Instance pp_instance, |
| 48 const WebURLResponse& response) { |
| 49 ::ppapi::URLResponseInfoData data; |
| 50 |
| 51 data.url = response.url().spec(); |
| 52 data.status_code = response.httpStatusCode(); |
| 53 data.status_text = response.httpStatusText().utf8(); |
| 54 if (IsRedirect(data.status_code)) { |
| 55 data.redirect_url = response.httpHeaderField( |
| 56 WebString::fromUTF8("Location")).utf8(); |
| 57 } |
| 58 |
| 59 HeaderFlattener flattener; |
| 60 response.visitHTTPHeaderFields(&flattener); |
| 61 data.headers = flattener.buffer(); |
| 62 |
| 63 WebString file_path = response.downloadFilePath(); |
| 64 if (!file_path.isEmpty()) { |
| 65 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 66 PPB_FileRef_Impl::CreateExternal( |
| 67 pp_instance, |
| 68 webkit_glue::WebStringToFilePath(file_path), |
| 69 std::string())); |
| 70 data.body_as_file_ref = file_ref->GetCreateInfo(); |
| 71 file_ref->GetReference(); // The returned data has one ref for the plugin. |
| 72 } |
| 73 return data; |
| 74 } |
| 75 |
| 76 } // namespace ppapi |
| 77 } // namespace webkit |
OLD | NEW |