diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 02:00:50 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 02:00:50 +0000 |
commit | be623b0f2ec23b3032fc6c8b61d6062accf51bb7 (patch) | |
tree | 2ffa24729ec7c5a0c1d9d92d200ec66fa675feef | |
parent | 956d5aecbbf21ab3f84c87a8aec7d3a47eefbd34 (diff) | |
download | chromium_src-be623b0f2ec23b3032fc6c8b61d6062accf51bb7.zip chromium_src-be623b0f2ec23b3032fc6c8b61d6062accf51bb7.tar.gz chromium_src-be623b0f2ec23b3032fc6c8b61d6062accf51bb7.tar.bz2 |
Clipboard:
- Move link construction logic to scoped_clipboard_writer.cc
- Make callers use EscapeForHTML on the anchor text
- Make WriteHyperlink just write html, and not a bookmark as well (only affects one caller, which I updated)
- implement WriteBookmark for gtk
BUG=18034,18035
Review URL: http://codereview.chromium.org/194052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25833 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/clipboard.cc | 5 | ||||
-rw-r--r-- | base/clipboard.h | 6 | ||||
-rw-r--r-- | base/clipboard_linux.cc | 26 | ||||
-rw-r--r-- | base/clipboard_mac.mm | 7 | ||||
-rw-r--r-- | base/clipboard_unittest.cc | 14 | ||||
-rw-r--r-- | base/clipboard_win.cc | 21 | ||||
-rw-r--r-- | base/scoped_clipboard_writer.cc | 18 | ||||
-rw-r--r-- | base/scoped_clipboard_writer.h | 7 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_win.cc | 4 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_drag_data.cc | 8 |
10 files changed, 42 insertions, 74 deletions
diff --git a/base/clipboard.cc b/base/clipboard.cc index b0f241e..510929e 100644 --- a/base/clipboard.cc +++ b/base/clipboard.cc @@ -38,11 +38,6 @@ void Clipboard::DispatchObject(ObjectType type, const ObjectMapParams& params) { &(params[1].front()), params[1].size()); break; - case CBF_LINK: - WriteHyperlink(&(params[0].front()), params[0].size(), - &(params[1].front()), params[1].size()); - break; - case CBF_FILES: WriteFiles(&(params[0].front()), params[0].size()); break; diff --git a/base/clipboard.h b/base/clipboard.h index cea5033..b960676 100644 --- a/base/clipboard.h +++ b/base/clipboard.h @@ -36,7 +36,6 @@ class Clipboard { CBF_TEXT, CBF_HTML, CBF_BOOKMARK, - CBF_LINK, CBF_FILES, CBF_WEBKIT, CBF_BITMAP, @@ -186,11 +185,6 @@ class Clipboard { const char* url_data, size_t url_len); - void WriteHyperlink(const char* title_data, - size_t title_len, - const char* url_data, - size_t url_len); - void WriteWebSmartPaste(); void WriteFiles(const char* file_data, size_t file_len); diff --git a/base/clipboard_linux.cc b/base/clipboard_linux.cc index 5d8d353..9a04d1c 100644 --- a/base/clipboard_linux.cc +++ b/base/clipboard_linux.cc @@ -21,6 +21,7 @@ namespace { const char kMimeBmp[] = "image/bmp"; const char kMimeHtml[] = "text/html"; const char kMimeText[] = "text/plain"; +const char kMimeURI[] = "text/uri-list"; const char kMimeWebkitSmartPaste[] = "chromium/x-webkit-paste"; std::string GdkAtomToString(const GdkAtom& atom) { @@ -52,6 +53,11 @@ void GetData(GtkClipboard* clipboard, if (target_string == kMimeBmp) { gtk_selection_data_set_pixbuf(selection_data, reinterpret_cast<GdkPixbuf*>(iter->second.first)); + } else if (target_string == kMimeURI) { + gchar* uri_list[2]; + uri_list[0] = reinterpret_cast<gchar*>(iter->second.first); + uri_list[1] = NULL; + gtk_selection_data_set_uris(selection_data, uri_list); } else { gtk_selection_data_set(selection_data, selection_data->target, 8, reinterpret_cast<guchar*>(iter->second.first), @@ -77,8 +83,9 @@ void ClearData(GtkClipboard* clipboard, } for (std::set<char*>::iterator iter = ptrs.begin(); - iter != ptrs.end(); ++iter) + iter != ptrs.end(); ++iter) { delete[] *iter; + } delete map; } @@ -183,14 +190,14 @@ void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) { void Clipboard::WriteBookmark(const char* title_data, size_t title_len, const char* url_data, size_t url_len) { - // TODO(estade): implement this, but for now fail silently so we do not - // write error output during layout tests. - // NOTIMPLEMENTED(); -} - -void Clipboard::WriteHyperlink(const char* title_data, size_t title_len, - const char* url_data, size_t url_len) { - NOTIMPLEMENTED(); + // Write as plain text. + WriteText(url_data, url_len); + + // Write as a URI. + char* data = new char[url_len + 1]; + memcpy(data, url_data, url_len); + data[url_len] = NULL; + InsertMapping(kMimeURI, data, url_len + 1); } void Clipboard::WriteFiles(const char* file_data, size_t file_len) { @@ -393,4 +400,3 @@ GtkClipboard* Clipboard::LookupBackingClipboard(Buffer clipboard) const { } return result; } - diff --git a/base/clipboard_mac.mm b/base/clipboard_mac.mm index 98812f3..954b601 100644 --- a/base/clipboard_mac.mm +++ b/base/clipboard_mac.mm @@ -73,13 +73,6 @@ void Clipboard::WriteBookmark(const char* title_data, size_t title_len, const char* url_data, size_t url_len) { - WriteHyperlink(title_data, title_len, url_data, url_len); -} - -void Clipboard::WriteHyperlink(const char* title_data, - size_t title_len, - const char* url_data, - size_t url_len) { std::string title_str(title_data, title_len); NSString *title = base::SysUTF8ToNSString(title_str); std::string url_str(url_data, url_len); diff --git a/base/clipboard_unittest.cc b/base/clipboard_unittest.cc index 1b77115..d26ba00 100644 --- a/base/clipboard_unittest.cc +++ b/base/clipboard_unittest.cc @@ -258,25 +258,21 @@ TEST_F(ClipboardTest, DataTest) { TEST_F(ClipboardTest, HyperlinkTest) { Clipboard clipboard; - string16 title(ASCIIToUTF16("The Example Company")), title_result; + std::string title("The Example Company"); std::string url("http://www.example.com/"), url_result; - string16 html(ASCIIToUTF16("<a href=\"http://www.example.com/\">" - "The Example Company</a>")), html_result; + std::string html("<a href=\"http://www.example.com/\">" + "The Example Company</a>"); + string16 html_result; { ScopedClipboardWriter clipboard_writer(&clipboard); clipboard_writer.WriteHyperlink(title, url); } - 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(Clipboard::BUFFER_STANDARD, &html_result, &url_result); - EXPECT_EQ(html, html_result); + EXPECT_EQ(UTF8ToUTF16(html), html_result); } TEST_F(ClipboardTest, WebSmartPasteTest) { diff --git a/base/clipboard_win.cc b/base/clipboard_win.cc index 5b190af..a8048e0 100644 --- a/base/clipboard_win.cc +++ b/base/clipboard_win.cc @@ -209,27 +209,6 @@ void Clipboard::WriteBookmark(const char* title_data, WriteToClipboard(StringToInt(GetUrlWFormatType()), glob); } -void Clipboard::WriteHyperlink(const char* title_data, - size_t title_len, - const char* url_data, - size_t url_len) { - // Store as a bookmark. - WriteBookmark(title_data, title_len, url_data, url_len); - - std::string title(title_data, title_len), - url(url_data, url_len), - link("<a href=\""); - - // Construct the hyperlink. - link.append(url); - link.append("\">"); - link.append(title); - link.append("</a>"); - - // Store hyperlink as html. - WriteHTML(link.c_str(), link.size(), NULL, 0); -} - void Clipboard::WriteWebSmartPaste() { DCHECK(clipboard_owner_); ::SetClipboardData(StringToInt(GetWebKitSmartPasteFormatType()), NULL); diff --git a/base/scoped_clipboard_writer.cc b/base/scoped_clipboard_writer.cc index 1e9e846..dff3321 100644 --- a/base/scoped_clipboard_writer.cc +++ b/base/scoped_clipboard_writer.cc @@ -67,18 +67,18 @@ void ScopedClipboardWriter::WriteBookmark(const string16& bookmark_title, objects_[Clipboard::CBF_BOOKMARK] = parameters; } -void ScopedClipboardWriter::WriteHyperlink(const string16& link_text, +void ScopedClipboardWriter::WriteHyperlink(const std::string& anchor_text, const std::string& url) { - if (link_text.empty() || url.empty()) + if (anchor_text.empty() || url.empty()) return; - std::string utf8_markup = UTF16ToUTF8(link_text); - - Clipboard::ObjectMapParams parameters; - parameters.push_back(Clipboard::ObjectMapParam(utf8_markup.begin(), - utf8_markup.end())); - parameters.push_back(Clipboard::ObjectMapParam(url.begin(), url.end())); - objects_[Clipboard::CBF_LINK] = parameters; + // Construct the hyperlink. + std::string html("<a href=\""); + html.append(url); + html.append("\">"); + html.append(anchor_text); + html.append("</a>"); + WriteHTML(UTF8ToUTF16(html), std::string()); } void ScopedClipboardWriter::WriteFile(const FilePath& file) { diff --git a/base/scoped_clipboard_writer.h b/base/scoped_clipboard_writer.h index 9d1760a..ed63050 100644 --- a/base/scoped_clipboard_writer.h +++ b/base/scoped_clipboard_writer.h @@ -41,10 +41,9 @@ class ScopedClipboardWriter { 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 string16& link_text, const std::string& url); + // Adds an html hyperlink (<a href>) to the clipboard. |anchor_text| should + // be escaped prior to being passed in. + void WriteHyperlink(const std::string& anchor_text, const std::string& url); // Adds a file or group of files to the clipboard. void WriteFile(const FilePath& file); diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc index 3347a34..7a09dac 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc @@ -39,6 +39,7 @@ #include "chrome/common/notification_service.h" #include "googleurl/src/url_util.h" #include "grit/generated_resources.h" +#include "net/base/escape.h" #include "skia/ext/skia_utils_win.h" #include "views/drag_utils.h" #include "views/focus/focus_util_win.h" @@ -1197,7 +1198,8 @@ void AutocompleteEditViewWin::OnCopy() { scw.WriteText(UTF8ToWide(url.spec())); else scw.WriteText(text); - scw.WriteHyperlink(text, url.spec()); + scw.WriteBookmark(text, url.spec()); + scw.WriteHyperlink(EscapeForHTML(UTF16ToUTF8(text)), url.spec()); return; } } diff --git a/chrome/browser/bookmarks/bookmark_drag_data.cc b/chrome/browser/bookmarks/bookmark_drag_data.cc index 47ea0c0..81a85fb 100644 --- a/chrome/browser/bookmarks/bookmark_drag_data.cc +++ b/chrome/browser/bookmarks/bookmark_drag_data.cc @@ -12,6 +12,7 @@ #include "chrome/browser/profile.h" #include "chrome/common/url_constants.h" #include "chrome/browser/browser_process.h" +#include "net/base/escape.h" const char* BookmarkDragData::kClipboardFormatString = "chromium/x-bookmark-entries"; @@ -96,8 +97,11 @@ void BookmarkDragData::WriteToClipboard(Profile* profile) const { // If there is only one element and it is a URL, write the URL to the // clipboard. if (elements.size() == 1 && elements[0].is_url) { - scw.WriteBookmark(WideToUTF16Hack(elements[0].title), - elements[0].url.spec()); + string16 title = WideToUTF16Hack(elements[0].title); + std::string url = elements[0].url.spec(); + + scw.WriteBookmark(title, url); + scw.WriteHyperlink(EscapeForHTML(UTF16ToUTF8(title)), url); } Pickle pickle; |