Title: [149985] trunk/Source/WebCore
Revision
149985
Author
[email protected]
Date
2013-05-12 22:35:20 -0700 (Sun, 12 May 2013)

Log Message

[Mac] Moved files function from ClipboardMac to PasteboardMac
https://bugs.webkit.org/show_bug.cgi?id=116008

Reviewed by Anders Carlsson.

* dom/Clipboard.cpp:
(WebCore::Clipboard::files): Added. Moved the DOM-depdendent and
platform-independent part of the files function in ClipboardMac here.

* dom/Clipboard.h: Made files function non-virtual in non-legacy case.

* platform/Pasteboard.h: Removed static member function
absoluteURLsFromPasteboardFilenames since it can now be private to
PasteboardMac. Added member function readFilenames.

* platform/mac/ClipboardMac.h: Removed function member files and also
now-unused data member m_clipboardContents.

* platform/mac/ClipboardMac.mm: Removed files function.
(WebCore::ClipboardMac::ClipboardMac): Removed code to initialize
m_clipboardContents.

* platform/mac/PasteboardMac.mm:
(WebCore::absoluteURLsFromPasteboardFilenames): Changed from a static
member function to a file-local function.
(WebCore::absoluteURLsFromPasteboard): Changed to call the function
above in its new location.
(WebCore::Pasteboard::readFilenames): Added. Code from ClipboardMac,
minus the DOM-specific parts. Added a FIXME about the peculiar round
trip through NSURL this code takes.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149984 => 149985)


--- trunk/Source/WebCore/ChangeLog	2013-05-13 05:32:57 UTC (rev 149984)
+++ trunk/Source/WebCore/ChangeLog	2013-05-13 05:35:20 UTC (rev 149985)
@@ -1,3 +1,36 @@
+2013-05-12  Darin Adler  <[email protected]>
+
+        [Mac] Moved files function from ClipboardMac to PasteboardMac
+        https://bugs.webkit.org/show_bug.cgi?id=116008
+
+        Reviewed by Anders Carlsson.
+
+        * dom/Clipboard.cpp:
+        (WebCore::Clipboard::files): Added. Moved the DOM-depdendent and
+        platform-independent part of the files function in ClipboardMac here.
+
+        * dom/Clipboard.h: Made files function non-virtual in non-legacy case.
+
+        * platform/Pasteboard.h: Removed static member function
+        absoluteURLsFromPasteboardFilenames since it can now be private to
+        PasteboardMac. Added member function readFilenames.
+
+        * platform/mac/ClipboardMac.h: Removed function member files and also
+        now-unused data member m_clipboardContents.
+
+        * platform/mac/ClipboardMac.mm: Removed files function.
+        (WebCore::ClipboardMac::ClipboardMac): Removed code to initialize
+        m_clipboardContents.
+
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::absoluteURLsFromPasteboardFilenames): Changed from a static
+        member function to a file-local function.
+        (WebCore::absoluteURLsFromPasteboard): Changed to call the function
+        above in its new location.
+        (WebCore::Pasteboard::readFilenames): Added. Code from ClipboardMac,
+        minus the DOM-specific parts. Added a FIXME about the peculiar round
+        trip through NSURL this code takes.
+
 2013-05-12  Anders Carlsson  <[email protected]>
 
         Fix WebKit2 build.

Modified: trunk/Source/WebCore/dom/Clipboard.cpp (149984 => 149985)


--- trunk/Source/WebCore/dom/Clipboard.cpp	2013-05-13 05:32:57 UTC (rev 149984)
+++ trunk/Source/WebCore/dom/Clipboard.cpp	2013-05-13 05:35:20 UTC (rev 149985)
@@ -299,6 +299,21 @@
     return m_pasteboard->types();
 }
 
+// FIXME: We could cache the computed fileList if necessary
+// Currently each access gets a new copy, setData() modifications to the
+// clipboard are not reflected in any FileList objects the page has accessed and stored
+PassRefPtr<FileList> Clipboard::files() const
+{
+    if (!canReadData() || (m_clipboardType == DragAndDrop && !m_forFileDrag))
+        return FileList::create();
+
+    Vector<String> filenames = m_pasteboard->readFilenames();
+    RefPtr<FileList> fileList = FileList::create();
+    for (size_t i = 0; i < filenames.size(); ++i)
+        fileList->append(File::create(filenames[i], File::AllContentTypes));
+    return fileList.release();
+}
+
 #endif
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/Clipboard.h (149984 => 149985)


--- trunk/Source/WebCore/dom/Clipboard.h	2013-05-13 05:32:57 UTC (rev 149984)
+++ trunk/Source/WebCore/dom/Clipboard.h	2013-05-13 05:35:20 UTC (rev 149985)
@@ -85,7 +85,7 @@
         LEGACY_VIRTUAL bool setData(const String& type, const String& data) LEGACY_PURE;
     
         LEGACY_VIRTUAL ListHashSet<String> types() const LEGACY_PURE;
-        virtual PassRefPtr<FileList> files() const = 0;
+        LEGACY_VIRTUAL PassRefPtr<FileList> files() const LEGACY_PURE;
 
         IntPoint dragLocation() const { return m_dragLoc; }
         CachedImage* dragImage() const { return m_dragImage.get(); }

Modified: trunk/Source/WebCore/platform/Pasteboard.h (149984 => 149985)


--- trunk/Source/WebCore/platform/Pasteboard.h	2013-05-13 05:32:57 UTC (rev 149984)
+++ trunk/Source/WebCore/platform/Pasteboard.h	2013-05-13 05:35:20 UTC (rev 149985)
@@ -87,9 +87,6 @@
     explicit Pasteboard(const String& pasteboardName);
     static String getStringSelection(Frame*, ShouldSerializeSelectedTextForClipboard);
     static PassRefPtr<SharedBuffer> getDataSelection(Frame*, const String& pasteboardType);
