summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-02 18:31:14 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-02 18:31:14 +0000
commit1d6be41bbbd90da118ba9a6295b2164ce97aca93 (patch)
tree2dffeae69e0860c191f8e0fb4a083eb0b68367e8 /app
parent25abb027ed2b8c45391fed9aeb8013b528428583 (diff)
downloadchromium_src-1d6be41bbbd90da118ba9a6295b2164ce97aca93.zip
chromium_src-1d6be41bbbd90da118ba9a6295b2164ce97aca93.tar.gz
chromium_src-1d6be41bbbd90da118ba9a6295b2164ce97aca93.tar.bz2
Linux: when reading html from clipboard, interpret BOM to mean
that the encoding is UTF-16. Otherwise, continue assuming it's utf-8. From firefox source: /* * "text/html" can be encoded UCS2. It is recommended that * documents transmitted as UCS2 always begin with a ZERO-WIDTH * NON-BREAKING SPACE character (hexadecimal FEFF, also called * Byte Order Mark (BOM)). Adding BOM can help other app to * detect mozilla use UCS2 encoding when copy-paste. */ BUG=29145 Review URL: http://codereview.chromium.org/455030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33585 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/clipboard/clipboard_linux.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/app/clipboard/clipboard_linux.cc b/app/clipboard/clipboard_linux.cc
index f06b9b2..dba93f0 100644
--- a/app/clipboard/clipboard_linux.cc
+++ b/app/clipboard/clipboard_linux.cc
@@ -326,7 +326,16 @@ void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup,
if (!data)
return;
- UTF8ToUTF16(reinterpret_cast<char*>(data->data), data->length, markup);
+ // If the data starts with 0xFEFF, i.e., Byte Order Mark, assume it is
+ // UTF-16, otherwise assume UTF-8.
+ if (data->length >= 2 &&
+ reinterpret_cast<uint16_t*>(data->data)[0] == 0xFEFF) {
+ markup->assign(reinterpret_cast<uint16_t*>(data->data) + 1,
+ (data->length / 2) - 1);
+ } else {
+ UTF8ToUTF16(reinterpret_cast<char*>(data->data), data->length, markup);
+ }
+
gtk_selection_data_free(data);
}