• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2010 Google Inc. 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 
31 #ifndef WritableDataObject_h
32 #define WritableDataObject_h
33 
34 #include "Clipboard.h"
35 #include "KURL.h"
36 #include "PlatformString.h"
37 #include "SharedBuffer.h"
38 #include <wtf/HashMap.h>
39 #include <wtf/RefCounted.h>
40 #include <wtf/RefPtr.h>
41 #include <wtf/text/StringHash.h>
42 
43 namespace WebCore {
44 
45 // Used for one way communication of drag/drop and copy/paste data from the
46 // renderer to the browser. This is intenteded to be used in dragstart/copy/cut
47 // events. Due to shortcomings, writes to the pasteboard cannot be performed
48 // atomically.
49 class WritableDataObject : public RefCounted<WritableDataObject> {
50 public:
51     static PassRefPtr<WritableDataObject> create(Clipboard::ClipboardType);
52 
53     void clearData(const String& type);
54     void clearAllExceptFiles();
55     void clearAll();
56     bool setData(const String& type, const String& data);
57 
setUrlTitle(const String & title)58     void setUrlTitle(const String& title) { m_urlTitle = title; }
setHtmlBaseUrl(const KURL & baseURL)59     void setHtmlBaseUrl(const KURL& baseURL) { m_htmlBaseURL = baseURL; }
60 
61     // Used for transferring drag data from the renderer to the browser.
dataMap()62     HashMap<String, String> dataMap() const { return m_dataMap; }
urlTitle()63     String urlTitle() const { return m_urlTitle; }
htmlBaseURL()64     KURL htmlBaseURL() const { return m_htmlBaseURL; }
65 
fileExtension()66     String fileExtension() const { return m_fileExtension; }
fileContentFilename()67     String fileContentFilename() const { return m_fileContentFilename; }
fileContent()68     PassRefPtr<SharedBuffer> fileContent() const { return m_fileContent; }
setFileExtension(const String & fileExtension)69     void setFileExtension(const String& fileExtension) { m_fileExtension = fileExtension; }
setFileContentFilename(const String & fileContentFilename)70     void setFileContentFilename(const String& fileContentFilename) { m_fileContentFilename = fileContentFilename; }
setFileContent(PassRefPtr<SharedBuffer> fileContent)71     void setFileContent(PassRefPtr<SharedBuffer> fileContent) { m_fileContent = fileContent; }
72 
73 private:
74     explicit WritableDataObject(Clipboard::ClipboardType);
75 
76     Clipboard::ClipboardType m_clipboardType;
77 
78     HashMap<String, String> m_dataMap;
79     String m_urlTitle;
80     KURL m_htmlBaseURL;
81     String m_fileExtension;
82     String m_fileContentFilename;
83     RefPtr<SharedBuffer> m_fileContent;
84 };
85 
86 } // namespace WebCore
87 
88 #endif
89