Home | History | Annotate | Download | only in chromium
      1 // Copyright (c) 2008, Google Inc.
      2 // All rights reserved.
      3 //
      4 // Redistribution and use in source and binary forms, with or without
      5 // modification, are permitted provided that the following conditions are
      6 // met:
      7 //
      8 //     * Redistributions of source code must retain the above copyright
      9 // notice, this list of conditions and the following disclaimer.
     10 //     * Redistributions in binary form must reproduce the above
     11 // copyright notice, this list of conditions and the following disclaimer
     12 // in the documentation and/or other materials provided with the
     13 // distribution.
     14 //     * Neither the name of Google Inc. nor the names of its
     15 // contributors may be used to endorse or promote products derived from
     16 // this software without specific prior written permission.
     17 //
     18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 
     30 #ifndef ClipboardChromium_h
     31 #define ClipboardChromium_h
     32 
     33 #include "core/dom/Clipboard.h"
     34 #include "core/dom/DataTransferItem.h"
     35 #include "core/loader/cache/ImageResourceClient.h"
     36 #include "core/platform/chromium/ChromiumDataObject.h"
     37 
     38 namespace WebCore {
     39 
     40 class ImageResource;
     41     class ChromiumDataObjectItem;
     42     class ClipboardChromium;
     43     class Frame;
     44     class IntPoint;
     45 
     46     // A wrapper class that invalidates a DataTransferItem when the associated Clipboard object goes out of scope.
     47     class DataTransferItemPolicyWrapper : public DataTransferItem {
     48     public:
     49         static PassRefPtr<DataTransferItemPolicyWrapper> create(PassRefPtr<ClipboardChromium>, PassRefPtr<ChromiumDataObjectItem>);
     50         virtual ~DataTransferItemPolicyWrapper();
     51 
     52         virtual String kind() const OVERRIDE;
     53         virtual String type() const OVERRIDE;
     54         virtual void getAsString(PassRefPtr<StringCallback>) const OVERRIDE;
     55         virtual PassRefPtr<Blob> getAsFile() const OVERRIDE;
     56 
     57         ClipboardChromium* clipboard() { return m_clipboard.get(); }
     58         ChromiumDataObjectItem* dataObjectItem() { return m_item.get(); }
     59 
     60     private:
     61         DataTransferItemPolicyWrapper(PassRefPtr<ClipboardChromium>, PassRefPtr<ChromiumDataObjectItem>);
     62 
     63         RefPtr<ClipboardChromium> m_clipboard;
     64         RefPtr<ChromiumDataObjectItem> m_item;
     65     };
     66 
     67     class ClipboardChromium : public Clipboard, public ImageResourceClient {
     68         WTF_MAKE_FAST_ALLOCATED;
     69     public:
     70         ~ClipboardChromium();
     71 
     72         static PassRefPtr<ClipboardChromium> create(
     73             ClipboardType, PassRefPtr<ChromiumDataObject>, ClipboardAccessPolicy, Frame*);
     74 
     75         // Validates a filename (without the extension) and the extension. This removes any invalid
     76         // file system characters as well as making sure the path + extension is not bigger than
     77         // allowed by the file system.
     78         static void validateFilename(String& name, String& extension);
     79 
     80         virtual void clearData(const String& type);
     81         void clearAllData();
     82         String getData(const String& type) const;
     83         bool setData(const String& type, const String& data);
     84         bool platformClipboardChanged() const;
     85 
     86         // extensions beyond IE's API
     87         virtual ListHashSet<String> types() const;
     88         virtual PassRefPtr<FileList> files() const;
     89 
     90         void setDragImage(ImageResource*, const IntPoint&);
     91         void setDragImageElement(Node*, const IntPoint&);
     92 
     93         PassRefPtr<ChromiumDataObject> dataObject()
     94         {
     95             return m_dataObject;
     96         }
     97 
     98         virtual PassOwnPtr<DragImage> createDragImage(IntPoint& dragLoc) const;
     99         virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*);
    100         virtual void writeURL(const KURL&, const String&, Frame*);
    101         virtual void writeRange(Range*, Frame*);
    102         virtual void writePlainText(const String&);
    103 
    104         virtual bool hasData();
    105 
    106         virtual PassRefPtr<DataTransferItemList> items();
    107         Frame* frame() const { return m_frame; }
    108 
    109     private:
    110         ClipboardChromium(ClipboardType, PassRefPtr<ChromiumDataObject>, ClipboardAccessPolicy, Frame*);
    111 
    112         void resetFromClipboard();
    113         void setDragImage(ImageResource*, Node*, const IntPoint&);
    114         RefPtr<ChromiumDataObject> m_dataObject;
    115         Frame* m_frame;
    116     };
    117 
    118 } // namespace WebCore
    119 
    120 #endif // ClipboardChromium_h
    121