Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: ui/base/clipboard/clipboard_mac.mm

Issue 8805030: Revert 113040 - Enable custom MIME types in web copy/paste. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/clipboard/clipboard_gtk.cc ('k') | ui/base/clipboard/clipboard_util_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 5 #include "ui/base/clipboard/clipboard.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/mac/mac_util.h" 11 #include "base/mac/mac_util.h"
12 #include "base/mac/scoped_cftyperef.h" 12 #include "base/mac/scoped_cftyperef.h"
13 #include "base/memory/scoped_nsobject.h" 13 #include "base/memory/scoped_nsobject.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #import "third_party/mozilla/NSPasteboard+Utils.h" 16 #import "third_party/mozilla/NSPasteboard+Utils.h"
17 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
18 #include "ui/base/clipboard/custom_data_helper.h"
19 #include "ui/gfx/canvas_skia.h" 18 #include "ui/gfx/canvas_skia.h"
20 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 19 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
21 #include "ui/gfx/size.h" 20 #include "ui/gfx/size.h"
22 21
23 namespace ui { 22 namespace ui {
24 23
25 namespace { 24 namespace {
26 25
27 // Would be nice if this were in UTCoreTypes.h, but it isn't 26 // Would be nice if this were in UTCoreTypes.h, but it isn't
28 NSString* const kUTTypeURLName = @"public.url-name"; 27 NSString* const kUTTypeURLName = @"public.url-name";
29 28
30 // Tells us if WebKit was the last to write to the pasteboard. There's no 29 // Tells us if WebKit was the last to write to the pasteboard. There's no
31 // actual data associated with this type. 30 // actual data associated with this type.
32 NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type"; 31 NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type";
33 32
34 // TODO(dcheng): This name is temporary. See crbug.com/106449.
35 NSString* const kWebCustomDataType = @"org.chromium.web-custom-data";
36
37 NSPasteboard* GetPasteboard() { 33 NSPasteboard* GetPasteboard() {
38 // The pasteboard should not be nil in a UI session, but this handy DCHECK 34 // The pasteboard should not be nil in a UI session, but this handy DCHECK
39 // can help track down problems if someone tries using clipboard code outside 35 // can help track down problems if someone tries using clipboard code outside
40 // of a UI session. 36 // of a UI session.
41 NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; 37 NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
42 DCHECK(pasteboard); 38 DCHECK(pasteboard);
43 return pasteboard; 39 return pasteboard;
44 } 40 }
45 41
46 } // namespace 42 } // namespace
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 217 }
222 218
223 types->clear(); 219 types->clear();
224 if (IsFormatAvailable(Clipboard::GetPlainTextFormatType(), buffer)) 220 if (IsFormatAvailable(Clipboard::GetPlainTextFormatType(), buffer))
225 types->push_back(UTF8ToUTF16(kMimeTypeText)); 221 types->push_back(UTF8ToUTF16(kMimeTypeText));
226 if (IsFormatAvailable(Clipboard::GetHtmlFormatType(), buffer)) 222 if (IsFormatAvailable(Clipboard::GetHtmlFormatType(), buffer))
227 types->push_back(UTF8ToUTF16(kMimeTypeHTML)); 223 types->push_back(UTF8ToUTF16(kMimeTypeHTML));
228 if ([NSImage canInitWithPasteboard:GetPasteboard()]) 224 if ([NSImage canInitWithPasteboard:GetPasteboard()])
229 types->push_back(UTF8ToUTF16(kMimeTypePNG)); 225 types->push_back(UTF8ToUTF16(kMimeTypePNG));
230 *contains_filenames = false; 226 *contains_filenames = false;
231
232 NSPasteboard* pb = GetPasteboard();
233 if ([[pb types] containsObject:kWebCustomDataType]) {
234 NSData* data = [pb dataForType:kWebCustomDataType];
235 if ([data length])
236 ReadCustomDataTypes([data bytes], [data length], types);
237 }
238 } 227 }
239 228
240 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { 229 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const {
241 DCHECK_EQ(buffer, BUFFER_STANDARD); 230 DCHECK_EQ(buffer, BUFFER_STANDARD);
242 NSPasteboard* pb = GetPasteboard(); 231 NSPasteboard* pb = GetPasteboard();
243 NSString* contents = [pb stringForType:NSStringPboardType]; 232 NSString* contents = [pb stringForType:NSStringPboardType];
244 233
245 UTF8ToUTF16([contents UTF8String], 234 UTF8ToUTF16([contents UTF8String],
246 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], 235 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
247 result); 236 result);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 fromRect:NSZeroRect 302 fromRect:NSZeroRect
314 operation:NSCompositeCopy 303 operation:NSCompositeCopy
315 fraction:1.0]; 304 fraction:1.0];
316 } 305 }
317 return canvas.ExtractBitmap(); 306 return canvas.ExtractBitmap();
318 } 307 }
319 308
320 void Clipboard::ReadCustomData(Buffer buffer, 309 void Clipboard::ReadCustomData(Buffer buffer,
321 const string16& type, 310 const string16& type,
322 string16* result) const { 311 string16* result) const {
323 DCHECK_EQ(buffer, BUFFER_STANDARD); 312 // TODO(dcheng): Implement this.
324 313 NOTIMPLEMENTED();
325 NSPasteboard* pb = GetPasteboard();
326 if ([[pb types] containsObject:kWebCustomDataType]) {
327 NSData* data = [pb dataForType:kWebCustomDataType];
328 if ([data length])
329 ReadCustomDataForType([data bytes], [data length], type, result);
330 }
331 } 314 }
332 315
333 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 316 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
334 NSPasteboard* pb = GetPasteboard(); 317 NSPasteboard* pb = GetPasteboard();
335 318
336 if (title) { 319 if (title) {
337 NSString* contents = [pb stringForType:kUTTypeURLName]; 320 NSString* contents = [pb stringForType:kUTTypeURLName];
338 UTF8ToUTF16([contents UTF8String], 321 UTF8ToUTF16([contents UTF8String],
339 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], 322 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
340 title); 323 title);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 // static 409 // static
427 Clipboard::FormatType Clipboard::GetBitmapFormatType() { 410 Clipboard::FormatType Clipboard::GetBitmapFormatType() {
428 return base::SysNSStringToUTF8(NSTIFFPboardType); 411 return base::SysNSStringToUTF8(NSTIFFPboardType);
429 } 412 }
430 413
431 // static 414 // static
432 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { 415 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
433 return base::SysNSStringToUTF8(kWebSmartPastePboardType); 416 return base::SysNSStringToUTF8(kWebSmartPastePboardType);
434 } 417 }
435 418
436 // static
437 Clipboard::FormatType Clipboard::GetWebCustomDataFormatType() {
438 return base::SysNSStringToUTF8(kWebCustomDataType);
439 }
440
441 } // namespace ui 419 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_gtk.cc ('k') | ui/base/clipboard/clipboard_util_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698