summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-19 01:20:01 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-19 01:20:01 +0000
commit22cf8687fe6c4fc4dbb2b9b2ac41d7d45f656d83 (patch)
treedf838980effe3721bdc41b6acea356bf6352df8e /webkit
parent234ebdecf98582ca141b9066b1e5f4f74d3bdbff (diff)
downloadchromium_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 'webkit')
-rw-r--r--webkit/glue/clipboard_conversion.cc116
-rw-r--r--webkit/glue/webdropdata.cc7
-rw-r--r--webkit/glue/webdropdata.h11
-rw-r--r--webkit/port/platform/chromium/ChromiumDataObject.cpp1
-rw-r--r--webkit/port/platform/chromium/ChromiumDataObject.h1
-rw-r--r--webkit/port/platform/chromium/ClipboardChromium.cpp2
-rw-r--r--webkit/port/platform/chromium/DragDataChromium.cpp30
7 files changed, 30 insertions, 138 deletions
diff --git a/webkit/glue/clipboard_conversion.cc b/webkit/glue/clipboard_conversion.cc
index 0c690c0..7bf8c51 100644
--- a/webkit/glue/clipboard_conversion.cc
+++ b/webkit/glue/clipboard_conversion.cc
@@ -16,114 +16,6 @@
#include "webkit/glue/glue_util.h"
-namespace {
-
-// TODO(tc): CF_HTML logic should move into the browser process since it only
-// makes sense on Windows.
-#if defined(OS_WIN)
-void append(WTF::Vector<char>& vector, const WebCore::CString& string) {
- vector.append(string.data(), string.length());
-}
-// Documentation for the CF_HTML format is available at
-// http://msdn.microsoft.com/workshop/networking/clipboard/htmlclipboard.asp
-void markupToCF_HTML(const WebCore::String& markup,
- const WebCore::String& src_url,
- WTF::Vector<char>& result) {
- if (markup.isEmpty())
- return;
-
- #define MAX_DIGITS 10
- #define MAKE_NUMBER_FORMAT_1(digits) MAKE_NUMBER_FORMAT_2(digits)
- #define MAKE_NUMBER_FORMAT_2(digits) "%0" #digits "u"
- #define NUMBER_FORMAT MAKE_NUMBER_FORMAT_1(MAX_DIGITS)
-
- static const char* header = "Version:0.9\n"
- "StartHTML:" NUMBER_FORMAT "\n"
- "EndHTML:" NUMBER_FORMAT "\n"
- "StartFragment:" NUMBER_FORMAT "\n"
- "EndFragment:" NUMBER_FORMAT "\n";
- static const char* source_url_prefix = "SourceURL:";
-
- static const char* start_markup = "<HTML>\n<BODY>\n<!--StartFragment-->\n";
- static const char* end_markup = "\n<!--EndFragment-->\n</BODY>\n</HTML>";
-
- WebCore::CString source_url_utf8 = (src_url == WebCore::blankURL()) ?
- "" : src_url.utf8();
- WebCore::CString markup_utf8 = markup.utf8();
-
- // calculate offsets
- size_t start_html_offset = strlen(header) - strlen(NUMBER_FORMAT) * 4 +
- MAX_DIGITS * 4;
- if (source_url_utf8.length()) {
- start_html_offset += strlen(source_url_prefix) +
- source_url_utf8.length() + 1;
- }
- size_t start_fragment_offset = start_html_offset + strlen(start_markup);
- size_t end_fragment_offset = start_fragment_offset + markup_utf8.length();
- size_t end_html_offset = end_fragment_offset + strlen(end_markup);
-
- append(result, WebCore::String::format(header, start_html_offset,
- end_html_offset, start_fragment_offset, end_fragment_offset).utf8());
- if (source_url_utf8.length()) {
- append(result, source_url_prefix);
- append(result, source_url_utf8);
- result.append('\n');
- }
- append(result, start_markup);
- append(result, markup_utf8);
- append(result, end_markup);
-
- #undef MAX_DIGITS
- #undef MAKE_NUMBER_FORMAT_1
- #undef MAKE_NUMBER_FORMAT_2
- #undef NUMBER_FORMAT
-}
-#endif
-
-std::wstring HTMLToCFHTML(const WebCore::String& html,
- const WebCore::KURL& url) {
-#if defined(OS_WIN)
- Vector<char> cf_html_data;
- markupToCF_HTML(html, url, cf_html_data);
- WebCore::String cf_html_str(cf_html_data.data(), cf_html_data.size());
- return webkit_glue::StringToStdWString(cf_html_str);
-#else
- return std::wstring();
-#endif
-}
-
-WebCore::String CFHTMLToHTML(const std::wstring& cf_html_wstr) {
-#if defined(OS_WIN)
- WebCore::String cf_html = webkit_glue::StdWStringToString(cf_html_wstr);
- // Obtain baseURL if present.
- WebCore::String src_url_str("sourceURL:");
- WebCore::String src_url;
- unsigned int line_start = cf_html.find(src_url_str, 0, false);
- if (line_start != -1) {
- unsigned int src_end = cf_html.find("\n", line_start, false);
- unsigned int src_start = line_start + src_url_str.length();
- WebCore::String raw_src_url = cf_html.substring(src_start, src_end - src_start);
- replaceNBSPWithSpace(raw_src_url);
- src_url = raw_src_url.stripWhiteSpace();
- }
-
- // find the markup between "<!--StartFragment -->" and "<!--EndFragment
- // -->", accounting for browser quirks
- unsigned markup_start = cf_html.find("<html", 0, false);
- unsigned tag_start = cf_html.find("startfragment", markup_start, false);
- unsigned fragment_start = cf_html.find('>', tag_start) + 1;
- unsigned tag_end = cf_html.find("endfragment", fragment_start, false);
- unsigned fragment_end = cf_html.reverseFind('<', tag_end);
- WebCore::String markup = cf_html.substring(fragment_start,
- fragment_end - fragment_start).stripWhiteSpace();
- return markup;
-#else
- return WebCore::String();
-#endif
-}
-
-} // namespace
-
namespace webkit_glue {
WebDropData ChromiumDataObjectToWebDropData(
@@ -139,9 +31,8 @@ WebDropData ChromiumDataObjectToWebDropData(
drop_data.plain_text = StringToStdWString(data_object->plain_text);
- drop_data.cf_html = HTMLToCFHTML(data_object->text_html, data_object->url);
-
drop_data.text_html = StringToStdWString(data_object->text_html);
+ drop_data.html_base_url = KURLToGURL(data_object->html_base_url);
drop_data.file_description_filename = StringToStdWString(
data_object->file_content_filename);
@@ -167,10 +58,7 @@ PassRefPtr<WebCore::ChromiumDataObject> WebDropDataToChromiumDataObject(
data_object->plain_text = StdWStringToString(drop_data.plain_text);
data_object->text_html = StdWStringToString(drop_data.text_html);
- if (data_object->text_html.isEmpty()) {
- // Use CF_HTML only if there's no text/html data.
- data_object->text_html = CFHTMLToHTML(drop_data.cf_html);
- }
+ data_object->html_base_url = GURLToKURL(drop_data.html_base_url);
data_object->file_content_filename = StdWStringToString(
drop_data.file_description_filename);
diff --git a/webkit/glue/webdropdata.cc b/webkit/glue/webdropdata.cc
index 28ed52d..cd96169 100644
--- a/webkit/glue/webdropdata.cc
+++ b/webkit/glue/webdropdata.cc
@@ -20,8 +20,11 @@ void WebDropData::PopulateWebDropData(IDataObject* data_object,
}
ClipboardUtil::GetFilenames(data_object, &drop_data->filenames);
ClipboardUtil::GetPlainText(data_object, &drop_data->plain_text);
- ClipboardUtil::GetCFHtml(data_object, &drop_data->cf_html);
- ClipboardUtil::GetTextHtml(data_object, &drop_data->text_html);
+ std::string base_url;
+ ClipboardUtil::GetHtml(data_object, &drop_data->text_html, &base_url);
+ if (!base_url.empty()) {
+ drop_data->html_base_url = GURL(base_url);
+ }
ClipboardUtil::GetFileContents(data_object,
&drop_data->file_description_filename, &drop_data->file_contents);
}
diff --git a/webkit/glue/webdropdata.h b/webkit/glue/webdropdata.h
index 38d67b4..e6d51f4 100644
--- a/webkit/glue/webdropdata.h
+++ b/webkit/glue/webdropdata.h
@@ -26,14 +26,11 @@ struct WebDropData {
// User is dragging plain text into the webview.
std::wstring plain_text;
- // User is dragging MS HTML into the webview (e.g., out of IE).
- // TODO(tc): We should remove this from webdropdata because not all platforms
- // have cf_html. On the browser side, we should do the necessary conversions
- // so we still support cf_html.
- std::wstring cf_html;
-
- // User is dragging text/html into the webview (e.g., out of Firefox).
+ // User is dragging text/html into the webview (e.g., out of Firefox).
+ // |html_base_url| is the URL that the html fragment is taken from (used to
+ // resolve relative links). It's ok for |html_base_url| to be empty.
std::wstring text_html;
+ GURL html_base_url;
// User is dragging data from the webview (e.g., an image).
std::wstring file_description_filename;
diff --git a/webkit/port/platform/chromium/ChromiumDataObject.cpp b/webkit/port/platform/chromium/ChromiumDataObject.cpp
index ddf9cd9..54da838 100644
--- a/webkit/port/platform/chromium/ChromiumDataObject.cpp
+++ b/webkit/port/platform/chromium/ChromiumDataObject.cpp
@@ -39,6 +39,7 @@ void ChromiumDataObject::clear()
filenames.clear();
plain_text = "";
text_html = "";
+ html_base_url = KURL();
file_content_filename = "";
if (file_content)
file_content->clear();
diff --git a/webkit/port/platform/chromium/ChromiumDataObject.h b/webkit/port/platform/chromium/ChromiumDataObject.h
index f6178f3..bdbb62c 100644
--- a/webkit/port/platform/chromium/ChromiumDataObject.h
+++ b/webkit/port/platform/chromium/ChromiumDataObject.h
@@ -57,6 +57,7 @@ namespace WebCore {
String plain_text;
String text_html;
+ KURL html_base_url;
String file_content_filename;
RefPtr<SharedBuffer> file_content;
diff --git a/webkit/port/platform/chromium/ClipboardChromium.cpp b/webkit/port/platform/chromium/ClipboardChromium.cpp
index 663a341..5087cdf 100644
--- a/webkit/port/platform/chromium/ClipboardChromium.cpp
+++ b/webkit/port/platform/chromium/ClipboardChromium.cpp
@@ -331,6 +331,7 @@ void ClipboardChromium::writeURL(const KURL& url, const String& title, Frame*)
// The URL can also be used as an HTML fragment.
m_dataObject->text_html = urlToMarkup(url, title);
+ m_dataObject->html_base_url = url;
}
void ClipboardChromium::writeRange(Range* selectedRange, Frame* frame)
@@ -341,6 +342,7 @@ void ClipboardChromium::writeRange(Range* selectedRange, Frame* frame)
m_dataObject->text_html = createMarkup(selectedRange, 0,
AnnotateForInterchange);
+ m_dataObject->html_base_url = frame->document()->url();
String str = frame->selectedText();
#if PLATFORM(WIN_OS)
diff --git a/webkit/port/platform/chromium/DragDataChromium.cpp b/webkit/port/platform/chromium/DragDataChromium.cpp
index 3507739..d615559 100644
--- a/webkit/port/platform/chromium/DragDataChromium.cpp
+++ b/webkit/port/platform/chromium/DragDataChromium.cpp
@@ -126,21 +126,21 @@ PassRefPtr<DocumentFragment> DragData::asFragment(Document* doc) const
* * PICT
*/
- // TODO(tc): Disabled because containsFilenames is hardcoded to return
- // false. We need to implement fragmentFromFilenames when this is
- // re-enabled in Apple's win port.
- //if (containsFilenames())
- // if (PassRefPtr<DocumentFragment> fragment = fragmentFromFilenames(doc, m_platformDragData))
- // return fragment;
-
- if (!m_platformDragData->text_html.isEmpty()) {
- String url;
- RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(doc,
- m_platformDragData->text_html, url);
- return fragment;
- }
-
- return 0;
+ if (containsFiles()) {
+ // TODO(tc): Implement this. Should be pretty simple to make some HTML
+ // and call createFragmentFromMarkup.
+ //if (RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(doc,
+ // ?, KURL()))
+ // return fragment;
+ }
+
+ if (!m_platformDragData->text_html.isEmpty()) {
+ RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(doc,
+ m_platformDragData->text_html, m_platformDragData->html_base_url);
+ return fragment.release();
+ }
+
+ return 0;
}
Color DragData::asColor() const