- Revision
- 149981
- Author
- [email protected]
- Date
- 2013-05-12 21:44:46 -0700 (Sun, 12 May 2013)
Log Message
[Mac] Move getData from ClipboardMac to PasteboardMac
https://bugs.webkit.org/show_bug.cgi?id=116005
Reviewed by Anders Carlsson.
* dom/Clipboard.cpp:
(WebCore::Clipboard::Clipboard): Added a new boolean argument, forFileDrag,
to the constructor. Maybe we can find a better way to do this once we move
all the platforms over, but this boolean seems a good way to do it for now.
(WebCore::Clipboard::getData): Added. Calls through to Pasteboard after
doing the canReadData check, which is part of DOM rules, not the platform.
Also checks for the file drag case like the old ClipboardMac code did.
* dom/Clipboard.h: Made getData non-virtual in non-legacy case.
* platform/Pasteboard.h: Added a static member function named
absoluteURLsFromPasteboardFilenames, temporary so it can be shared between
ClipboardMac and PasteboardMac. Added a readString public function member,
and a m_changeCount data member. The type of m_changeCount is long since
that can always hold an NSInteger but yet is a type we can compile without
including the header file that defines NSInteger.
* platform/mac/ClipboardMac.h: Removed getData.
* platform/mac/ClipboardMac.mm: Removed getData.
(WebCore::ClipboardMac::ClipboardMac): Added code to pass in the new
forFileDrag boolean.
(WebCore::ClipboardMac::files): Call absoluteURLsFromPasteboardFilenames
as a static member function in Pasteboard since we moved it there.
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::Pasteboard): Initialize the change count, so later
pasteboard operations can check it.
(WebCore::Pasteboard::absoluteURLsFromPasteboardFilenames): Added. Moved
here from ClipboardMac.
(WebCore::absoluteURLsFromPasteboard): Ditto.
(WebCore::Pasteboard::readString): Added. Moved here from ClipboardMac.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (149980 => 149981)
--- trunk/Source/WebCore/ChangeLog 2013-05-13 04:24:20 UTC (rev 149980)
+++ trunk/Source/WebCore/ChangeLog 2013-05-13 04:44:46 UTC (rev 149981)
@@ -1,3 +1,42 @@
+2013-05-12 Darin Adler <[email protected]>
+
+ [Mac] Move getData from ClipboardMac to PasteboardMac
+ https://bugs.webkit.org/show_bug.cgi?id=116005
+
+ Reviewed by Anders Carlsson.
+
+ * dom/Clipboard.cpp:
+ (WebCore::Clipboard::Clipboard): Added a new boolean argument, forFileDrag,
+ to the constructor. Maybe we can find a better way to do this once we move
+ all the platforms over, but this boolean seems a good way to do it for now.
+ (WebCore::Clipboard::getData): Added. Calls through to Pasteboard after
+ doing the canReadData check, which is part of DOM rules, not the platform.
+ Also checks for the file drag case like the old ClipboardMac code did.
+
+ * dom/Clipboard.h: Made getData non-virtual in non-legacy case.
+
+ * platform/Pasteboard.h: Added a static member function named
+ absoluteURLsFromPasteboardFilenames, temporary so it can be shared between
+ ClipboardMac and PasteboardMac. Added a readString public function member,
+ and a m_changeCount data member. The type of m_changeCount is long since
+ that can always hold an NSInteger but yet is a type we can compile without
+ including the header file that defines NSInteger.
+
+ * platform/mac/ClipboardMac.h: Removed getData.
+ * platform/mac/ClipboardMac.mm: Removed getData.
+ (WebCore::ClipboardMac::ClipboardMac): Added code to pass in the new
+ forFileDrag boolean.
+ (WebCore::ClipboardMac::files): Call absoluteURLsFromPasteboardFilenames
+ as a static member function in Pasteboard since we moved it there.
+
+ * platform/mac/PasteboardMac.mm:
+ (WebCore::Pasteboard::Pasteboard): Initialize the change count, so later
+ pasteboard operations can check it.
+ (WebCore::Pasteboard::absoluteURLsFromPasteboardFilenames): Added. Moved
+ here from ClipboardMac.
+ (WebCore::absoluteURLsFromPasteboard): Ditto.
+ (WebCore::Pasteboard::readString): Added. Moved here from ClipboardMac.
+
2013-05-12 Anders Carlsson <[email protected]>
Stop including UnusedParam.h
Modified: trunk/Source/WebCore/dom/Clipboard.cpp (149980 => 149981)
--- trunk/Source/WebCore/dom/Clipboard.cpp 2013-05-13 04:24:20 UTC (rev 149980)
+++ trunk/Source/WebCore/dom/Clipboard.cpp 2013-05-13 04:44:46 UTC (rev 149981)
@@ -36,7 +36,7 @@
Clipboard::Clipboard(ClipboardAccessPolicy policy, ClipboardType clipboardType
#if !USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS)
- , PassOwnPtr<Pasteboard> pasteboard
+ , PassOwnPtr<Pasteboard> pasteboard, bool forFileDrag
#endif
)
: m_policy(policy)
@@ -46,6 +46,7 @@
, m_clipboardType(clipboardType)
#if !USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS)
, m_pasteboard(pasteboard)
+ , m_forFileDrag(forFileDrag)
#endif
{
}
@@ -274,6 +275,14 @@
m_pasteboard->clear();
}
+String Clipboard::getData(const String& type) const
+{
+ if (!canReadData() || m_forFileDrag)
+ return String();
+
+ return m_pasteboard->readString(type);
+}
+
#endif
} // namespace WebCore
Modified: trunk/Source/WebCore/dom/Clipboard.h (149980 => 149981)
--- trunk/Source/WebCore/dom/Clipboard.h 2013-05-13 04:24:20 UTC (rev 149980)
+++ trunk/Source/WebCore/dom/Clipboard.h 2013-05-13 04:44:46 UTC (rev 149981)
@@ -81,7 +81,7 @@
LEGACY_VIRTUAL void clearData(const String& type) LEGACY_PURE;
LEGACY_VIRTUAL void clearAllData() LEGACY_PURE;
- virtual String getData(const String& type) const = 0;
+ LEGACY_VIRTUAL String getData(const String& type) const LEGACY_PURE;
virtual bool setData(const String& type, const String& data) = 0;
// extensions beyond IE's API
@@ -129,7 +129,7 @@
protected:
#if !USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS)
- Clipboard(ClipboardAccessPolicy, ClipboardType, PassOwnPtr<Pasteboard>);
+ Clipboard(ClipboardAccessPolicy, ClipboardType, PassOwnPtr<Pasteboard>, bool forFileDrag);
#else
Clipboard(ClipboardAccessPolicy, ClipboardType);
#endif
@@ -155,6 +155,7 @@
#if !USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS)
private:
OwnPtr<Pasteboard> m_pasteboard;
+ bool m_forFileDrag;
#endif
};
Modified: trunk/Source/WebCore/platform/Pasteboard.h (149980 => 149981)
--- trunk/Source/WebCore/platform/Pasteboard.h 2013-05-13 04:24:20 UTC (rev 149980)
+++ trunk/Source/WebCore/platform/Pasteboard.h 2013-05-13 04:44:46 UTC (rev 149981)
@@ -94,12 +94,15 @@
// Functions needed temporarily until all code from ClipboardMac is moved to PasteboardMac.
static String cocoaTypeFromHTMLClipboardType(const String& type);
+ static Vector<String> absoluteURLsFromPasteboardFilenames(const String& pasteboardName, bool _onlyFirstURL_ = false);
#endif
static Pasteboard* generalPasteboard();
bool hasData();
+ String readString(const String& type);
+
void writeSelection(Range*, bool canSmartCopyOrDelete, Frame*, ShouldSerializeSelectedTextForClipboard = DefaultSelectedTextType);
void writePlainText(const String&, SmartReplaceOption);
void writeURL(const KURL&, const String&, Frame* = 0);
@@ -133,6 +136,7 @@
#if PLATFORM(MAC)
String m_pasteboardName;
+ long m_changeCount;
#endif
#if PLATFORM(WIN)
Modified: trunk/Source/WebCore/platform/mac/ClipboardMac.h (149980 => 149981)
--- trunk/Source/WebCore/platform/mac/ClipboardMac.h 2013-05-13 04:24:20 UTC (rev 149980)
+++ trunk/Source/WebCore/platform/mac/ClipboardMac.h 2013-05-13 04:44:46 UTC (rev 149981)
@@ -53,7 +53,6 @@
virtual ~ClipboardMac();
- String getData(const String& type) const;
bool setData(const String& type, const String& data);
// extensions beyond IE's API
Modified: trunk/Source/WebCore/platform/mac/ClipboardMac.mm (149980 => 149981)
--- trunk/Source/WebCore/platform/mac/ClipboardMac.mm 2013-05-13 04:24:20 UTC (rev 149980)
+++ trunk/Source/WebCore/platform/mac/ClipboardMac.mm 2013-05-13 04:44:46 UTC (rev 149981)
@@ -56,7 +56,7 @@
#endif
ClipboardMac::ClipboardMac(ClipboardType clipboardType, const String& pasteboardName, ClipboardAccessPolicy policy, ClipboardContents clipboardContents, Frame *frame)
- : Clipboard(policy, clipboardType, Pasteboard::create(pasteboardName))
+ : Clipboard(policy, clipboardType, Pasteboard::create(pasteboardName), clipboardContents == DragAndDropFiles)
, m_pasteboardName(pasteboardName)
, m_clipboardContents(clipboardContents)
, m_frame(frame)
@@ -113,77 +113,6 @@
resultTypes.add(cocoaType);
}
-static Vector<String> absoluteURLsFromPasteboardFilenames(const String& pasteboardName, bool _onlyFirstURL_ = false)
-{
- Vector<String> fileList;
- platformStrategies()->pasteboardStrategy()->getPathnamesForType(fileList, String(NSFilenamesPboardType), pasteboardName);
-
- if (fileList.isEmpty())
- return fileList;
-
- size_t count = onlyFirstURL ? 1 : fileList.size();
- Vector<String> urls;
- for (size_t i = 0; i < count; i++) {
- NSURL *url = "" fileURLWithPath:fileList[i]];
- urls.append(String([url absoluteString]));
- }
- return urls;
-}
-
-static Vector<String> absoluteURLsFromPasteboard(const String& pasteboardName, bool _onlyFirstURL_ = false)
-{
- // NOTE: We must always check [availableTypes containsObject:] before accessing pasteboard data
- // or CoreFoundation will printf when there is not data of the corresponding type.
- Vector<String> availableTypes;
- Vector<String> absoluteURLs;
- platformStrategies()->pasteboardStrategy()->getTypes(availableTypes, pasteboardName);
-
- // Try NSFilenamesPboardType because it contains a list
- if (availableTypes.contains(String(NSFilenamesPboardType))) {
- absoluteURLs = absoluteURLsFromPasteboardFilenames(pasteboardName, onlyFirstURL);
- if (!absoluteURLs.isEmpty())
- return absoluteURLs;
- }
-
- // Fallback to NSURLPboardType (which is a single URL)
- if (availableTypes.contains(String(NSURLPboardType))) {
- absoluteURLs.append(platformStrategies()->pasteboardStrategy()->stringForType(String(NSURLPboardType), pasteboardName));
- return absoluteURLs;
- }
-
- // No file paths on the pasteboard, return nil
- return Vector<String>();
-}
-
-String ClipboardMac::getData(const String& type) const
-{
- if (!canReadData() || m_clipboardContents == DragAndDropFiles)
- return String();
-
- const String& cocoaType = Pasteboard::cocoaTypeFromHTMLClipboardType(type);
- String cocoaValue;
-
- // Grab the value off the pasteboard corresponding to the cocoaType
- if (cocoaType == String(NSURLPboardType)) {
- // "url" and "text/url-list" both map to NSURLPboardType in cocoaTypeFromHTMLClipboardType(), "url" only wants the first URL
- bool _onlyFirstURL_ = (equalIgnoringCase(type, "url"));
- Vector<String> absoluteURLs = absoluteURLsFromPasteboard(m_pasteboardName, onlyFirstURL);
- for (size_t i = 0; i < absoluteURLs.size(); i++)
- cocoaValue = i ? "\n" + absoluteURLs[i]: absoluteURLs[i];
- } else if (cocoaType == String(NSStringPboardType))
- cocoaValue = [platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, m_pasteboardName) precomposedStringWithCanonicalMapping];
- else if (!cocoaType.isEmpty())
- cocoaValue = platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, m_pasteboardName);
-
- // Enforce changeCount ourselves for security. We check after reading instead of before to be
- // sure it doesn't change between our testing the change count and accessing the data.
- if (!cocoaValue.isEmpty() && m_changeCount == platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName)) {
- return cocoaValue;
- }
-
- return String();
-}
-
bool ClipboardMac::setData(const String &type, const String &data)
{
if (!canWriteData() || m_clipboardContents == DragAndDropFiles)
@@ -252,7 +181,7 @@
if (!canReadData() || m_clipboardContents == DragAndDropData)
return FileList::create();
- Vector<String> absoluteURLs = absoluteURLsFromPasteboardFilenames(m_pasteboardName);
+ Vector<String> absoluteURLs = Pasteboard::absoluteURLsFromPasteboardFilenames(m_pasteboardName);
RefPtr<FileList> fileList = FileList::create();
for (size_t i = 0; i < absoluteURLs.size(); i++) {
Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (149980 => 149981)
--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm 2013-05-13 04:24:20 UTC (rev 149980)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm 2013-05-13 04:44:46 UTC (rev 149981)
@@ -125,6 +125,7 @@
Pasteboard::Pasteboard(const String& pasteboardName)
: m_pasteboardName(pasteboardName)
+ , m_changeCount(platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
{
ASSERT(pasteboardName);
}
@@ -635,4 +636,71 @@
platformStrategies()->pasteboardStrategy()->setStringForType("", cocoaType, m_pasteboardName);
}
+Vector<String> Pasteboard::absoluteURLsFromPasteboardFilenames(const String& pasteboardName, bool onlyFirstURL)
+{
+ Vector<String> fileList;
+ platformStrategies()->pasteboardStrategy()->getPathnamesForType(fileList, String(NSFilenamesPboardType), pasteboardName);
+
+ if (fileList.isEmpty())
+ return fileList;
+
+ size_t count = onlyFirstURL ? 1 : fileList.size();
+ Vector<String> urls;
+ for (size_t i = 0; i < count; i++) {
+ NSURL *url = "" fileURLWithPath:fileList[i]];
+ urls.append(String([url absoluteString]));
+ }
+ return urls;
}
+
+static Vector<String> absoluteURLsFromPasteboard(const String& pasteboardName, bool _onlyFirstURL_ = false)
+{
+ // NOTE: We must always check [availableTypes containsObject:] before accessing pasteboard data
+ // or CoreFoundation will printf when there is not data of the corresponding type.
+ Vector<String> availableTypes;
+ Vector<String> absoluteURLs;
+ platformStrategies()->pasteboardStrategy()->getTypes(availableTypes, pasteboardName);
+
+ // Try NSFilenamesPboardType because it contains a list
+ if (availableTypes.contains(String(NSFilenamesPboardType))) {
+ absoluteURLs = Pasteboard::absoluteURLsFromPasteboardFilenames(pasteboardName, onlyFirstURL);
+ if (!absoluteURLs.isEmpty())
+ return absoluteURLs;
+ }
+
+ // Fallback to NSURLPboardType (which is a single URL)
+ if (availableTypes.contains(String(NSURLPboardType))) {
+ absoluteURLs.append(platformStrategies()->pasteboardStrategy()->stringForType(String(NSURLPboardType), pasteboardName));
+ return absoluteURLs;
+ }
+
+ // No file paths on the pasteboard, return nil
+ return Vector<String>();
+}
+
+String Pasteboard::readString(const String& type)
+{
+ const String& cocoaType = Pasteboard::cocoaTypeFromHTMLClipboardType(type);
+ String cocoaValue;
+
+ // Grab the value off the pasteboard corresponding to the cocoaType
+ if (cocoaType == String(NSURLPboardType)) {
+ // "url" and "text/url-list" both map to NSURLPboardType in cocoaTypeFromHTMLClipboardType(), "url" only wants the first URL
+ bool _onlyFirstURL_ = (equalIgnoringCase(type, "url"));
+ Vector<String> absoluteURLs = absoluteURLsFromPasteboard(m_pasteboardName, onlyFirstURL);
+ for (size_t i = 0; i < absoluteURLs.size(); i++)
+ cocoaValue = i ? "\n" + absoluteURLs[i]: absoluteURLs[i];
+ } else if (cocoaType == String(NSStringPboardType))
+ cocoaValue = [platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, m_pasteboardName) precomposedStringWithCanonicalMapping];
+ else if (!cocoaType.isEmpty())
+ cocoaValue = platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, m_pasteboardName);
+
+ // Enforce changeCount ourselves for security. We check after reading instead of before to be
+ // sure it doesn't change between our testing the change count and accessing the data.
+ if (!cocoaValue.isEmpty() && m_changeCount == platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
+ return cocoaValue;
+
+ return String();
+}
+
+}