• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_base_export.h"
17 
18 namespace ui {
19 
20 class UI_BASE_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, bool convert_filenames);
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                      base::string16* url,
36                      base::string16* title,
37                      bool convert_filenames);
38   static bool GetFilenames(IDataObject* data_object,
39                            std::vector<base::string16>* filenames);
40   static bool GetPlainText(IDataObject* data_object,
41                            base::string16* plain_text);
42   static bool GetHtml(IDataObject* data_object,
43                       base::string16* text_html,
44                       std::string* base_url);
45   static bool GetFileContents(IDataObject* data_object,
46                               base::string16* filename,
47                               std::string* file_contents);
48   // This represents custom MIME types a web page might set to transport its
49   // own types of data for drag and drop. It is sandboxed in its own CLIPFORMAT
50   // to avoid polluting the ::RegisterClipboardFormat() namespace with random
51   // strings from web content.
52   static bool GetWebCustomData(
53       IDataObject* data_object,
54       std::map<base::string16, base::string16>* custom_data);
55 
56   // Helper method for converting between MS CF_HTML format and plain
57   // text/html.
58   static std::string HtmlToCFHtml(const std::string& html,
59                                   const std::string& base_url);
60   static void CFHtmlToHtml(const std::string& cf_html,
61                            std::string* html,
62                            std::string* base_url);
63   static void CFHtmlExtractMetadata(const std::string& cf_html,
64                                     std::string* base_url,
65                                     size_t* html_start,
66                                     size_t* fragment_start,
67                                     size_t* fragment_end);
68 };
69 
70 }
71 
72 #endif  // UI_BASE_CLIPBOARD_CLIPBOARD_UTIL_WIN_H_
73