- add sources.
[platform/framework/web/crosswalk.git] / src / ui / base / clipboard / clipboard_util_win.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // Some helper functions for working with the clipboard and IDataObjects.
6
7 #ifndef UI_BASE_CLIPBOARD_CLIPBOARD_UTIL_WIN_H_
8 #define UI_BASE_CLIPBOARD_CLIPBOARD_UTIL_WIN_H_
9
10 #include <shlobj.h>
11 #include <map>
12 #include <string>
13 #include <vector>
14
15 #include "base/strings/string16.h"
16 #include "ui/base/ui_export.h"
17
18 namespace ui {
19
20 class UI_EXPORT ClipboardUtil {
21  public:
22   /////////////////////////////////////////////////////////////////////////////
23   // These methods check to see if |data_object| has the requested type.
24   // Returns true if it does.
25   static bool HasUrl(IDataObject* data_object);
26   static bool HasFilenames(IDataObject* data_object);
27   static bool HasPlainText(IDataObject* data_object);
28   static bool HasFileContents(IDataObject* data_object);
29   static bool HasHtml(IDataObject* data_object);
30
31   /////////////////////////////////////////////////////////////////////////////
32   // Helper methods to extract information from an IDataObject.  These methods
33   // return true if the requested data type is found in |data_object|.
34   static bool GetUrl(IDataObject* data_object,
35                      string16* url,
36                      string16* title,
37                      bool convert_filenames);
38   static bool GetFilenames(IDataObject* data_object,
39                            std::vector<string16>* filenames);
40   static bool GetPlainText(IDataObject* data_object, string16* plain_text);
41   static bool GetHtml(IDataObject* data_object,
42                       string16* text_html,
43                       std::string* base_url);
44   static bool GetFileContents(IDataObject* data_object,
45                               string16* filename,
46                               std::string* file_contents);
47   // This represents custom MIME types a web page might set to transport its
48   // own types of data for drag and drop. It is sandboxed in its own CLIPFORMAT
49   // to avoid polluting the ::RegisterClipboardFormat() namespace with random
50   // strings from web content.
51   static bool GetWebCustomData(IDataObject* data_object,
52                                std::map<string16, string16>* custom_data);
53
54   // Helper method for converting between MS CF_HTML format and plain
55   // text/html.
56   static std::string HtmlToCFHtml(const std::string& html,
57                                   const std::string& base_url);
58   static void CFHtmlToHtml(const std::string& cf_html,
59                            std::string* html,
60                            std::string* base_url);
61   static void CFHtmlExtractMetadata(const std::string& cf_html,
62                                     std::string* base_url,
63                                     size_t* html_start,
64                                     size_t* fragment_start,
65                                     size_t* fragment_end);
66 };
67
68 }
69
70 #endif  // UI_BASE_CLIPBOARD_CLIPBOARD_UTIL_WIN_H_