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 "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 "ui/base/device_form_factor.h" | 24 #include "ui/base/device_form_factor.h" |
24 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 const char kCreditsJsPath[] = "credits.js"; | 30 const char kCreditsJsPath[] = "credits.js"; |
30 const char kStringsJsPath[] = "strings.js"; | 31 const char kStringsJsPath[] = "strings.js"; |
31 | 32 |
32 class AboutUIHTMLSource : public web::URLDataSourceIOS { | 33 class AboutUIHTMLSource : public web::URLDataSourceIOS { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 const std::string& path, | 120 const std::string& path, |
120 const web::URLDataSourceIOS::GotDataCallback& callback) { | 121 const web::URLDataSourceIOS::GotDataCallback& callback) { |
121 std::string response; | 122 std::string response; |
122 // Add your data source here, in alphabetical order. | 123 // Add your data source here, in alphabetical order. |
123 if (source_name_ == kChromeUIChromeURLsHost) { | 124 if (source_name_ == kChromeUIChromeURLsHost) { |
124 response = ChromeURLs(); | 125 response = ChromeURLs(); |
125 } else if (source_name_ == kChromeUICreditsHost) { | 126 } else if (source_name_ == kChromeUICreditsHost) { |
126 int idr = IDR_ABOUT_UI_CREDITS_HTML; | 127 int idr = IDR_ABOUT_UI_CREDITS_HTML; |
127 if (path == kCreditsJsPath) | 128 if (path == kCreditsJsPath) |
128 idr = IDR_ABOUT_UI_CREDITS_JS; | 129 idr = IDR_ABOUT_UI_CREDITS_JS; |
129 response = | 130 base::StringPiece raw_response = |
130 ResourceBundle::GetSharedInstance().GetRawDataResource(idr).as_string(); | 131 ResourceBundle::GetSharedInstance().GetRawDataResource(idr); |
| 132 if (idr == IDR_ABOUT_UI_CREDITS_HTML) { |
| 133 size_t decoded_size; |
| 134 const uint8_t* encoded_response_buffer = |
| 135 reinterpret_cast<const uint8_t*>(raw_response.data()); |
| 136 CHECK(BrotliDecompressedSize(raw_response.size(), encoded_response_buffer, |
| 137 &decoded_size)); |
| 138 // Resizing the response and using it as the buffer Brotli decompresses |
| 139 // into. |
| 140 response.resize(decoded_size); |
| 141 CHECK(BrotliDecompressBuffer(raw_response.size(), encoded_response_buffer, |
| 142 &decoded_size, |
| 143 reinterpret_cast<uint8_t*>(&response[0])) == |
| 144 BROTLI_RESULT_SUCCESS); |
| 145 } else { |
| 146 response = raw_response.as_string(); |
| 147 } |
131 } else if (source_name_ == kChromeUIHistogramHost) { | 148 } else if (source_name_ == kChromeUIHistogramHost) { |
132 // Note: On other platforms, this is implemented in //content. If there is | 149 // Note: On other platforms, this is implemented in //content. If there is |
133 // ever a need for embedders other than //ios/chrome to use | 150 // ever a need for embedders other than //ios/chrome to use |
134 // chrome://histograms, this code could likely be moved to //io/web. | 151 // chrome://histograms, this code could likely be moved to //io/web. |
135 base::StatisticsRecorder::WriteHTMLGraph("", &response); | 152 base::StatisticsRecorder::WriteHTMLGraph("", &response); |
136 } | 153 } |
137 | 154 |
138 FinishDataRequest(response, callback); | 155 FinishDataRequest(response, callback); |
139 } | 156 } |
140 | 157 |
(...skipping 15 matching lines...) Expand all Loading... |
156 return web::URLDataSourceIOS::ShouldDenyXFrameOptions(); | 173 return web::URLDataSourceIOS::ShouldDenyXFrameOptions(); |
157 } | 174 } |
158 | 175 |
159 AboutUI::AboutUI(web::WebUIIOS* web_ui, const std::string& name) | 176 AboutUI::AboutUI(web::WebUIIOS* web_ui, const std::string& name) |
160 : web::WebUIIOSController(web_ui) { | 177 : web::WebUIIOSController(web_ui) { |
161 web::URLDataSourceIOS::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui), | 178 web::URLDataSourceIOS::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui), |
162 new AboutUIHTMLSource(name)); | 179 new AboutUIHTMLSource(name)); |
163 } | 180 } |
164 | 181 |
165 AboutUI::~AboutUI() {} | 182 AboutUI::~AboutUI() {} |
OLD | NEW |