summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/clipboard.h18
-rw-r--r--base/clipboard_linux.cc16
-rw-r--r--base/clipboard_mac.mm38
-rw-r--r--base/clipboard_unittest.cc54
-rw-r--r--base/clipboard_win.cc45
-rw-r--r--base/pickle.cc26
-rw-r--r--base/pickle.h3
-rw-r--r--base/scoped_clipboard_writer.cc47
-rw-r--r--base/scoped_clipboard_writer.h17
-rw-r--r--base/string_util.h1
-rw-r--r--chrome/browser/download/download_util.cc6
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.h5
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc4
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h5
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_controller.cc6
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_controller.h3
-rw-r--r--chrome/common/ipc_message_utils.h16
-rw-r--r--chrome/common/render_messages_internal.h4
-rw-r--r--chrome/renderer/renderer_glue.cc4
-rw-r--r--webkit/glue/simple_clipboard_impl.cc5
-rw-r--r--webkit/glue/webclipboard_impl.cc27
-rw-r--r--webkit/glue/webkit_glue.h4
22 files changed, 199 insertions, 155 deletions
diff --git a/base/clipboard.h b/base/clipboard.h
index 631a516..5abf4774 100644
--- a/base/clipboard.h
+++ b/base/clipboard.h
@@ -9,7 +9,9 @@
#include <string>
#include <vector>
+#include "base/file_path.h"
#include "base/process.h"
+#include "base/string16.h"
#include "base/gfx/size.h"
#if defined(OS_MACOSX)
@@ -66,6 +68,8 @@ class Clipboard {
// CBF_FILES files char array representing multiple files.
// Filenames are separated by null characters and
// the final filename is double null terminated.
+ // The filenames are encoded in platform-specific
+ // encoding.
// CBF_WEBKIT none empty vector
// CBF_BITMAP pixels byte array
// size gfx::Size struct
@@ -94,21 +98,21 @@ class Clipboard {
bool IsFormatAvailable(FormatType format) const;
// Reads UNICODE text from the clipboard, if available.
- void ReadText(std::wstring* result) const;
+ void ReadText(string16* result) const;
// Reads ASCII text from the clipboard, if available.
void ReadAsciiText(std::string* result) const;
// Reads HTML from the clipboard, if available.
- void ReadHTML(std::wstring* markup, std::string* src_url) const;
+ void ReadHTML(string16* markup, std::string* src_url) const;
// Reads a bookmark from the clipboard, if available.
- void ReadBookmark(std::wstring* title, std::string* url) const;
+ void ReadBookmark(string16* title, std::string* url) const;
// Reads a file or group of files from the clipboard, if available, into the
// out parameter.
- void ReadFile(std::wstring* file) const;
- void ReadFiles(std::vector<std::wstring>* files) const;
+ void ReadFile(FilePath* file) const;
+ void ReadFiles(std::vector<FilePath>* files) const;
// Get format Identifiers for various types.
static FormatType GetUrlFormatType();
@@ -171,8 +175,8 @@ class Clipboard {
// Safely write to system clipboard. Free |handle| on failure.
void WriteToClipboard(FormatType format, HANDLE handle);
- static void ParseBookmarkClipboardFormat(const std::wstring& bookmark,
- std::wstring* title,
+ static void ParseBookmarkClipboardFormat(const string16& bookmark,
+ string16* title,
std::string* url);
// Free a handle depending on its type (as intuited from format)
diff --git a/base/clipboard_linux.cc b/base/clipboard_linux.cc
index e535942..17ecf6c 100644
--- a/base/clipboard_linux.cc
+++ b/base/clipboard_linux.cc
@@ -200,7 +200,7 @@ bool Clipboard::IsFormatAvailable(Clipboard::FormatType format) const {
return retval;
}
-void Clipboard::ReadText(std::wstring* result) const {
+void Clipboard::ReadText(string16* result) const {
result->clear();
gchar* text = gtk_clipboard_wait_for_text(clipboard_);
@@ -208,7 +208,7 @@ void Clipboard::ReadText(std::wstring* result) const {
return;
// TODO(estade): do we want to handle the possible error here?
- UTF8ToWide(text, strlen(text), result);
+ UTF8ToUTF16(text, strlen(text), result);
g_free(text);
}
@@ -223,8 +223,12 @@ void Clipboard::ReadAsciiText(std::string* result) const {
g_free(text);
}
+void Clipboard::ReadFile(FilePath* file) const {
+ *file = FilePath();
+}
+
// TODO(estade): handle different charsets.
-void Clipboard::ReadHTML(std::wstring* markup, std::string* src_url) const {
+void Clipboard::ReadHTML(string16* markup, std::string* src_url) const {
markup->clear();
GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard_,
@@ -233,9 +237,9 @@ void Clipboard::ReadHTML(std::wstring* markup, std::string* src_url) const {
if (!data)
return;
- UTF8ToWide(reinterpret_cast<char*>(data->data),
- strlen(reinterpret_cast<char*>(data->data)),
- markup);
+ UTF8ToUTF16(reinterpret_cast<char*>(data->data),
+ strlen(reinterpret_cast<char*>(data->data)),
+ markup);
gtk_selection_data_free(data);
}
diff --git a/base/clipboard_mac.mm b/base/clipboard_mac.mm
index 592b4c6..f2b6294 100644
--- a/base/clipboard_mac.mm
+++ b/base/clipboard_mac.mm
@@ -140,13 +140,13 @@ bool Clipboard::IsFormatAvailable(NSString* format) const {
return [types containsObject:format];
}
-void Clipboard::ReadText(std::wstring* result) const {
+void Clipboard::ReadText(string16* result) const {
NSPasteboard* pb = GetPasteboard();
NSString* contents = [pb stringForType:NSStringPboardType];
- UTF8ToWide([contents UTF8String],
- [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
- result);
+ UTF8ToUTF16([contents UTF8String],
+ [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
+ result);
}
void Clipboard::ReadAsciiText(std::string* result) const {
@@ -159,7 +159,7 @@ void Clipboard::ReadAsciiText(std::string* result) const {
result->assign([contents UTF8String]);
}
-void Clipboard::ReadHTML(std::wstring* markup, std::string* src_url) const {
+void Clipboard::ReadHTML(string16* markup, std::string* src_url) const {
if (markup) {
NSPasteboard* pb = GetPasteboard();
NSArray *supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType,
@@ -167,9 +167,9 @@ void Clipboard::ReadHTML(std::wstring* markup, std::string* src_url) const {
nil];
NSString *bestType = [pb availableTypeFromArray:supportedTypes];
NSString* contents = [pb stringForType:bestType];
- UTF8ToWide([contents UTF8String],
- [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
- markup);
+ UTF8ToUTF16([contents UTF8String],
+ [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
+ markup);
}
// TODO(avi): src_url?
@@ -177,14 +177,14 @@ void Clipboard::ReadHTML(std::wstring* markup, std::string* src_url) const {
src_url->clear();
}
-void Clipboard::ReadBookmark(std::wstring* title, std::string* url) const {
+void Clipboard::ReadBookmark(string16* title, std::string* url) const {
NSPasteboard* pb = GetPasteboard();
if (title) {
NSString* contents = [pb stringForType:kUTTypeURLName];
- UTF8ToWide([contents UTF8String],
- [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
- title);
+ UTF8ToUTF16([contents UTF8String],
+ [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
+ title);
}
if (url) {
@@ -196,22 +196,22 @@ void Clipboard::ReadBookmark(std::wstring* title, std::string* url) const {
}
}
-void Clipboard::ReadFile(std::wstring* file) const {
+void Clipboard::ReadFile(FilePath* file) const {
if (!file) {
NOTREACHED();
return;
}
- file->clear();
- std::vector<std::wstring> files;
+ *file = FilePath();
+ std::vector<FilePath> files;
ReadFiles(&files);
// Take the first file, if available.
if (!files.empty())
- file->assign(files[0]);
+ *file = files[0];
}
-void Clipboard::ReadFiles(std::vector<std::wstring>* files) const {
+void Clipboard::ReadFiles(std::vector<FilePath>* files) const {
if (!files) {
NOTREACHED();
return;
@@ -223,8 +223,8 @@ void Clipboard::ReadFiles(std::vector<std::wstring>* files) const {
NSArray* fileList = [pb propertyListForType:NSFilenamesPboardType];
for (unsigned int i = 0; i < [fileList count]; ++i) {
- std::wstring file = UTF8ToWide([[fileList objectAtIndex:i] UTF8String]);
- files->push_back(file);
+ std::string file = [[fileList objectAtIndex:i] UTF8String];
+ files->push_back(FilePath(file));
}
}
diff --git a/base/clipboard_unittest.cc b/base/clipboard_unittest.cc
index 1015753..6a0ca09 100644
--- a/base/clipboard_unittest.cc
+++ b/base/clipboard_unittest.cc
@@ -33,12 +33,12 @@ TEST_F(ClipboardTest, ClearTest) {
{
ScopedClipboardWriter clipboard_writer(&clipboard);
- clipboard_writer.WriteText(std::wstring(L"clear me"));
+ clipboard_writer.WriteText(ASCIIToUTF16("clear me"));
}
{
ScopedClipboardWriter clipboard_writer(&clipboard);
- clipboard_writer.WriteHTML(std::wstring(L"<b>broom</b>"), "");
+ clipboard_writer.WriteHTML(ASCIIToUTF16("<b>broom</b>"), "");
}
EXPECT_FALSE(clipboard.IsFormatAvailable(
@@ -50,7 +50,7 @@ TEST_F(ClipboardTest, ClearTest) {
TEST_F(ClipboardTest, TextTest) {
Clipboard clipboard;
- std::wstring text(L"This is a wstring!#$"), text_result;
+ string16 text(ASCIIToUTF16("This is a string16!#$")), text_result;
std::string ascii_text;
{
@@ -63,15 +63,16 @@ TEST_F(ClipboardTest, TextTest) {
EXPECT_TRUE(clipboard.IsFormatAvailable(
Clipboard::GetPlainTextFormatType()));
clipboard.ReadText(&text_result);
+
EXPECT_EQ(text, text_result);
clipboard.ReadAsciiText(&ascii_text);
- EXPECT_EQ(WideToUTF8(text), ascii_text);
+ EXPECT_EQ(UTF16ToUTF8(text), ascii_text);
}
TEST_F(ClipboardTest, HTMLTest) {
Clipboard clipboard;
- std::wstring markup(L"<string>Hi!</string>"), markup_result;
+ string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result;
std::string url("http://www.example.com/"), url_result;
{
@@ -93,7 +94,8 @@ TEST_F(ClipboardTest, HTMLTest) {
TEST_F(ClipboardTest, TrickyHTMLTest) {
Clipboard clipboard;
- std::wstring markup(L"<em>Bye!<!--EndFragment --></em>"), markup_result;
+ string16 markup(ASCIIToUTF16("<em>Bye!<!--EndFragment --></em>")),
+ markup_result;
std::string url, url_result;
{
@@ -117,7 +119,7 @@ TEST_F(ClipboardTest, TrickyHTMLTest) {
TEST_F(ClipboardTest, BookmarkTest) {
Clipboard clipboard;
- std::wstring title(L"The Example Company"), title_result;
+ string16 title(ASCIIToUTF16("The Example Company")), title_result;
std::string url("http://www.example.com/"), url_result;
{
@@ -136,8 +138,8 @@ TEST_F(ClipboardTest, BookmarkTest) {
TEST_F(ClipboardTest, MultiFormatTest) {
Clipboard clipboard;
- std::wstring text(L"Hi!"), text_result;
- std::wstring markup(L"<strong>Hi!</string>"), markup_result;
+ string16 text(ASCIIToUTF16("Hi!")), text_result;
+ string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result;
std::string url("http://www.example.com/"), url_result;
std::string ascii_text;
@@ -163,7 +165,7 @@ TEST_F(ClipboardTest, MultiFormatTest) {
clipboard.ReadText(&text_result);
EXPECT_EQ(text, text_result);
clipboard.ReadAsciiText(&ascii_text);
- EXPECT_EQ(WideToUTF8(text), ascii_text);
+ EXPECT_EQ(UTF16ToUTF8(text), ascii_text);
}
// TODO(estade): Port the following tests (decide what targets we use for files)
@@ -173,11 +175,11 @@ TEST_F(ClipboardTest, MultiFormatTest) {
TEST_F(ClipboardTest, FileTest) {
Clipboard clipboard;
#if defined(OS_WIN)
- std::wstring file = L"C:\\Downloads\\My Downloads\\A Special File.txt";
+ FilePath file(L"C:\\Downloads\\My Downloads\\A Special File.txt");
#elif defined(OS_MACOSX)
// OS X will print a warning message if we stick a non-existant file on the
// clipboard.
- std::wstring file = L"/usr/bin/make";
+ FilePath file("/usr/bin/make");
#endif // defined(OS_MACOSX)
{
@@ -185,26 +187,26 @@ TEST_F(ClipboardTest, FileTest) {
clipboard_writer.WriteFile(file);
}
- std::wstring out_file;
+ FilePath out_file;
clipboard.ReadFile(&out_file);
- EXPECT_EQ(file, out_file);
+ EXPECT_EQ(file.value(), out_file.value());
}
TEST_F(ClipboardTest, MultipleFilesTest) {
Clipboard clipboard;
#if defined(OS_WIN)
- std::wstring file1 = L"C:\\Downloads\\My Downloads\\File 1.exe";
- std::wstring file2 = L"C:\\Downloads\\My Downloads\\File 2.pdf";
- std::wstring file3 = L"C:\\Downloads\\My Downloads\\File 3.doc";
+ FilePath file1(L"C:\\Downloads\\My Downloads\\File 1.exe");
+ FilePath file2(L"C:\\Downloads\\My Downloads\\File 2.pdf");
+ FilePath file3(L"C:\\Downloads\\My Downloads\\File 3.doc");
#elif defined(OS_MACOSX)
// OS X will print a warning message if we stick a non-existant file on the
// clipboard.
- std::wstring file1 = L"/usr/bin/make";
- std::wstring file2 = L"/usr/bin/man";
- std::wstring file3 = L"/usr/bin/perl";
+ FilePath file1("/usr/bin/make");
+ FilePath file2("/usr/bin/man");
+ FilePath file3("/usr/bin/perl");
#endif // defined(OS_MACOSX)
- std::vector<std::wstring> files;
+ std::vector<FilePath> files;
files.push_back(file1);
files.push_back(file2);
files.push_back(file3);
@@ -214,12 +216,12 @@ TEST_F(ClipboardTest, MultipleFilesTest) {
clipboard_writer.WriteFiles(files);
}
- std::vector<std::wstring> out_files;
+ std::vector<FilePath> out_files;
clipboard.ReadFiles(&out_files);
EXPECT_EQ(files.size(), out_files.size());
for (size_t i = 0; i < out_files.size(); ++i)
- EXPECT_EQ(files[i], out_files[i]);
+ EXPECT_EQ(files[i].value(), out_files[i].value());
}
#endif // !defined(OS_LINUX)
@@ -227,10 +229,10 @@ TEST_F(ClipboardTest, MultipleFilesTest) {
TEST_F(ClipboardTest, HyperlinkTest) {
Clipboard clipboard;
- std::wstring title(L"The Example Company"), title_result;
+ string16 title(ASCIIToUTF16("The Example Company")), title_result;
std::string url("http://www.example.com/"), url_result;
- std::wstring html(L"<a href=\"http://www.example.com/\">"
- L"The Example Company</a>"), html_result;
+ string16 html(ASCIIToUTF16("<a href=\"http://www.example.com/\">"
+ "The Example Company</a>")), html_result;
{
ScopedClipboardWriter clipboard_writer(&clipboard);
diff --git a/base/clipboard_win.cc b/base/clipboard_win.cc
index 3efe7d36..b765f5f 100644
--- a/base/clipboard_win.cc
+++ b/base/clipboard_win.cc
@@ -11,6 +11,7 @@
#include <shellapi.h>
#include "base/clipboard_util.h"
+#include "base/lock.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/shared_memory.h"
@@ -169,8 +170,8 @@ void Clipboard::WriteObjects(const ObjectMap& objects,
}
void Clipboard::WriteText(const char* text_data, size_t text_len) {
- std::wstring text;
- UTF8ToWide(text_data, text_len, &text);
+ string16 text;
+ UTF8ToUTF16(text_data, text_len, &text);
HGLOBAL glob = CreateGlobalData(text);
WriteToClipboard(CF_UNICODETEXT, glob);
@@ -200,7 +201,7 @@ void Clipboard::WriteBookmark(const char* title_data,
bookmark.append(1, L'\n');
bookmark.append(url_data, url_len);
- std::wstring wide_bookmark = UTF8ToWide(bookmark);
+ string16 wide_bookmark = UTF8ToWide(bookmark);
HGLOBAL glob = CreateGlobalData(wide_bookmark);
WriteToClipboard(GetUrlWFormatType(), glob);
@@ -351,10 +352,9 @@ void Clipboard::WriteBitmapFromHandle(HBITMAP source_hbitmap,
// invokes a paste command (in a Windows explorer shell, for example), the files
// will be copied to the paste location.
void Clipboard::WriteFiles(const char* file_data, size_t file_len) {
- std::wstring filenames(UTF8ToWide(std::string(file_data, file_len)));
// Calculate the amount of space we'll need store the strings and
// a DROPFILES struct.
- size_t bytes = sizeof(DROPFILES) + filenames.length() * sizeof(wchar_t);
+ size_t bytes = sizeof(DROPFILES) + file_len;
HANDLE hdata = ::GlobalAlloc(GMEM_MOVEABLE, bytes);
if (!hdata)
@@ -365,8 +365,7 @@ void Clipboard::WriteFiles(const char* file_data, size_t file_len) {
drop_files->pFiles = sizeof(DROPFILES);
drop_files->fWide = TRUE;
- memcpy(data + sizeof DROPFILES, filenames.c_str(),
- filenames.length() * sizeof(wchar_t));
+ memcpy(data + sizeof(DROPFILES), file_data, file_len);
::GlobalUnlock(hdata);
WriteToClipboard(CF_HDROP, hdata);
@@ -384,7 +383,7 @@ bool Clipboard::IsFormatAvailable(unsigned int format) const {
return ::IsClipboardFormatAvailable(format) != FALSE;
}
-void Clipboard::ReadText(std::wstring* result) const {
+void Clipboard::ReadText(string16* result) const {
if (!result) {
NOTREACHED();
return;
@@ -401,7 +400,7 @@ void Clipboard::ReadText(std::wstring* result) const {
if (!data)
return;
- result->assign(static_cast<const wchar_t*>(::GlobalLock(data)));
+ result->assign(static_cast<const char16*>(::GlobalLock(data)));
::GlobalUnlock(data);
}
@@ -426,7 +425,7 @@ void Clipboard::ReadAsciiText(std::string* result) const {
::GlobalUnlock(data);
}
-void Clipboard::ReadHTML(std::wstring* markup, std::string* src_url) const {
+void Clipboard::ReadHTML(string16* markup, std::string* src_url) const {
if (markup)
markup->clear();
@@ -450,7 +449,7 @@ void Clipboard::ReadHTML(std::wstring* markup, std::string* src_url) const {
markup->assign(UTF8ToWide(markup_utf8));
}
-void Clipboard::ReadBookmark(std::wstring* title, std::string* url) const {
+void Clipboard::ReadBookmark(string16* title, std::string* url) const {
if (title)
title->clear();
@@ -466,30 +465,30 @@ void Clipboard::ReadBookmark(std::wstring* title, std::string* url) const {
if (!data)
return;
- std::wstring bookmark(static_cast<const wchar_t*>(::GlobalLock(data)));
+ string16 bookmark(static_cast<const char16*>(::GlobalLock(data)));
::GlobalUnlock(data);
ParseBookmarkClipboardFormat(bookmark, title, url);
}
// Read a file in HDROP format from the clipboard.
-void Clipboard::ReadFile(std::wstring* file) const {
+void Clipboard::ReadFile(FilePath* file) const {
if (!file) {
NOTREACHED();
return;
}
- file->clear();
- std::vector<std::wstring> files;
+ *file = FilePath();
+ std::vector<FilePath> files;
ReadFiles(&files);
// Take the first file, if available.
if (!files.empty())
- file->assign(files[0]);
+ *file = files[0];
}
// Read a set of files in HDROP format from the clipboard.
-void Clipboard::ReadFiles(std::vector<std::wstring>* files) const {
+void Clipboard::ReadFiles(std::vector<FilePath>* files) const {
if (!files) {
NOTREACHED();
return;
@@ -513,16 +512,16 @@ void Clipboard::ReadFiles(std::vector<std::wstring>* files) const {
int size = ::DragQueryFile(drop, i, NULL, 0) + 1;
std::wstring file;
::DragQueryFile(drop, i, WriteInto(&file, size), size);
- files->push_back(file);
+ files->push_back(FilePath(file));
}
}
}
// static
-void Clipboard::ParseBookmarkClipboardFormat(const std::wstring& bookmark,
- std::wstring* title,
+void Clipboard::ParseBookmarkClipboardFormat(const string16& bookmark,
+ string16* title,
std::string* url) {
- const wchar_t* const kDelim = L"\r\n";
+ const string16 kDelim = ASCIIToUTF16("\r\n");
const size_t title_end = bookmark.find_first_of(kDelim);
if (title)
@@ -530,8 +529,8 @@ void Clipboard::ParseBookmarkClipboardFormat(const std::wstring& bookmark,
if (url) {
const size_t url_start = bookmark.find_first_not_of(kDelim, title_end);
- if (url_start != std::wstring::npos)
- *url = WideToUTF8(bookmark.substr(url_start, std::wstring::npos));
+ if (url_start != string16::npos)
+ *url = UTF16ToUTF8(bookmark.substr(url_start, string16::npos));
}
}
diff --git a/base/pickle.cc b/base/pickle.cc
index aac59df..c2b3341 100644
--- a/base/pickle.cc
+++ b/base/pickle.cc
@@ -218,6 +218,22 @@ bool Pickle::ReadWString(void** iter, std::wstring* result) const {
return true;
}
+bool Pickle::ReadString16(void** iter, string16* result) const {
+ DCHECK(iter);
+
+ int len;
+ if (!ReadLength(iter, &len))
+ return false;
+ if (!IteratorHasRoomFor(*iter, len))
+ return false;
+
+ char16* chars = reinterpret_cast<char16*>(*iter);
+ result->assign(chars, len);
+
+ UpdateIter(iter, len * sizeof(char16));
+ return true;
+}
+
bool Pickle::ReadBytes(void** iter, const char** data, int length) const {
DCHECK(iter);
DCHECK(data);
@@ -290,7 +306,15 @@ bool Pickle::WriteWString(const std::wstring& value) {
return false;
return WriteBytes(value.data(),
- static_cast<int>(value.size() * sizeof(value.data()[0])));
+ static_cast<int>(value.size() * sizeof(wchar_t)));
+}
+
+bool Pickle::WriteString16(const string16& value) {
+ if (!WriteInt(static_cast<int>(value.size())))
+ return false;
+
+ return WriteBytes(value.data(),
+ static_cast<int>(value.size()) * sizeof(char16));
}
bool Pickle::WriteData(const char* data, int length) {
diff --git a/base/pickle.h b/base/pickle.h
index 66340ca..9f03662 100644
--- a/base/pickle.h
+++ b/base/pickle.h
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/string16.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
// This class provides facilities for basic binary value packing and unpacking.
@@ -72,6 +73,7 @@ class Pickle {
bool ReadIntPtr(void** iter, intptr_t* result) const;
bool ReadString(void** iter, std::string* result) const;
bool ReadWString(void** iter, std::wstring* result) const;
+ bool ReadString16(void** iter, string16* result) const;
bool ReadData(void** iter, const char** data, int* length) const;
bool ReadBytes(void** iter, const char** data, int length) const;
@@ -106,6 +108,7 @@ class Pickle {
}
bool WriteString(const std::string& value);
bool WriteWString(const std::wstring& value);
+ bool WriteString16(const string16& value);
bool WriteData(const char* data, int length);
bool WriteBytes(const void* data, int data_len);
diff --git a/base/scoped_clipboard_writer.cc b/base/scoped_clipboard_writer.cc
index f940462..5114a22 100644
--- a/base/scoped_clipboard_writer.cc
+++ b/base/scoped_clipboard_writer.cc
@@ -19,11 +19,11 @@ ScopedClipboardWriter::~ScopedClipboardWriter() {
clipboard_->WriteObjects(objects_);
}
-void ScopedClipboardWriter::WriteText(const std::wstring& text) {
+void ScopedClipboardWriter::WriteText(const string16& text) {
if (text.empty())
return;
- std::string utf8_text = WideToUTF8(text);
+ std::string utf8_text = UTF16ToUTF8(text);
Clipboard::ObjectMapParams parameters;
parameters.push_back(Clipboard::ObjectMapParam(utf8_text.begin(),
@@ -31,12 +31,12 @@ void ScopedClipboardWriter::WriteText(const std::wstring& text) {
objects_[Clipboard::CBF_TEXT] = parameters;
}
-void ScopedClipboardWriter::WriteHTML(const std::wstring& markup,
+void ScopedClipboardWriter::WriteHTML(const string16& markup,
const std::string& source_url) {
if (markup.empty())
return;
- std::string utf8_markup = WideToUTF8(markup);
+ std::string utf8_markup = UTF16ToUTF8(markup);
Clipboard::ObjectMapParams parameters;
parameters.push_back(
@@ -50,12 +50,12 @@ void ScopedClipboardWriter::WriteHTML(const std::wstring& markup,
objects_[Clipboard::CBF_HTML] = parameters;
}
-void ScopedClipboardWriter::WriteBookmark(const std::wstring& bookmark_title,
+void ScopedClipboardWriter::WriteBookmark(const string16& bookmark_title,
const std::string& url) {
if (bookmark_title.empty() || url.empty())
return;
- std::string utf8_markup = WideToUTF8(bookmark_title);
+ std::string utf8_markup = UTF16ToUTF8(bookmark_title);
Clipboard::ObjectMapParams parameters;
parameters.push_back(Clipboard::ObjectMapParam(utf8_markup.begin(),
@@ -64,12 +64,12 @@ void ScopedClipboardWriter::WriteBookmark(const std::wstring& bookmark_title,
objects_[Clipboard::CBF_BOOKMARK] = parameters;
}
-void ScopedClipboardWriter::WriteHyperlink(const std::wstring& link_text,
+void ScopedClipboardWriter::WriteHyperlink(const string16& link_text,
const std::string& url) {
if (link_text.empty() || url.empty())
return;
- std::string utf8_markup = WideToUTF8(link_text);
+ std::string utf8_markup = UTF16ToUTF8(link_text);
Clipboard::ObjectMapParams parameters;
parameters.push_back(Clipboard::ObjectMapParam(utf8_markup.begin(),
@@ -78,29 +78,38 @@ void ScopedClipboardWriter::WriteHyperlink(const std::wstring& link_text,
objects_[Clipboard::CBF_LINK] = parameters;
}
-void ScopedClipboardWriter::WriteFile(const std::wstring& file) {
- WriteFiles(std::vector<std::wstring>(1, file));
+void ScopedClipboardWriter::WriteFile(const FilePath& file) {
+ WriteFiles(std::vector<FilePath>(1, file));
}
// Save the filenames as a string separated by nulls and terminated with an
// extra null.
-void ScopedClipboardWriter::WriteFiles(const std::vector<std::wstring>& files) {
+void ScopedClipboardWriter::WriteFiles(const std::vector<FilePath>& files) {
if (files.empty())
return;
Clipboard::ObjectMapParam parameter;
- for (std::vector<std::wstring>::const_iterator iter = files.begin();
+ for (std::vector<FilePath>::const_iterator iter = files.begin();
iter != files.end(); ++iter) {
- std::string filename = WideToUTF8(*iter);
- for (std::string::const_iterator filename_iter = filename.begin();
- filename_iter != filename.end(); ++filename_iter) {
- parameter.push_back(*filename_iter);
- }
- parameter.push_back('\0');
+ FilePath filepath = *iter;
+ FilePath::StringType filename = filepath.value();
+
+ size_t data_length = filename.length() * sizeof(FilePath::CharType);
+ const char* data = reinterpret_cast<const char*>(filename.data());
+ const char* data_end = data + data_length;
+
+ for (const char* ch = data; ch < data_end; ++ch)
+ parameter.push_back(*ch);
+
+ // NUL-terminate the string.
+ for (size_t i = 0; i < sizeof(FilePath::CharType); ++i)
+ parameter.push_back('\0');
}
- parameter.push_back('\0');
+ // NUL-terminate the string list.
+ for (size_t i = 0; i < sizeof(FilePath::CharType); ++i)
+ parameter.push_back('\0');
Clipboard::ObjectMapParams parameters;
parameters.push_back(parameter);
diff --git a/base/scoped_clipboard_writer.h b/base/scoped_clipboard_writer.h
index 7bfedf4..a62a94c 100644
--- a/base/scoped_clipboard_writer.h
+++ b/base/scoped_clipboard_writer.h
@@ -10,7 +10,12 @@
#ifndef BASE_SCOPED_CLIPBOARD_WRITER_H_
#define BASE_SCOPED_CLIPBOARD_WRITER_H_
+#include <string>
+#include <vector>
+
#include "base/clipboard.h"
+#include "base/file_path.h"
+#include "base/string16.h"
// This class is a wrapper for |Clipboard| that handles packing data
// into a Clipboard::ObjectMap.
@@ -24,24 +29,24 @@ class ScopedClipboardWriter {
~ScopedClipboardWriter();
// Converts |text| to UTF-8 and adds it to the clipboard.
- void WriteText(const std::wstring& text);
+ void WriteText(const string16& text);
// Adds HTML to the clipboard. The url parameter is optional, but especially
// useful if the HTML fragment contains relative links.
- void WriteHTML(const std::wstring& markup, const std::string& source_url);
+ void WriteHTML(const string16& markup, const std::string& source_url);
// Adds a bookmark to the clipboard.
- void WriteBookmark(const std::wstring& bookmark_title,
+ void WriteBookmark(const string16& bookmark_title,
const std::string& url);
// Adds both a bookmark and an HTML hyperlink to the clipboard. It is a
// convenience wrapper around WriteBookmark and WriteHTML. |link_text| is
// used as the bookmark title.
- void WriteHyperlink(const std::wstring& link_text, const std::string& url);
+ void WriteHyperlink(const string16& link_text, const std::string& url);
// Adds a file or group of files to the clipboard.
- void WriteFile(const std::wstring& file);
- void WriteFiles(const std::vector<std::wstring>& files);
+ void WriteFile(const FilePath& file);
+ void WriteFiles(const std::vector<FilePath>& files);
// Used by WebKit to determine whether WebKit wrote the clipboard last
void WriteWebSmartPaste();
diff --git a/base/string_util.h b/base/string_util.h
index 26c42e5..1247cd5 100644
--- a/base/string_util.h
+++ b/base/string_util.h
@@ -596,4 +596,5 @@ bool MatchPattern(const std::string& string, const std::string& pattern);
// std::numeric_limits<size_t>::max() / 2
std::string HexEncode(const void* bytes, size_t size);
+
#endif // BASE_STRING_UTIL_H_
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index fd80886..4933945 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -113,14 +113,14 @@ void BaseContextMenu::ExecuteCommand(int id) {
download_->manager()->ShowDownloadInShell(download_);
break;
case COPY_LINK:
- scw.WriteText(UTF8ToWide(download_->url().spec()));
+ scw.WriteText(UTF8ToUTF16(download_->url().spec()));
break;
case COPY_PATH:
- scw.WriteText(download_->full_path().ToWStringHack());
+ scw.WriteText(WideToUTF16(download_->full_path().ToWStringHack()));
break;
case COPY_FILE:
// TODO(paulg): Move to OSExchangeData when implementing drag and drop?
- scw.WriteFile(download_->full_path().ToWStringHack());
+ scw.WriteFile(download_->full_path());
break;
case OPEN_WHEN_COMPLETE:
OpenDownload(download_);
diff --git a/chrome/browser/renderer_host/browser_render_process_host.h b/chrome/browser/renderer_host/browser_render_process_host.h
index dad06b5..03dfc43 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.h
+++ b/chrome/browser/renderer_host/browser_render_process_host.h
@@ -13,6 +13,7 @@
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "base/shared_memory.h"
+#include "base/string16.h"
#include "base/timer.h"
#include "chrome/common/transport_dib.h"
#include "chrome/browser/renderer_host/audio_renderer_host.h"
@@ -99,9 +100,9 @@ class BrowserRenderProcessHost : public RenderProcessHost,
void OnClipboardWriteBookmark(const std::wstring& title, const GURL& url);
void OnClipboardWriteBitmap(base::SharedMemoryHandle bitmap, gfx::Size size);
void OnClipboardIsFormatAvailable(unsigned int format, bool* result);
- void OnClipboardReadText(std::wstring* result);
+ void OnClipboardReadText(string16* result);
void OnClipboardReadAsciiText(std::string* result);
- void OnClipboardReadHTML(std::wstring* markup, GURL* src_url);
+ void OnClipboardReadHTML(string16* markup, GURL* src_url);
void OnUpdatedCacheStats(const CacheManager::UsageStats& stats);
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index edec4d7..1f78df1 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -551,7 +551,7 @@ void ResourceMessageFilter::OnClipboardIsFormatAvailable(unsigned int format,
#endif
}
-void ResourceMessageFilter::OnClipboardReadText(std::wstring* result) {
+void ResourceMessageFilter::OnClipboardReadText(string16* result) {
GetClipboardService()->ReadText(result);
}
@@ -559,7 +559,7 @@ void ResourceMessageFilter::OnClipboardReadAsciiText(std::string* result) {
GetClipboardService()->ReadAsciiText(result);
}
-void ResourceMessageFilter::OnClipboardReadHTML(std::wstring* markup,
+void ResourceMessageFilter::OnClipboardReadHTML(string16* markup,
GURL* src_url) {
std::string src_url_str;
GetClipboardService()->ReadHTML(markup, &src_url_str);
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index b131488..679a0ac 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -14,6 +14,7 @@
#include "base/gfx/native_widget_types.h"
#include "base/ref_counted.h"
#include "base/shared_memory.h"
+#include "base/string16.h"
#include "build/build_config.h"
#include "chrome/browser/net/resolve_proxy_msg_helper.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
@@ -156,9 +157,9 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
// Clipboard messages
void OnClipboardWriteObjects(const Clipboard::ObjectMap& objects);
void OnClipboardIsFormatAvailable(unsigned int format, bool* result);
- void OnClipboardReadText(std::wstring* result);
+ void OnClipboardReadText(string16* result);
void OnClipboardReadAsciiText(std::string* result);
- void OnClipboardReadHTML(std::wstring* markup, GURL* src_url);
+ void OnClipboardReadHTML(string16* markup, GURL* src_url);
#if defined(OS_WIN)|| defined(OS_LINUX)
void OnGetWindowRect(gfx::NativeViewId window, gfx::Rect *rect);
void OnGetRootWindowRect(gfx::NativeViewId window, gfx::Rect *rect);
diff --git a/chrome/browser/tab_contents/render_view_context_menu_controller.cc b/chrome/browser/tab_contents/render_view_context_menu_controller.cc
index 714f24c..4afcc86 100644
--- a/chrome/browser/tab_contents/render_view_context_menu_controller.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu_controller.cc
@@ -67,7 +67,7 @@ void RenderViewContextMenuController::Inspect(int x, int y) {
}
void RenderViewContextMenuController::WriteTextToClipboard(
- const std::wstring& text) {
+ const string16& text) {
ClipboardService* clipboard = g_browser_process->clipboard_service();
if (!clipboard)
@@ -79,9 +79,9 @@ void RenderViewContextMenuController::WriteTextToClipboard(
void RenderViewContextMenuController::WriteURLToClipboard(const GURL& url) {
if (url.SchemeIs(chrome::kMailToScheme))
- WriteTextToClipboard(UTF8ToWide(url.path()));
+ WriteTextToClipboard(UTF8ToUTF16(url.path()));
else
- WriteTextToClipboard(UTF8ToWide(url.spec()));
+ WriteTextToClipboard(UTF8ToUTF16(url.spec()));
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/tab_contents/render_view_context_menu_controller.h b/chrome/browser/tab_contents/render_view_context_menu_controller.h
index 9d18ff6..0c72dcc 100644
--- a/chrome/browser/tab_contents/render_view_context_menu_controller.h
+++ b/chrome/browser/tab_contents/render_view_context_menu_controller.h
@@ -7,6 +7,7 @@
#include "build/build_config.h"
+#include "base/string16.h"
#include "chrome/common/pref_member.h"
#include "chrome/common/page_transition_types.h"
#include "webkit/glue/context_menu.h"
@@ -49,7 +50,7 @@ class RenderViewContextMenuController : public Menu::Delegate {
void Inspect(int x, int y);
// Writes the specified text/url to the system clipboard
- void WriteTextToClipboard(const std::wstring& text);
+ void WriteTextToClipboard(const string16& text);
void WriteURLToClipboard(const GURL& url);
bool IsDevCommandEnabled(int id) const;
diff --git a/chrome/common/ipc_message_utils.h b/chrome/common/ipc_message_utils.h
index 61243f5..e877221 100644
--- a/chrome/common/ipc_message_utils.h
+++ b/chrome/common/ipc_message_utils.h
@@ -512,32 +512,22 @@ struct ParamTraits<std::wstring> {
}
};
-
// If WCHAR_T_IS_UTF16 is defined, then string16 is a std::wstring so we don't
// need this trait.
#if !defined(WCHAR_T_IS_UTF16)
-
template <>
struct ParamTraits<string16> {
typedef string16 param_type;
static void Write(Message* m, const param_type& p) {
- m->WriteData(reinterpret_cast<const char*>(p.data()),
- static_cast<int>(p.size() * sizeof(char16)));
+ m->WriteString16(p);
}
static bool Read(const Message* m, void** iter, param_type* r) {
- const char *data;
- int data_size = 0;
- if (!m->ReadData(iter, &data, &data_size))
- return false;
- r->assign(reinterpret_cast<const char16*>(data),
- data_size / sizeof(char16));
- return true;
+ return m->ReadString16(iter, r);
}
static void Log(const param_type& p, std::wstring* l) {
l->append(UTF16ToWide(p));
}
};
-
#endif
template <>
@@ -704,7 +694,6 @@ struct ParamTraits<gfx::Size> {
};
#if defined(OS_POSIX)
-
template<>
struct ParamTraits<base::FileDescriptor> {
typedef base::FileDescriptor param_type;
@@ -723,7 +712,6 @@ struct ParamTraits<base::FileDescriptor> {
}
}
};
-
#endif // defined(OS_POSIX)
template<>
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index af42627..963afae 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -840,11 +840,11 @@ IPC_BEGIN_MESSAGES(ViewHost)
int /* format */,
bool /* result */)
IPC_SYNC_MESSAGE_CONTROL0_1(ViewHostMsg_ClipboardReadText,
- std::wstring /* result */)
+ string16 /* result */)
IPC_SYNC_MESSAGE_CONTROL0_1(ViewHostMsg_ClipboardReadAsciiText,
std::string /* result */)
IPC_SYNC_MESSAGE_CONTROL0_2(ViewHostMsg_ClipboardReadHTML,
- std::wstring /* markup */,
+ string16 /* markup */,
GURL /* url */)
#if defined(OS_WIN)
diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc
index 97a26ff..9508c50 100644
--- a/chrome/renderer/renderer_glue.cc
+++ b/chrome/renderer/renderer_glue.cc
@@ -211,7 +211,7 @@ bool ClipboardIsFormatAvailable(unsigned int format) {
return result;
}
-void ClipboardReadText(std::wstring* result) {
+void ClipboardReadText(string16* result) {
RenderThread::current()->Send(new ViewHostMsg_ClipboardReadText(result));
}
@@ -219,7 +219,7 @@ void ClipboardReadAsciiText(std::string* result) {
RenderThread::current()->Send(new ViewHostMsg_ClipboardReadAsciiText(result));
}
-void ClipboardReadHTML(std::wstring* markup, GURL* url) {
+void ClipboardReadHTML(string16* markup, GURL* url) {
RenderThread::current()->Send(new ViewHostMsg_ClipboardReadHTML(markup, url));
}
diff --git a/webkit/glue/simple_clipboard_impl.cc b/webkit/glue/simple_clipboard_impl.cc
index 39f9cee..1674f4f 100644
--- a/webkit/glue/simple_clipboard_impl.cc
+++ b/webkit/glue/simple_clipboard_impl.cc
@@ -8,6 +8,7 @@
#include "base/clipboard.h"
#include "base/lazy_instance.h"
+#include "base/string16.h"
#include "googleurl/src/gurl.h"
#include "webkit/glue/scoped_clipboard_writer_glue.h"
@@ -37,7 +38,7 @@ bool ClipboardIsFormatAvailable(Clipboard::FormatType format) {
return ClipboardGetClipboard()->IsFormatAvailable(format);
}
-void ClipboardReadText(std::wstring* result) {
+void ClipboardReadText(string16* result) {
ClipboardGetClipboard()->ReadText(result);
}
@@ -45,7 +46,7 @@ void ClipboardReadAsciiText(std::string* result) {
ClipboardGetClipboard()->ReadAsciiText(result);
}
-void ClipboardReadHTML(std::wstring* markup, GURL* url) {
+void ClipboardReadHTML(string16* markup, GURL* url) {
std::string url_str;
ClipboardGetClipboard()->ReadHTML(markup, url ? &url_str : NULL);
if (url)
diff --git a/webkit/glue/webclipboard_impl.cc b/webkit/glue/webclipboard_impl.cc
index 029643f..04b0ef6 100644
--- a/webkit/glue/webclipboard_impl.cc
+++ b/webkit/glue/webclipboard_impl.cc
@@ -11,6 +11,7 @@
#include "base/clipboard.h"
#include "base/logging.h"
#include "base/string_util.h"
+#include "base/string16.h"
#include "googleurl/src/gurl.h"
#include "net/base/escape.h"
#include "webkit/glue/scoped_clipboard_writer_glue.h"
@@ -72,36 +73,36 @@ bool WebClipboardImpl::isFormatAvailable(Format format) {
WebString WebClipboardImpl::readPlainText() {
if (ClipboardIsFormatAvailable(Clipboard::GetPlainTextWFormatType())) {
- std::wstring text;
+ string16 text;
ClipboardReadText(&text);
if (!text.empty())
- return WideToUTF16Hack(text);
+ return text;
}
if (ClipboardIsFormatAvailable(Clipboard::GetPlainTextFormatType())) {
std::string text;
ClipboardReadAsciiText(&text);
if (!text.empty())
- return UTF8ToUTF16(text);
+ return ASCIIToUTF16(text);
}
return WebString();
}
WebString WebClipboardImpl::readHTML(WebURL* source_url) {
- std::wstring html_stdstr;
+ string16 html_stdstr;
GURL gurl;
ClipboardReadHTML(&html_stdstr, &gurl);
*source_url = gurl;
- return WideToUTF16Hack(html_stdstr);
+ return html_stdstr;
}
void WebClipboardImpl::writeHTML(
const WebString& html_text, const WebURL& source_url,
const WebString& plain_text, bool write_smart_paste) {
ScopedClipboardWriterGlue scw(ClipboardGetClipboard());
- scw.WriteHTML(UTF16ToWideHack(html_text), source_url.spec());
- scw.WriteText(UTF16ToWideHack(plain_text));
+ scw.WriteHTML(html_text, source_url.spec());
+ scw.WriteText(plain_text);
if (write_smart_paste)
scw.WriteWebSmartPaste();
@@ -110,9 +111,9 @@ void WebClipboardImpl::writeHTML(
void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) {
ScopedClipboardWriterGlue scw(ClipboardGetClipboard());
- scw.WriteBookmark(UTF16ToWideHack(title), url.spec());
- scw.WriteHTML(UTF8ToWide(URLToMarkup(url, title)), "");
- scw.WriteText(UTF8ToWide(url.spec()));
+ scw.WriteBookmark(title, url.spec());
+ scw.WriteHTML(UTF8ToUTF16(URLToMarkup(url, title)), "");
+ scw.WriteText(UTF8ToUTF16(url.spec()));
}
void WebClipboardImpl::writeImage(
@@ -125,9 +126,9 @@ void WebClipboardImpl::writeImage(
#endif
if (!url.isEmpty()) {
- scw.WriteBookmark(UTF16ToWideHack(title), url.spec());
- scw.WriteHTML(UTF8ToWide(URLToImageMarkup(url, title)), "");
- scw.WriteText(UTF8ToWide(url.spec()));
+ scw.WriteBookmark(title, url.spec());
+ scw.WriteHTML(UTF8ToUTF16(URLToImageMarkup(url, title)), "");
+ scw.WriteText(UTF8ToUTF16(url.spec()));
}
}
diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h
index 264d23a..003b0da 100644
--- a/webkit/glue/webkit_glue.h
+++ b/webkit/glue/webkit_glue.h
@@ -187,13 +187,13 @@ Clipboard* ClipboardGetClipboard();
bool ClipboardIsFormatAvailable(Clipboard::FormatType format);
// Reads UNICODE text from the clipboard, if available.
-void ClipboardReadText(std::wstring* result);
+void ClipboardReadText(string16* result);
// Reads ASCII text from the clipboard, if available.
void ClipboardReadAsciiText(std::string* result);
// Reads HTML from the clipboard, if available.
-void ClipboardReadHTML(std::wstring* markup, GURL* url);
+void ClipboardReadHTML(string16* markup, GURL* url);
// Gets the directory where the application data and libraries exist. This
// may be a versioned subdirectory, or it may be the same directory as the