OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "ui/base/clipboard/clipboard_util_win.h" | 5 #include "ui/base/clipboard/clipboard_util_win.h" |
6 | 6 |
7 #include <shellapi.h> | 7 #include <shellapi.h> |
8 #include <shlwapi.h> | 8 #include <shlwapi.h> |
9 #include <wininet.h> // For INTERNET_MAX_URL_LENGTH. | 9 #include <wininet.h> // For INTERNET_MAX_URL_LENGTH. |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/sys_string_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "base/win/scoped_hglobal.h" | 17 #include "base/win/scoped_hglobal.h" |
| 18 #include "net/base/filename_util.h" |
17 #include "ui/base/clipboard/clipboard.h" | 19 #include "ui/base/clipboard/clipboard.h" |
18 #include "ui/base/clipboard/custom_data_helper.h" | 20 #include "ui/base/clipboard/custom_data_helper.h" |
| 21 #include "url/gurl.h" |
19 | 22 |
20 namespace ui { | 23 namespace ui { |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 bool HasData(IDataObject* data_object, const Clipboard::FormatType& format) { | 27 bool HasData(IDataObject* data_object, const Clipboard::FormatType& format) { |
25 FORMATETC format_etc = format.ToFormatEtc(); | 28 FORMATETC format_etc = format.ToFormatEtc(); |
26 return SUCCEEDED(data_object->QueryGetData(&format_etc)); | 29 return SUCCEEDED(data_object->QueryGetData(&format_etc)); |
27 } | 30 } |
28 | 31 |
29 bool GetData(IDataObject* data_object, | 32 bool GetData(IDataObject* data_object, |
30 const Clipboard::FormatType& format, | 33 const Clipboard::FormatType& format, |
31 STGMEDIUM* medium) { | 34 STGMEDIUM* medium) { |
32 FORMATETC format_etc = format.ToFormatEtc(); | 35 FORMATETC format_etc = format.ToFormatEtc(); |
33 return SUCCEEDED(data_object->GetData(&format_etc, medium)); | 36 return SUCCEEDED(data_object->GetData(&format_etc, medium)); |
34 } | 37 } |
35 | 38 |
36 bool GetUrlFromHDrop(IDataObject* data_object, | 39 bool GetUrlFromHDrop(IDataObject* data_object, |
37 base::string16* url, | 40 GURL* url, |
38 base::string16* title) { | 41 base::string16* title) { |
39 DCHECK(data_object && url && title); | 42 DCHECK(data_object && url && title); |
40 | 43 |
| 44 bool success = false; |
41 STGMEDIUM medium; | 45 STGMEDIUM medium; |
42 if (!GetData(data_object, Clipboard::GetCFHDropFormatType(), &medium)) | 46 if (!GetData(data_object, Clipboard::GetCFHDropFormatType(), &medium)) |
43 return false; | 47 return false; |
44 | 48 |
45 HDROP hdrop = static_cast<HDROP>(GlobalLock(medium.hGlobal)); | 49 { |
| 50 base::win::ScopedHGlobal<HDROP> hdrop(medium.hGlobal); |
46 | 51 |
47 if (!hdrop) | 52 if (!hdrop.get()) |
48 return false; | 53 return false; |
49 | 54 |
50 bool success = false; | 55 wchar_t filename[MAX_PATH]; |
51 wchar_t filename[MAX_PATH]; | 56 if (DragQueryFileW(hdrop.get(), 0, filename, arraysize(filename))) { |
52 if (DragQueryFileW(hdrop, 0, filename, arraysize(filename))) { | 57 wchar_t url_buffer[INTERNET_MAX_URL_LENGTH]; |
53 wchar_t url_buffer[INTERNET_MAX_URL_LENGTH]; | 58 if (0 == _wcsicmp(PathFindExtensionW(filename), L".url") && |
54 if (0 == _wcsicmp(PathFindExtensionW(filename), L".url") && | 59 GetPrivateProfileStringW(L"InternetShortcut", |
55 GetPrivateProfileStringW(L"InternetShortcut", L"url", 0, url_buffer, | 60 L"url", |
56 arraysize(url_buffer), filename)) { | 61 0, |
57 url->assign(url_buffer); | 62 url_buffer, |
58 PathRemoveExtension(filename); | 63 arraysize(url_buffer), |
59 title->assign(PathFindFileName(filename)); | 64 filename)) { |
60 success = true; | 65 *url = GURL(url_buffer); |
| 66 PathRemoveExtension(filename); |
| 67 title->assign(PathFindFileName(filename)); |
| 68 success = url->is_valid(); |
| 69 } |
61 } | 70 } |
62 } | 71 } |
63 | 72 |
64 DragFinish(hdrop); | 73 ReleaseStgMedium(&medium); |
65 GlobalUnlock(medium.hGlobal); | |
66 // We don't need to call ReleaseStgMedium here because as far as I can tell, | |
67 // DragFinish frees the hGlobal for us. | |
68 return success; | 74 return success; |
69 } | 75 } |
70 | 76 |
71 void SplitUrlAndTitle(const base::string16& str, | 77 void SplitUrlAndTitle(const base::string16& str, |
72 base::string16* url, | 78 GURL* url, |
73 base::string16* title) { | 79 base::string16* title) { |
74 DCHECK(url && title); | 80 DCHECK(url && title); |
75 size_t newline_pos = str.find('\n'); | 81 size_t newline_pos = str.find('\n'); |
76 if (newline_pos != base::string16::npos) { | 82 if (newline_pos != base::string16::npos) { |
77 url->assign(str, 0, newline_pos); | 83 *url = GURL(base::string16(str, 0, newline_pos)); |
78 title->assign(str, newline_pos + 1, base::string16::npos); | 84 title->assign(str, newline_pos + 1, base::string16::npos); |
79 } else { | 85 } else { |
80 url->assign(str); | 86 *url = GURL(str); |
81 title->assign(str); | 87 title->assign(str); |
82 } | 88 } |
83 } | 89 } |
84 | 90 |
85 bool GetFileUrl(IDataObject* data_object, base::string16* url, | |
86 base::string16* title) { | |
87 STGMEDIUM store; | |
88 if (GetData(data_object, Clipboard::GetFilenameWFormatType(), &store)) { | |
89 bool success = false; | |
90 { | |
91 // filename using unicode | |
92 base::win::ScopedHGlobal<wchar_t> data(store.hGlobal); | |
93 if (data.get() && data.get()[0] && | |
94 (PathFileExists(data.get()) || PathIsUNC(data.get()))) { | |
95 wchar_t file_url[INTERNET_MAX_URL_LENGTH]; | |
96 DWORD file_url_len = arraysize(file_url); | |
97 if (SUCCEEDED(::UrlCreateFromPathW(data.get(), file_url, &file_url_len, | |
98 0))) { | |
99 url->assign(file_url); | |
100 title->assign(file_url); | |
101 success = true; | |
102 } | |
103 } | |
104 } | |
105 ReleaseStgMedium(&store); | |
106 if (success) | |
107 return true; | |
108 } | |
109 | |
110 if (GetData(data_object, Clipboard::GetFilenameFormatType(), &store)) { | |
111 bool success = false; | |
112 { | |
113 // filename using ascii | |
114 base::win::ScopedHGlobal<char> data(store.hGlobal); | |
115 if (data.get() && data.get()[0] && (PathFileExistsA(data.get()) || | |
116 PathIsUNCA(data.get()))) { | |
117 char file_url[INTERNET_MAX_URL_LENGTH]; | |
118 DWORD file_url_len = arraysize(file_url); | |
119 if (SUCCEEDED(::UrlCreateFromPathA(data.get(), file_url, &file_url_len, | |
120 0))) { | |
121 url->assign(base::UTF8ToWide(file_url)); | |
122 title->assign(*url); | |
123 success = true; | |
124 } | |
125 } | |
126 } | |
127 ReleaseStgMedium(&store); | |
128 if (success) | |
129 return true; | |
130 } | |
131 return false; | |
132 } | |
133 | |
134 } // namespace | 91 } // namespace |
135 | 92 |
136 bool ClipboardUtil::HasUrl(IDataObject* data_object, bool convert_filenames) { | 93 bool ClipboardUtil::HasUrl(IDataObject* data_object, bool convert_filenames) { |
137 DCHECK(data_object); | 94 DCHECK(data_object); |
138 return HasData(data_object, Clipboard::GetMozUrlFormatType()) || | 95 return HasData(data_object, Clipboard::GetMozUrlFormatType()) || |
139 HasData(data_object, Clipboard::GetUrlWFormatType()) || | 96 HasData(data_object, Clipboard::GetUrlWFormatType()) || |
140 HasData(data_object, Clipboard::GetUrlFormatType()) || | 97 HasData(data_object, Clipboard::GetUrlFormatType()) || |
141 (convert_filenames && ( | 98 (convert_filenames && HasFilenames(data_object)); |
142 HasData(data_object, Clipboard::GetFilenameWFormatType()) || | |
143 HasData(data_object, Clipboard::GetFilenameFormatType()))); | |
144 } | 99 } |
145 | 100 |
146 bool ClipboardUtil::HasFilenames(IDataObject* data_object) { | 101 bool ClipboardUtil::HasFilenames(IDataObject* data_object) { |
147 DCHECK(data_object); | 102 DCHECK(data_object); |
148 return HasData(data_object, Clipboard::GetCFHDropFormatType()); | 103 return HasData(data_object, Clipboard::GetCFHDropFormatType()) || |
| 104 HasData(data_object, Clipboard::GetFilenameWFormatType()) || |
| 105 HasData(data_object, Clipboard::GetFilenameFormatType()); |
149 } | 106 } |
150 | 107 |
151 bool ClipboardUtil::HasFileContents(IDataObject* data_object) { | 108 bool ClipboardUtil::HasFileContents(IDataObject* data_object) { |
152 DCHECK(data_object); | 109 DCHECK(data_object); |
153 return HasData(data_object, Clipboard::GetFileContentZeroFormatType()); | 110 return HasData(data_object, Clipboard::GetFileContentZeroFormatType()); |
154 } | 111 } |
155 | 112 |
156 bool ClipboardUtil::HasHtml(IDataObject* data_object) { | 113 bool ClipboardUtil::HasHtml(IDataObject* data_object) { |
157 DCHECK(data_object); | 114 DCHECK(data_object); |
158 return HasData(data_object, Clipboard::GetHtmlFormatType()) || | 115 return HasData(data_object, Clipboard::GetHtmlFormatType()) || |
159 HasData(data_object, Clipboard::GetTextHtmlFormatType()); | 116 HasData(data_object, Clipboard::GetTextHtmlFormatType()); |
160 } | 117 } |
161 | 118 |
162 bool ClipboardUtil::HasPlainText(IDataObject* data_object) { | 119 bool ClipboardUtil::HasPlainText(IDataObject* data_object) { |
163 DCHECK(data_object); | 120 DCHECK(data_object); |
164 return HasData(data_object, Clipboard::GetPlainTextWFormatType()) || | 121 return HasData(data_object, Clipboard::GetPlainTextWFormatType()) || |
165 HasData(data_object, Clipboard::GetPlainTextFormatType()); | 122 HasData(data_object, Clipboard::GetPlainTextFormatType()); |
166 } | 123 } |
167 | 124 |
168 bool ClipboardUtil::GetUrl(IDataObject* data_object, | 125 bool ClipboardUtil::GetUrl(IDataObject* data_object, |
169 base::string16* url, base::string16* title, bool convert_filenames) { | 126 GURL* url, |
| 127 base::string16* title, |
| 128 bool convert_filenames) { |
170 DCHECK(data_object && url && title); | 129 DCHECK(data_object && url && title); |
171 if (!HasUrl(data_object, convert_filenames)) | 130 if (!HasUrl(data_object, convert_filenames)) |
172 return false; | 131 return false; |
173 | 132 |
174 // Try to extract a URL from |data_object| in a variety of formats. | 133 // Try to extract a URL from |data_object| in a variety of formats. |
175 STGMEDIUM store; | 134 STGMEDIUM store; |
176 if (GetUrlFromHDrop(data_object, url, title)) | 135 if (GetUrlFromHDrop(data_object, url, title)) |
177 return true; | 136 return true; |
178 | 137 |
179 if (GetData(data_object, Clipboard::GetMozUrlFormatType(), &store) || | 138 if (GetData(data_object, Clipboard::GetMozUrlFormatType(), &store) || |
180 GetData(data_object, Clipboard::GetUrlWFormatType(), &store)) { | 139 GetData(data_object, Clipboard::GetUrlWFormatType(), &store)) { |
181 { | 140 { |
182 // Mozilla URL format or unicode URL | 141 // Mozilla URL format or unicode URL |
183 base::win::ScopedHGlobal<wchar_t> data(store.hGlobal); | 142 base::win::ScopedHGlobal<wchar_t*> data(store.hGlobal); |
184 SplitUrlAndTitle(data.get(), url, title); | 143 SplitUrlAndTitle(data.get(), url, title); |
185 } | 144 } |
186 ReleaseStgMedium(&store); | 145 ReleaseStgMedium(&store); |
187 return true; | 146 return url->is_valid(); |
188 } | 147 } |
189 | 148 |
190 if (GetData(data_object, Clipboard::GetUrlFormatType(), &store)) { | 149 if (GetData(data_object, Clipboard::GetUrlFormatType(), &store)) { |
191 { | 150 { |
192 // URL using ascii | 151 // URL using ascii |
193 base::win::ScopedHGlobal<char> data(store.hGlobal); | 152 base::win::ScopedHGlobal<char*> data(store.hGlobal); |
194 SplitUrlAndTitle(base::UTF8ToWide(data.get()), url, title); | 153 SplitUrlAndTitle(base::UTF8ToWide(data.get()), url, title); |
195 } | 154 } |
196 ReleaseStgMedium(&store); | 155 ReleaseStgMedium(&store); |
197 return true; | 156 return url->is_valid(); |
198 } | 157 } |
199 | 158 |
200 if (convert_filenames) { | 159 if (convert_filenames) { |
201 return GetFileUrl(data_object, url, title); | 160 std::vector<base::string16> filenames; |
202 } else { | 161 if (!GetFilenames(data_object, &filenames)) |
203 return false; | 162 return false; |
| 163 DCHECK_GT(filenames.size(), 0U); |
| 164 *url = net::FilePathToFileURL(base::FilePath(filenames[0])); |
| 165 return url->is_valid(); |
204 } | 166 } |
| 167 |
| 168 return false; |
205 } | 169 } |
206 | 170 |
207 bool ClipboardUtil::GetFilenames(IDataObject* data_object, | 171 bool ClipboardUtil::GetFilenames(IDataObject* data_object, |
208 std::vector<base::string16>* filenames) { | 172 std::vector<base::string16>* filenames) { |
209 DCHECK(data_object && filenames); | 173 DCHECK(data_object && filenames); |
210 if (!HasFilenames(data_object)) | 174 if (!HasFilenames(data_object)) |
211 return false; | 175 return false; |
212 | 176 |
213 STGMEDIUM medium; | 177 STGMEDIUM medium; |
214 if (!GetData(data_object, Clipboard::GetCFHDropFormatType(), &medium)) | 178 if (GetData(data_object, Clipboard::GetCFHDropFormatType(), &medium)) { |
215 return false; | 179 { |
| 180 base::win::ScopedHGlobal<HDROP> hdrop(medium.hGlobal); |
| 181 if (!hdrop.get()) |
| 182 return false; |
216 | 183 |
217 HDROP hdrop = static_cast<HDROP>(GlobalLock(medium.hGlobal)); | 184 const int kMaxFilenameLen = 4096; |
218 if (!hdrop) | 185 const unsigned num_files = DragQueryFileW(hdrop.get(), 0xffffffff, 0, 0); |
219 return false; | 186 for (unsigned int i = 0; i < num_files; ++i) { |
220 | 187 wchar_t filename[kMaxFilenameLen]; |
221 const int kMaxFilenameLen = 4096; | 188 if (!DragQueryFileW(hdrop.get(), i, filename, kMaxFilenameLen)) |
222 const unsigned num_files = DragQueryFileW(hdrop, 0xffffffff, 0, 0); | 189 continue; |
223 for (unsigned int i = 0; i < num_files; ++i) { | 190 filenames->push_back(filename); |
224 wchar_t filename[kMaxFilenameLen]; | 191 } |
225 if (!DragQueryFileW(hdrop, i, filename, kMaxFilenameLen)) | 192 } |
226 continue; | 193 ReleaseStgMedium(&medium); |
227 filenames->push_back(filename); | 194 return true; |
228 } | 195 } |
229 | 196 |
230 DragFinish(hdrop); | 197 if (GetData(data_object, Clipboard::GetFilenameWFormatType(), &medium)) { |
231 GlobalUnlock(medium.hGlobal); | 198 { |
232 // We don't need to call ReleaseStgMedium here because as far as I can tell, | 199 // filename using unicode |
233 // DragFinish frees the hGlobal for us. | 200 base::win::ScopedHGlobal<wchar_t*> data(medium.hGlobal); |
234 return true; | 201 if (data.get() && data.get()[0]) |
| 202 filenames->push_back(data.get()); |
| 203 } |
| 204 ReleaseStgMedium(&medium); |
| 205 return true; |
| 206 } |
| 207 |
| 208 if (GetData(data_object, Clipboard::GetFilenameFormatType(), &medium)) { |
| 209 { |
| 210 // filename using ascii |
| 211 base::win::ScopedHGlobal<char*> data(medium.hGlobal); |
| 212 if (data.get() && data.get()[0]) |
| 213 filenames->push_back(base::SysNativeMBToWide(data.get())); |
| 214 } |
| 215 ReleaseStgMedium(&medium); |
| 216 return true; |
| 217 } |
| 218 |
| 219 return false; |
235 } | 220 } |
236 | 221 |
237 bool ClipboardUtil::GetPlainText(IDataObject* data_object, | 222 bool ClipboardUtil::GetPlainText(IDataObject* data_object, |
238 base::string16* plain_text) { | 223 base::string16* plain_text) { |
239 DCHECK(data_object && plain_text); | 224 DCHECK(data_object && plain_text); |
240 if (!HasPlainText(data_object)) | 225 if (!HasPlainText(data_object)) |
241 return false; | 226 return false; |
242 | 227 |
243 STGMEDIUM store; | 228 STGMEDIUM store; |
244 if (GetData(data_object, Clipboard::GetPlainTextWFormatType(), &store)) { | 229 if (GetData(data_object, Clipboard::GetPlainTextWFormatType(), &store)) { |
245 { | 230 { |
246 // Unicode text | 231 // Unicode text |
247 base::win::ScopedHGlobal<wchar_t> data(store.hGlobal); | 232 base::win::ScopedHGlobal<wchar_t*> data(store.hGlobal); |
248 plain_text->assign(data.get()); | 233 plain_text->assign(data.get()); |
249 } | 234 } |
250 ReleaseStgMedium(&store); | 235 ReleaseStgMedium(&store); |
251 return true; | 236 return true; |
252 } | 237 } |
253 | 238 |
254 if (GetData(data_object, Clipboard::GetPlainTextFormatType(), &store)) { | 239 if (GetData(data_object, Clipboard::GetPlainTextFormatType(), &store)) { |
255 { | 240 { |
256 // ascii text | 241 // ascii text |
257 base::win::ScopedHGlobal<char> data(store.hGlobal); | 242 base::win::ScopedHGlobal<char*> data(store.hGlobal); |
258 plain_text->assign(base::UTF8ToWide(data.get())); | 243 plain_text->assign(base::UTF8ToWide(data.get())); |
259 } | 244 } |
260 ReleaseStgMedium(&store); | 245 ReleaseStgMedium(&store); |
261 return true; | 246 return true; |
262 } | 247 } |
263 | 248 |
264 // If a file is dropped on the window, it does not provide either of the | 249 // If a file is dropped on the window, it does not provide either of the |
265 // plain text formats, so here we try to forcibly get a url. | 250 // plain text formats, so here we try to forcibly get a url. |
| 251 GURL url; |
266 base::string16 title; | 252 base::string16 title; |
267 return GetUrl(data_object, plain_text, &title, false); | 253 if (GetUrl(data_object, &url, &title, false)) { |
| 254 *plain_text = base::UTF8ToUTF16(url.spec()); |
| 255 return true; |
| 256 } |
| 257 return false; |
268 } | 258 } |
269 | 259 |
270 bool ClipboardUtil::GetHtml(IDataObject* data_object, | 260 bool ClipboardUtil::GetHtml(IDataObject* data_object, |
271 base::string16* html, std::string* base_url) { | 261 base::string16* html, std::string* base_url) { |
272 DCHECK(data_object && html && base_url); | 262 DCHECK(data_object && html && base_url); |
273 | 263 |
274 STGMEDIUM store; | 264 STGMEDIUM store; |
275 if (HasData(data_object, Clipboard::GetHtmlFormatType()) && | 265 if (HasData(data_object, Clipboard::GetHtmlFormatType()) && |
276 GetData(data_object, Clipboard::GetHtmlFormatType(), &store)) { | 266 GetData(data_object, Clipboard::GetHtmlFormatType(), &store)) { |
277 { | 267 { |
278 // MS CF html | 268 // MS CF html |
279 base::win::ScopedHGlobal<char> data(store.hGlobal); | 269 base::win::ScopedHGlobal<char*> data(store.hGlobal); |
280 | 270 |
281 std::string html_utf8; | 271 std::string html_utf8; |
282 CFHtmlToHtml(std::string(data.get(), data.Size()), &html_utf8, base_url); | 272 CFHtmlToHtml(std::string(data.get(), data.Size()), &html_utf8, base_url); |
283 html->assign(base::UTF8ToWide(html_utf8)); | 273 html->assign(base::UTF8ToWide(html_utf8)); |
284 } | 274 } |
285 ReleaseStgMedium(&store); | 275 ReleaseStgMedium(&store); |
286 return true; | 276 return true; |
287 } | 277 } |
288 | 278 |
289 if (!HasData(data_object, Clipboard::GetTextHtmlFormatType())) | 279 if (!HasData(data_object, Clipboard::GetTextHtmlFormatType())) |
290 return false; | 280 return false; |
291 | 281 |
292 if (!GetData(data_object, Clipboard::GetTextHtmlFormatType(), &store)) | 282 if (!GetData(data_object, Clipboard::GetTextHtmlFormatType(), &store)) |
293 return false; | 283 return false; |
294 | 284 |
295 { | 285 { |
296 // text/html | 286 // text/html |
297 base::win::ScopedHGlobal<wchar_t> data(store.hGlobal); | 287 base::win::ScopedHGlobal<wchar_t*> data(store.hGlobal); |
298 html->assign(data.get()); | 288 html->assign(data.get()); |
299 } | 289 } |
300 ReleaseStgMedium(&store); | 290 ReleaseStgMedium(&store); |
301 return true; | 291 return true; |
302 } | 292 } |
303 | 293 |
304 bool ClipboardUtil::GetFileContents(IDataObject* data_object, | 294 bool ClipboardUtil::GetFileContents(IDataObject* data_object, |
305 base::string16* filename, std::string* file_contents) { | 295 base::string16* filename, std::string* file_contents) { |
306 DCHECK(data_object && filename && file_contents); | 296 DCHECK(data_object && filename && file_contents); |
307 if (!HasData(data_object, Clipboard::GetFileContentZeroFormatType()) && | 297 if (!HasData(data_object, Clipboard::GetFileContentZeroFormatType()) && |
308 !HasData(data_object, Clipboard::GetFileDescriptorFormatType())) | 298 !HasData(data_object, Clipboard::GetFileDescriptorFormatType())) |
309 return false; | 299 return false; |
310 | 300 |
311 STGMEDIUM content; | 301 STGMEDIUM content; |
312 // The call to GetData can be very slow depending on what is in | 302 // The call to GetData can be very slow depending on what is in |
313 // |data_object|. | 303 // |data_object|. |
314 if (GetData( | 304 if (GetData( |
315 data_object, Clipboard::GetFileContentZeroFormatType(), &content)) { | 305 data_object, Clipboard::GetFileContentZeroFormatType(), &content)) { |
316 if (TYMED_HGLOBAL == content.tymed) { | 306 if (TYMED_HGLOBAL == content.tymed) { |
317 base::win::ScopedHGlobal<char> data(content.hGlobal); | 307 base::win::ScopedHGlobal<char*> data(content.hGlobal); |
318 file_contents->assign(data.get(), data.Size()); | 308 file_contents->assign(data.get(), data.Size()); |
319 } | 309 } |
320 ReleaseStgMedium(&content); | 310 ReleaseStgMedium(&content); |
321 } | 311 } |
322 | 312 |
323 STGMEDIUM description; | 313 STGMEDIUM description; |
324 if (GetData(data_object, | 314 if (GetData(data_object, |
325 Clipboard::GetFileDescriptorFormatType(), | 315 Clipboard::GetFileDescriptorFormatType(), |
326 &description)) { | 316 &description)) { |
327 { | 317 { |
328 base::win::ScopedHGlobal<FILEGROUPDESCRIPTOR> fgd(description.hGlobal); | 318 base::win::ScopedHGlobal<FILEGROUPDESCRIPTOR*> fgd(description.hGlobal); |
329 // We expect there to be at least one file in here. | 319 // We expect there to be at least one file in here. |
330 DCHECK_GE(fgd->cItems, 1u); | 320 DCHECK_GE(fgd->cItems, 1u); |
331 filename->assign(fgd->fgd[0].cFileName); | 321 filename->assign(fgd->fgd[0].cFileName); |
332 } | 322 } |
333 ReleaseStgMedium(&description); | 323 ReleaseStgMedium(&description); |
334 } | 324 } |
335 return true; | 325 return true; |
336 } | 326 } |
337 | 327 |
338 bool ClipboardUtil::GetWebCustomData( | 328 bool ClipboardUtil::GetWebCustomData( |
339 IDataObject* data_object, | 329 IDataObject* data_object, |
340 std::map<base::string16, base::string16>* custom_data) { | 330 std::map<base::string16, base::string16>* custom_data) { |
341 DCHECK(data_object && custom_data); | 331 DCHECK(data_object && custom_data); |
342 | 332 |
343 if (!HasData(data_object, Clipboard::GetWebCustomDataFormatType())) | 333 if (!HasData(data_object, Clipboard::GetWebCustomDataFormatType())) |
344 return false; | 334 return false; |
345 | 335 |
346 STGMEDIUM store; | 336 STGMEDIUM store; |
347 if (GetData(data_object, Clipboard::GetWebCustomDataFormatType(), &store)) { | 337 if (GetData(data_object, Clipboard::GetWebCustomDataFormatType(), &store)) { |
348 { | 338 { |
349 base::win::ScopedHGlobal<char> data(store.hGlobal); | 339 base::win::ScopedHGlobal<char*> data(store.hGlobal); |
350 ReadCustomDataIntoMap(data.get(), data.Size(), custom_data); | 340 ReadCustomDataIntoMap(data.get(), data.Size(), custom_data); |
351 } | 341 } |
352 ReleaseStgMedium(&store); | 342 ReleaseStgMedium(&store); |
353 return true; | 343 return true; |
354 } | 344 } |
355 return false; | 345 return false; |
356 } | 346 } |
357 | 347 |
358 | 348 |
359 // HtmlToCFHtml and CFHtmlToHtml are based on similar methods in | 349 // HtmlToCFHtml and CFHtmlToHtml are based on similar methods in |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 end_fragment_start + end_fragment_str.length())); | 493 end_fragment_start + end_fragment_str.length())); |
504 } | 494 } |
505 } else { | 495 } else { |
506 *fragment_start = cf_html.find('>', tag_start) + 1; | 496 *fragment_start = cf_html.find('>', tag_start) + 1; |
507 size_t tag_end = cf_html.rfind("<!--EndFragment", std::string::npos); | 497 size_t tag_end = cf_html.rfind("<!--EndFragment", std::string::npos); |
508 *fragment_end = cf_html.rfind('<', tag_end); | 498 *fragment_end = cf_html.rfind('<', tag_end); |
509 } | 499 } |
510 } | 500 } |
511 | 501 |
512 } // namespace ui | 502 } // namespace ui |
OLD | NEW |