Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef BASE_STRINGS_UTF_STRING_CONVERSIONS_H_ |
michael@0 | 6 | #define BASE_STRINGS_UTF_STRING_CONVERSIONS_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include <string> |
michael@0 | 9 | |
michael@0 | 10 | #include "base/base_export.h" |
michael@0 | 11 | #include "base/strings/string16.h" |
michael@0 | 12 | #include "base/strings/string_piece.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace base { |
michael@0 | 15 | |
michael@0 | 16 | // These convert between UTF-8, -16, and -32 strings. They are potentially slow, |
michael@0 | 17 | // so avoid unnecessary conversions. The low-level versions return a boolean |
michael@0 | 18 | // indicating whether the conversion was 100% valid. In this case, it will still |
michael@0 | 19 | // do the best it can and put the result in the output buffer. The versions that |
michael@0 | 20 | // return strings ignore this error and just return the best conversion |
michael@0 | 21 | // possible. |
michael@0 | 22 | BASE_EXPORT bool WideToUTF8(const wchar_t* src, size_t src_len, |
michael@0 | 23 | std::string* output); |
michael@0 | 24 | BASE_EXPORT std::string WideToUTF8(const std::wstring& wide); |
michael@0 | 25 | BASE_EXPORT bool UTF8ToWide(const char* src, size_t src_len, |
michael@0 | 26 | std::wstring* output); |
michael@0 | 27 | BASE_EXPORT std::wstring UTF8ToWide(const StringPiece& utf8); |
michael@0 | 28 | |
michael@0 | 29 | BASE_EXPORT bool WideToUTF16(const wchar_t* src, size_t src_len, |
michael@0 | 30 | string16* output); |
michael@0 | 31 | BASE_EXPORT string16 WideToUTF16(const std::wstring& wide); |
michael@0 | 32 | BASE_EXPORT bool UTF16ToWide(const char16* src, size_t src_len, |
michael@0 | 33 | std::wstring* output); |
michael@0 | 34 | BASE_EXPORT std::wstring UTF16ToWide(const string16& utf16); |
michael@0 | 35 | |
michael@0 | 36 | BASE_EXPORT bool UTF8ToUTF16(const char* src, size_t src_len, string16* output); |
michael@0 | 37 | BASE_EXPORT string16 UTF8ToUTF16(const StringPiece& utf8); |
michael@0 | 38 | BASE_EXPORT bool UTF16ToUTF8(const char16* src, size_t src_len, |
michael@0 | 39 | std::string* output); |
michael@0 | 40 | BASE_EXPORT std::string UTF16ToUTF8(const string16& utf16); |
michael@0 | 41 | |
michael@0 | 42 | // We are trying to get rid of wstring as much as possible, but it's too big |
michael@0 | 43 | // a mess to do it all at once. These conversions should be used when we |
michael@0 | 44 | // really should just be passing a string16 around, but we haven't finished |
michael@0 | 45 | // porting whatever module uses wstring and the conversion is being used as a |
michael@0 | 46 | // stopcock. This makes it easy to grep for the ones that should be removed. |
michael@0 | 47 | #if defined(OS_WIN) |
michael@0 | 48 | # define WideToUTF16Hack |
michael@0 | 49 | # define UTF16ToWideHack |
michael@0 | 50 | #else |
michael@0 | 51 | # define WideToUTF16Hack WideToUTF16 |
michael@0 | 52 | # define UTF16ToWideHack UTF16ToWide |
michael@0 | 53 | #endif |
michael@0 | 54 | |
michael@0 | 55 | // These convert an ASCII string, typically a hardcoded constant, to a |
michael@0 | 56 | // UTF16/Wide string. |
michael@0 | 57 | BASE_EXPORT std::wstring ASCIIToWide(const StringPiece& ascii); |
michael@0 | 58 | BASE_EXPORT string16 ASCIIToUTF16(const StringPiece& ascii); |
michael@0 | 59 | |
michael@0 | 60 | } // namespace base |
michael@0 | 61 | |
michael@0 | 62 | // TODO(brettw) remove these when callers are fixed up. |
michael@0 | 63 | using base::WideToUTF8; |
michael@0 | 64 | using base::UTF8ToWide; |
michael@0 | 65 | using base::WideToUTF16; |
michael@0 | 66 | using base::UTF16ToWide; |
michael@0 | 67 | using base::UTF8ToUTF16; |
michael@0 | 68 | using base::UTF16ToUTF8; |
michael@0 | 69 | using base::ASCIIToWide; |
michael@0 | 70 | using base::ASCIIToUTF16; |
michael@0 | 71 | |
michael@0 | 72 | #endif // BASE_STRINGS_UTF_STRING_CONVERSIONS_H_ |