OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file defines utility functions for fetching localized resources. | 5 // This file defines utility functions for fetching localized resources. |
6 | 6 |
7 #include "chrome/installer/util/l10n_string_util.h" | 7 #include "chrome/installer/util/l10n_string_util.h" |
8 | 8 |
9 #include <atlbase.h> | 9 #include <atlbase.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <limits> | 13 #include <limits> |
| 14 #include <memory> |
14 | 15 |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "chrome/installer/util/language_selector.h" | 19 #include "chrome/installer/util/language_selector.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const installer::LanguageSelector& GetLanguageSelector() { | 23 const installer::LanguageSelector& GetLanguageSelector() { |
24 static const installer::LanguageSelector instance; | 24 static const installer::LanguageSelector instance; |
25 | 25 |
26 return instance; | 26 return instance; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 resource = L"IDR_OEMPG_EN.HTML"; | 86 resource = L"IDR_OEMPG_EN.HTML"; |
87 | 87 |
88 // Spaces and DOS paths must be url encoded. | 88 // Spaces and DOS paths must be url encoded. |
89 std::wstring url_path = | 89 std::wstring url_path = |
90 base::StringPrintf(L"res://%ls/#23/%ls", full_exe_path, resource.c_str()); | 90 base::StringPrintf(L"res://%ls/#23/%ls", full_exe_path, resource.c_str()); |
91 | 91 |
92 // The cast is safe because url_path has limited length | 92 // The cast is safe because url_path has limited length |
93 // (see the definition of full_exe_path and resource). | 93 // (see the definition of full_exe_path and resource). |
94 DCHECK(std::numeric_limits<uint32_t>::max() > (url_path.size() * 3)); | 94 DCHECK(std::numeric_limits<uint32_t>::max() > (url_path.size() * 3)); |
95 DWORD count = static_cast<DWORD>(url_path.size() * 3); | 95 DWORD count = static_cast<DWORD>(url_path.size() * 3); |
96 scoped_ptr<wchar_t[]> url_canon(new wchar_t[count]); | 96 std::unique_ptr<wchar_t[]> url_canon(new wchar_t[count]); |
97 HRESULT hr = ::UrlCanonicalizeW(url_path.c_str(), url_canon.get(), | 97 HRESULT hr = ::UrlCanonicalizeW(url_path.c_str(), url_canon.get(), |
98 &count, URL_ESCAPE_UNSAFE); | 98 &count, URL_ESCAPE_UNSAFE); |
99 if (SUCCEEDED(hr)) | 99 if (SUCCEEDED(hr)) |
100 return std::wstring(url_canon.get()); | 100 return std::wstring(url_canon.get()); |
101 return url_path; | 101 return url_path; |
102 } | 102 } |
103 | 103 |
104 std::wstring GetCurrentTranslation() { | 104 std::wstring GetCurrentTranslation() { |
105 return GetLanguageSelector().selected_translation(); | 105 return GetLanguageSelector().selected_translation(); |
106 } | 106 } |
107 | 107 |
108 } // namespace installer | 108 } // namespace installer |
OLD | NEW |