| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "extensions/browser/api/mime_handler_private/mime_handler_private.h" | 5 #include "extensions/browser/api/mime_handler_private/mime_handler_private.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" |
| 7 #include "content/public/browser/stream_handle.h" | 8 #include "content/public/browser/stream_handle.h" |
| 8 #include "content/public/browser/stream_info.h" | 9 #include "content/public/browser/stream_info.h" |
| 9 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" | 10 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" |
| 10 #include "extensions/common/constants.h" | 11 #include "extensions/common/constants.h" |
| 11 #include "net/http/http_response_headers.h" | 12 #include "net/http/http_response_headers.h" |
| 12 #include "third_party/mojo/src/mojo/public/cpp/bindings/map.h" | 13 #include "third_party/mojo/src/mojo/public/cpp/bindings/map.h" |
| 13 | 14 |
| 14 namespace extensions { | 15 namespace extensions { |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 mojo::Map<mojo::String, mojo::String> CreateResponseHeadersMap( | 18 mojo::Map<mojo::String, mojo::String> CreateResponseHeadersMap( |
| 18 const net::HttpResponseHeaders* headers) { | 19 const net::HttpResponseHeaders* headers) { |
| 19 std::map<std::string, std::string> result; | 20 std::map<std::string, std::string> result; |
| 20 if (!headers) | 21 if (!headers) |
| 21 return mojo::Map<mojo::String, mojo::String>::From(result); | 22 return mojo::Map<mojo::String, mojo::String>::From(result); |
| 22 | 23 |
| 23 void* iter = nullptr; | 24 void* iter = nullptr; |
| 24 std::string header_name; | 25 std::string header_name; |
| 25 std::string header_value; | 26 std::string header_value; |
| 26 while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { | 27 while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { |
| 28 // mojo strings must be UTF-8 and headers might not be, so drop any headers |
| 29 // that aren't ASCII. The PDF plugin does not use any headers with non-ASCII |
| 30 // names and non-ASCII values are never useful for the headers the plugin |
| 31 // does use. |
| 32 // |
| 33 // TODO(sammc): Send as bytes instead of a string and let the client decide |
| 34 // how to decode. |
| 35 if (!base::IsStringASCII(header_name) || !base::IsStringASCII(header_value)) |
| 36 continue; |
| 27 auto& current_value = result[header_name]; | 37 auto& current_value = result[header_name]; |
| 28 if (!current_value.empty()) | 38 if (!current_value.empty()) |
| 29 current_value += ", "; | 39 current_value += ", "; |
| 30 current_value += header_value; | 40 current_value += header_value; |
| 31 } | 41 } |
| 32 return mojo::Map<mojo::String, mojo::String>::From(result); | 42 return mojo::Map<mojo::String, mojo::String>::From(result); |
| 33 } | 43 } |
| 34 | 44 |
| 35 } // namespace | 45 } // namespace |
| 36 | 46 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 const content::StreamInfo* info = stream.stream_info(); | 100 const content::StreamInfo* info = stream.stream_info(); |
| 91 result->mime_type = info->mime_type; | 101 result->mime_type = info->mime_type; |
| 92 result->original_url = info->original_url.spec(); | 102 result->original_url = info->original_url.spec(); |
| 93 result->stream_url = info->handle->GetURL().spec(); | 103 result->stream_url = info->handle->GetURL().spec(); |
| 94 result->response_headers = | 104 result->response_headers = |
| 95 extensions::CreateResponseHeadersMap(info->response_headers.get()); | 105 extensions::CreateResponseHeadersMap(info->response_headers.get()); |
| 96 return result.Pass(); | 106 return result.Pass(); |
| 97 } | 107 } |
| 98 | 108 |
| 99 } // namespace mojo | 109 } // namespace mojo |
| OLD | NEW |