diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-19 01:20:01 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-19 01:20:01 +0000 |
commit | 22cf8687fe6c4fc4dbb2b9b2ac41d7d45f656d83 (patch) | |
tree | df838980effe3721bdc41b6acea356bf6352df8e /chrome/common | |
parent | 234ebdecf98582ca141b9066b1e5f4f74d3bdbff (diff) | |
download | chromium_src-22cf8687fe6c4fc4dbb2b9b2ac41d7d45f656d83.zip chromium_src-22cf8687fe6c4fc4dbb2b9b2ac41d7d45f656d83.tar.gz chromium_src-22cf8687fe6c4fc4dbb2b9b2ac41d7d45f656d83.tar.bz2 |
Remove cf_html from webdropdata.h. This is windows
specific code so we should handle it before we get
to webkit.
CF_HTML needs the source URL to resolve relative URLs
so I added that to the format and plumb it through
from webcore.
I also did some small refactoring so we only have one
implementation of converting to/from CF_HTML and regular
markup. We can tweak these converters (and add unit tests)
in follow up changes.
Review URL: http://codereview.chromium.org/11247
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5662 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/os_exchange_data.cc | 23 | ||||
-rw-r--r-- | chrome/common/os_exchange_data.h | 8 | ||||
-rw-r--r-- | chrome/common/os_exchange_data_unittest.cc | 30 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 4 |
4 files changed, 48 insertions, 17 deletions
diff --git a/chrome/common/os_exchange_data.cc b/chrome/common/os_exchange_data.cc index 36553c1..e86ce33 100644 --- a/chrome/common/os_exchange_data.cc +++ b/chrome/common/os_exchange_data.cc @@ -335,11 +335,20 @@ void OSExchangeData::SetFileContents(const std::wstring& filename, ClipboardUtil::GetFileContentFormatZero()->cfFormat, storage)); } -void OSExchangeData::SetCFHtml(const std::wstring& cf_html) { - std::string utf8 = WideToUTF8(cf_html); - STGMEDIUM* storage = GetStorageForBytes(utf8.c_str(), utf8.size()); +void OSExchangeData::SetHtml(const std::wstring& html, const GURL& base_url) { + // Add both MS CF_HTML and text/html format. CF_HTML should be in utf-8. + std::string utf8_html = WideToUTF8(html); + std::string url = base_url.is_valid() ? base_url.spec() : std::string(); + + std::string cf_html = ClipboardUtil::HtmlToCFHtml(utf8_html, url); + STGMEDIUM* storage = GetStorageForBytes(cf_html.c_str(), cf_html.size()); contents_.push_back(new StoredDataInfo( ClipboardUtil::GetHtmlFormat()->cfFormat, storage)); + + STGMEDIUM* storage_plain = GetStorageForBytes(utf8_html.c_str(), + utf8_html.size()); + contents_.push_back(new StoredDataInfo( + ClipboardUtil::GetTextHtmlFormat()->cfFormat, storage_plain)); } bool OSExchangeData::GetString(std::wstring* data) const { @@ -395,8 +404,12 @@ bool OSExchangeData::GetFileContents(std::wstring* filename, file_contents); } -bool OSExchangeData::GetCFHtml(std::wstring* cf_html) const { - return ClipboardUtil::GetCFHtml(source_object_, cf_html); +bool OSExchangeData::GetHtml(std::wstring* html, GURL* base_url) const { + std::string url; + bool success = ClipboardUtil::GetHtml(source_object_, html, &url); + if (success) + *base_url = GURL(url); + return success; } bool OSExchangeData::HasString() const { diff --git a/chrome/common/os_exchange_data.h b/chrome/common/os_exchange_data.h index 55ed6ad..735e366 100644 --- a/chrome/common/os_exchange_data.h +++ b/chrome/common/os_exchange_data.h @@ -56,8 +56,9 @@ class OSExchangeData : public IDataObject { // Adds the bytes of a file (CFSTR_FILECONTENTS and CFSTR_FILEDESCRIPTOR). void SetFileContents(const std::wstring& filename, const std::string& file_contents); - // Adds a snippet of Windows HTML (CF_HTML). - void SetCFHtml(const std::wstring& cf_html); + // Adds a snippet of HTML. |html| is just raw html but this sets both + // text/html and CF_HTML. + void SetHtml(const std::wstring& html, const GURL& base_url); // These functions retrieve data of the specified type. If data exists, the // functions return and the result is in the out parameter. If the data does @@ -70,7 +71,7 @@ class OSExchangeData : public IDataObject { bool GetPickledData(CLIPFORMAT format, Pickle* data) const; bool GetFileContents(std::wstring* filename, std::string* file_contents) const; - bool GetCFHtml(std::wstring* cf_html) const; + bool GetHtml(std::wstring* html, GURL* base_url) const; // Test whether or not data of certain types is present, without actually // returning anything. @@ -141,4 +142,3 @@ class OSExchangeData : public IDataObject { }; #endif // #ifndef CHROME_COMMON_OS_EXCHANGE_DATA_H__ - diff --git a/chrome/common/os_exchange_data_unittest.cc b/chrome/common/os_exchange_data_unittest.cc index f54cb72..427208f 100644 --- a/chrome/common/os_exchange_data_unittest.cc +++ b/chrome/common/os_exchange_data_unittest.cc @@ -5,6 +5,7 @@ #include <atlbase.h> #include <shlobj.h> +#include "base/clipboard_util.h" #include "base/pickle.h" #include "base/ref_counted.h" #include "base/scoped_handle.h" @@ -313,16 +314,33 @@ TEST(OSExchangeDataTest, FileContents) { TEST(OSExchangeDataTest, Html) { scoped_refptr<OSExchangeData> data(new OSExchangeData); - std::wstring html(L"Version:0.9\nStartHTML:71\nEndHTML:160\n" - L"StartFragment:130\nEndFragment:150\n<HTML>\n<BODY>\n" - L"<!--StartFragment-->\n<b>bold.</b> <i><b>This is bold italic.</b></i>\n" - L"<!--EndFragment-->\n</BODY>\n</HTML>"); - data->SetCFHtml(html); + GURL url("http://www.google.com/"); + std::wstring html( + L"<HTML>\n<BODY>\n" + L"<b>bold.</b> <i><b>This is bold italic.</b></i>\n" + L"</BODY>\n</HTML>"); + data->SetHtml(html, url); scoped_refptr<OSExchangeData> copy(new OSExchangeData(data.get())); std::wstring read_html; - EXPECT_TRUE(copy->GetCFHtml(&read_html)); + EXPECT_TRUE(copy->GetHtml(&read_html, &url)); EXPECT_EQ(html, read_html); + + // Check the CF_HTML too. + std::string expected_cf_html( + "Version:0.9\r\nStartHTML:0000000138\r\nEndHTML:0000000291\r\n" + "StartFragment:0000000176\r\nEndFragment:0000000253\r\n" + "SourceURL:http://www.google.com/\r\n<html>\r\n<body>\r\n" + "<!--StartFragment-->\r\n"); + expected_cf_html += WideToUTF8(html); + expected_cf_html.append("\r\n<!--EndFragment-->\r\n</body>\r\n</html>"); + + STGMEDIUM medium; + EXPECT_EQ(S_OK, data->GetData(ClipboardUtil::GetHtmlFormat(), &medium)); + ScopedHGlobal<char> glob(medium.hGlobal); + std::string output(glob.get(), glob.Size()); + EXPECT_EQ(expected_cf_html, output); + ReleaseStgMedium(&medium); } TEST(OSExchangeDataTest, SetURLWithMaxPath) { diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 7c6f2c1..d74091a 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -1662,8 +1662,8 @@ struct ParamTraits<WebDropData> { WriteParam(m, p.url_title); WriteParam(m, p.filenames); WriteParam(m, p.plain_text); - WriteParam(m, p.cf_html); WriteParam(m, p.text_html); + WriteParam(m, p.html_base_url); WriteParam(m, p.file_description_filename); WriteParam(m, p.file_contents); } @@ -1673,8 +1673,8 @@ struct ParamTraits<WebDropData> { ReadParam(m, iter, &p->url_title) && ReadParam(m, iter, &p->filenames) && ReadParam(m, iter, &p->plain_text) && - ReadParam(m, iter, &p->cf_html) && ReadParam(m, iter, &p->text_html) && + ReadParam(m, iter, &p->html_base_url) && ReadParam(m, iter, &p->file_description_filename) && ReadParam(m, iter, &p->file_contents); } |