OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/ui/webui/settings/about_handler.h" | 5 #include "chrome/browser/ui/webui/settings/about_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 185 |
186 // Try the fallback region code if no directory was found. | 186 // Try the fallback region code if no directory was found. |
187 if (region_path.empty() && region != kDefaultRegionCode) | 187 if (region_path.empty() && region != kDefaultRegionCode) |
188 region_path = GetRegulatoryLabelDirForRegion(kDefaultRegionCode); | 188 region_path = GetRegulatoryLabelDirForRegion(kDefaultRegionCode); |
189 | 189 |
190 return region_path; | 190 return region_path; |
191 } | 191 } |
192 | 192 |
193 // Reads the file containing the regulatory label text, if found, relative to | 193 // Reads the file containing the regulatory label text, if found, relative to |
194 // the asset directory. Must be called from the blocking pool. | 194 // the asset directory. Must be called from the blocking pool. |
195 std::string ReadRegulatoryLabelText(const base::FilePath& path) { | 195 std::string ReadRegulatoryLabelText(const base::FilePath& label_dir_path) { |
196 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 196 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
197 base::FilePath text_path(chrome::kChromeOSAssetPath); | 197 base::FilePath text_path(chrome::kChromeOSAssetPath); |
198 text_path = text_path.Append(path); | 198 text_path = text_path.Append(label_dir_path); |
199 text_path = text_path.AppendASCII(kRegulatoryLabelTextFilename); | 199 text_path = text_path.AppendASCII(kRegulatoryLabelTextFilename); |
200 | 200 |
201 std::string contents; | 201 std::string contents; |
202 if (base::ReadFileToString(text_path, &contents)) | 202 if (base::ReadFileToString(text_path, &contents)) |
203 return contents; | 203 return contents; |
204 return std::string(); | 204 return std::string(); |
205 } | 205 } |
206 | 206 |
207 std::unique_ptr<base::DictionaryValue> GetVersionInfo() { | 207 std::unique_ptr<base::DictionaryValue> GetVersionInfo() { |
208 std::unique_ptr<base::DictionaryValue> version_info( | 208 std::unique_ptr<base::DictionaryValue> version_info( |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 break; | 612 break; |
613 } | 613 } |
614 | 614 |
615 CallJavascriptFunction("cr.webUIListenerCallback", | 615 CallJavascriptFunction("cr.webUIListenerCallback", |
616 base::StringValue("promotion-state-changed"), | 616 base::StringValue("promotion-state-changed"), |
617 base::StringValue(state_str)); | 617 base::StringValue(state_str)); |
618 } | 618 } |
619 #endif // defined(OS_MACOSX) | 619 #endif // defined(OS_MACOSX) |
620 | 620 |
621 #if defined(OS_CHROMEOS) | 621 #if defined(OS_CHROMEOS) |
622 void AboutHandler::OnRegulatoryLabelDirFound(std::string callback_id, | 622 void AboutHandler::OnRegulatoryLabelDirFound( |
623 const base::FilePath& path) { | 623 std::string callback_id, |
624 if (path.empty()) { | 624 const base::FilePath& label_dir_path) { |
| 625 if (label_dir_path.empty()) { |
625 ResolveJavascriptCallback(base::StringValue(callback_id), | 626 ResolveJavascriptCallback(base::StringValue(callback_id), |
626 *base::Value::CreateNullValue()); | 627 *base::Value::CreateNullValue()); |
627 return; | 628 return; |
628 } | 629 } |
629 | 630 |
630 base::PostTaskAndReplyWithResult( | 631 base::PostTaskAndReplyWithResult( |
631 content::BrowserThread::GetBlockingPool(), FROM_HERE, | 632 content::BrowserThread::GetBlockingPool(), FROM_HERE, |
632 base::Bind(&ReadRegulatoryLabelText, path), | 633 base::Bind(&ReadRegulatoryLabelText, label_dir_path), |
633 base::Bind(&AboutHandler::OnRegulatoryLabelTextRead, | 634 base::Bind(&AboutHandler::OnRegulatoryLabelTextRead, |
634 weak_factory_.GetWeakPtr(), callback_id, path)); | 635 weak_factory_.GetWeakPtr(), callback_id, label_dir_path)); |
635 } | 636 } |
636 | 637 |
637 void AboutHandler::OnRegulatoryLabelTextRead(std::string callback_id, | 638 void AboutHandler::OnRegulatoryLabelTextRead( |
638 const base::FilePath& path, | 639 std::string callback_id, |
639 const std::string& text) { | 640 const base::FilePath& label_dir_path, |
| 641 const std::string& text) { |
640 std::unique_ptr<base::DictionaryValue> regulatory_info( | 642 std::unique_ptr<base::DictionaryValue> regulatory_info( |
641 new base::DictionaryValue); | 643 new base::DictionaryValue); |
642 // Remove unnecessary whitespace. | 644 // Remove unnecessary whitespace. |
643 regulatory_info->SetString("text", base::CollapseWhitespaceASCII(text, true)); | 645 regulatory_info->SetString("text", base::CollapseWhitespaceASCII(text, true)); |
644 std::string url = std::string("chrome://") + chrome::kChromeOSAssetHost + | 646 |
645 "/" + path.MaybeAsASCII(); | 647 std::string image_path = |
| 648 label_dir_path.AppendASCII(kRegulatoryLabelImageFilename).MaybeAsASCII(); |
| 649 std::string url = |
| 650 std::string("chrome://") + chrome::kChromeOSAssetHost + "/" + image_path; |
646 regulatory_info->SetString("url", url); | 651 regulatory_info->SetString("url", url); |
647 | 652 |
648 ResolveJavascriptCallback(base::StringValue(callback_id), *regulatory_info); | 653 ResolveJavascriptCallback(base::StringValue(callback_id), *regulatory_info); |
649 } | 654 } |
650 | 655 |
651 #endif // defined(OS_CHROMEOS) | 656 #endif // defined(OS_CHROMEOS) |
652 | 657 |
653 } // namespace settings | 658 } // namespace settings |
OLD | NEW |