diff options
author | japhet@chromium.org <japhet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-08 22:16:05 +0000 |
---|---|---|
committer | japhet@chromium.org <japhet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-08 22:16:05 +0000 |
commit | 65a6150d49263ff6e3135c5631f9ba5eb12823df (patch) | |
tree | 36f5b8624ae02cc69ae29ade9923404f6fec80b3 /base | |
parent | 9f53c7d5f1ce83bb2025b1797300c6d60dd7d8ff (diff) | |
download | chromium_src-65a6150d49263ff6e3135c5631f9ba5eb12823df.zip chromium_src-65a6150d49263ff6e3135c5631f9ba5eb12823df.tar.gz chromium_src-65a6150d49263ff6e3135c5631f9ba5eb12823df.tar.bz2 |
Roll webkit deps 48155:48185 and remove a couple of passing tests from test_expectations.txt.
Also, merge in http://codereview.chromium.org/174367 (original author: vandebo@chromium.org), which is the downstream half of r48168.
BUG=4360
BUG=21228
BUG=18792
TEST=none
TBR=eroman
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25669 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/clipboard.h | 43 | ||||
-rw-r--r-- | base/clipboard_linux.cc | 63 | ||||
-rw-r--r-- | base/clipboard_mac.mm | 15 | ||||
-rw-r--r-- | base/clipboard_unittest.cc | 55 | ||||
-rw-r--r-- | base/clipboard_win.cc | 18 |
5 files changed, 145 insertions, 49 deletions
diff --git a/base/clipboard.h b/base/clipboard.h index bd4aefd..cea5033 100644 --- a/base/clipboard.h +++ b/base/clipboard.h @@ -74,6 +74,34 @@ class Clipboard { typedef std::vector<ObjectMapParam> ObjectMapParams; typedef std::map<int /* ObjectType */, ObjectMapParams> ObjectMap; + // Buffer designates which clipboard the action should be applied to. + // Only platforms that use the X Window System support the selection + // buffer. Furthermore we currently only use a buffer other than the + // standard buffer when reading from the clipboard so only those + // functions accept a buffer parameter. + enum Buffer { + BUFFER_STANDARD, +#if defined(OS_LINUX) + BUFFER_SELECTION, +#endif + }; + + static bool IsValidBuffer(int32 buffer) { + switch (buffer) { + case BUFFER_STANDARD: + return true; +#if defined(OS_LINUX) + case BUFFER_SELECTION: + return true; +#endif + } + return false; + } + + static Buffer FromInt(int32 buffer) { + return static_cast<Buffer>(buffer); + } + Clipboard(); ~Clipboard(); @@ -90,20 +118,21 @@ class Clipboard { void WriteObjects(const ObjectMap& objects, base::ProcessHandle process); // Tests whether the clipboard contains a certain format - bool IsFormatAvailable(const FormatType& format) const; + bool IsFormatAvailable(const FormatType& format, Buffer buffer) const; // As above, but instead of interpreting |format| by some platform-specific // definition, interpret it as a literal MIME type. - bool IsFormatAvailableByString(const std::string& format) const; + bool IsFormatAvailableByString(const std::string& format, + Buffer buffer) const; // Reads UNICODE text from the clipboard, if available. - void ReadText(string16* result) const; + void ReadText(Buffer buffer, string16* result) const; // Reads ASCII text from the clipboard, if available. - void ReadAsciiText(std::string* result) const; + void ReadAsciiText(Buffer buffer, std::string* result) const; // Reads HTML from the clipboard, if available. - void ReadHTML(string16* markup, std::string* src_url) const; + void ReadHTML(Buffer buffer, string16* markup, std::string* src_url) const; // Reads a bookmark from the clipboard, if available. void ReadBookmark(string16* title, std::string* url) const; @@ -213,8 +242,12 @@ class Clipboard { // Insert a mapping into clipboard_data_. void InsertMapping(const char* key, char* data, size_t data_len); + // find the gtk clipboard for the passed buffer enum + GtkClipboard* LookupBackingClipboard(Buffer clipboard) const; + TargetMap* clipboard_data_; GtkClipboard* clipboard_; + GtkClipboard* primary_selection_; #endif DISALLOW_COPY_AND_ASSIGN(Clipboard); diff --git a/base/clipboard_linux.cc b/base/clipboard_linux.cc index 6aedc91..5d8d353 100644 --- a/base/clipboard_linux.cc +++ b/base/clipboard_linux.cc @@ -92,6 +92,7 @@ void GdkPixbufFree(guchar* pixels, gpointer data) { Clipboard::Clipboard() { clipboard_ = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); + primary_selection_ = gtk_clipboard_get(GDK_SELECTION_PRIMARY); } Clipboard::~Clipboard() { @@ -207,18 +208,23 @@ void Clipboard::WriteData(const char* format_name, size_t format_len, // We do not use gtk_clipboard_wait_is_target_available because of // a bug with the gtk clipboard. It caches the available targets // and does not always refresh the cache when it is appropriate. -bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { +bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, + Clipboard::Buffer buffer) const { + GtkClipboard* clipboard = LookupBackingClipboard(buffer); + if (clipboard == NULL) + return false; + bool format_is_plain_text = GetPlainTextFormatType() == format; if (format_is_plain_text) { // This tries a number of common text targets. - if (gtk_clipboard_wait_is_text_available(clipboard_)) + if (gtk_clipboard_wait_is_text_available(clipboard)) return true; } bool retval = false; GdkAtom* targets = NULL; GtkSelectionData* data = - gtk_clipboard_wait_for_contents(clipboard_, + gtk_clipboard_wait_for_contents(clipboard, gdk_atom_intern("TARGETS", false)); if (!data) @@ -234,7 +240,7 @@ bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { // programs. if (num <= 0) { if (format_is_plain_text) { - gchar* text = gtk_clipboard_wait_for_text(clipboard_); + gchar* text = gtk_clipboard_wait_for_text(clipboard); if (text) { g_free(text); retval = true; @@ -257,13 +263,18 @@ bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { return retval; } -bool Clipboard::IsFormatAvailableByString(const std::string& format) const { - return IsFormatAvailable(format); +bool Clipboard::IsFormatAvailableByString(const std::string& format, + Clipboard::Buffer buffer) const { + return IsFormatAvailable(format, buffer); } -void Clipboard::ReadText(string16* result) const { +void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { + GtkClipboard* clipboard = LookupBackingClipboard(buffer); + if (clipboard == NULL) + return; + result->clear(); - gchar* text = gtk_clipboard_wait_for_text(clipboard_); + gchar* text = gtk_clipboard_wait_for_text(clipboard); if (text == NULL) return; @@ -273,9 +284,14 @@ void Clipboard::ReadText(string16* result) const { g_free(text); } -void Clipboard::ReadAsciiText(std::string* result) const { +void Clipboard::ReadAsciiText(Clipboard::Buffer buffer, + std::string* result) const { + GtkClipboard* clipboard = LookupBackingClipboard(buffer); + if (clipboard == NULL) + return; + result->clear(); - gchar* text = gtk_clipboard_wait_for_text(clipboard_); + gchar* text = gtk_clipboard_wait_for_text(clipboard); if (text == NULL) return; @@ -290,10 +306,14 @@ void Clipboard::ReadFile(FilePath* file) const { // TODO(estade): handle different charsets. // TODO(port): set *src_url. -void Clipboard::ReadHTML(string16* markup, std::string* src_url) const { +void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup, + std::string* src_url) const { + GtkClipboard* clipboard = LookupBackingClipboard(buffer); + if (clipboard == NULL) + return; markup->clear(); - GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard_, + GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, StringToGdkAtom(GetHtmlFormatType())); if (!data) @@ -355,3 +375,22 @@ void Clipboard::InsertMapping(const char* key, (*clipboard_data_)[key] = std::make_pair(data, data_len); } + +GtkClipboard* Clipboard::LookupBackingClipboard(Buffer clipboard) const { + GtkClipboard* result; + + switch (clipboard) { + case BUFFER_STANDARD: + result = clipboard_; + break; + case BUFFER_SELECTION: + result = primary_selection_; + break; + default: + NOTREACHED(); + result = NULL; + break; + } + return result; +} + diff --git a/base/clipboard_mac.mm b/base/clipboard_mac.mm index 889655f..98812f3 100644 --- a/base/clipboard_mac.mm +++ b/base/clipboard_mac.mm @@ -135,7 +135,9 @@ void Clipboard::WriteWebSmartPaste() { [pb setData:nil forType:format]; } -bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { +bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, + Clipboard::Buffer buffer) const { + DCHECK_EQ(buffer, BUFFER_STANDARD); NSString* format_ns = base::SysUTF8ToNSString(format); NSPasteboard* pb = GetPasteboard(); @@ -144,7 +146,8 @@ bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { return [types containsObject:format_ns]; } -void Clipboard::ReadText(string16* result) const { +void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { + DCHECK_EQ(buffer, BUFFER_STANDARD); NSPasteboard* pb = GetPasteboard(); NSString* contents = [pb stringForType:NSStringPboardType]; @@ -153,7 +156,9 @@ void Clipboard::ReadText(string16* result) const { result); } -void Clipboard::ReadAsciiText(std::string* result) const { +void Clipboard::ReadAsciiText(Clipboard::Buffer buffer, + std::string* result) const { + DCHECK_EQ(buffer, BUFFER_STANDARD); NSPasteboard* pb = GetPasteboard(); NSString* contents = [pb stringForType:NSStringPboardType]; @@ -163,7 +168,9 @@ void Clipboard::ReadAsciiText(std::string* result) const { result->assign([contents UTF8String]); } -void Clipboard::ReadHTML(string16* markup, std::string* src_url) const { +void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup, + std::string* src_url) const { + DCHECK_EQ(buffer, BUFFER_STANDARD); if (markup) { NSPasteboard* pb = GetPasteboard(); NSArray *supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, diff --git a/base/clipboard_unittest.cc b/base/clipboard_unittest.cc index dbcaa44..1b77115 100644 --- a/base/clipboard_unittest.cc +++ b/base/clipboard_unittest.cc @@ -44,9 +44,9 @@ TEST_F(ClipboardTest, ClearTest) { } EXPECT_FALSE(clipboard.IsFormatAvailable( - Clipboard::GetPlainTextWFormatType())); + Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD)); EXPECT_FALSE(clipboard.IsFormatAvailable( - Clipboard::GetPlainTextFormatType())); + Clipboard::GetPlainTextFormatType(), Clipboard::BUFFER_STANDARD)); } TEST_F(ClipboardTest, TextTest) { @@ -61,12 +61,13 @@ TEST_F(ClipboardTest, TextTest) { } EXPECT_TRUE(clipboard.IsFormatAvailable( - Clipboard::GetPlainTextWFormatType())); - EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetPlainTextFormatType())); - clipboard.ReadText(&text_result); + Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD)); + EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetPlainTextFormatType(), + Clipboard::BUFFER_STANDARD)); + clipboard.ReadText(Clipboard::BUFFER_STANDARD, &text_result); EXPECT_EQ(text, text_result); - clipboard.ReadAsciiText(&ascii_text); + clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &ascii_text); EXPECT_EQ(UTF16ToUTF8(text), ascii_text); } @@ -81,8 +82,9 @@ TEST_F(ClipboardTest, HTMLTest) { clipboard_writer.WriteHTML(markup, url); } - EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); - clipboard.ReadHTML(&markup_result, &url_result); + EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(), + Clipboard::BUFFER_STANDARD)); + clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result); EXPECT_EQ(markup, markup_result); #if defined(OS_WIN) // TODO(playmobil): It's not clear that non windows clipboards need to support @@ -103,8 +105,9 @@ TEST_F(ClipboardTest, TrickyHTMLTest) { clipboard_writer.WriteHTML(markup, url); } - EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); - clipboard.ReadHTML(&markup_result, &url_result); + EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(), + Clipboard::BUFFER_STANDARD)); + clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result); EXPECT_EQ(markup, markup_result); #if defined(OS_WIN) // TODO(playmobil): It's not clear that non windows clipboards need to support @@ -126,7 +129,8 @@ TEST_F(ClipboardTest, BookmarkTest) { clipboard_writer.WriteBookmark(title, url); } - EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType())); + EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType(), + Clipboard::BUFFER_STANDARD)); clipboard.ReadBookmark(&title_result, &url_result); EXPECT_EQ(title, title_result); EXPECT_EQ(url, url_result); @@ -147,21 +151,22 @@ TEST_F(ClipboardTest, MultiFormatTest) { clipboard_writer.WriteText(text); } - EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); + EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(), + Clipboard::BUFFER_STANDARD)); EXPECT_TRUE(clipboard.IsFormatAvailable( - Clipboard::GetPlainTextWFormatType())); + Clipboard::GetPlainTextWFormatType(), Clipboard::BUFFER_STANDARD)); EXPECT_TRUE(clipboard.IsFormatAvailable( - Clipboard::GetPlainTextFormatType())); - clipboard.ReadHTML(&markup_result, &url_result); + Clipboard::GetPlainTextFormatType(), Clipboard::BUFFER_STANDARD)); + clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result); EXPECT_EQ(markup, markup_result); #if defined(OS_WIN) // TODO(playmobil): It's not clear that non windows clipboards need to support // this. EXPECT_EQ(url, url_result); #endif // defined(OS_WIN) - clipboard.ReadText(&text_result); + clipboard.ReadText(Clipboard::BUFFER_STANDARD, &text_result); EXPECT_EQ(text, text_result); - clipboard.ReadAsciiText(&ascii_text); + clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &ascii_text); EXPECT_EQ(UTF16ToUTF8(text), ascii_text); } @@ -235,7 +240,8 @@ TEST_F(ClipboardTest, DataTest) { clipboard_writer.WritePickledData(write_pickle, format); } - ASSERT_TRUE(clipboard.IsFormatAvailableByString(format)); + ASSERT_TRUE(clipboard.IsFormatAvailableByString( + format, Clipboard::BUFFER_STANDARD)); std::string output; clipboard.ReadData(format, &output); ASSERT_FALSE(output.empty()); @@ -262,12 +268,14 @@ TEST_F(ClipboardTest, HyperlinkTest) { clipboard_writer.WriteHyperlink(title, url); } - EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType())); - EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); + EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType(), + Clipboard::BUFFER_STANDARD)); + EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(), + Clipboard::BUFFER_STANDARD)); clipboard.ReadBookmark(&title_result, &url_result); EXPECT_EQ(title, title_result); EXPECT_EQ(url, url_result); - clipboard.ReadHTML(&html_result, &url_result); + clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &html_result, &url_result); EXPECT_EQ(html, html_result); } @@ -280,7 +288,7 @@ TEST_F(ClipboardTest, WebSmartPasteTest) { } EXPECT_TRUE(clipboard.IsFormatAvailable( - Clipboard::GetWebKitSmartPasteFormatType())); + Clipboard::GetWebKitSmartPasteFormatType(), Clipboard::BUFFER_STANDARD)); } TEST_F(ClipboardTest, BitmapTest) { @@ -297,6 +305,7 @@ TEST_F(ClipboardTest, BitmapTest) { clipboard_writer.WriteBitmapFromPixels(fake_bitmap, gfx::Size(3, 4)); } - EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetBitmapFormatType())); + EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetBitmapFormatType(), + Clipboard::BUFFER_STANDARD)); } #endif // defined(OS_WIN) diff --git a/base/clipboard_win.cc b/base/clipboard_win.cc index bd88efa..5b190af 100644 --- a/base/clipboard_win.cc +++ b/base/clipboard_win.cc @@ -397,18 +397,22 @@ void Clipboard::WriteToClipboard(unsigned int format, HANDLE handle) { } } -bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { +bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, + Clipboard::Buffer buffer) const { + DCHECK_EQ(buffer, BUFFER_STANDARD); return ::IsClipboardFormatAvailable(StringToInt(format)) != FALSE; } bool Clipboard::IsFormatAvailableByString( - const std::string& ascii_format) const { + const std::string& ascii_format, Clipboard::Buffer buffer) const { + DCHECK_EQ(buffer, BUFFER_STANDARD); std::wstring wide_format = ASCIIToWide(ascii_format); CLIPFORMAT format = ::RegisterClipboardFormat(wide_format.c_str()); return ::IsClipboardFormatAvailable(format) != FALSE; } -void Clipboard::ReadText(string16* result) const { +void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { + DCHECK_EQ(buffer, BUFFER_STANDARD); if (!result) { NOTREACHED(); return; @@ -429,7 +433,9 @@ void Clipboard::ReadText(string16* result) const { ::GlobalUnlock(data); } -void Clipboard::ReadAsciiText(std::string* result) const { +void Clipboard::ReadAsciiText(Clipboard::Buffer buffer, + std::string* result) const { + DCHECK_EQ(buffer, BUFFER_STANDARD); if (!result) { NOTREACHED(); return; @@ -450,7 +456,9 @@ void Clipboard::ReadAsciiText(std::string* result) const { ::GlobalUnlock(data); } -void Clipboard::ReadHTML(string16* markup, std::string* src_url) const { +void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup, + std::string* src_url) const { + DCHECK_EQ(buffer, BUFFER_STANDARD); if (markup) markup->clear(); |