Chromium Code Reviews| Index: content/browser/webui/web_ui_data_source_impl.cc |
| diff --git a/content/browser/webui/web_ui_data_source_impl.cc b/content/browser/webui/web_ui_data_source_impl.cc |
| index 0a4c341649709c106323a5199d3900d3afbed755..5c35e7549896506ebe8a8d5cb00b928fa52973ca 100644 |
| --- a/content/browser/webui/web_ui_data_source_impl.cc |
| +++ b/content/browser/webui/web_ui_data_source_impl.cc |
| @@ -9,6 +9,7 @@ |
| #include <string> |
| #include "base/bind.h" |
| +#include "base/bit_cast.h" |
| #include "base/macros.h" |
| #include "base/memory/ref_counted_memory.h" |
| #include "base/strings/string_util.h" |
| @@ -16,6 +17,7 @@ |
| #include "content/grit/content_resources.h" |
| #include "content/public/browser/content_browser_client.h" |
| #include "content/public/common/content_client.h" |
| +#include "third_party/zlib/zlib.h" |
| #include "ui/base/template_expressions.h" |
| #include "ui/base/webui/jstemplate_builder.h" |
| #include "ui/base/webui/web_ui_util.h" |
| @@ -239,6 +241,34 @@ void WebUIDataSourceImpl::StartDataRequest( |
| scoped_refptr<base::RefCountedMemory> response( |
| GetContentClient()->GetDataResourceBytes(resource_id)); |
| + const unsigned char* response_array = response->front(); |
| + if (response_array[0] == 0x1f && response_array[1] == 0x8b) { |
|
agrieve
2016/05/11 18:29:52
I think this is a big enough chunk of logic that i
smaier
2016/05/13 15:27:25
Done.
|
| + // We are assuming that since we have hit the "magic header" (1f:8b) of a |
| + // gzipped file, we can now decode it. |
| + z_stream infstream; |
| + infstream.zalloc = Z_NULL; |
| + infstream.zfree = Z_NULL; |
| + infstream.opaque = Z_NULL; |
| + |
| + infstream.avail_in = response->size(); // size of input |
| + infstream.next_in = bit_cast<Bytef*>(response_array); // input buffer |
|
agrieve
2016/05/11 18:29:52
nit: I don't think bit_cast<> is meant for pointer
smaier
2016/05/13 15:27:25
Done.
|
| + |
| + // Size of output comes from footer of gzip file format, found as the last 4 |
| + // bytes in the compressed file. |
| + infstream.avail_out = *reinterpret_cast<const uint32_t*>( |
|
agrieve
2016/05/11 18:29:52
This assumes a certain endianness. Probably better
smaier
2016/05/13 15:27:25
Done.
|
| + &response_array[response->size() - 4]); |
| + |
| + std::string output; |
| + output.resize(infstream.avail_out); |
| + infstream.next_out = bit_cast<Bytef*>(&output[0]); // output buffer |
| + |
| + CHECK(inflateInit2(&infstream, 16) == Z_OK); |
| + CHECK(inflate(&infstream, Z_FINISH) == Z_STREAM_END); |
| + CHECK(inflateEnd(&infstream) == Z_OK); |
| + |
| + response = base::RefCountedString::TakeString(&output); |
| + } |
| + |
| // TODO(dschuyler): improve filtering of which resource to run template |
| // expansion upon. |
| if (GetMimeType(path) == "text/html") { |