summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/chromium/ClipboardChromium.cpp
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-04-27 16:31:00 +0100
committerSteve Block <steveblock@google.com>2010-05-11 14:42:12 +0100
commitdcc8cf2e65d1aa555cce12431a16547e66b469ee (patch)
tree92a8d65cd5383bca9749f5327fb5e440563926e6 /WebCore/platform/chromium/ClipboardChromium.cpp
parentccac38a6b48843126402088a309597e682f40fe6 (diff)
downloadexternal_webkit-dcc8cf2e65d1aa555cce12431a16547e66b469ee.zip
external_webkit-dcc8cf2e65d1aa555cce12431a16547e66b469ee.tar.gz
external_webkit-dcc8cf2e65d1aa555cce12431a16547e66b469ee.tar.bz2
Merge webkit.org at r58033 : Initial merge by git
Change-Id: If006c38561af287c50cd578d251629b51e4d8cd1
Diffstat (limited to 'WebCore/platform/chromium/ClipboardChromium.cpp')
-rw-r--r--WebCore/platform/chromium/ClipboardChromium.cpp231
1 files changed, 194 insertions, 37 deletions
diff --git a/WebCore/platform/chromium/ClipboardChromium.cpp b/WebCore/platform/chromium/ClipboardChromium.cpp
index a1f60a6..21d7edf 100644
--- a/WebCore/platform/chromium/ClipboardChromium.cpp
+++ b/WebCore/platform/chromium/ClipboardChromium.cpp
@@ -36,15 +36,16 @@
#include "FileList.h"
#include "Frame.h"
#include "HTMLNames.h"
-#include "NamedAttrMap.h"
+#include "Image.h"
#include "MIMETypeRegistry.h"
-#include "markup.h"
+#include "NamedAttrMap.h"
#include "NamedNodeMap.h"
#include "Pasteboard.h"
#include "PlatformString.h"
#include "Range.h"
#include "RenderImage.h"
#include "StringBuilder.h"
+#include "markup.h"
namespace WebCore {
@@ -53,21 +54,40 @@ using namespace HTMLNames;
// We provide the IE clipboard types (URL and Text), and the clipboard types specified in the WHATWG Web Applications 1.0 draft
// see http://www.whatwg.org/specs/web-apps/current-work/ Section 6.3.5.3
-enum ClipboardDataType { ClipboardDataTypeNone, ClipboardDataTypeURL, ClipboardDataTypeText, ClipboardDataTypeDownloadURL };
+enum ClipboardDataType {
+ ClipboardDataTypeNone,
+
+ ClipboardDataTypeURL,
+ ClipboardDataTypeURIList,
+ ClipboardDataTypeDownloadURL,
+ ClipboardDataTypePlainText,
+ ClipboardDataTypeHTML,
+
+ ClipboardDataTypeOther,
+};
+
+// Per RFC 2483, the line separator for "text/..." MIME types is CR-LF.
+static char const* const textMIMETypeLineSeparator = "\r\n";
static ClipboardDataType clipboardTypeFromMIMEType(const String& type)
{
String cleanType = type.stripWhiteSpace().lower();
+ if (cleanType.isEmpty())
+ return ClipboardDataTypeNone;
- // two special cases for IE compatibility
+ // Includes two special cases for IE compatibility.
if (cleanType == "text" || cleanType == "text/plain" || cleanType.startsWith("text/plain;"))
- return ClipboardDataTypeText;
- if (cleanType == "url" || cleanType == "text/uri-list")
+ return ClipboardDataTypePlainText;
+ if (cleanType == "url")
return ClipboardDataTypeURL;
+ if (cleanType == "text/uri-list")
+ return ClipboardDataTypeURIList;
if (cleanType == "downloadurl")
return ClipboardDataTypeDownloadURL;
+ if (cleanType == "text/html")
+ return ClipboardDataTypeHTML;
- return ClipboardDataTypeNone;
+ return ClipboardDataTypeOther;
}
ClipboardChromium::ClipboardChromium(bool isForDragging,
@@ -90,14 +110,37 @@ void ClipboardChromium::clearData(const String& type)
return;
ClipboardDataType dataType = clipboardTypeFromMIMEType(type);
+ switch (dataType) {
+ case ClipboardDataTypeNone:
+ // If called with no arguments, everything except the file list must be cleared.
+ // (See HTML5 spec, "The DragEvent and DataTransfer interfaces")
+ m_dataObject->clearAllExceptFiles();
+ return;
- if (dataType == ClipboardDataTypeURL) {
- m_dataObject->url = KURL();
- m_dataObject->urlTitle = "";
- }
+ case ClipboardDataTypeURL:
+ case ClipboardDataTypeURIList:
+ m_dataObject->clearURL();
+ return;
- if (dataType == ClipboardDataTypeText)
+ case ClipboardDataTypeDownloadURL:
+ m_dataObject->downloadMetadata = "";
+ return;
+
+ case ClipboardDataTypePlainText:
m_dataObject->plainText = "";
+ return;
+
+ case ClipboardDataTypeHTML:
+ m_dataObject->textHtml = "";
+ m_dataObject->htmlBaseUrl = KURL();
+ return;
+
+ case ClipboardDataTypeOther:
+ // Not yet implemented, see https://bugs.webkit.org/show_bug.cgi?id=34410
+ return;
+ }
+
+ ASSERT_NOT_REACHED();
}
void ClipboardChromium::clearAllData()
@@ -115,8 +158,52 @@ String ClipboardChromium::getData(const String& type, bool& success) const
return String();
ClipboardDataType dataType = clipboardTypeFromMIMEType(type);
- String text;
- if (dataType == ClipboardDataTypeText) {
+ switch (dataType) {
+ case ClipboardDataTypeNone:
+ return String();
+
+ case ClipboardDataTypeURIList:
+ {
+ String text;
+ for (size_t i = 0; i < m_dataObject->uriList.size(); ++i) {
+ const String& uri = m_dataObject->uriList[i];
+ ASSERT(!uri.isEmpty());
+ if (!text.isEmpty())
+ text.append(textMIMETypeLineSeparator);
+ // URIs have already been canonicalized, so copy everything verbatim.
+ text.append(uri);
+ }
+ // Also create file:// URLs out of the entries in the file list.
+ for (size_t i = 0; i < m_dataObject->filenames.size(); ++i) {
+ String fileURL = ChromiumBridge::filePathToURL(m_dataObject->filenames[i]);
+ ASSERT(!fileURL.isEmpty());
+ if (!text.isEmpty())
+ text.append(textMIMETypeLineSeparator);
+ text.append(fileURL);
+ }
+ success = !text.isEmpty();
+ return text;
+ }
+
+ case ClipboardDataTypeURL:
+ // In case of a previous setData('text/uri-list'), setData() has already
+ // prepared the 'url' member, so we can just retrieve it here.
+ if (!m_dataObject->url.isEmpty()) {
+ success = true;
+ return m_dataObject->url.string();
+ }
+ // Otherwise check if we have a file that we could convert to a file:// URL.
+ if (!m_dataObject->filenames.isEmpty()) {
+ success = true;
+ return ChromiumBridge::filePathToURL(m_dataObject->filenames[0]);
+ }
+ return String();
+
+ case ClipboardDataTypeDownloadURL:
+ success = !m_dataObject->downloadMetadata.isEmpty();
+ return m_dataObject->downloadMetadata;
+
+ case ClipboardDataTypePlainText:
if (!isForDragging()) {
// If this isn't for a drag, it's for a cut/paste event handler.
// In this case, we need to check the clipboard.
@@ -124,22 +211,39 @@ String ClipboardChromium::getData(const String& type, bool& success) const
Pasteboard::generalPasteboard()->isSelectionMode() ?
PasteboardPrivate::SelectionBuffer :
PasteboardPrivate::StandardBuffer;
- text = ChromiumBridge::clipboardReadPlainText(buffer);
+ String text = ChromiumBridge::clipboardReadPlainText(buffer);
success = !text.isEmpty();
- } else if (!m_dataObject->plainText.isEmpty()) {
- success = true;
- text = m_dataObject->plainText;
+ return text;
}
- } else if (dataType == ClipboardDataTypeURL) {
- // FIXME: Handle the cut/paste event. This requires adding a new IPC
- // message to get the URL from the clipboard directly.
- if (!m_dataObject->url.isEmpty()) {
- success = true;
- text = m_dataObject->url.string();
+ // Otherwise return whatever is stored in plainText.
+ success = !m_dataObject->plainText.isEmpty();
+ return m_dataObject->plainText;
+
+ case ClipboardDataTypeHTML:
+ if (!isForDragging()) {
+ // If this isn't for a drag, it's for a cut/paste event handler.
+ // In this case, we need to check the clipboard.
+ PasteboardPrivate::ClipboardBuffer buffer =
+ Pasteboard::generalPasteboard()->isSelectionMode() ?
+ PasteboardPrivate::SelectionBuffer :
+ PasteboardPrivate::StandardBuffer;
+ String htmlText;
+ KURL sourceURL;
+ ChromiumBridge::clipboardReadHTML(buffer, &htmlText, &sourceURL);
+ success = !htmlText.isEmpty();
+ return htmlText;
}
+ // Otherwise return whatever is stored in textHtml.
+ success = !m_dataObject->textHtml.isEmpty();
+ return m_dataObject->textHtml;
+
+ case ClipboardDataTypeOther:
+ // not yet implemented, see https://bugs.webkit.org/show_bug.cgi?id=34410
+ return String();
}
- return text;
+ ASSERT_NOT_REACHED();
+ return String();
}
bool ClipboardChromium::setData(const String& type, const String& data)
@@ -147,23 +251,68 @@ bool ClipboardChromium::setData(const String& type, const String& data)
if (policy() != ClipboardWritable)
return false;
- ClipboardDataType winType = clipboardTypeFromMIMEType(type);
+ ClipboardDataType dataType = clipboardTypeFromMIMEType(type);
+ switch (dataType) {
+ case ClipboardDataTypeNone:
+ return false;
- if (winType == ClipboardDataTypeURL) {
- m_dataObject->url = KURL(ParsedURLString, data);
- return m_dataObject->url.isValid();
- }
+ case ClipboardDataTypeURL:
+ // For setData(), "URL" must be treated as "text/uri-list".
+ // (See HTML5 spec, "The DragEvent and DataTransfer interfaces")
+ case ClipboardDataTypeURIList:
+ m_dataObject->url = KURL();
+ // Line separator is \r\n per RFC 2483 - however, for compatibility reasons
+ // we also allow just \n here.
+ data.split('\n', m_dataObject->uriList);
+ // Strip white space on all lines, including trailing \r from above split.
+ // If this leaves a line empty, remove it completely.
+ //
+ // Also, copy the first valid URL into the 'url' member as well.
+ // In case no entry is a valid URL (i.e., remarks only), then we leave 'url' empty.
+ // I.e., in that case subsequent calls to getData("URL") will get an empty string.
+ // This is in line with the HTML5 spec (see "The DragEvent and DataTransfer interfaces").
+ for (size_t i = 0; i < m_dataObject->uriList.size(); /**/) {
+ String& line = m_dataObject->uriList[i];
+ line = line.stripWhiteSpace();
+ if (line.isEmpty()) {
+ m_dataObject->uriList.remove(i);
+ continue;
+ }
+ ++i;
+ // Only copy the first valid URL.
+ if (m_dataObject->url.isValid())
+ continue;
+ // Skip remarks.
+ if (line[0] == '#')
+ continue;
+ KURL url = KURL(ParsedURLString, line);
+ if (url.isValid())
+ m_dataObject->url = url;
+ }
+ if (m_dataObject->uriList.isEmpty()) {
+ ASSERT(m_dataObject->url.isEmpty());
+ return data.isEmpty();
+ }
+ return true;
+
+ case ClipboardDataTypeDownloadURL:
+ m_dataObject->downloadMetadata = data;
+ return true;
- if (winType == ClipboardDataTypeText) {
+ case ClipboardDataTypePlainText:
m_dataObject->plainText = data;
return true;
- }
-
- if (winType == ClipboardDataTypeDownloadURL) {
- m_dataObject->downloadMetadata = data;
+
+ case ClipboardDataTypeHTML:
+ m_dataObject->textHtml = data;
return true;
- }
+ case ClipboardDataTypeOther:
+ // Not yet implemented, see https://bugs.webkit.org/show_bug.cgi?id=34410
+ return false;
+ }
+
+ ASSERT_NOT_REACHED();
return false;
}
@@ -177,11 +326,19 @@ HashSet<String> ClipboardChromium::types() const
if (!m_dataObject)
return results;
- if (!m_dataObject->filenames.isEmpty())
+ if (!m_dataObject->filenames.isEmpty()) {
+ results.add("text/uri-list");
results.add("Files");
+ }
if (m_dataObject->url.isValid()) {
+ ASSERT(!m_dataObject->uriList.isEmpty());
results.add("URL");
+ }
+
+ if (!m_dataObject->uriList.isEmpty()) {
+ // Note that even if the URI list is not empty, it may not actually
+ // contain a valid URL, so we can't return "URL" here.
results.add("text/uri-list");
}