| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_CLIPBOARD_H_ | 5 #ifndef BASE_CLIPBOARD_H_ |
| 6 #define BASE_CLIPBOARD_H_ | 6 #define BASE_CLIPBOARD_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // ObjectType maps to "text/plain", "STRING", and several other formats. On | 33 // ObjectType maps to "text/plain", "STRING", and several other formats. On |
| 34 // windows it maps to CF_UNICODETEXT. | 34 // windows it maps to CF_UNICODETEXT. |
| 35 enum ObjectType { | 35 enum ObjectType { |
| 36 CBF_TEXT, | 36 CBF_TEXT, |
| 37 CBF_HTML, | 37 CBF_HTML, |
| 38 CBF_BOOKMARK, | 38 CBF_BOOKMARK, |
| 39 CBF_LINK, | 39 CBF_LINK, |
| 40 CBF_FILES, | 40 CBF_FILES, |
| 41 CBF_WEBKIT, | 41 CBF_WEBKIT, |
| 42 CBF_BITMAP, | 42 CBF_BITMAP, |
| 43 CBF_SMBITMAP // bitmap from shared memory | 43 CBF_SMBITMAP, // Bitmap from shared memory. |
| 44 CBF_DATA, // Arbitrary block of bytes. |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 // ObjectMap is a map from ObjectType to associated data. | 47 // ObjectMap is a map from ObjectType to associated data. |
| 47 // The data is organized differently for each ObjectType. The following | 48 // The data is organized differently for each ObjectType. The following |
| 48 // table summarizes what kind of data is stored for each key. | 49 // table summarizes what kind of data is stored for each key. |
| 49 // * indicates an optional argument. | 50 // * indicates an optional argument. |
| 50 // | 51 // |
| 51 // Key Arguments Type | 52 // Key Arguments Type |
| 52 // ------------------------------------- | 53 // ------------------------------------- |
| 53 // CBF_TEXT text char array | 54 // CBF_TEXT text char array |
| 54 // CBF_HTML html char array | 55 // CBF_HTML html char array |
| 55 // url* char array | 56 // url* char array |
| 56 // CBF_BOOKMARK html char array | 57 // CBF_BOOKMARK html char array |
| 57 // url char array | 58 // url char array |
| 58 // CBF_LINK html char array | 59 // CBF_LINK html char array |
| 59 // url char array | 60 // url char array |
| 60 // CBF_FILES files char array representing multiple files. | 61 // CBF_FILES files char array representing multiple files. |
| 61 // Filenames are separated by null characters and | 62 // Filenames are separated by null characters and |
| 62 // the final filename is double null terminated. | 63 // the final filename is double null terminated. |
| 63 // The filenames are encoded in platform-specific | 64 // The filenames are encoded in platform-specific |
| 64 // encoding. | 65 // encoding. |
| 65 // CBF_WEBKIT none empty vector | 66 // CBF_WEBKIT none empty vector |
| 66 // CBF_BITMAP pixels byte array | 67 // CBF_BITMAP pixels byte array |
| 67 // size gfx::Size struct | 68 // size gfx::Size struct |
| 68 // CBF_SMBITMAP shared_mem shared memory handle | 69 // CBF_SMBITMAP shared_mem shared memory handle |
| 69 // size gfx::Size struct | 70 // size gfx::Size struct |
| 71 // CBF_DATA format char array |
| 72 // data byte array |
| 70 typedef std::vector<char> ObjectMapParam; | 73 typedef std::vector<char> ObjectMapParam; |
| 71 typedef std::vector<ObjectMapParam> ObjectMapParams; | 74 typedef std::vector<ObjectMapParam> ObjectMapParams; |
| 72 typedef std::map<int /* ObjectType */, ObjectMapParams> ObjectMap; | 75 typedef std::map<int /* ObjectType */, ObjectMapParams> ObjectMap; |
| 73 | 76 |
| 74 Clipboard(); | 77 Clipboard(); |
| 75 ~Clipboard(); | 78 ~Clipboard(); |
| 76 | 79 |
| 77 // Write a bunch of objects to the system clipboard. Copies are made of the | 80 // Write a bunch of objects to the system clipboard. Copies are made of the |
| 78 // contents of |objects|. On Windows they are copied to the system clipboard. | 81 // contents of |objects|. On Windows they are copied to the system clipboard. |
| 79 // On linux they are copied into a structure owned by the Clipboard object and | 82 // On linux they are copied into a structure owned by the Clipboard object and |
| 80 // kept until the system clipboard is set again. | 83 // kept until the system clipboard is set again. |
| 81 void WriteObjects(const ObjectMap& objects); | 84 void WriteObjects(const ObjectMap& objects); |
| 82 | 85 |
| 83 // Behaves as above. If there is some shared memory handle passed as one of | 86 // Behaves as above. If there is some shared memory handle passed as one of |
| 84 // the objects, it came from the process designated by |process|. This will | 87 // the objects, it came from the process designated by |process|. This will |
| 85 // assist in turning it into a shared memory region that the current process | 88 // assist in turning it into a shared memory region that the current process |
| 86 // can use. | 89 // can use. |
| 87 void WriteObjects(const ObjectMap& objects, base::ProcessHandle process); | 90 void WriteObjects(const ObjectMap& objects, base::ProcessHandle process); |
| 88 | 91 |
| 89 // Tests whether the clipboard contains a certain format | 92 // Tests whether the clipboard contains a certain format |
| 90 bool IsFormatAvailable(const FormatType& format) const; | 93 bool IsFormatAvailable(const FormatType& format) const; |
| 91 | 94 |
| 95 // As above, but instead of interpreting |format| by some platform-specific |
| 96 // definition, interpret it as a literal MIME type. |
| 97 bool IsFormatAvailableByString(const std::string& format) const; |
| 98 |
| 92 // Reads UNICODE text from the clipboard, if available. | 99 // Reads UNICODE text from the clipboard, if available. |
| 93 void ReadText(string16* result) const; | 100 void ReadText(string16* result) const; |
| 94 | 101 |
| 95 // Reads ASCII text from the clipboard, if available. | 102 // Reads ASCII text from the clipboard, if available. |
| 96 void ReadAsciiText(std::string* result) const; | 103 void ReadAsciiText(std::string* result) const; |
| 97 | 104 |
| 98 // Reads HTML from the clipboard, if available. | 105 // Reads HTML from the clipboard, if available. |
| 99 void ReadHTML(string16* markup, std::string* src_url) const; | 106 void ReadHTML(string16* markup, std::string* src_url) const; |
| 100 | 107 |
| 101 // Reads a bookmark from the clipboard, if available. | 108 // Reads a bookmark from the clipboard, if available. |
| 102 void ReadBookmark(string16* title, std::string* url) const; | 109 void ReadBookmark(string16* title, std::string* url) const; |
| 103 | 110 |
| 104 // Reads a file or group of files from the clipboard, if available, into the | 111 // Reads a file or group of files from the clipboard, if available, into the |
| 105 // out parameter. | 112 // out parameter. |
| 106 void ReadFile(FilePath* file) const; | 113 void ReadFile(FilePath* file) const; |
| 107 void ReadFiles(std::vector<FilePath>* files) const; | 114 void ReadFiles(std::vector<FilePath>* files) const; |
| 108 | 115 |
| 116 // Reads raw data from the clipboard with the given format type. Stores result |
| 117 // as a byte vector. |
| 118 void ReadData(const std::string& format, std::string* result); |
| 119 |
| 109 // Get format Identifiers for various types. | 120 // Get format Identifiers for various types. |
| 110 static FormatType GetUrlFormatType(); | 121 static FormatType GetUrlFormatType(); |
| 111 static FormatType GetUrlWFormatType(); | 122 static FormatType GetUrlWFormatType(); |
| 112 static FormatType GetMozUrlFormatType(); | 123 static FormatType GetMozUrlFormatType(); |
| 113 static FormatType GetPlainTextFormatType(); | 124 static FormatType GetPlainTextFormatType(); |
| 114 static FormatType GetPlainTextWFormatType(); | 125 static FormatType GetPlainTextWFormatType(); |
| 115 static FormatType GetFilenameFormatType(); | 126 static FormatType GetFilenameFormatType(); |
| 116 static FormatType GetFilenameWFormatType(); | 127 static FormatType GetFilenameWFormatType(); |
| 117 static FormatType GetWebKitSmartPasteFormatType(); | 128 static FormatType GetWebKitSmartPasteFormatType(); |
| 118 // Win: MS HTML Format, Other: Generic HTML format | 129 // Win: MS HTML Format, Other: Generic HTML format |
| 119 static FormatType GetHtmlFormatType(); | 130 static FormatType GetHtmlFormatType(); |
| 120 #if defined(OS_WIN) | 131 #if defined(OS_WIN) |
| 121 static FormatType GetBitmapFormatType(); | 132 static FormatType GetBitmapFormatType(); |
| 122 // Firefox text/html | 133 // Firefox text/html |
| 123 static FormatType GetTextHtmlFormatType(); | 134 static FormatType GetTextHtmlFormatType(); |
| 124 static FormatType GetCFHDropFormatType(); | 135 static FormatType GetCFHDropFormatType(); |
| 125 static FormatType GetFileDescriptorFormatType(); | 136 static FormatType GetFileDescriptorFormatType(); |
| 126 static FormatType GetFileContentFormatZeroType(); | 137 static FormatType GetFileContentFormatZeroType(); |
| 127 | 138 |
| 128 // Duplicates any remote shared memory handle embedded inside |objects| that | 139 // Duplicates any remote shared memory handle embedded inside |objects| that |
| 129 // was created by |process| so that it can be used by this process. | 140 // was created by |process| so that it can be used by this process. |
| 130 static void DuplicateRemoteHandles(base::ProcessHandle process, | 141 static void DuplicateRemoteHandles(base::ProcessHandle process, |
| 131 ObjectMap* objects); | 142 ObjectMap* objects); |
| 132 #endif | 143 #endif |
| 133 | 144 |
| 134 private: | 145 private: |
| 146 void DispatchObject(ObjectType type, const ObjectMapParams& params); |
| 147 |
| 135 void WriteText(const char* text_data, size_t text_len); | 148 void WriteText(const char* text_data, size_t text_len); |
| 136 | 149 |
| 137 void WriteHTML(const char* markup_data, | 150 void WriteHTML(const char* markup_data, |
| 138 size_t markup_len, | 151 size_t markup_len, |
| 139 const char* url_data, | 152 const char* url_data, |
| 140 size_t url_len); | 153 size_t url_len); |
| 141 | 154 |
| 142 void WriteBookmark(const char* title_data, | 155 void WriteBookmark(const char* title_data, |
| 143 size_t title_len, | 156 size_t title_len, |
| 144 const char* url_data, | 157 const char* url_data, |
| 145 size_t url_len); | 158 size_t url_len); |
| 146 | 159 |
| 147 void WriteHyperlink(const char* title_data, | 160 void WriteHyperlink(const char* title_data, |
| 148 size_t title_len, | 161 size_t title_len, |
| 149 const char* url_data, | 162 const char* url_data, |
| 150 size_t url_len); | 163 size_t url_len); |
| 151 | 164 |
| 152 void WriteWebSmartPaste(); | 165 void WriteWebSmartPaste(); |
| 153 | 166 |
| 154 void WriteFiles(const char* file_data, size_t file_len); | 167 void WriteFiles(const char* file_data, size_t file_len); |
| 155 | 168 |
| 156 void DispatchObject(ObjectType type, const ObjectMapParams& params); | |
| 157 | |
| 158 void WriteBitmap(const char* pixel_data, const char* size_data); | 169 void WriteBitmap(const char* pixel_data, const char* size_data); |
| 170 #if defined(OS_WIN) || defined(OS_LINUX) |
| 171 // |format_name| is an ASCII string and should be NULL-terminated. |
| 172 // TODO(estade): port to mac. |
| 173 void WriteData(const char* format_name, size_t format_len, |
| 174 const char* data_data, size_t data_len); |
| 175 #endif |
| 159 #if defined(OS_WIN) | 176 #if defined(OS_WIN) |
| 160 void WriteBitmapFromSharedMemory(const char* bitmap_data, | 177 void WriteBitmapFromSharedMemory(const char* bitmap_data, |
| 161 const char* size_data, | 178 const char* size_data, |
| 162 base::ProcessHandle handle); | 179 base::ProcessHandle handle); |
| 163 | 180 |
| 164 void WriteBitmapFromHandle(HBITMAP source_hbitmap, | 181 void WriteBitmapFromHandle(HBITMAP source_hbitmap, |
| 165 const gfx::Size& size); | 182 const gfx::Size& size); |
| 166 | 183 |
| 167 // Safely write to system clipboard. Free |handle| on failure. | 184 // Safely write to system clipboard. Free |handle| on failure. |
| 168 void WriteToClipboard(unsigned int format, HANDLE handle); | 185 void WriteToClipboard(unsigned int format, HANDLE handle); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 193 | 210 |
| 194 // Write changes to gtk clipboard. | 211 // Write changes to gtk clipboard. |
| 195 void SetGtkClipboard(); | 212 void SetGtkClipboard(); |
| 196 // Insert a mapping into clipboard_data_. | 213 // Insert a mapping into clipboard_data_. |
| 197 void InsertMapping(const char* key, char* data, size_t data_len); | 214 void InsertMapping(const char* key, char* data, size_t data_len); |
| 198 | 215 |
| 199 TargetMap* clipboard_data_; | 216 TargetMap* clipboard_data_; |
| 200 GtkClipboard* clipboard_; | 217 GtkClipboard* clipboard_; |
| 201 #endif | 218 #endif |
| 202 | 219 |
| 203 DISALLOW_EVIL_CONSTRUCTORS(Clipboard); | 220 DISALLOW_COPY_AND_ASSIGN(Clipboard); |
| 204 }; | 221 }; |
| 205 | 222 |
| 206 #endif // BASE_CLIPBOARD_H_ | 223 #endif // BASE_CLIPBOARD_H_ |
| OLD | NEW |