• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2008, 2009, 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 ChromiumDataObject_h
32 #define ChromiumDataObject_h
33 
34 #include "Clipboard.h"
35 #include "KURL.h"
36 #include "PlatformString.h"
37 #include "SharedBuffer.h"
38 #include <wtf/HashSet.h>
39 #include <wtf/RefPtr.h>
40 #include <wtf/Vector.h>
41 #include <wtf/text/StringHash.h>
42 
43 namespace WebCore {
44 
45 // A data object for holding data that would be in a clipboard or moved
46 // during a drag-n-drop operation.  This is the data that WebCore is aware
47 // of and is not specific to a platform.
48 class ChromiumDataObject : public RefCounted<ChromiumDataObject> {
49 public:
create(Clipboard::ClipboardType clipboardType)50     static PassRefPtr<ChromiumDataObject> create(Clipboard::ClipboardType clipboardType)
51     {
52         return adoptRef(new ChromiumDataObject(clipboardType));
53     }
54 
copy()55     PassRefPtr<ChromiumDataObject> copy() const
56     {
57         return adoptRef(new ChromiumDataObject(*this));
58     }
59 
60     void clearData(const String& type);
61     void clearAll();
62     void clearAllExceptFiles();
63 
64     bool hasData() const;
65 
66     HashSet<String> types() const;
67     String getData(const String& type, bool& success);
68     bool setData(const String& type, const String& data);
69 
70     // Special handlers for URL/HTML metadata.
urlTitle()71     String urlTitle() const { return m_urlTitle; }
setUrlTitle(const String & urlTitle)72     void setUrlTitle(const String& urlTitle) { m_urlTitle = urlTitle; }
htmlBaseUrl()73     KURL htmlBaseUrl() const { return m_htmlBaseUrl; }
setHtmlBaseUrl(const KURL & url)74     void setHtmlBaseUrl(const KURL& url) { m_htmlBaseUrl = url; }
75 
76     // Used to handle files being dragged in.
77     bool containsFilenames() const;
filenames()78     Vector<String> filenames() const { return m_filenames; }
setFilenames(const Vector<String> & filenames)79     void setFilenames(const Vector<String>& filenames) { m_filenames = filenames; }
80 
81     // Used to handle files (images) being dragged out.
fileExtension()82     String fileExtension() const { return m_fileExtension; }
setFileExtension(const String & fileExtension)83     void setFileExtension(const String& fileExtension) { m_fileExtension = fileExtension; }
fileContentFilename()84     String fileContentFilename() const { return m_fileContentFilename; }
setFileContentFilename(const String & fileContentFilename)85     void setFileContentFilename(const String& fileContentFilename) { m_fileContentFilename = fileContentFilename; }
fileContent()86     PassRefPtr<SharedBuffer> fileContent() const { return m_fileContent; }
setFileContent(PassRefPtr<SharedBuffer> fileContent)87     void setFileContent(PassRefPtr<SharedBuffer> fileContent) { m_fileContent = fileContent; }
88 
89 private:
90     ChromiumDataObject(Clipboard::ClipboardType);
91     ChromiumDataObject(const ChromiumDataObject&);
92 
93     Clipboard::ClipboardType m_clipboardType;
94 
95     String m_urlTitle;
96 
97     String m_downloadMetadata;
98 
99     String m_fileExtension;
100     Vector<String> m_filenames;
101 
102     String m_plainText;
103 
104     String m_textHtml;
105     KURL m_htmlBaseUrl;
106 
107     String m_fileContentFilename;
108     RefPtr<SharedBuffer> m_fileContent;
109 
110     // These two are linked. Setting m_url will set m_uriList to the same
111     // string value; setting m_uriList will cause its contents to be parsed
112     // according to RFC 2483 and the first URL found will be set in m_url.
113     KURL m_url;
114     String m_uriList;
115 };
116 
117 } // namespace WebCore
118 
119 #endif
120 
121