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

Side by Side Diff: third_party/mozilla/NSPasteboard+Utils.mm

Issue 2014733003: Removing parsing of text from pasteboard. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compilation fix Created 4 years, 6 months 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
« no previous file with comments | « third_party/mozilla/NSPasteboard+Utils.h ('k') | third_party/mozilla/README.chromium » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* ***** BEGIN LICENSE BLOCK ***** 1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 * 3 *
4 * The contents of this file are subject to the Mozilla Public License Version 4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with 5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at 6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/ 7 * http://www.mozilla.org/MPL/
8 * 8 *
9 * Software distributed under the License is distributed on an "AS IS" basis, 9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 - (int)declareURLPasteboardWithAdditionalTypes:(NSArray*)additionalTypes owner:( id)newOwner 73 - (int)declareURLPasteboardWithAdditionalTypes:(NSArray*)additionalTypes owner:( id)newOwner
74 { 74 {
75 NSArray* allTypes = [additionalTypes arrayByAddingObjectsFromArray: 75 NSArray* allTypes = [additionalTypes arrayByAddingObjectsFromArray:
76 [NSArray arrayWithObjects: 76 [NSArray arrayWithObjects:
77 kWebURLsWithTitlesPboardType, 77 kWebURLsWithTitlesPboardType,
78 NSURLPboardType, 78 NSURLPboardType,
79 NSStringPboardType, 79 NSStringPboardType,
80 kCorePasteboardFlavorType_url, 80 kCorePasteboardFlavorType_url,
81 kCorePasteboardFlavorType_urln, 81 kCorePasteboardFlavorType_urln,
82 nil]]; 82 nil]];
83 » return [self declareTypes:allTypes owner:newOwner]; 83 return [self declareTypes:allTypes owner:newOwner];
84 } 84 }
85 85
86 // 86 //
87 // Copy a single URL (with an optional title) to the clipboard in all relevant 87 // Copy a single URL (with an optional title) to the clipboard in all relevant
88 // formats. Convenience method for clients that can only ever deal with one 88 // formats. Convenience method for clients that can only ever deal with one
89 // URL and shouldn't have to build up the arrays for setURLs:withTitles:. 89 // URL and shouldn't have to build up the arrays for setURLs:withTitles:.
90 // 90 //
91 - (void)setDataForURL:(NSString*)url title:(NSString*)title 91 - (void)setDataForURL:(NSString*)url title:(NSString*)title
92 { 92 {
93 NSArray* urlList = [NSArray arrayWithObject:url]; 93 NSArray* urlList = [NSArray arrayWithObject:url];
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 166 }
167 } 167 }
168 168
169 // Get the set of URLs and their corresponding titles from the pasteboard. 169 // Get the set of URLs and their corresponding titles from the pasteboard.
170 // If there are no URLs in a format we understand on the pasteboard empty 170 // If there are no URLs in a format we understand on the pasteboard empty
171 // arrays will be returned. The two arrays will always be the same size. 171 // arrays will be returned. The two arrays will always be the same size.
172 // The arrays returned are on the auto release pool. If |convertFilenames| 172 // The arrays returned are on the auto release pool. If |convertFilenames|
173 // is YES, then the function will attempt to convert filenames in the drag 173 // is YES, then the function will attempt to convert filenames in the drag
174 // to file URLs. 174 // to file URLs.
175 - (void) getURLs:(NSArray**)outUrls 175 - (void) getURLs:(NSArray**)outUrls
176 andTitles:(NSArray**)outTitles 176 andTitles:(NSArray**)outTitles
177 convertingFilenames:(BOOL)convertFilenames 177 convertingFilenames:(BOOL)convertFilenames
178 convertingTextToURL:(BOOL)convertTextToURL
178 { 179 {
179 NSArray* types = [self types]; 180 NSArray* types = [self types];
180 NSURL* urlFromNSURL = nil; // Used below in getting an URL from the NSURLPboa rdType. 181 NSURL* urlFromNSURL = nil; // Used below in getting an URL from the NSURLPboa rdType.
181 if ([types containsObject:kWebURLsWithTitlesPboardType]) { 182 if ([types containsObject:kWebURLsWithTitlesPboardType]) {
182 NSArray* urlAndTitleContainer = [self propertyListForType:kWebURLsWithTitles PboardType]; 183 NSArray* urlAndTitleContainer = [self propertyListForType:kWebURLsWithTitles PboardType];
183 *outUrls = [urlAndTitleContainer objectAtIndex:0]; 184 *outUrls = [urlAndTitleContainer objectAtIndex:0];
184 *outTitles = [urlAndTitleContainer objectAtIndex:1]; 185 *outTitles = [urlAndTitleContainer objectAtIndex:1];
185 } else if ([types containsObject:NSFilenamesPboardType]) { 186 } else if ([types containsObject:NSFilenamesPboardType]) {
186 NSArray *files = [self propertyListForType:NSFilenamesPboardType]; 187 NSArray *files = [self propertyListForType:NSFilenamesPboardType];
187 *outUrls = [NSMutableArray arrayWithCapacity:[files count]]; 188 *outUrls = [NSMutableArray arrayWithCapacity:[files count]];
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } else if ([types containsObject:NSURLPboardType] && (urlFromNSURL = [NSURL UR LFromPasteboard:self])) { 225 } else if ([types containsObject:NSURLPboardType] && (urlFromNSURL = [NSURL UR LFromPasteboard:self])) {
225 *outUrls = [NSArray arrayWithObject:[urlFromNSURL absoluteString]]; 226 *outUrls = [NSArray arrayWithObject:[urlFromNSURL absoluteString]];
226 NSString* title = nil; 227 NSString* title = nil;
227 if ([types containsObject:kCorePasteboardFlavorType_urld]) 228 if ([types containsObject:kCorePasteboardFlavorType_urld])
228 title = [self stringForType:kCorePasteboardFlavorType_urld]; 229 title = [self stringForType:kCorePasteboardFlavorType_urld];
229 if (!title && [types containsObject:kCorePasteboardFlavorType_urln]) 230 if (!title && [types containsObject:kCorePasteboardFlavorType_urln])
230 title = [self stringForType:kCorePasteboardFlavorType_urln]; 231 title = [self stringForType:kCorePasteboardFlavorType_urln];
231 if (!title && [types containsObject:NSStringPboardType]) 232 if (!title && [types containsObject:NSStringPboardType])
232 title = [self stringForType:NSStringPboardType]; 233 title = [self stringForType:NSStringPboardType];
233 *outTitles = [NSArray arrayWithObject:(title ? title : @"")]; 234 *outTitles = [NSArray arrayWithObject:(title ? title : @"")];
234 } else if ([types containsObject:NSStringPboardType]) { 235 } else if (convertTextToURL && [types containsObject:NSStringPboardType]) {
235 NSString* potentialURLString = [self cleanedStringWithPasteboardString:[self stringForType:NSStringPboardType]]; 236 NSString* potentialURLString = [self cleanedStringWithPasteboardString:[self stringForType:NSStringPboardType]];
236 if ([potentialURLString isValidURI]) { 237 if ([potentialURLString isValidURI]) {
237 *outUrls = [NSArray arrayWithObject:potentialURLString]; 238 *outUrls = [NSArray arrayWithObject:potentialURLString];
238 NSString* title = nil; 239 NSString* title = nil;
239 if ([types containsObject:kCorePasteboardFlavorType_urld]) 240 if ([types containsObject:kCorePasteboardFlavorType_urld])
240 title = [self stringForType:kCorePasteboardFlavorType_urld]; 241 title = [self stringForType:kCorePasteboardFlavorType_urld];
241 if (!title && [types containsObject:kCorePasteboardFlavorType_urln]) 242 if (!title && [types containsObject:kCorePasteboardFlavorType_urln])
242 title = [self stringForType:kCorePasteboardFlavorType_urln]; 243 title = [self stringForType:kCorePasteboardFlavorType_urln];
243 *outTitles = [NSArray arrayWithObject:(title ? title : @"")]; 244 *outTitles = [NSArray arrayWithObject:(title ? title : @"")];
244 } else { 245 } else {
245 // The string doesn't look like a URL - return empty arrays 246 // The string doesn't look like a URL - return empty arrays
246 *outUrls = [NSArray array]; 247 *outUrls = [NSArray array];
247 *outTitles = [NSArray array]; 248 *outTitles = [NSArray array];
248 } 249 }
249 } else { 250 } else {
250 // We don't recognise any of these formats - return empty arrays 251 // We don't recognise any of these formats - return empty arrays
251 *outUrls = [NSArray array]; 252 *outUrls = [NSArray array];
252 *outTitles = [NSArray array]; 253 *outTitles = [NSArray array];
253 } 254 }
254 } 255 }
255 256
256 // 257 //
257 // Indicates if this pasteboard contains URL data that we understand 258 // Indicates if this pasteboard contains URL data that we understand
258 // Deals with all our URL formats. Only strings that are valid URLs count. 259 // Deals with all our URL formats. Only strings that are valid URLs count.
259 // If this returns YES it is safe to use getURLs:andTitles: to retrieve the data . 260 // If this returns YES it is safe to use getURLs:andTitles: to retrieve the data .
260 // 261 //
261 // NB: Does not consider our internal bookmark list format, because callers 262 // NB: Does not consider our internal bookmark list format, because callers
262 // usually need to deal with this separately because it can include folders etc. 263 // usually need to deal with this separately because it can include folders etc.
263 // 264 //
264 - (BOOL) containsURLData 265 - (BOOL) containsURLDataConvertingTextToURL:(BOOL)convertTextToURL
265 { 266 {
266 NSArray* types = [self types]; 267 NSArray* types = [self types];
267 if ( [types containsObject:kWebURLsWithTitlesPboardType] 268 if ([types containsObject:kWebURLsWithTitlesPboardType] ||
268 || [types containsObject:NSURLPboardType] 269 [types containsObject:NSURLPboardType] ||
269 || [types containsObject:NSFilenamesPboardType] ) 270 [types containsObject:NSFilenamesPboardType])
270 return YES; 271 return YES;
271 272
272 if ([types containsObject:NSStringPboardType]) { 273 if (convertTextToURL && [types containsObject:NSStringPboardType]) {
273 // Trim whitespace off the ends and newlines out of the middle so we don't r eject otherwise-valid URLs; 274 // Trim whitespace off the ends and newlines out of the middle so we don't r eject otherwise-valid URLs;
274 // we'll do another cleaning when we set the URLs and titles later, so this is safe. 275 // we'll do another cleaning when we set the URLs and titles later, so this is safe.
275 NSString* potentialURLString = [self cleanedStringWithPasteboardString:[self stringForType:NSStringPboardType]]; 276 NSString* potentialURLString = [self cleanedStringWithPasteboardString:[self stringForType:NSStringPboardType]];
276 return [potentialURLString isValidURI]; 277 return [potentialURLString isValidURI];
277 } 278 }
278 279
279 return NO; 280 return NO;
280 } 281 }
281 @end 282 @end
282 283
(...skipping 14 matching lines...) Expand all
297 NSData* htmlData = 298 NSData* htmlData =
298 [attributed dataFromRange:NSMakeRange(0, [attributed length]) 299 [attributed dataFromRange:NSMakeRange(0, [attributed length])
299 documentAttributes:attributeDict 300 documentAttributes:attributeDict
300 error:nil]; 301 error:nil];
301 // According to the docs, NSHTMLTextDocumentType is UTF8. 302 // According to the docs, NSHTMLTextDocumentType is UTF8.
302 return [[[NSString alloc] 303 return [[[NSString alloc]
303 initWithData:htmlData encoding:NSUTF8StringEncoding] autorelease]; 304 initWithData:htmlData encoding:NSUTF8StringEncoding] autorelease];
304 } 305 }
305 306
306 @end 307 @end
OLDNEW
« no previous file with comments | « third_party/mozilla/NSPasteboard+Utils.h ('k') | third_party/mozilla/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698