summaryrefslogtreecommitdiffstats
path: root/webkit/port
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-07 23:25:03 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-07 23:25:03 +0000
commit0bcde72cee05bb587e7069a490081834e6ceac1c (patch)
tree7b5e59f055a1f038ceb7e891a054c26acc6d1d7e /webkit/port
parent4f8b87a4c6d06ebad053160a61fc90492afc8439 (diff)
downloadchromium_src-0bcde72cee05bb587e7069a490081834e6ceac1c.zip
chromium_src-0bcde72cee05bb587e7069a490081834e6ceac1c.tar.gz
chromium_src-0bcde72cee05bb587e7069a490081834e6ceac1c.tar.bz2
Remove windows-isms from drag & drop. This
makes it more portable, fixes some bugs, and removes glue from port. Review URL: http://codereview.chromium.org/9801 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5032 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/port')
-rw-r--r--webkit/port/page/chromium/EventHandlerChromium.cpp17
-rw-r--r--webkit/port/platform/chromium/ChromiumDataObject.cpp52
-rw-r--r--webkit/port/platform/chromium/ChromiumDataObject.h69
-rw-r--r--webkit/port/platform/chromium/ClipboardChromium.cpp399
-rw-r--r--webkit/port/platform/chromium/ClipboardChromium.h (renamed from webkit/port/platform/win/ClipboardWin.h)45
-rw-r--r--webkit/port/platform/chromium/DragDataChromium.cpp75
-rw-r--r--webkit/port/platform/chromium/DragDataRef.h4
-rw-r--r--webkit/port/platform/chromium/EditorChromium.cpp (renamed from webkit/port/platform/chromium/EditorLinux.cpp)8
-rw-r--r--webkit/port/platform/win/ClipboardUtilitiesWin.h5
-rw-r--r--webkit/port/platform/win/ClipboardWin.cpp808
-rw-r--r--webkit/port/platform/win/EditorWin.cpp52
-rw-r--r--webkit/port/platform/win/WCDataObject.cpp382
-rw-r--r--webkit/port/platform/win/WCDataObject.h74
13 files changed, 575 insertions, 1415 deletions
diff --git a/webkit/port/page/chromium/EventHandlerChromium.cpp b/webkit/port/page/chromium/EventHandlerChromium.cpp
index d7082e5..2ac7d07 100644
--- a/webkit/port/page/chromium/EventHandlerChromium.cpp
+++ b/webkit/port/page/chromium/EventHandlerChromium.cpp
@@ -26,7 +26,8 @@
#include "config.h"
#include "EventHandler.h"
-#include "Clipboard.h"
+#include "ChromiumDataObject.h"
+#include "ClipboardChromium.h"
#include "Cursor.h"
#include "FloatPoint.h"
#include "FocusController.h"
@@ -42,11 +43,6 @@
#include "SelectionController.h"
#include "NotImplemented.h"
-#if PLATFORM(WIN_OS)
-#include "ClipboardWin.h"
-#include "WCDataObject.h"
-#endif
-
namespace WebCore {
unsigned EventHandler::s_accessKeyModifiers = PlatformKeyboardEvent::AltKey;
@@ -132,13 +128,8 @@ bool EventHandler::eventActivatedView(const PlatformMouseEvent& event) const
PassRefPtr<Clipboard> EventHandler::createDraggingClipboard() const
{
-#if PLATFORM(WIN_OS)
- COMPtr<WCDataObject> dataObject;
- WCDataObject::createInstance(&dataObject);
- return ClipboardWin::create(true, dataObject.get(), ClipboardWritable);
-#else
- return PassRefPtr<Clipboard>(0);
-#endif
+ RefPtr<ChromiumDataObject> dataObject = ChromiumDataObject::create();
+ return ClipboardChromium::create(true, dataObject.get(), ClipboardWritable);
}
void EventHandler::focusDocumentView()
diff --git a/webkit/port/platform/chromium/ChromiumDataObject.cpp b/webkit/port/platform/chromium/ChromiumDataObject.cpp
new file mode 100644
index 0000000..ddf9cd9
--- /dev/null
+++ b/webkit/port/platform/chromium/ChromiumDataObject.cpp
@@ -0,0 +1,52 @@
+// Copyright (c) 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "config.h"
+#include "ChromiumDataObject.h"
+
+using namespace WebCore;
+
+void ChromiumDataObject::clear()
+{
+ url = KURL();
+ url_title = "";
+ filenames.clear();
+ plain_text = "";
+ text_html = "";
+ file_content_filename = "";
+ if (file_content)
+ file_content->clear();
+}
+
+bool ChromiumDataObject::hasData()
+{
+ return !url.isEmpty() || !filenames.isEmpty() ||
+ !plain_text.isEmpty() || !text_html.isEmpty() ||
+ file_content;
+}
diff --git a/webkit/port/platform/chromium/ChromiumDataObject.h b/webkit/port/platform/chromium/ChromiumDataObject.h
new file mode 100644
index 0000000..f6178f3
--- /dev/null
+++ b/webkit/port/platform/chromium/ChromiumDataObject.h
@@ -0,0 +1,69 @@
+// Copyright (c) 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// A data object for holding data that would be in a clipboard or moved
+// during a drag&drop operation. This is the data that webkit is aware
+// of and is not specific to a platform.
+
+#ifndef ChromiumDataObject_h
+#define ChromiumDataObject_h
+
+#include "KURL.h"
+#include "PlatformString.h"
+#include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+ class ChromiumDataObject : public RefCounted<ChromiumDataObject> {
+ public:
+ static PassRefPtr<ChromiumDataObject> create() {
+ return adoptRef(new ChromiumDataObject);
+ }
+
+ void clear();
+ bool hasData();
+
+ KURL url;
+ String url_title;
+
+ Vector<String> filenames;
+
+ String plain_text;
+
+ String text_html;
+
+ String file_content_filename;
+ RefPtr<SharedBuffer> file_content;
+ private:
+ ChromiumDataObject() {}
+
+ };
+}
+
+#endif // ChromiumDataObject_h
diff --git a/webkit/port/platform/chromium/ClipboardChromium.cpp b/webkit/port/platform/chromium/ClipboardChromium.cpp
new file mode 100644
index 0000000..c080eea
--- /dev/null
+++ b/webkit/port/platform/chromium/ClipboardChromium.cpp
@@ -0,0 +1,399 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#pragma warning(push, 0)
+#include "CachedImage.h"
+#include "ChromiumDataObject.h"
+#include "ClipboardChromium.h"
+#include "CSSHelper.h"
+#include "CString.h"
+#include "Document.h"
+#include "DragData.h"
+#include "Editor.h"
+#include "Element.h"
+#include "EventHandler.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "FrameView.h"
+#include "HTMLNames.h"
+#include "Image.h"
+#include "MIMETypeRegistry.h"
+#include "markup.h"
+#include "Page.h"
+#include "Pasteboard.h"
+#include "PlatformString.h"
+#include "Range.h"
+#include "RenderImage.h"
+#include "StringBuilder.h"
+#include "StringHash.h"
+#include <wtf/RefPtr.h>
+#pragma warning(pop)
+
+// TODO(tc): Once the clipboard methods get moved to the bridge,
+// we can get rid of our dependency on webkit_glue and base.
+#undef LOG
+#include "base/string_util.h"
+#include "webkit/glue/glue_util.h"
+#include "webkit/glue/webkit_glue.h"
+
+namespace WebCore {
+
+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 };
+
+static ClipboardDataType clipboardTypeFromMIMEType(const String& type)
+{
+ String qType = type.stripWhiteSpace().lower();
+
+ // two special cases for IE compatibility
+ if (qType == "text" || qType == "text/plain" || qType.startsWith("text/plain;"))
+ return ClipboardDataTypeText;
+ if (qType == "url" || qType == "text/uri-list")
+ return ClipboardDataTypeURL;
+
+ return ClipboardDataTypeNone;
+}
+
+#if PLATFORM(WIN_OS)
+static void replaceNewlinesWithWindowsStyleNewlines(String& str)
+{
+ static const UChar Newline = '\n';
+ static const char* const WindowsNewline("\r\n");
+ str.replace(Newline, WindowsNewline);
+}
+#endif
+
+static void replaceNBSPWithSpace(String& str)
+{
+ static const UChar NonBreakingSpaceCharacter = 0xA0;
+ static const UChar SpaceCharacter = ' ';
+ str.replace(NonBreakingSpaceCharacter, SpaceCharacter);
+}
+
+
+ClipboardChromium::ClipboardChromium(bool isForDragging,
+ ChromiumDataObject* dataObject,
+ ClipboardAccessPolicy policy)
+ : Clipboard(policy, isForDragging)
+ , m_dataObject(dataObject)
+{
+}
+
+PassRefPtr<ClipboardChromium> ClipboardChromium::create(bool isForDragging,
+ ChromiumDataObject* dataObject, ClipboardAccessPolicy policy)
+{
+ return adoptRef(new ClipboardChromium(isForDragging, dataObject, policy));
+}
+
+void ClipboardChromium::clearData(const String& type)
+{
+ if (policy() != ClipboardWritable || !m_dataObject)
+ return;
+
+ ClipboardDataType dataType = clipboardTypeFromMIMEType(type);
+
+ if (dataType == ClipboardDataTypeURL) {
+ m_dataObject->url = KURL();
+ m_dataObject->url_title = "";
+ }
+ if (dataType == ClipboardDataTypeText) {
+ m_dataObject->plain_text = "";
+ }
+}
+
+void ClipboardChromium::clearAllData()
+{
+ if (policy() != ClipboardWritable)
+ return;
+
+ m_dataObject->clear();
+}
+
+String ClipboardChromium::getData(const String& type, bool& success) const
+{
+ success = false;
+ if (policy() != ClipboardReadable || !m_dataObject) {
+ return "";
+ }
+
+ ClipboardDataType dataType = clipboardTypeFromMIMEType(type);
+ if (dataType == ClipboardDataTypeText) {
+ String text;
+ if (!isForDragging()) {
+#if PLATFORM(WIN_OS)
+ // If this isn't for a drag, it's for a cut/paste event handler.
+ // In this case, we need to use our glue methods to access the
+ // clipboard contents.
+ std::wstring wideStr;
+ // TODO(tc): Once the clipboard methods get moved to the bridge,
+ // we can get rid of our dependency on webkit_glue.
+ webkit_glue::ClipboardReadText(&wideStr);
+ if (wideStr.empty()) {
+ std::string asciiText;
+ webkit_glue::ClipboardReadAsciiText(&asciiText);
+ wideStr = ASCIIToWide(asciiText);
+ }
+ success = !wideStr.empty();
+ text = webkit_glue::StdWStringToString(wideStr);
+#endif
+ } else if (!m_dataObject->plain_text.isEmpty()) {
+ success = true;
+ text = m_dataObject->plain_text;
+ }
+ return text;
+ } else if (dataType == ClipboardDataTypeURL) {
+ if (!m_dataObject->url.isEmpty()) {
+ success = true;
+ return m_dataObject->url.string();
+ }
+ }
+
+ return "";
+}
+
+bool ClipboardChromium::setData(const String& type, const String& data)
+{
+ if (policy() != ClipboardWritable)
+ return false;
+
+ ClipboardDataType winType = clipboardTypeFromMIMEType(type);
+
+ if (winType == ClipboardDataTypeURL) {
+ m_dataObject->url = KURL(data);
+ return m_dataObject->url.isValid();
+ }
+
+ if (winType == ClipboardDataTypeText) {
+ m_dataObject->plain_text = data;
+ return true;
+ }
+ return false;
+}
+
+// extensions beyond IE's API
+HashSet<String> ClipboardChromium::types() const
+{
+ HashSet<String> results;
+ if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
+ return results;
+
+ if (!m_dataObject)
+ return results;
+
+ if (m_dataObject->url.isValid()) {
+ results.add("URL");
+ results.add("text/uri-list");
+ }
+
+ if (!m_dataObject->plain_text.isEmpty()) {
+ results.add("Text");
+ results.add("text/plain");
+ }
+
+ return results;
+}
+
+void ClipboardChromium::setDragImage(CachedImage* image, Node *node, const IntPoint &loc)
+{
+ if (policy() != ClipboardImageWritable && policy() != ClipboardWritable)
+ return;
+
+ if (m_dragImage)
+ m_dragImage->removeClient(this);
+ m_dragImage = image;
+ if (m_dragImage)
+ m_dragImage->addClient(this);
+
+ m_dragLoc = loc;
+ m_dragImageElement = node;
+}
+
+void ClipboardChromium::setDragImage(CachedImage* img, const IntPoint &loc)
+{
+ setDragImage(img, 0, loc);
+}
+
+void ClipboardChromium::setDragImageElement(Node *node, const IntPoint &loc)
+{
+ setDragImage(0, node, loc);
+}
+
+DragImageRef ClipboardChromium::createDragImage(IntPoint& loc) const
+{
+ DragImageRef result = 0;
+ if (m_dragImage) {
+ result = createDragImageFromImage(m_dragImage->image());
+ loc = m_dragLoc;
+ }
+ return result;
+}
+
+static String imageToMarkup(const String& url, Element* element)
+{
+ StringBuilder markup;
+ markup.append("<img src=\"");
+ markup.append(url);
+ markup.append("\"");
+ // Copy over attributes. If we are dragging an image, we expect things like
+ // the id to be copied as well.
+ NamedAttrMap* attrs = element->attributes();
+ unsigned int length = attrs->length();
+ for (unsigned int i = 0; i < length; ++i) {
+ Attribute* attr = attrs->attributeItem(i);
+ if (attr->localName() == "src")
+ continue;
+ markup.append(" ");
+ markup.append(attr->localName());
+ markup.append("=\"");
+ String escapedAttr = attr->value();
+ escapedAttr.replace("\"", "&quot;");
+ markup.append(escapedAttr);
+ markup.append("\"");
+ }
+
+ markup.append("/>");
+ return markup.toString();
+}
+
+static CachedImage* getCachedImage(Element* element)
+{
+ // Attempt to pull CachedImage from element
+ ASSERT(element);
+ RenderObject* renderer = element->renderer();
+ if (!renderer || !renderer->isImage())
+ return 0;
+
+ RenderImage* image = static_cast<RenderImage*>(renderer);
+ if (image->cachedImage() && !image->cachedImage()->errorOccurred())
+ return image->cachedImage();
+
+ return 0;
+}
+
+static void writeImageToDataObject(ChromiumDataObject* dataObject, Element* element,
+ const KURL& url)
+{
+ // Shove image data into a DataObject for use as a file
+ CachedImage* cachedImage = getCachedImage(element);
+ if (!cachedImage || !cachedImage->image() || !cachedImage->isLoaded())
+ return;
+
+ SharedBuffer* imageBuffer = cachedImage->image()->data();
+ if (!imageBuffer || !imageBuffer->size())
+ return;
+
+ dataObject->file_content = imageBuffer;
+
+ // Determine the filename for the file contents of the image. We try to
+ // use the alt tag if one exists, otherwise we fall back on the suggested
+ // filename in the http header, and finally we resort to using the filename
+ // in the URL.
+ String extension(".");
+ extension += WebCore::MIMETypeRegistry::getPreferredExtensionForMIMEType(
+ cachedImage->response().mimeType());
+ String title = element->getAttribute(altAttr);
+ if (title.isEmpty()) {
+ title = cachedImage->response().suggestedFilename();
+ if (title.isEmpty()) {
+ // TODO(tc): Get the filename from the URL.
+ }
+ }
+ dataObject->file_content_filename = title + extension;
+}
+
+void ClipboardChromium::declareAndWriteDragImage(Element* element, const KURL& url, const String& title, Frame* frame)
+{
+ if (!m_dataObject)
+ return;
+
+ m_dataObject->url = url;
+ m_dataObject->url_title = title;
+
+ // Write the bytes in the image to the file format.
+ writeImageToDataObject(m_dataObject.get(), element, url);
+
+ AtomicString imageURL = element->getAttribute(srcAttr);
+ if (imageURL.isEmpty())
+ return;
+
+ String fullURL = frame->document()->completeURL(parseURL(imageURL));
+ if (fullURL.isEmpty())
+ return;
+
+ // Put img tag on the clipboard referencing the image
+ m_dataObject->text_html = imageToMarkup(fullURL, element);
+}
+
+void ClipboardChromium::writeURL(const KURL& url, const String& title, Frame*)
+{
+ if (!m_dataObject)
+ return;
+ m_dataObject->url = url;
+ m_dataObject->url_title = title;
+
+ // The URL can also be used as plain text.
+ m_dataObject->plain_text = url.string();
+
+ // The URL can also be used as an HTML fragment.
+ String markup("<a href=\"");
+ markup.append(url.string());
+ markup.append("\">");
+ markup.append(title);
+ markup.append("</a>");
+ m_dataObject->text_html = markup;
+}
+
+void ClipboardChromium::writeRange(Range* selectedRange, Frame* frame)
+{
+ ASSERT(selectedRange);
+ if (!m_dataObject)
+ return;
+
+ m_dataObject->text_html = createMarkup(selectedRange, 0,
+ AnnotateForInterchange);
+
+ String str = frame->selectedText();
+#if PLATFORM(WIN_OS)
+ replaceNewlinesWithWindowsStyleNewlines(str);
+#endif
+ replaceNBSPWithSpace(str);
+ m_dataObject->plain_text = str;
+}
+
+bool ClipboardChromium::hasData()
+{
+ if (!m_dataObject)
+ return false;
+
+ return m_dataObject->hasData();
+}
+
+} // namespace WebCore
diff --git a/webkit/port/platform/win/ClipboardWin.h b/webkit/port/platform/chromium/ClipboardChromium.h
index a52c242..9585988 100644
--- a/webkit/port/platform/win/ClipboardWin.h
+++ b/webkit/port/platform/chromium/ClipboardChromium.h
@@ -20,64 +20,61 @@
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef ClipboardWin_h
-#define ClipboardWin_h
+#ifndef ClipboardChromium_h
+#define ClipboardChromium_h
#include "Clipboard.h"
#include "CachedResourceClient.h"
-#include "IntPoint.h"
-#include "COMPtr.h"
-
-struct IDataObject;
namespace WebCore {
class CachedImage;
+ class ChromiumDataObject;
class IntPoint;
- class WCDataObject;
- // State available during IE's events for drag and drop and copy/paste
- class ClipboardWin : public Clipboard, public CachedResourceClient {
+ class ClipboardChromium : public Clipboard, public CachedResourceClient {
public:
- ~ClipboardWin();
+ ~ClipboardChromium() {}
+
+ static PassRefPtr<ClipboardChromium> create(bool, ChromiumDataObject*,
+ ClipboardAccessPolicy);
- static PassRefPtr<ClipboardWin> create(bool isForDragging, IDataObject*, ClipboardAccessPolicy);
- static PassRefPtr<ClipboardWin> create(bool isForDragging, WCDataObject*, ClipboardAccessPolicy);
-
- void clearData(const String& type);
+ virtual void clearData(const String& type);
void clearAllData();
String getData(const String& type, bool& success) const;
bool setData(const String& type, const String& data);
-
+
// extensions beyond IE's API
HashSet<String> types() const;
-
+
void setDragImage(CachedImage*, const IntPoint&);
void setDragImageElement(Node*, const IntPoint&);
+ PassRefPtr<ChromiumDataObject> dataObject() {
+ return m_dataObject;
+ }
+
virtual DragImageRef createDragImage(IntPoint& dragLoc) const;
- virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*);
+ virtual void declareAndWriteDragImage(Element*, const KURL&,
+ const String& title, Frame*);
virtual void writeURL(const KURL&, const String&, Frame*);
virtual void writeRange(Range*, Frame*);
virtual bool hasData();
- COMPtr<IDataObject> dataObject() { return m_dataObject; }
private:
- ClipboardWin(bool isForDragging, IDataObject*, ClipboardAccessPolicy);
- ClipboardWin(bool isForDragging, WCDataObject*, ClipboardAccessPolicy);
+ ClipboardChromium(bool, ChromiumDataObject*, ClipboardAccessPolicy);
void resetFromClipboard();
void setDragImage(CachedImage*, Node*, const IntPoint&);
- COMPtr<IDataObject> m_dataObject;
- COMPtr<WCDataObject> m_writableDataObject;
+ RefPtr<ChromiumDataObject> m_dataObject;
Frame* m_frame;
};
} // namespace WebCore
-#endif // ClipboardWin_h
+#endif // ClipboardChromium_h
diff --git a/webkit/port/platform/chromium/DragDataChromium.cpp b/webkit/port/platform/chromium/DragDataChromium.cpp
index 49c4630..3507739 100644
--- a/webkit/port/platform/chromium/DragDataChromium.cpp
+++ b/webkit/port/platform/chromium/DragDataChromium.cpp
@@ -29,33 +29,18 @@
#include "config.h"
#include "DragData.h"
-#if PLATFORM(WIN_OS)
-#include "ClipboardWin.h"
-#include "ClipboardUtilitiesWin.h"
-#include "WCDataObject.h"
-#else
-#include "Clipboard.h" // This and ClipboardWin.h should be ClipboardChromium.h
-#endif
-
+#include "ChromiumDataObject.h"
+#include "Clipboard.h"
+#include "ClipboardChromium.h"
#include "DocumentFragment.h"
#include "KURL.h"
#include "PlatformString.h"
#include "markup.h"
-#undef LOG
-#include "base/file_util.h"
-#include "base/string_util.h"
-#include "net/base/base64.h"
-#include "webkit/glue/glue_util.h"
-#include "webkit/glue/webdropdata.h"
-#include "webkit/glue/webkit_glue.h"
-
namespace {
-bool containsHTML(const WebDropData& drop_data) {
- std::wstring html;
- return drop_data.cf_html.length() > 0
- || drop_data.text_html.length() > 0;
+bool containsHTML(const WebCore::ChromiumDataObject* drop_data) {
+ return drop_data->text_html.length() > 0;
}
}
@@ -64,57 +49,47 @@ namespace WebCore {
PassRefPtr<Clipboard> DragData::createClipboard(ClipboardAccessPolicy policy) const
{
-// TODO(darin): Invent ClipboardChromium and use that instead.
-#if PLATFORM(WIN_OS)
- WCDataObject* data;
- WCDataObject::createInstance(&data);
- RefPtr<ClipboardWin> clipboard = ClipboardWin::create(true, data, policy);
- // The clipboard keeps a reference to the WCDataObject, so we can release
- // our reference to it.
- data->Release();
+ RefPtr<ClipboardChromium> clipboard = ClipboardChromium::create(true,
+ m_platformDragData, policy);
return clipboard.release();
-#else
- return PassRefPtr<Clipboard>(0);
-#endif
}
bool DragData::containsURL() const
{
- return m_platformDragData->url.is_valid();
+ return m_platformDragData->url.isValid();
}
String DragData::asURL(String* title) const
{
- if (!m_platformDragData->url.is_valid())
+ if (!m_platformDragData->url.isValid())
return String();
// |title| can be NULL
if (title)
- *title = webkit_glue::StdWStringToString(m_platformDragData->url_title);
- return webkit_glue::StdStringToString(m_platformDragData->url.spec());
+ *title = m_platformDragData->url_title;
+ return m_platformDragData->url.string();
}
bool DragData::containsFiles() const
{
- return !m_platformDragData->filenames.empty();
+ return !m_platformDragData->filenames.isEmpty();
}
void DragData::asFilenames(Vector<String>& result) const
{
for (size_t i = 0; i < m_platformDragData->filenames.size(); ++i)
- result.append(webkit_glue::StdWStringToString(m_platformDragData->filenames[i]));
+ result.append(m_platformDragData->filenames[i]);
}
bool DragData::containsPlainText() const
{
- return !m_platformDragData->plain_text.empty();
+ return !m_platformDragData->plain_text.isEmpty();
}
String DragData::asPlainText() const
{
- return webkit_glue::StdWStringToString(
- m_platformDragData->plain_text);
+ return m_platformDragData->plain_text;
}
bool DragData::containsColor() const
@@ -128,15 +103,14 @@ bool DragData::canSmartReplace() const
// This is allowed whenever the drag data contains a 'range' (ie.,
// ClipboardWin::writeRange is called). For example, dragging a link
// should not result in a space being added.
- return !m_platformDragData->cf_html.empty() &&
- !m_platformDragData->plain_text.empty() &&
- !m_platformDragData->url.is_valid();
+ return !m_platformDragData->plain_text.isEmpty() &&
+ !m_platformDragData->url.isValid();
}
bool DragData::containsCompatibleContent() const
{
return containsPlainText() || containsURL()
- || ::containsHTML(*m_platformDragData)
+ || ::containsHTML(m_platformDragData)
|| containsColor();
}
@@ -159,19 +133,10 @@ PassRefPtr<DocumentFragment> DragData::asFragment(Document* doc) const
// if (PassRefPtr<DocumentFragment> fragment = fragmentFromFilenames(doc, m_platformDragData))
// return fragment;
-#if PLATFORM(WIN_OS)
- // fragmentFromCF_HTML comes from ClipboardUtilitiesWin.
- if (!m_platformDragData->cf_html.empty()) {
- RefPtr<DocumentFragment> fragment = fragmentFromCF_HTML(doc,
- webkit_glue::StdWStringToString(m_platformDragData->cf_html));
- return fragment;
- }
-#endif
-
- if (!m_platformDragData->text_html.empty()) {
+ if (!m_platformDragData->text_html.isEmpty()) {
String url;
RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(doc,
- webkit_glue::StdWStringToString(m_platformDragData->text_html), url);
+ m_platformDragData->text_html, url);
return fragment;
}
diff --git a/webkit/port/platform/chromium/DragDataRef.h b/webkit/port/platform/chromium/DragDataRef.h
index c588819..4ddc1ac 100644
--- a/webkit/port/platform/chromium/DragDataRef.h
+++ b/webkit/port/platform/chromium/DragDataRef.h
@@ -30,11 +30,11 @@
#ifndef DragDataRef_h
#define DragDataRef_h
-#include "webkit/glue/webdropdata.h"
+#include "ChromiumDataObject.h"
namespace WebCore {
-typedef WebDropData* DragDataRef;
+typedef ChromiumDataObject* DragDataRef;
}
diff --git a/webkit/port/platform/chromium/EditorLinux.cpp b/webkit/port/platform/chromium/EditorChromium.cpp
index 808d617..8636ed1 100644
--- a/webkit/port/platform/chromium/EditorLinux.cpp
+++ b/webkit/port/platform/chromium/EditorChromium.cpp
@@ -26,15 +26,15 @@
#include "config.h"
#include "Editor.h"
-#include "Clipboard.h"
-#include "NotImplemented.h"
+#include "ChromiumDataObject.h"
+#include "ClipboardChromium.h"
namespace WebCore {
PassRefPtr<Clipboard> Editor::newGeneralClipboard(ClipboardAccessPolicy policy)
{
- notImplemented();
- return NULL;
+ RefPtr<ChromiumDataObject> dataObject = ChromiumDataObject::create();
+ return ClipboardChromium::create(false, dataObject.get(), policy);
}
} // namespace WebCore
diff --git a/webkit/port/platform/win/ClipboardUtilitiesWin.h b/webkit/port/platform/win/ClipboardUtilitiesWin.h
index bc8fb0a..a7669ad 100644
--- a/webkit/port/platform/win/ClipboardUtilitiesWin.h
+++ b/webkit/port/platform/win/ClipboardUtilitiesWin.h
@@ -26,7 +26,10 @@
#ifndef ClipboardUtilitiesWin_h
#define ClipboardUtilitiesWin_h
-#include "DragData.h"
+#include "DocumentFragment.h"
+#include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
+
#include <windows.h>
#include <objidl.h>
diff --git a/webkit/port/platform/win/ClipboardWin.cpp b/webkit/port/platform/win/ClipboardWin.cpp
deleted file mode 100644
index 0383610..0000000
--- a/webkit/port/platform/win/ClipboardWin.cpp
+++ /dev/null
@@ -1,808 +0,0 @@
-/*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include <shlwapi.h>
-#include <wininet.h>
-
-#pragma warning(push, 0)
-#include "ClipboardWin.h"
-#include "CachedImage.h"
-#include "ClipboardUtilitiesWin.h"
-#include "csshelper.h"
-#include "CString.h"
-#include "Document.h"
-#include "DragData.h"
-#include "Editor.h"
-#include "Element.h"
-#include "EventHandler.h"
-#include "Frame.h"
-#include "FrameLoader.h"
-#include "FrameView.h"
-#include "HTMLNames.h"
-#include "Image.h"
-#include "MIMETypeRegistry.h"
-#include "markup.h"
-#include "Page.h"
-#include "Pasteboard.h"
-#include "PlatformMouseEvent.h"
-#include "PlatformString.h"
-#include "Range.h"
-#include "RenderImage.h"
-#include "ResourceResponse.h"
-#include "StringBuilder.h"
-#include "StringHash.h"
-#include "WCDataObject.h"
-#include <wtf/RefPtr.h>
-#pragma warning(pop)
-
-#undef LOG
-#include "base/clipboard_util.h"
-#include "base/string_util.h"
-#include "googleurl/src/gurl.h"
-#include "webkit/glue/glue_util.h"
-#include "webkit/glue/webkit_glue.h"
-
-namespace WebCore {
-
-using namespace HTMLNames;
-
-// format string for
-static const char szShellDotUrlTemplate[] = "[InternetShortcut]\r\nURL=%s\r\n";
-
-// 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 };
-
-static ClipboardDataType clipboardTypeFromMIMEType(const String& type)
-{
- String qType = type.stripWhiteSpace().lower();
-
- // two special cases for IE compatibility
- if (qType == "text" || qType == "text/plain" || qType.startsWith("text/plain;"))
- return ClipboardDataTypeText;
- if (qType == "url" || qType == "text/uri-list")
- return ClipboardDataTypeURL;
-
- return ClipboardDataTypeNone;
-}
-
-static inline void pathRemoveBadFSCharacters(PWSTR psz, size_t length)
-{
- size_t writeTo = 0;
- size_t readFrom = 0;
- while (readFrom < length) {
- UINT type = PathGetCharType(psz[readFrom]);
- if (psz[readFrom] == 0 || type & (GCT_LFNCHAR | GCT_SHORTCHAR)) {
- psz[writeTo++] = psz[readFrom];
- }
-
- readFrom++;
- }
- psz[writeTo] = 0;
-}
-
-static String filesystemPathFromUrlOrTitle(const String& url, const String& title, TCHAR* extension, bool isLink)
-{
- bool usedURL = false;
- WCHAR fsPathBuffer[MAX_PATH];
- fsPathBuffer[0] = 0;
- int extensionLen = extension ? min(MAX_PATH - 1, lstrlen(extension)) : 0;
- String extensionString = extension ? String(extension, extensionLen) : String(L"");
-
- // We make the filename based on the title only if there's an extension.
- if (!title.isEmpty() && extension) {
- size_t len = min<size_t>(title.length(), MAX_PATH - extensionLen - 1);
- CopyMemory(fsPathBuffer, title.characters(), len * sizeof(UChar));
- fsPathBuffer[len] = 0;
- pathRemoveBadFSCharacters(fsPathBuffer, len);
- }
-
- if (!lstrlen(fsPathBuffer)) {
- DWORD len = MAX_PATH - 1;
- String nullTermURL = url;
- usedURL = true;
- if (UrlIsFileUrl((LPCWSTR)nullTermURL.charactersWithNullTermination())
- && SUCCEEDED(PathCreateFromUrl((LPCWSTR)nullTermURL.charactersWithNullTermination(), fsPathBuffer, &len, 0))) {
- // When linking to a file URL we can trivially find the file name
- PWSTR fn = PathFindFileName(fsPathBuffer);
- if (fn && fn != fsPathBuffer)
- lstrcpyn(fsPathBuffer, fn, lstrlen(fn) + 1);
- } else {
- // The filename for any content based drag should be the last element of
- // the path. If we can't find it, or we're coming up with the name for a link
- // we just use the entire url.
- KURL kurl(url);
- String lastComponent;
- if (!isLink && !(lastComponent = kurl.lastPathComponent()).isEmpty()) {
- len = min<DWORD>(MAX_PATH - 1, lastComponent.length());
- CopyMemory(fsPathBuffer, lastComponent.characters(), len * sizeof(UChar));
- } else {
- len = min<DWORD>(MAX_PATH - 1, nullTermURL.length());
- CopyMemory(fsPathBuffer, nullTermURL.characters(), len * sizeof(UChar));
- }
- fsPathBuffer[len] = 0;
- pathRemoveBadFSCharacters(fsPathBuffer, len);
- }
- }
-
- if (!extension)
- return String((UChar*)fsPathBuffer);
-
- if (!isLink && usedURL) {
- PathRenameExtension(fsPathBuffer, extensionString.charactersWithNullTermination());
- return String((UChar*)fsPathBuffer);
- }
-
- String result((UChar*)fsPathBuffer);
- result += extensionString;
- return result.length() >= MAX_PATH ? result.substring(0, MAX_PATH - 1) : result;
-}
-
-static HGLOBAL createGlobalURLContent(const String& url, int estimatedFileSize)
-{
- HRESULT hr = S_OK;
- HGLOBAL memObj = 0;
-
- char* fileContents;
- char ansiUrl[INTERNET_MAX_URL_LENGTH + 1];
- // Used to generate the buffer. This is null terminated whereas the fileContents won't be.
- char contentGenerationBuffer[INTERNET_MAX_URL_LENGTH + ARRAYSIZE(szShellDotUrlTemplate) + 1];
-
- if (estimatedFileSize > 0 && estimatedFileSize > ARRAYSIZE(contentGenerationBuffer))
- return 0;
-
- int ansiUrlSize = ::WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)url.characters(), url.length(), ansiUrl, ARRAYSIZE(ansiUrl) - 1, 0, 0);
- if (!ansiUrlSize)
- return 0;
-
- ansiUrl[ansiUrlSize] = 0;
-
- int fileSize = (int) (ansiUrlSize+strlen(szShellDotUrlTemplate)-2); // -2 to remove the %s
- ASSERT(estimatedFileSize < 0 || fileSize == estimatedFileSize);
-
- memObj = GlobalAlloc(GPTR, fileSize);
- if (!memObj)
- return 0;
-
- fileContents = (PSTR)GlobalLock(memObj);
-
- sprintf_s(contentGenerationBuffer, ARRAYSIZE(contentGenerationBuffer), szShellDotUrlTemplate, ansiUrl);
- CopyMemory(fileContents, contentGenerationBuffer, fileSize);
-
- GlobalUnlock(memObj);
-
- return memObj;
-}
-
-static HGLOBAL createGlobalImageFileContent(SharedBuffer* data)
-{
- HGLOBAL memObj = GlobalAlloc(GPTR, data->size());
- if (!memObj)
- return 0;
-
- char* fileContents = (PSTR)GlobalLock(memObj);
-
- CopyMemory(fileContents, data->data(), data->size());
-
- GlobalUnlock(memObj);
-
- return memObj;
-}
-
-static HGLOBAL createGlobalHDropContent(const KURL& url, String& fileName, SharedBuffer* data)
-{
- if (fileName.isEmpty() || !data )
- return 0;
-
- WCHAR filePath[MAX_PATH];
-
- if (url.isLocalFile()) {
- String localPath = url.path();
- // windows does not enjoy a leading slash on paths
- if (localPath[0] == '/')
- localPath = localPath.substring(1);
- LPCTSTR localPathStr = localPath.charactersWithNullTermination();
- if (wcslen(localPathStr) + 1 < MAX_PATH)
- wcscpy_s(filePath, MAX_PATH, localPathStr);
- else
- return 0;
- } else {
- WCHAR tempPath[MAX_PATH];
- WCHAR extension[MAX_PATH];
- if (!::GetTempPath(ARRAYSIZE(tempPath), tempPath))
- return 0;
- if (!::PathAppend(tempPath, fileName.charactersWithNullTermination()))
- return 0;
- LPCWSTR foundExtension = ::PathFindExtension(tempPath);
- if (foundExtension) {
- if (wcscpy_s(extension, MAX_PATH, foundExtension))
- return 0;
- } else
- *extension = 0;
- ::PathRemoveExtension(tempPath);
- for (int i = 1; i < 10000; i++) {
- if (swprintf_s(filePath, MAX_PATH, TEXT("%s-%d%s"), tempPath, i, extension) == -1)
- return 0;
- if (!::PathFileExists(filePath))
- break;
- }
- HANDLE tempFileHandle = CreateFile(filePath, GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
- if (tempFileHandle == INVALID_HANDLE_VALUE)
- return 0;
-
- // Write the data to this temp file.
- DWORD written;
- BOOL tempWriteSucceeded = WriteFile(tempFileHandle, data->data(), data->size(), &written, 0);
- CloseHandle(tempFileHandle);
- if (!tempWriteSucceeded)
- return 0;
- }
-
- SIZE_T dropFilesSize = sizeof(DROPFILES) + (sizeof(WCHAR) * (wcslen(filePath) + 2));
- HGLOBAL memObj = GlobalAlloc(GHND | GMEM_SHARE, dropFilesSize);
- if (!memObj)
- return 0;
-
- DROPFILES* dropFiles = (DROPFILES*) GlobalLock(memObj);
- dropFiles->pFiles = sizeof(DROPFILES);
- dropFiles->fWide = TRUE;
- wcscpy((LPWSTR)(dropFiles + 1), filePath);
- GlobalUnlock(memObj);
-
- return memObj;
-}
-
-static HGLOBAL createGlobalUrlFileDescriptor(const String& url, const String& title, int& /*out*/ estimatedSize)
-{
- HRESULT hr = S_OK;
- HGLOBAL memObj = 0;
- String fsPath;
- memObj = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTOR));
- if (!memObj)
- return 0;
-
- FILEGROUPDESCRIPTOR* fgd = (FILEGROUPDESCRIPTOR*)GlobalLock(memObj);
- memset(fgd, 0, sizeof(FILEGROUPDESCRIPTOR));
- fgd->cItems = 1;
- fgd->fgd[0].dwFlags = FD_FILESIZE;
- int fileSize = ::WideCharToMultiByte(CP_ACP, 0, url.characters(), url.length(), 0, 0, 0, 0);
- fileSize += strlen(szShellDotUrlTemplate) - 2; // -2 is for getting rid of %s in the template string
- fgd->fgd[0].nFileSizeLow = fileSize;
- estimatedSize = fileSize;
- fsPath = filesystemPathFromUrlOrTitle(url, title, L".URL", true);
-
- if (fsPath.length() <= 0) {
- GlobalUnlock(memObj);
- GlobalFree(memObj);
- return 0;
- }
-
- int maxSize = min(fsPath.length(), ARRAYSIZE(fgd->fgd[0].cFileName));
- CopyMemory(fgd->fgd[0].cFileName, (LPCWSTR)fsPath.characters(), maxSize * sizeof(UChar));
- GlobalUnlock(memObj);
-
- return memObj;
-}
-
-
-static HGLOBAL createGlobalImageFileDescriptor(const String& url, const String& title, CachedImage* image)
-{
- ASSERT_ARG(image, image);
- ASSERT(image->image()->data());
-
- HRESULT hr = S_OK;
- HGLOBAL memObj = 0;
- String fsPath;
- memObj = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTOR));
- if (!memObj)
- return 0;
-
- FILEGROUPDESCRIPTOR* fgd = (FILEGROUPDESCRIPTOR*)GlobalLock(memObj);
- memset(fgd, 0, sizeof(FILEGROUPDESCRIPTOR));
- fgd->cItems = 1;
- fgd->fgd[0].dwFlags = FD_FILESIZE;
- fgd->fgd[0].nFileSizeLow = image->image()->data()->size();
-
- String extension(".");
- extension += WebCore::MIMETypeRegistry::getPreferredExtensionForMIMEType(image->response().mimeType());
- const String& preferredTitle = title.isEmpty() ? image->response().suggestedFilename() : title;
- fsPath = filesystemPathFromUrlOrTitle(url, preferredTitle, extension.isEmpty() ? 0 : (TCHAR*)extension.charactersWithNullTermination(), false);
-
- if (fsPath.length() <= 0) {
- GlobalUnlock(memObj);
- GlobalFree(memObj);
- return 0;
- }
-
- int maxSize = min(fsPath.length(), ARRAYSIZE(fgd->fgd[0].cFileName));
- CopyMemory(fgd->fgd[0].cFileName, (LPCWSTR)fsPath.characters(), maxSize * sizeof(UChar));
- GlobalUnlock(memObj);
-
- return memObj;
-}
-
-
-// writeFileToDataObject takes ownership of fileDescriptor and fileContent
-static HRESULT writeFileToDataObject(IDataObject* dataObject, HGLOBAL fileDescriptor, HGLOBAL fileContent, HGLOBAL hDropContent)
-{
- HRESULT hr = S_OK;
- FORMATETC* fe;
- STGMEDIUM medium = {0};
- medium.tymed = TYMED_HGLOBAL;
-
- if (!fileDescriptor || !fileContent)
- goto exit;
-
- // Descriptor
- fe = ClipboardUtil::GetFileDescriptorFormat();
-
- medium.hGlobal = fileDescriptor;
-
- if (FAILED(hr = dataObject->SetData(fe, &medium, TRUE)))
- goto exit;
-
- // Contents
- fe = ClipboardUtil::GetFileContentFormatZero();
- medium.hGlobal = fileContent;
- if (FAILED(hr = dataObject->SetData(fe, &medium, TRUE)))
- goto exit;
-
- // HDROP
- if (hDropContent) {
- medium.hGlobal = hDropContent;
- hr = dataObject->SetData(ClipboardUtil::GetCFHDropFormat(), &medium, TRUE);
- }
-
-exit:
- if (FAILED(hr)) {
- if (fileDescriptor)
- GlobalFree(fileDescriptor);
- if (fileContent)
- GlobalFree(fileContent);
- if (hDropContent)
- GlobalFree(hDropContent);
- }
- return hr;
-}
-
-ClipboardWin::ClipboardWin(bool isForDragging, IDataObject* dataObject, ClipboardAccessPolicy policy)
- : Clipboard(policy, isForDragging)
- , m_dataObject(dataObject)
- , m_writableDataObject(0)
-{
-}
-
-ClipboardWin::ClipboardWin(bool isForDragging, WCDataObject* dataObject, ClipboardAccessPolicy policy)
- : Clipboard(policy, isForDragging)
- , m_dataObject(dataObject)
- , m_writableDataObject(dataObject)
-{
-}
-
-ClipboardWin::~ClipboardWin()
-{
-}
-
-PassRefPtr<ClipboardWin> ClipboardWin::create(bool isForDragging, IDataObject* dataObject, ClipboardAccessPolicy policy)
-{
- return adoptRef(new ClipboardWin(isForDragging, dataObject, policy));
-}
-
-PassRefPtr<ClipboardWin> ClipboardWin::create(bool isForDragging, WCDataObject* dataObject, ClipboardAccessPolicy policy)
-{
- return adoptRef(new ClipboardWin(isForDragging, dataObject, policy));
-}
-
-static bool writeURL(WCDataObject *data, const KURL& url, String title, bool withPlainText, bool withHTML)
-{
- ASSERT(data);
-
- if (url.isEmpty())
- return false;
-
- if (title.isEmpty()) {
- title = url.lastPathComponent();
- if (title.isEmpty())
- title = url.host();
- }
-
- STGMEDIUM medium = {0};
- medium.tymed = TYMED_HGLOBAL;
-
- medium.hGlobal = createGlobalData(url, title);
- bool success = false;
- if (medium.hGlobal && FAILED(data->SetData(ClipboardUtil::GetUrlWFormat(), &medium, TRUE)))
- ::GlobalFree(medium.hGlobal);
- else
- success = true;
-
- if (withHTML) {
- Vector<char> cfhtmlData;
- markupToCF_HTML(urlToMarkup(url, title), "", cfhtmlData);
- medium.hGlobal = createGlobalData(cfhtmlData);
- if (medium.hGlobal && FAILED(data->SetData(htmlFormat(), &medium, TRUE)))
- ::GlobalFree(medium.hGlobal);
- else
- success = true;
- }
-
- if (withPlainText) {
- medium.hGlobal = createGlobalData(url.string());
- if (medium.hGlobal && FAILED(data->SetData(ClipboardUtil::GetPlainTextWFormat(), &medium, TRUE)))
- ::GlobalFree(medium.hGlobal);
- else
- success = true;
- }
-
- return success;
-}
-
-void ClipboardWin::clearData(const String& type)
-{
- //FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941>
- ASSERT(isForDragging());
- if (policy() != ClipboardWritable || !m_writableDataObject)
- return;
-
- ClipboardDataType dataType = clipboardTypeFromMIMEType(type);
-
- if (dataType == ClipboardDataTypeURL) {
- m_writableDataObject->clearData(ClipboardUtil::GetUrlWFormat()->cfFormat);
- m_writableDataObject->clearData(ClipboardUtil::GetUrlFormat()->cfFormat);
- }
- if (dataType == ClipboardDataTypeText) {
- m_writableDataObject->clearData(ClipboardUtil::GetPlainTextFormat()->cfFormat);
- m_writableDataObject->clearData(ClipboardUtil::GetPlainTextWFormat()->cfFormat);
- }
-
-}
-
-void ClipboardWin::clearAllData()
-{
- //FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941>
- ASSERT(isForDragging());
- if (policy() != ClipboardWritable)
- return;
-
- m_writableDataObject = 0;
- WCDataObject::createInstance(&m_writableDataObject);
- m_dataObject = m_writableDataObject;
-}
-
-String ClipboardWin::getData(const String& type, bool& success) const
-{
- success = false;
- if (policy() != ClipboardReadable || !m_dataObject) {
- return "";
- }
-
- ClipboardDataType dataType = clipboardTypeFromMIMEType(type);
- if (dataType == ClipboardDataTypeText) {
- std::wstring text;
- if (!isForDragging()) {
- // If this isn't for a drag, it's for a cut/paste event handler.
- // In this case, we need to use our glue methods to access the
- // clipboard contents.
- webkit_glue::ClipboardReadText(&text);
- if (text.empty()) {
- std::string asciiText;
- webkit_glue::ClipboardReadAsciiText(&asciiText);
- text = ASCIIToWide(asciiText);
- }
- success = !text.empty();
- } else {
- success = ClipboardUtil::GetPlainText(m_dataObject.get(), &text);
- }
- return webkit_glue::StdWStringToString(text);
- } else if (dataType == ClipboardDataTypeURL) {
- std::wstring url;
- std::wstring title;
- success = ClipboardUtil::GetUrl(m_dataObject.get(), &url, &title);
- return webkit_glue::StdWStringToString(url);
- }
-
- return "";
-}
-
-bool ClipboardWin::setData(const String& type, const String& data)
-{
- // FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941>
- ASSERT(isForDragging());
- if (policy() != ClipboardWritable || !m_writableDataObject)
- return false;
-
- ClipboardDataType winType = clipboardTypeFromMIMEType(type);
-
- if (winType == ClipboardDataTypeURL)
- return WebCore::writeURL(m_writableDataObject.get(), KURL(data), String(), false, true);
-
- if (winType == ClipboardDataTypeText) {
- STGMEDIUM medium = {0};
- medium.tymed = TYMED_HGLOBAL;
- medium.hGlobal = createGlobalData(data);
- if (!medium.hGlobal)
- return false;
-
- if (FAILED(m_writableDataObject->SetData(ClipboardUtil::GetPlainTextWFormat(), &medium, TRUE))) {
- ::GlobalFree(medium.hGlobal);
- return false;
- }
- return true;
- }
- return false;
-}
-
-static void addMimeTypesForFormat(HashSet<String>& results, FORMATETC& format)
-{
- // URL and Text are provided for compatibility with IE's model
- if (format.cfFormat == ClipboardUtil::GetUrlFormat()->cfFormat ||
- format.cfFormat == ClipboardUtil::GetUrlWFormat()->cfFormat) {
- results.add("URL");
- results.add("text/uri-list");
- }
-
- if (format.cfFormat == ClipboardUtil::GetPlainTextWFormat()->cfFormat ||
- format.cfFormat == ClipboardUtil::GetPlainTextFormat()->cfFormat) {
- results.add("Text");
- results.add("text/plain");
- }
-}
-
-// extensions beyond IE's API
-HashSet<String> ClipboardWin::types() const
-{
- HashSet<String> results;
- if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
- return results;
-
- if (!m_dataObject)
- return results;
-
- COMPtr<IEnumFORMATETC> itr;
-
- if (FAILED(m_dataObject->EnumFormatEtc(0, &itr)))
- return results;
-
- if (!itr)
- return results;
-
- FORMATETC data;
-
- while (SUCCEEDED(itr->Next(1, &data, 0))) {
- addMimeTypesForFormat(results, data);
- }
-
- return results;
-}
-
-void ClipboardWin::setDragImage(CachedImage* image, Node *node, const IntPoint &loc)
-{
- if (policy() != ClipboardImageWritable && policy() != ClipboardWritable)
- return;
-
- if (m_dragImage)
- m_dragImage->removeClient(this);
- m_dragImage = image;
- if (m_dragImage)
- m_dragImage->addClient(this);
-
- m_dragLoc = loc;
- m_dragImageElement = node;
-}
-
-void ClipboardWin::setDragImage(CachedImage* img, const IntPoint &loc)
-{
- setDragImage(img, 0, loc);
-}
-
-void ClipboardWin::setDragImageElement(Node *node, const IntPoint &loc)
-{
- setDragImage(0, node, loc);
-}
-
-DragImageRef ClipboardWin::createDragImage(IntPoint& loc) const
-{
- HBITMAP result = 0;
- //FIXME: Need to be able to draw element <rdar://problem/5015942>
- if (m_dragImage) {
- result = createDragImageFromImage(m_dragImage->image());
- loc = m_dragLoc;
- }
- return result;
-}
-
-static String imageToMarkup(const String& url, Element* element)
-{
- StringBuilder markup;
- markup.append("<img src=\"");
- markup.append(url);
- markup.append("\"");
- // Copy over attributes. If we are dragging an image, we expect things like
- // the id to be copied as well.
- NamedAttrMap* attrs = element->attributes();
- unsigned int length = attrs->length();
- for (unsigned int i = 0; i < length; ++i) {
- Attribute* attr = attrs->attributeItem(i);
- if (attr->localName() == "src")
- continue;
- markup.append(" ");
- markup.append(attr->localName());
- markup.append("=\"");
- String escapedAttr = attr->value();
- escapedAttr.replace("\"", "&quot;");
- markup.append(escapedAttr);
- markup.append("\"");
- }
-
- markup.append("/>");
- return markup.toString();
-}
-
-static CachedImage* getCachedImage(Element* element)
-{
- // Attempt to pull CachedImage from element
- ASSERT(element);
- RenderObject* renderer = element->renderer();
- if (!renderer || !renderer->isImage())
- return 0;
-
- RenderImage* image = static_cast<RenderImage*>(renderer);
- if (image->cachedImage() && !image->cachedImage()->errorOccurred())
- return image->cachedImage();
-
- return 0;
-}
-
-static void writeImageToDataObject(IDataObject* dataObject, Element* element, const KURL& url)
-{
- // Shove image data into a DataObject for use as a file
- CachedImage* cachedImage = getCachedImage(element);
- if (!cachedImage || !cachedImage->image() || !cachedImage->isLoaded())
- return;
-
- SharedBuffer* imageBuffer = cachedImage->image()->data();
- if (!imageBuffer || !imageBuffer->size())
- return;
-
- HGLOBAL imageFileDescriptor = createGlobalImageFileDescriptor(url.string(), element->getAttribute(altAttr), cachedImage);
- if (!imageFileDescriptor)
- return;
-
- HGLOBAL imageFileContent = createGlobalImageFileContent(imageBuffer);
- if (!imageFileContent) {
- GlobalFree(imageFileDescriptor);
- return;
- }
-
- // When running in the sandbox, it's possible that hDropContent is NULL.
- // That's ok, we should keep going anyway.
- String fileName = cachedImage->response().suggestedFilename();
- HGLOBAL hDropContent = createGlobalHDropContent(url, fileName, imageBuffer);
-
- writeFileToDataObject(dataObject, imageFileDescriptor, imageFileContent, hDropContent);
-}
-
-void ClipboardWin::declareAndWriteDragImage(Element* element, const KURL& url, const String& title, Frame* frame)
-{
- // Order is important here for Explorer's sake
- if (!m_writableDataObject)
- return;
- WebCore::writeURL(m_writableDataObject.get(), url, title, true, false);
-
- writeImageToDataObject(m_writableDataObject.get(), element, url);
-
- AtomicString imageURL = element->getAttribute(srcAttr);
- if (imageURL.isEmpty())
- return;
-
- String fullURL = frame->document()->completeURL(parseURL(imageURL));
- if (fullURL.isEmpty())
- return;
- STGMEDIUM medium = {0};
- medium.tymed = TYMED_HGLOBAL;
- ExceptionCode ec = 0;
-
- // Put img tag on the clipboard referencing the image
- Vector<char> data;
- markupToCF_HTML(imageToMarkup(fullURL, element), "", data);
- medium.hGlobal = createGlobalData(data);
- if (medium.hGlobal && FAILED(m_writableDataObject->SetData(htmlFormat(), &medium, TRUE)))
- ::GlobalFree(medium.hGlobal);
-}
-
-void ClipboardWin::writeURL(const KURL& kurl, const String& titleStr, Frame*)
-{
- if (!m_writableDataObject)
- return;
- WebCore::writeURL(m_writableDataObject.get(), kurl, titleStr, true, true);
-
- int estimatedSize = 0;
- String url = kurl.string();
-
- HGLOBAL urlFileDescriptor = createGlobalUrlFileDescriptor(url, titleStr, estimatedSize);
- if (!urlFileDescriptor)
- return;
- HGLOBAL urlFileContent = createGlobalURLContent(url, estimatedSize);
- if (!urlFileContent) {
- GlobalFree(urlFileDescriptor);
- return;
- }
- writeFileToDataObject(m_writableDataObject.get(), urlFileDescriptor, urlFileContent, 0);
-}
-
-void ClipboardWin::writeRange(Range* selectedRange, Frame* frame)
-{
- ASSERT(selectedRange);
- if (!m_writableDataObject)
- return;
-
- STGMEDIUM medium = {0};
- medium.tymed = TYMED_HGLOBAL;
- ExceptionCode ec = 0;
-
- Vector<char> data;
- markupToCF_HTML(createMarkup(selectedRange, 0, AnnotateForInterchange),
- selectedRange->startContainer(ec)->document()->url().string(), data);
- medium.hGlobal = createGlobalData(data);
- if (medium.hGlobal && FAILED(m_writableDataObject->SetData(htmlFormat(), &medium, TRUE)))
- ::GlobalFree(medium.hGlobal);
-
- String str = frame->selectedText();
- replaceNewlinesWithWindowsStyleNewlines(str);
- replaceNBSPWithSpace(str);
- medium.hGlobal = createGlobalData(str);
- if (medium.hGlobal && FAILED(m_writableDataObject->SetData(plainTextWFormat(), &medium, TRUE)))
- ::GlobalFree(medium.hGlobal);
-
- medium.hGlobal = 0;
- if (frame->editor()->canSmartCopyOrDelete())
- m_writableDataObject->SetData(smartPasteFormat(), &medium, TRUE);
-}
-
-bool ClipboardWin::hasData()
-{
- if (!m_dataObject)
- return false;
-
- COMPtr<IEnumFORMATETC> itr;
- if (FAILED(m_dataObject->EnumFormatEtc(0, &itr)))
- return false;
-
- if (!itr)
- return false;
-
- FORMATETC data;
-
- if (SUCCEEDED(itr->Next(1, &data, 0))) {
- // There is at least one item in the IDataObject
- return true;
- }
-
- return false;
-}
-
-} // namespace WebCore
diff --git a/webkit/port/platform/win/EditorWin.cpp b/webkit/port/platform/win/EditorWin.cpp
deleted file mode 100644
index 8ffcf9a..0000000
--- a/webkit/port/platform/win/EditorWin.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include <windows.h>
-#include <ole2.h>
-
-#pragma warning(push, 0)
-#include "Editor.h"
-#include "EditorClient.h"
-#include "ClipboardWin.h"
-#include "Document.h"
-#include "Element.h"
-#include "htmlediting.h"
-#include "TextIterator.h"
-#include "visible_units.h"
-#pragma warning(pop)
-
-namespace WebCore {
-
-PassRefPtr<Clipboard> Editor::newGeneralClipboard(ClipboardAccessPolicy policy)
-{
- COMPtr<IDataObject> clipboardData;
- if (!SUCCEEDED(OleGetClipboard(&clipboardData)))
- clipboardData = 0;
-
- return ClipboardWin::create(false, clipboardData.get(), policy);
-}
-
-} // namespace WebCore
diff --git a/webkit/port/platform/win/WCDataObject.cpp b/webkit/port/platform/win/WCDataObject.cpp
deleted file mode 100644
index 57e062a..0000000
--- a/webkit/port/platform/win/WCDataObject.cpp
+++ /dev/null
@@ -1,382 +0,0 @@
-/*
- * Copyright (C) 2007 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#include "WCDataObject.h"
-
-#include "PlatformString.h"
-
-namespace WebCore {
-
-class WCEnumFormatEtc : public IEnumFORMATETC
-{
-public:
- WCEnumFormatEtc(const Vector<FORMATETC>& formats);
- WCEnumFormatEtc(const Vector<FORMATETC*>& formats);
-
- //IUnknown members
- STDMETHOD(QueryInterface)(REFIID, void**);
- STDMETHOD_(ULONG, AddRef)(void);
- STDMETHOD_(ULONG, Release)(void);
-
- //IEnumFORMATETC members
- STDMETHOD(Next)(ULONG, LPFORMATETC, ULONG*);
- STDMETHOD(Skip)(ULONG);
- STDMETHOD(Reset)(void);
- STDMETHOD(Clone)(IEnumFORMATETC**);
-
-private:
- long m_ref;
- Vector<FORMATETC> m_formats;
- size_t m_current;
-};
-
-
-
-WCEnumFormatEtc::WCEnumFormatEtc(const Vector<FORMATETC>& formats)
-: m_ref(1)
-, m_current(0)
-{
- for(size_t i = 0; i < formats.size(); ++i)
- m_formats.append(formats[i]);
-}
-
-WCEnumFormatEtc::WCEnumFormatEtc(const Vector<FORMATETC*>& formats)
-: m_ref(1)
-, m_current(0)
-{
- for(size_t i = 0; i < formats.size(); ++i)
- m_formats.append(*formats[i]);
-}
-
-STDMETHODIMP WCEnumFormatEtc::QueryInterface(REFIID riid, void** ppvObject)
-{
- *ppvObject = 0;
- if (IsEqualIID(riid, IID_IUnknown) ||
- IsEqualIID(riid, IID_IEnumFORMATETC)) {
- *ppvObject = this;
- AddRef();
- return S_OK;
- }
-
- return E_NOINTERFACE;
-}
-
-STDMETHODIMP_(ULONG) WCEnumFormatEtc::AddRef(void)
-{
- return InterlockedIncrement(&m_ref);
-}
-
-STDMETHODIMP_(ULONG) WCEnumFormatEtc::Release(void)
-{
- long c = InterlockedDecrement(&m_ref);
- if (c == 0)
- delete this;
- return c;
-}
-
-STDMETHODIMP WCEnumFormatEtc::Next(ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
-{
- if(pceltFetched != 0)
- *pceltFetched=0;
-
- ULONG cReturn = celt;
-
- if(celt <= 0 || lpFormatEtc == 0 || m_current >= m_formats.size())
- return S_FALSE;
-
- if(pceltFetched == 0 && celt != 1) // pceltFetched can be 0 only for 1 item request
- return S_FALSE;
-
- while (m_current < m_formats.size() && cReturn > 0) {
- *lpFormatEtc++ = m_formats[m_current++];
- --cReturn;
- }
- if (pceltFetched != 0)
- *pceltFetched = celt - cReturn;
-
- return (cReturn == 0) ? S_OK : S_FALSE;
-}
-
-STDMETHODIMP WCEnumFormatEtc::Skip(ULONG celt)
-{
- if((m_current + int(celt)) >= m_formats.size())
- return S_FALSE;
- m_current += celt;
- return S_OK;
-}
-
-STDMETHODIMP WCEnumFormatEtc::Reset(void)
-{
- m_current = 0;
- return S_OK;
-}
-
-STDMETHODIMP WCEnumFormatEtc::Clone(IEnumFORMATETC** ppCloneEnumFormatEtc)
-{
- if(!ppCloneEnumFormatEtc)
- return E_POINTER;
-
- WCEnumFormatEtc *newEnum = new WCEnumFormatEtc(m_formats);
- if(!newEnum)
- return E_OUTOFMEMORY;
-
- newEnum->AddRef();
- newEnum->m_current = m_current;
- *ppCloneEnumFormatEtc = newEnum;
- return S_OK;
-}
-
-
-
-//////////////////////////////////////////////////////////////////////////
-
-HRESULT WCDataObject::createInstance(WCDataObject** result)
-{
- if (!result)
- return E_POINTER;
- *result = new WCDataObject();
- return S_OK;
-}
-
-WCDataObject::WCDataObject()
-: m_ref(1)
-{
-}
-
-WCDataObject::~WCDataObject()
-{
- for(size_t i = 0; i < m_medium.size(); ++i) {
- ReleaseStgMedium(m_medium[i]);
- delete m_medium[i];
- }
- WTF::deleteAllValues(m_formats);
-}
-
-STDMETHODIMP WCDataObject::QueryInterface(REFIID riid,void** ppvObject)
-{
- *ppvObject = 0;
- if (IID_IUnknown==riid || IID_IDataObject==riid)
- *ppvObject=this;
- if (*ppvObject) {
- AddRef();
- return S_OK;
- }
- return E_NOINTERFACE;
-}
-
-STDMETHODIMP_(ULONG) WCDataObject::AddRef( void)
-{
- return InterlockedIncrement(&m_ref);
-}
-
-STDMETHODIMP_(ULONG) WCDataObject::Release( void)
-{
- long c = InterlockedDecrement(&m_ref);
- if (c == 0)
- delete this;
- return c;
-}
-
-STDMETHODIMP WCDataObject::GetData(FORMATETC* pformatetcIn, STGMEDIUM* pmedium)
-{
- if(!pformatetcIn || !pmedium)
- return E_POINTER;
- pmedium->hGlobal = 0;
-
- for(size_t i=0; i < m_formats.size(); ++i) {
- if(/*pformatetcIn->tymed & m_formats[i]->tymed &&*/ // tymed can be 0 (TYMED_NULL) - but it can have a medium that contains an pUnkForRelease
- pformatetcIn->lindex == m_formats[i]->lindex &&
- pformatetcIn->dwAspect == m_formats[i]->dwAspect &&
- pformatetcIn->cfFormat == m_formats[i]->cfFormat) {
- CopyMedium(pmedium, m_medium[i], m_formats[i]);
- return S_OK;
- }
- }
- return DV_E_FORMATETC;
-}
-
-STDMETHODIMP WCDataObject::GetDataHere(FORMATETC*, STGMEDIUM*)
-{
- return E_NOTIMPL;
-}
-
-STDMETHODIMP WCDataObject::QueryGetData(FORMATETC* pformatetc)
-{
- if(!pformatetc)
- return E_POINTER;
-
- if (!(DVASPECT_CONTENT & pformatetc->dwAspect))
- return (DV_E_DVASPECT);
- HRESULT hr = DV_E_TYMED;
- for(size_t i = 0; i < m_formats.size(); ++i) {
- if(pformatetc->tymed & m_formats[i]->tymed) {
- if(pformatetc->cfFormat == m_formats[i]->cfFormat)
- return S_OK;
- else
- hr = DV_E_CLIPFORMAT;
- }
- else
- hr = DV_E_TYMED;
- }
- return hr;
-}
-
-STDMETHODIMP WCDataObject::GetCanonicalFormatEtc(FORMATETC*, FORMATETC*)
-{
- return DATA_S_SAMEFORMATETC;
-}
-
-STDMETHODIMP WCDataObject::SetData(FORMATETC* pformatetc, STGMEDIUM* pmedium, BOOL fRelease)
-{
- if(!pformatetc || !pmedium)
- return E_POINTER;
-
- FORMATETC* fetc=new FORMATETC;
- if (!fetc)
- return E_OUTOFMEMORY;
-
- STGMEDIUM* pStgMed = new STGMEDIUM;
-
- if(!pStgMed) {
- delete fetc;
- return E_OUTOFMEMORY;
- }
-
- ZeroMemory(fetc,sizeof(FORMATETC));
- ZeroMemory(pStgMed,sizeof(STGMEDIUM));
-
- *fetc = *pformatetc;
- m_formats.append(fetc);
-
- if(fRelease)
- *pStgMed = *pmedium;
- else
- CopyMedium(pStgMed, pmedium, pformatetc);
- m_medium.append(pStgMed);
-
- return S_OK;
-}
-
-void WCDataObject::CopyMedium(STGMEDIUM* pMedDest, STGMEDIUM* pMedSrc, FORMATETC* pFmtSrc)
-{
- switch(pMedSrc->tymed)
- {
- case TYMED_HGLOBAL:
- pMedDest->hGlobal = (HGLOBAL)OleDuplicateData(pMedSrc->hGlobal,pFmtSrc->cfFormat, 0);
- break;
- case TYMED_GDI:
- pMedDest->hBitmap = (HBITMAP)OleDuplicateData(pMedSrc->hBitmap,pFmtSrc->cfFormat, 0);
- break;
- case TYMED_MFPICT:
- pMedDest->hMetaFilePict = (HMETAFILEPICT)OleDuplicateData(pMedSrc->hMetaFilePict,pFmtSrc->cfFormat, 0);
- break;
- case TYMED_ENHMF:
- pMedDest->hEnhMetaFile = (HENHMETAFILE)OleDuplicateData(pMedSrc->hEnhMetaFile,pFmtSrc->cfFormat, 0);
- break;
- case TYMED_FILE:
- pMedSrc->lpszFileName = (LPOLESTR)OleDuplicateData(pMedSrc->lpszFileName,pFmtSrc->cfFormat, 0);
- break;
- case TYMED_ISTREAM:
- pMedDest->pstm = pMedSrc->pstm;
- pMedSrc->pstm->AddRef();
- break;
- case TYMED_ISTORAGE:
- pMedDest->pstg = pMedSrc->pstg;
- pMedSrc->pstg->AddRef();
- break;
- default:
- break;
- }
- pMedDest->tymed = pMedSrc->tymed;
- pMedDest->pUnkForRelease = 0;
- if(pMedSrc->pUnkForRelease != 0) {
- pMedDest->pUnkForRelease = pMedSrc->pUnkForRelease;
- pMedSrc->pUnkForRelease->AddRef();
- }
-}
-STDMETHODIMP WCDataObject::EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC** ppenumFormatEtc)
-{
- if(!ppenumFormatEtc)
- return E_POINTER;
-
- *ppenumFormatEtc=0;
- switch (dwDirection)
- {
- case DATADIR_GET:
- *ppenumFormatEtc= new WCEnumFormatEtc(m_formats);
- if(!(*ppenumFormatEtc))
- return E_OUTOFMEMORY;
- break;
-
- case DATADIR_SET:
- default:
- return E_NOTIMPL;
- break;
- }
-
- return S_OK;
-}
-
-STDMETHODIMP WCDataObject::DAdvise(FORMATETC*, DWORD, IAdviseSink*,DWORD*)
-{
- return OLE_E_ADVISENOTSUPPORTED;
-}
-
-STDMETHODIMP WCDataObject::DUnadvise(DWORD)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WCDataObject::EnumDAdvise(IEnumSTATDATA**)
-{
- return OLE_E_ADVISENOTSUPPORTED;
-}
-
-void WCDataObject::clearData(CLIPFORMAT format)
-{
- size_t ptr = 0;
- while (ptr < m_formats.size()) {
- if (m_formats[ptr]->cfFormat == format) {
- FORMATETC* current = m_formats[ptr];
- m_formats[ptr] = m_formats[m_formats.size() - 1];
- m_formats[m_formats.size() - 1] = 0;
- m_formats.removeLast();
- delete current;
- STGMEDIUM* medium = m_medium[ptr];
- m_medium[ptr] = m_medium[m_medium.size() - 1];
- m_medium[m_medium.size() - 1] = 0;
- m_medium.removeLast();
- ReleaseStgMedium(medium);
- delete medium;
- continue;
- }
- ptr++;
- }
-}
-
-
-}
diff --git a/webkit/port/platform/win/WCDataObject.h b/webkit/port/platform/win/WCDataObject.h
deleted file mode 100644
index 51e37a0..0000000
--- a/webkit/port/platform/win/WCDataObject.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2007 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef WCDataObject_h
-#define WCDataObject_h
-
-#include "COMPtr.h"
-#include <wtf/Vector.h>
-
-using namespace std;
-
-#include <ShlObj.h>
-#include <objidl.h>
-
-namespace WebCore {
-
-class String;
-
-class WCDataObject : public IDataObject {
-public:
- void CopyMedium(STGMEDIUM* pMedDest, STGMEDIUM* pMedSrc, FORMATETC* pFmtSrc);
-
- //IUnknown
- virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
- virtual ULONG STDMETHODCALLTYPE AddRef(void);
- virtual ULONG STDMETHODCALLTYPE Release(void);
-
- //IDataObject
- virtual HRESULT STDMETHODCALLTYPE GetData(FORMATETC* pformatIn, STGMEDIUM* pmedium);
- virtual HRESULT STDMETHODCALLTYPE GetDataHere(FORMATETC* pformat, STGMEDIUM* pmedium);
- virtual HRESULT STDMETHODCALLTYPE QueryGetData(FORMATETC* pformat);
- virtual HRESULT STDMETHODCALLTYPE GetCanonicalFormatEtc(FORMATETC* pformatectIn,FORMATETC* pformatOut);
- virtual HRESULT STDMETHODCALLTYPE SetData(FORMATETC* pformat, STGMEDIUM*pmedium, BOOL release);
- virtual HRESULT STDMETHODCALLTYPE EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC** ppenumFormatEtc);
- virtual HRESULT STDMETHODCALLTYPE DAdvise(FORMATETC*, DWORD, IAdviseSink*, DWORD*);
- virtual HRESULT STDMETHODCALLTYPE DUnadvise(DWORD);
- virtual HRESULT STDMETHODCALLTYPE EnumDAdvise(IEnumSTATDATA**);
-
- void clearData(CLIPFORMAT);
-
- static HRESULT createInstance(WCDataObject**);
-private:
- WCDataObject();
- virtual ~WCDataObject();
- long m_ref;
- Vector<FORMATETC*> m_formats;
- Vector<STGMEDIUM*> m_medium;
-};
-
-}
-
-#endif //!WCDataObject_h