-
-    // Functions needed temporarily until all code from ClipboardMac is moved to PasteboardMac.
-    static Vector<String> absoluteURLsFromPasteboardFilenames(const String& pasteboardName, bool _onlyFirstURL_ = false);
 #endif
     
     static Pasteboard* generalPasteboard();
@@ -98,6 +95,7 @@
     ListHashSet<String> types();
 
     String readString(const String& type);
+    Vector<String> readFilenames();
 
     bool writeString(const String& type, const String& data);
     void writeSelection(Range*, bool canSmartCopyOrDelete, Frame*, ShouldSerializeSelectedTextForClipboard = DefaultSelectedTextType);

Modified: trunk/Source/WebCore/platform/mac/ClipboardMac.h (149984 => 149985)


--- trunk/Source/WebCore/platform/mac/ClipboardMac.h	2013-05-13 05:32:57 UTC (rev 149984)
+++ trunk/Source/WebCore/platform/mac/ClipboardMac.h	2013-05-13 05:35:20 UTC (rev 149985)
@@ -52,8 +52,6 @@
     }
 
     virtual ~ClipboardMac();
-    
-    virtual PassRefPtr<FileList> files() const;
 
     void setDragImage(CachedImage*, const IntPoint&);
     void setDragImageElement(Node *, const IntPoint&);
@@ -77,7 +75,6 @@
 
     String m_pasteboardName;
     int m_changeCount;
-    ClipboardContents m_clipboardContents;
     Frame* m_frame; // used on the source side to generate dragging images
 };
 

Modified: trunk/Source/WebCore/platform/mac/ClipboardMac.mm (149984 => 149985)


--- trunk/Source/WebCore/platform/mac/ClipboardMac.mm	2013-05-13 05:32:57 UTC (rev 149984)
+++ trunk/Source/WebCore/platform/mac/ClipboardMac.mm	2013-05-13 05:35:20 UTC (rev 149985)
@@ -58,7 +58,6 @@
 ClipboardMac::ClipboardMac(ClipboardType clipboardType, const String& pasteboardName, ClipboardAccessPolicy policy, ClipboardContents clipboardContents, Frame *frame)
     : Clipboard(policy, clipboardType, Pasteboard::create(pasteboardName), clipboardContents == DragAndDropFiles)
     , m_pasteboardName(pasteboardName)
-    , m_clipboardContents(clipboardContents)
     , m_frame(frame)
 {
     m_changeCount = platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName);
@@ -70,25 +69,6 @@
         m_dragImage->removeClient(this);
 }
 
-// FIXME: We could cache the computed fileList if necessary
-// Currently each access gets a new copy, setData() modifications to the
-// clipboard are not reflected in any FileList objects the page has accessed and stored
-PassRefPtr<FileList> ClipboardMac::files() const
-{
-    if (!canReadData() || m_clipboardContents == DragAndDropData)
-        return FileList::create();
-
-    Vector<String> absoluteURLs = Pasteboard::absoluteURLsFromPasteboardFilenames(m_pasteboardName);
-
-    RefPtr<FileList> fileList = FileList::create();
-    for (size_t i = 0; i < absoluteURLs.size(); i++) {
-        NSURL *absoluteURL = [NSURL URLWithString:absoluteURLs[i]];
-        ASSERT([absoluteURL isFileURL]);
-        fileList->append(File::create([absoluteURL path], File::AllContentTypes));
-    }
-    return fileList.release(); // We will always return a FileList, sometimes empty
-}
-
 // The rest of these getters don't really have any impact on security, so for now make no checks
 
 void ClipboardMac::setDragImage(CachedImage* img, const IntPoint &loc)

Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (149984 => 149985)


--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2013-05-13 05:32:57 UTC (rev 149984)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2013-05-13 05:35:20 UTC (rev 149985)
@@ -635,7 +635,7 @@
         platformStrategies()->pasteboardStrategy()->setStringForType("", cocoaType, m_pasteboardName);
 }
 
-Vector<String> Pasteboard::absoluteURLsFromPasteboardFilenames(const String& pasteboardName, bool onlyFirstURL)
+static Vector<String> absoluteURLsFromPasteboardFilenames(const String& pasteboardName, bool _onlyFirstURL_ = false)
 {
     Vector<String> fileList;
     platformStrategies()->pasteboardStrategy()->getPathnamesForType(fileList, String(NSFilenamesPboardType), pasteboardName);
@@ -662,7 +662,7 @@
 
     // Try NSFilenamesPboardType because it contains a list
     if (availableTypes.contains(String(NSFilenamesPboardType))) {
-        absoluteURLs = Pasteboard::absoluteURLsFromPasteboardFilenames(pasteboardName, onlyFirstURL);
+        absoluteURLs = absoluteURLsFromPasteboardFilenames(pasteboardName, onlyFirstURL);
         if (!absoluteURLs.isEmpty())
             return absoluteURLs;
     }
@@ -798,4 +798,18 @@
     return result;
 }
 
+Vector<String> Pasteboard::readFilenames()
+{
+    // FIXME: Seems silly to convert paths to URLs and then back to paths. Does that do anything helpful?
+    Vector<String> absoluteURLs = absoluteURLsFromPasteboardFilenames(m_pasteboardName);
+    Vector<String> paths;
+    paths.reserveCapacity(absoluteURLs.size());
+    for (size_t i = 0; i < absoluteURLs.size(); i++) {
+        NSURL *absoluteURL = [NSURL URLWithString:absoluteURLs[i]];
+        ASSERT([absoluteURL isFileURL]);
+        paths.uncheckedAppend([absoluteURL path]);
+    }
+    return paths;
 }
+
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to