| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "content/browser/webui/web_ui_url_loader_factory.h" | 5 #include "content/browser/webui/web_ui_url_loader_factory.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 source = input; | 83 source = input; |
| 84 } | 84 } |
| 85 temp_str = ui::ReplaceTemplateExpressions(source, *replacements); | 85 temp_str = ui::ReplaceTemplateExpressions(source, *replacements); |
| 86 bytes = base::RefCountedString::TakeString(&temp_str); | 86 bytes = base::RefCountedString::TakeString(&temp_str); |
| 87 input.set(reinterpret_cast<const char*>(bytes->front()), bytes->size()); | 87 input.set(reinterpret_cast<const char*>(bytes->front()), bytes->size()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 uint32_t output_size = | 90 uint32_t output_size = |
| 91 gzipped ? compression::GetUncompressedSize(input) : bytes->size(); | 91 gzipped ? compression::GetUncompressedSize(input) : bytes->size(); |
| 92 | 92 |
| 93 MojoCreateDataPipeOptions options; | 93 mojo::DataPipe data_pipe(output_size); |
| 94 options.struct_size = sizeof(MojoCreateDataPipeOptions); | |
| 95 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | |
| 96 options.element_num_bytes = 1; | |
| 97 options.capacity_num_bytes = output_size; | |
| 98 mojo::DataPipe data_pipe(options); | |
| 99 | |
| 100 DCHECK(data_pipe.producer_handle.is_valid()); | |
| 101 DCHECK(data_pipe.consumer_handle.is_valid()); | |
| 102 | 94 |
| 103 void* buffer = nullptr; | 95 void* buffer = nullptr; |
| 104 uint32_t num_bytes = output_size; | 96 uint32_t num_bytes = output_size; |
| 105 MojoResult result = | 97 MojoResult result = |
| 106 BeginWriteDataRaw(data_pipe.producer_handle.get(), &buffer, &num_bytes, | 98 BeginWriteDataRaw(data_pipe.producer_handle.get(), &buffer, &num_bytes, |
| 107 MOJO_WRITE_DATA_FLAG_NONE); | 99 MOJO_WRITE_DATA_FLAG_NONE); |
| 108 CHECK_EQ(result, MOJO_RESULT_OK); | 100 CHECK_EQ(result, MOJO_RESULT_OK); |
| 109 CHECK_EQ(num_bytes, output_size); | 101 CHECK_EQ(num_bytes, output_size); |
| 110 | 102 |
| 111 if (gzipped) { | 103 if (gzipped) { |
| 112 base::StringPiece output(static_cast<char*>(buffer), num_bytes); | 104 base::StringPiece output(static_cast<char*>(buffer), num_bytes); |
| 113 CHECK(compression::GzipUncompress(input, output)); | 105 CHECK(compression::GzipUncompress(input, output)); |
| 114 } else { | 106 } else { |
| 115 memcpy(buffer, bytes->front(), output_size); | 107 memcpy(buffer, bytes->front(), output_size); |
| 116 } | 108 } |
| 117 result = EndWriteDataRaw(data_pipe.producer_handle.get(), num_bytes); | 109 result = EndWriteDataRaw(data_pipe.producer_handle.get(), num_bytes); |
| 118 CHECK_EQ(result, MOJO_RESULT_OK); | 110 CHECK_EQ(result, MOJO_RESULT_OK); |
| 119 | 111 |
| 120 client->OnStartLoadingResponseBody(std::move(data_pipe.consumer_handle)); | 112 client->OnStartLoadingResponseBody(std::move(data_pipe.consumer_handle)); |
| 121 | 113 client->OnComplete(ResourceRequestCompletionStatus(output_size)); |
| 122 ResourceRequestCompletionStatus request_complete_data; | |
| 123 request_complete_data.error_code = net::OK; | |
| 124 request_complete_data.exists_in_cache = false; | |
| 125 request_complete_data.completion_time = base::TimeTicks::Now(); | |
| 126 request_complete_data.encoded_data_length = output_size; | |
| 127 request_complete_data.encoded_body_length = output_size; | |
| 128 client->OnComplete(request_complete_data); | |
| 129 } | 114 } |
| 130 | 115 |
| 131 void DataAvailable(scoped_refptr<ResourceResponse> headers, | 116 void DataAvailable(scoped_refptr<ResourceResponse> headers, |
| 132 const ui::TemplateReplacements* replacements, | 117 const ui::TemplateReplacements* replacements, |
| 133 bool gzipped, | 118 bool gzipped, |
| 134 scoped_refptr<URLDataSourceImpl> source, | 119 scoped_refptr<URLDataSourceImpl> source, |
| 135 mojom::URLLoaderClientPtrInfo client_info, | 120 mojom::URLLoaderClientPtrInfo client_info, |
| 136 scoped_refptr<base::RefCountedMemory> bytes) { | 121 scoped_refptr<base::RefCountedMemory> bytes) { |
| 137 // Since the bytes are from the memory mapped resource file, copying the | 122 // Since the bytes are from the memory mapped resource file, copying the |
| 138 // data can lead to disk access. | 123 // data can lead to disk access. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } // namespace | 289 } // namespace |
| 305 | 290 |
| 306 mojom::URLLoaderFactoryPtr GetWebUIURLLoader(FrameTreeNode* node) { | 291 mojom::URLLoaderFactoryPtr GetWebUIURLLoader(FrameTreeNode* node) { |
| 307 int ftn_id = node->frame_tree_node_id(); | 292 int ftn_id = node->frame_tree_node_id(); |
| 308 if (g_factories.Get()[ftn_id].get() == nullptr) | 293 if (g_factories.Get()[ftn_id].get() == nullptr) |
| 309 g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node); | 294 g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node); |
| 310 return g_factories.Get()[ftn_id]->CreateBinding(); | 295 return g_factories.Get()[ftn_id]->CreateBinding(); |
| 311 } | 296 } |
| 312 | 297 |
| 313 } // namespace content | 298 } // namespace content |
| OLD | NEW |