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

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

Issue 8802004: 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
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"
18 #include "ui/gfx/canvas_skia.h" 19 #include "ui/gfx/canvas_skia.h"
19 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 20 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
20 #include "ui/gfx/size.h" 21 #include "ui/gfx/size.h"
21 22
22 namespace ui { 23 namespace ui {
23 24
24 namespace { 25 namespace {
25 26
26 // Would be nice if this were in UTCoreTypes.h, but it isn't 27 // Would be nice if this were in UTCoreTypes.h, but it isn't
27 NSString* const kUTTypeURLName = @"public.url-name"; 28 NSString* const kUTTypeURLName = @"public.url-name";
28 29
29 // Tells us if WebKit was the last to write to the pasteboard. There's no 30 // Tells us if WebKit was the last to write to the pasteboard. There's no
30 // actual data associated with this type. 31 // actual data associated with this type.
31 NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type"; 32 NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type";
32 33
34 NSString* const kWebCustomDataType = @"org.chromium.web-custom-data";
tony 2011/12/05 18:40:39 Ditto.
35
33 NSPasteboard* GetPasteboard() { 36 NSPasteboard* GetPasteboard() {
34 // The pasteboard should not be nil in a UI session, but this handy DCHECK 37 // The pasteboard should not be nil in a UI session, but this handy DCHECK
35 // can help track down problems if someone tries using clipboard code outside 38 // can help track down problems if someone tries using clipboard code outside
36 // of a UI session. 39 // of a UI session.
37 NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; 40 NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
38 DCHECK(pasteboard); 41 DCHECK(pasteboard);
39 return pasteboard; 42 return pasteboard;
40 } 43 }
41 44
42 } // namespace 45 } // namespace
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 198 }
196 199
197 types->clear(); 200 types->clear();
198 if (IsFormatAvailable(Clipboard::GetPlainTextFormatType(), buffer)) 201 if (IsFormatAvailable(Clipboard::GetPlainTextFormatType(), buffer))
199 types->push_back(UTF8ToUTF16(kMimeTypeText)); 202 types->push_back(UTF8ToUTF16(kMimeTypeText));
200 if (IsFormatAvailable(Clipboard::GetHtmlFormatType(), buffer)) 203 if (IsFormatAvailable(Clipboard::GetHtmlFormatType(), buffer))
201 types->push_back(UTF8ToUTF16(kMimeTypeHTML)); 204 types->push_back(UTF8ToUTF16(kMimeTypeHTML));
202 if ([NSImage canInitWithPasteboard:GetPasteboard()]) 205 if ([NSImage canInitWithPasteboard:GetPasteboard()])
203 types->push_back(UTF8ToUTF16(kMimeTypePNG)); 206 types->push_back(UTF8ToUTF16(kMimeTypePNG));
204 *contains_filenames = false; 207 *contains_filenames = false;
208
209 NSPasteboard* pb = GetPasteboard();
210 if ([[pb types] containsObject:kWebCustomDataType]) {
211 NSData* data = [pb dataForType:kWebCustomDataType];
212 if ([data length])
213 ReadCustomDataTypes([data bytes], [data length], types);
214 }
205 } 215 }
206 216
207 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { 217 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const {
208 DCHECK_EQ(buffer, BUFFER_STANDARD); 218 DCHECK_EQ(buffer, BUFFER_STANDARD);
209 NSPasteboard* pb = GetPasteboard(); 219 NSPasteboard* pb = GetPasteboard();
210 NSString* contents = [pb stringForType:NSStringPboardType]; 220 NSString* contents = [pb stringForType:NSStringPboardType];
211 221
212 UTF8ToUTF16([contents UTF8String], 222 UTF8ToUTF16([contents UTF8String],
213 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], 223 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
214 result); 224 result);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 fromRect:NSZeroRect 290 fromRect:NSZeroRect
281 operation:NSCompositeCopy 291 operation:NSCompositeCopy
282 fraction:1.0]; 292 fraction:1.0];
283 } 293 }
284 return canvas.ExtractBitmap(); 294 return canvas.ExtractBitmap();
285 } 295 }
286 296
287 void Clipboard::ReadCustomData(Buffer buffer, 297 void Clipboard::ReadCustomData(Buffer buffer,
288 const string16& type, 298 const string16& type,
289 string16* result) const { 299 string16* result) const {
290 // TODO(dcheng): Implement this. 300 DCHECK_EQ(buffer, BUFFER_STANDARD);
291 NOTIMPLEMENTED(); 301
302 NSPasteboard* pb = GetPasteboard();
303 if ([[pb types] containsObject:kWebCustomDataType]) {
304 NSData* data = [pb dataForType:kWebCustomDataType];
305 if ([data length])
306 ReadCustomDataForType([data bytes], [data length], type, result);
307 }
292 } 308 }
293 309
294 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 310 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
295 NSPasteboard* pb = GetPasteboard(); 311 NSPasteboard* pb = GetPasteboard();
296 312
297 if (title) { 313 if (title) {
298 NSString* contents = [pb stringForType:kUTTypeURLName]; 314 NSString* contents = [pb stringForType:kUTTypeURLName];
299 UTF8ToUTF16([contents UTF8String], 315 UTF8ToUTF16([contents UTF8String],
300 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], 316 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
301 title); 317 title);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // static 396 // static
381 Clipboard::FormatType Clipboard::GetBitmapFormatType() { 397 Clipboard::FormatType Clipboard::GetBitmapFormatType() {
382 return base::SysNSStringToUTF8(NSTIFFPboardType); 398 return base::SysNSStringToUTF8(NSTIFFPboardType);
383 } 399 }
384 400
385 // static 401 // static
386 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { 402 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
387 return base::SysNSStringToUTF8(kWebSmartPastePboardType); 403 return base::SysNSStringToUTF8(kWebSmartPastePboardType);
388 } 404 }
389 405
406 // static
407 Clipboard::FormatType Clipboard::GetWebCustomDataFormatType() {
408 return base::SysNSStringToUTF8(kWebCustomDataType);
409 }
410
390 } // namespace ui 411 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698