| 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 <unordered_map> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 10 #include "content/public/browser/stream_handle.h" | 11 #include "content/public/browser/stream_handle.h" |
| 11 #include "content/public/browser/stream_info.h" | 12 #include "content/public/browser/stream_info.h" |
| 12 #include "content/public/common/content_constants.h" | 13 #include "content/public/common/content_constants.h" |
| 13 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" | 14 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" |
| 14 #include "extensions/common/constants.h" | 15 #include "extensions/common/constants.h" |
| 15 #include "mojo/public/cpp/bindings/map.h" | |
| 16 #include "mojo/public/cpp/bindings/strong_binding.h" | 16 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
| 18 | 18 |
| 19 namespace extensions { | 19 namespace extensions { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 mojo::Map<mojo::String, mojo::String> CreateResponseHeadersMap( | 22 std::unordered_map<std::string, std::string> CreateResponseHeadersMap( |
| 23 const net::HttpResponseHeaders* headers) { | 23 const net::HttpResponseHeaders* headers) { |
| 24 std::map<std::string, std::string> result; | 24 std::unordered_map<std::string, std::string> result; |
| 25 if (!headers) | 25 if (!headers) |
| 26 return mojo::Map<mojo::String, mojo::String>::From(result); | 26 return result; |
| 27 | 27 |
| 28 size_t iter = 0; | 28 size_t iter = 0; |
| 29 std::string header_name; | 29 std::string header_name; |
| 30 std::string header_value; | 30 std::string header_value; |
| 31 while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { | 31 while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { |
| 32 // mojo strings must be UTF-8 and headers might not be, so drop any headers | 32 // mojo strings must be UTF-8 and headers might not be, so drop any headers |
| 33 // that aren't ASCII. The PDF plugin does not use any headers with non-ASCII | 33 // that aren't ASCII. The PDF plugin does not use any headers with non-ASCII |
| 34 // names and non-ASCII values are never useful for the headers the plugin | 34 // names and non-ASCII values are never useful for the headers the plugin |
| 35 // does use. | 35 // does use. |
| 36 // | 36 // |
| 37 // TODO(sammc): Send as bytes instead of a string and let the client decide | 37 // TODO(sammc): Send as bytes instead of a string and let the client decide |
| 38 // how to decode. | 38 // how to decode. |
| 39 if (!base::IsStringASCII(header_name) || !base::IsStringASCII(header_value)) | 39 if (!base::IsStringASCII(header_name) || !base::IsStringASCII(header_value)) |
| 40 continue; | 40 continue; |
| 41 auto& current_value = result[header_name]; | 41 auto& current_value = result[header_name]; |
| 42 if (!current_value.empty()) | 42 if (!current_value.empty()) |
| 43 current_value += ", "; | 43 current_value += ", "; |
| 44 current_value += header_value; | 44 current_value += header_value; |
| 45 } | 45 } |
| 46 return mojo::Map<mojo::String, mojo::String>::From(result); | 46 return result; |
| 47 } | 47 } |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 MimeHandlerServiceImpl::MimeHandlerServiceImpl( | 51 MimeHandlerServiceImpl::MimeHandlerServiceImpl( |
| 52 base::WeakPtr<StreamContainer> stream_container) | 52 base::WeakPtr<StreamContainer> stream_container) |
| 53 : stream_(stream_container), weak_factory_(this) {} | 53 : stream_(stream_container), weak_factory_(this) {} |
| 54 | 54 |
| 55 MimeHandlerServiceImpl::~MimeHandlerServiceImpl() {} | 55 MimeHandlerServiceImpl::~MimeHandlerServiceImpl() {} |
| 56 | 56 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 result->original_url = info->original_url.spec(); | 114 result->original_url = info->original_url.spec(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 result->stream_url = info->handle->GetURL().spec(); | 117 result->stream_url = info->handle->GetURL().spec(); |
| 118 result->response_headers = | 118 result->response_headers = |
| 119 extensions::CreateResponseHeadersMap(info->response_headers.get()); | 119 extensions::CreateResponseHeadersMap(info->response_headers.get()); |
| 120 return result; | 120 return result; |
| 121 } | 121 } |
| 122 | 122 |
| 123 } // namespace mojo | 123 } // namespace mojo |
| OLD | NEW |