Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: ios/chrome/browser/ui/webui/about_ui.cc

Issue 2537133002: Update brotli to v1.0.0-snapshot. (Closed)
Patch Set: Rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ios/chrome/browser/ui/webui/about_ui.h" 5 #include "ios/chrome/browser/ui/webui/about_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/format_macros.h" 12 #include "base/format_macros.h"
13 #include "base/i18n/number_formatting.h" 13 #include "base/i18n/number_formatting.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/metrics/statistics_recorder.h" 15 #include "base/metrics/statistics_recorder.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "components/grit/components_resources.h" 17 #include "components/grit/components_resources.h"
18 #include "google_apis/gaia/google_service_auth_error.h" 18 #include "google_apis/gaia/google_service_auth_error.h"
19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
20 #include "ios/chrome/browser/chrome_url_constants.h" 20 #include "ios/chrome/browser/chrome_url_constants.h"
21 #include "ios/web/public/url_data_source_ios.h" 21 #include "ios/web/public/url_data_source_ios.h"
22 #include "net/base/escape.h" 22 #include "net/base/escape.h"
23 #include "third_party/brotli/dec/decode.h" 23 #include "third_party/brotli/include/brotli/decode.h"
24 #include "ui/base/device_form_factor.h" 24 #include "ui/base/device_form_factor.h"
25 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 27
28 namespace { 28 namespace {
29 29
30 const char kCreditsJsPath[] = "credits.js"; 30 const char kCreditsJsPath[] = "credits.js";
31 const char kStringsJsPath[] = "strings.js"; 31 const char kStringsJsPath[] = "strings.js";
32 32
33 class AboutUIHTMLSource : public web::URLDataSourceIOS { 33 class AboutUIHTMLSource : public web::URLDataSourceIOS {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // Add your data source here, in alphabetical order. 124 // Add your data source here, in alphabetical order.
125 if (source_name_ == kChromeUIChromeURLsHost) { 125 if (source_name_ == kChromeUIChromeURLsHost) {
126 response = ChromeURLs(); 126 response = ChromeURLs();
127 } else if (source_name_ == kChromeUICreditsHost) { 127 } else if (source_name_ == kChromeUICreditsHost) {
128 int idr = IDR_ABOUT_UI_CREDITS_HTML; 128 int idr = IDR_ABOUT_UI_CREDITS_HTML;
129 if (path == kCreditsJsPath) 129 if (path == kCreditsJsPath)
130 idr = IDR_ABOUT_UI_CREDITS_JS; 130 idr = IDR_ABOUT_UI_CREDITS_JS;
131 base::StringPiece raw_response = 131 base::StringPiece raw_response =
132 ResourceBundle::GetSharedInstance().GetRawDataResource(idr); 132 ResourceBundle::GetSharedInstance().GetRawDataResource(idr);
133 if (idr == IDR_ABOUT_UI_CREDITS_HTML) { 133 if (idr == IDR_ABOUT_UI_CREDITS_HTML) {
134 size_t decoded_size; 134 const uint8_t* next_encoded_byte =
135 const uint8_t* encoded_response_buffer =
136 reinterpret_cast<const uint8_t*>(raw_response.data()); 135 reinterpret_cast<const uint8_t*>(raw_response.data());
137 CHECK(BrotliDecompressedSize(raw_response.size(), encoded_response_buffer, 136 size_t input_size_remaining = raw_response.size();
138 &decoded_size)); 137 BrotliDecoderState* decoder =
139 // Resizing the response and using it as the buffer Brotli decompresses 138 BrotliDecoderCreateInstance(nullptr /* no custom allocator */,
140 // into. 139 nullptr /* no custom deallocator */,
141 response.resize(decoded_size); 140 nullptr /* no custom memory handle */);
142 CHECK(BrotliDecompressBuffer(raw_response.size(), encoded_response_buffer, 141 CHECK(!!decoder);
143 &decoded_size, 142 while (!BrotliDecoderIsFinished(decoder)) {
144 reinterpret_cast<uint8_t*>(&response[0])) == 143 size_t output_size_remianing = 0;
145 BROTLI_RESULT_SUCCESS); 144 CHECK(BrotliDecoderDecompressStream(
145 decoder, &input_size_remaining, &next_encoded_byte,
146 &output_size_remianing, nullptr,
147 nullptr) != BROTLI_DECODER_RESULT_ERROR);
148 const uint8_t* out =
marq (ping after 24h) 2016/12/07 10:11:40 Can you please use a slightly more descriptive nam
eustas 2016/12/07 12:34:28 Of course. Done.
149 BrotliDecoderTakeOutput(decoder, &output_size_remianing);
150 response.insert(response.end(), out, out + output_size_remianing);
151 }
152 BrotliDecoderDestroyInstance(decoder);
146 } else { 153 } else {
147 response = raw_response.as_string(); 154 response = raw_response.as_string();
148 } 155 }
149 } else if (source_name_ == kChromeUIHistogramHost) { 156 } else if (source_name_ == kChromeUIHistogramHost) {
150 // Note: On other platforms, this is implemented in //content. If there is 157 // Note: On other platforms, this is implemented in //content. If there is
151 // ever a need for embedders other than //ios/chrome to use 158 // ever a need for embedders other than //ios/chrome to use
152 // chrome://histograms, this code could likely be moved to //io/web. 159 // chrome://histograms, this code could likely be moved to //io/web.
153 base::StatisticsRecorder::WriteHTMLGraph("", &response); 160 base::StatisticsRecorder::WriteHTMLGraph("", &response);
154 } 161 }
155 162
(...skipping 18 matching lines...) Expand all
174 return web::URLDataSourceIOS::ShouldDenyXFrameOptions(); 181 return web::URLDataSourceIOS::ShouldDenyXFrameOptions();
175 } 182 }
176 183
177 AboutUI::AboutUI(web::WebUIIOS* web_ui, const std::string& name) 184 AboutUI::AboutUI(web::WebUIIOS* web_ui, const std::string& name)
178 : web::WebUIIOSController(web_ui) { 185 : web::WebUIIOSController(web_ui) {
179 web::URLDataSourceIOS::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui), 186 web::URLDataSourceIOS::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui),
180 new AboutUIHTMLSource(name)); 187 new AboutUIHTMLSource(name));
181 } 188 }
182 189
183 AboutUI::~AboutUI() {} 190 AboutUI::~AboutUI() {}
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/webui/BUILD.gn ('k') | net/BUILD.gn » ('j') | third_party/brotli/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698