summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-17 18:10:26 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-17 18:10:26 +0000
commit021052dbd3619f6ea8a248dab8f7bea35521048f (patch)
treef0d6b9c7b37342b8471ccd7433aaefd3f5a1b8f8 /app
parent69f1e8f3b85a7f81b3beb64e4b060ebf25db7adb (diff)
downloadchromium_src-021052dbd3619f6ea8a248dab8f7bea35521048f.zip
chromium_src-021052dbd3619f6ea8a248dab8f7bea35521048f.tar.gz
chromium_src-021052dbd3619f6ea8a248dab8f7bea35521048f.tar.bz2
Linux: Null terminate text/html data we send to the clipboard. Change WriteHyperlink to take string16 anchor text.
BUG=42624 TEST=none Review URL: http://codereview.chromium.org/2036013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47432 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/clipboard/clipboard_linux.cc9
-rw-r--r--app/clipboard/clipboard_unittest.cc41
-rw-r--r--app/clipboard/scoped_clipboard_writer.cc7
-rw-r--r--app/clipboard/scoped_clipboard_writer.h4
4 files changed, 35 insertions, 26 deletions
diff --git a/app/clipboard/clipboard_linux.cc b/app/clipboard/clipboard_linux.cc
index d03d356..71a429f 100644
--- a/app/clipboard/clipboard_linux.cc
+++ b/app/clipboard/clipboard_linux.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -153,8 +153,9 @@ void Clipboard::SetGtkClipboard() {
}
void Clipboard::WriteText(const char* text_data, size_t text_len) {
- char* data = new char[text_len];
+ char* data = new char[text_len + 1];
memcpy(data, text_data, text_len);
+ data[text_len] = '\0';
InsertMapping(kMimeText, data, text_len);
InsertMapping("TEXT", data, text_len);
@@ -171,11 +172,12 @@ void Clipboard::WriteHTML(const char* markup_data,
static const char* html_prefix = "<meta http-equiv=\"content-type\" "
"content=\"text/html; charset=utf-8\">";
size_t html_prefix_len = strlen(html_prefix);
- size_t total_len = html_prefix_len + markup_len;
+ size_t total_len = html_prefix_len + markup_len + 1;
char* data = new char[total_len];
snprintf(data, total_len, "%s", html_prefix);
memcpy(data + html_prefix_len, markup_data, markup_len);
+ data[total_len - 1] = '\0';
InsertMapping(kMimeHtml, data, total_len);
}
@@ -353,6 +355,7 @@ void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup,
void Clipboard::ReadBookmark(string16* title, std::string* url) const {
// TODO(estade): implement this.
+ NOTIMPLEMENTED();
}
void Clipboard::ReadData(const std::string& format, std::string* result) {
diff --git a/app/clipboard/clipboard_unittest.cc b/app/clipboard/clipboard_unittest.cc
index 89702f1..7039e6b 100644
--- a/app/clipboard/clipboard_unittest.cc
+++ b/app/clipboard/clipboard_unittest.cc
@@ -1,17 +1,14 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "build/build_config.h"
+
#include <string>
#include "app/clipboard/clipboard.h"
-#if defined(OS_WIN)
-#include "app/clipboard/clipboard_util_win.h"
-#endif
#include "app/clipboard/scoped_clipboard_writer.h"
#include "base/basictypes.h"
-#include "base/message_loop.h"
-#include "base/pickle.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "gfx/size.h"
@@ -19,6 +16,15 @@
#include "testing/platform_test.h"
#if defined(OS_WIN)
+#include "app/clipboard/clipboard_util_win.h"
+#include "base/message_loop.h"
+#endif
+
+#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
+#include "base/pickle.h"
+#endif
+
+#if defined(OS_WIN)
class ClipboardTest : public PlatformTest {
protected:
virtual void SetUp() {
@@ -264,20 +270,20 @@ TEST_F(ClipboardTest, SharedBitmapTest) {
#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
TEST_F(ClipboardTest, DataTest) {
Clipboard clipboard;
- const char* format = "chromium/x-test-format";
+ const char* kFormat = "chromium/x-test-format";
std::string payload("test string");
Pickle write_pickle;
write_pickle.WriteString(payload);
{
ScopedClipboardWriter clipboard_writer(&clipboard);
- clipboard_writer.WritePickledData(write_pickle, format);
+ clipboard_writer.WritePickledData(write_pickle, kFormat);
}
ASSERT_TRUE(clipboard.IsFormatAvailableByString(
- format, Clipboard::BUFFER_STANDARD));
+ kFormat, Clipboard::BUFFER_STANDARD));
std::string output;
- clipboard.ReadData(format, &output);
+ clipboard.ReadData(kFormat, &output);
ASSERT_FALSE(output.empty());
Pickle read_pickle(output.data(), output.size());
@@ -292,21 +298,22 @@ TEST_F(ClipboardTest, DataTest) {
TEST_F(ClipboardTest, HyperlinkTest) {
Clipboard clipboard;
- std::string title("The Example Company");
- std::string url("http://www.example.com/"), url_result;
- std::string html("<a href=\"http://www.example.com/\">"
- "The Example Company</a>");
+ const std::string kTitle("The Example Company");
+ const std::string kUrl("http://www.example.com/");
+ const std::string kExpectedHtml("<a href=\"http://www.example.com/\">"
+ "The Example Company</a>");
+ std::string url_result;
string16 html_result;
{
ScopedClipboardWriter clipboard_writer(&clipboard);
- clipboard_writer.WriteHyperlink(title, url);
+ clipboard_writer.WriteHyperlink(ASCIIToUTF16(kTitle), kUrl);
}
EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
Clipboard::BUFFER_STANDARD));
clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &html_result, &url_result);
- EXPECT_EQ(UTF8ToUTF16(html), html_result);
+ EXPECT_EQ(ASCIIToUTF16(kExpectedHtml), html_result);
}
TEST_F(ClipboardTest, WebSmartPasteTest) {
@@ -392,7 +399,7 @@ TEST_F(ClipboardTest, WriteEverything) {
writer.WriteURL(UTF8ToUTF16("foo"));
writer.WriteHTML(UTF8ToUTF16("foo"), "bar");
writer.WriteBookmark(UTF8ToUTF16("foo"), "bar");
- writer.WriteHyperlink("foo", "bar");
+ writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar");
writer.WriteWebSmartPaste();
// Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData.
}
diff --git a/app/clipboard/scoped_clipboard_writer.cc b/app/clipboard/scoped_clipboard_writer.cc
index 01885ba7..e2cb6ec 100644
--- a/app/clipboard/scoped_clipboard_writer.cc
+++ b/app/clipboard/scoped_clipboard_writer.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -65,7 +65,7 @@ void ScopedClipboardWriter::WriteBookmark(const string16& bookmark_title,
objects_[Clipboard::CBF_BOOKMARK] = parameters;
}
-void ScopedClipboardWriter::WriteHyperlink(const std::string& anchor_text,
+void ScopedClipboardWriter::WriteHyperlink(const string16& anchor_text,
const std::string& url) {
if (anchor_text.empty() || url.empty())
return;
@@ -74,7 +74,7 @@ void ScopedClipboardWriter::WriteHyperlink(const std::string& anchor_text,
std::string html("<a href=\"");
html.append(url);
html.append("\">");
- html.append(anchor_text);
+ html.append(UTF16ToUTF8(anchor_text));
html.append("</a>");
WriteHTML(UTF8ToUTF16(html), std::string());
}
@@ -134,4 +134,3 @@ void ScopedClipboardWriter::WriteTextOrURL(const string16& text, bool is_url) {
url_text_.clear();
}
}
-
diff --git a/app/clipboard/scoped_clipboard_writer.h b/app/clipboard/scoped_clipboard_writer.h
index aa918a2..73edab8 100644
--- a/app/clipboard/scoped_clipboard_writer.h
+++ b/app/clipboard/scoped_clipboard_writer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -48,7 +48,7 @@ class ScopedClipboardWriter {
// 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);
+ void WriteHyperlink(const string16& anchor_text, const std::string& url);
// Used by WebKit to determine whether WebKit wrote the clipboard last
void WriteWebSmartPaste();