| OLD | NEW |
| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } else if ([types containsObject:NSURLPboardType] && (urlFromNSURL = [NSURL UR
LFromPasteboard:self])) { | 224 } else if ([types containsObject:NSURLPboardType] && (urlFromNSURL = [NSURL UR
LFromPasteboard:self])) { |
| 225 *outUrls = [NSArray arrayWithObject:[urlFromNSURL absoluteString]]; | 225 *outUrls = [NSArray arrayWithObject:[urlFromNSURL absoluteString]]; |
| 226 NSString* title = nil; | 226 NSString* title = nil; |
| 227 if ([types containsObject:kCorePasteboardFlavorType_urld]) | 227 if ([types containsObject:kCorePasteboardFlavorType_urld]) |
| 228 title = [self stringForType:kCorePasteboardFlavorType_urld]; | 228 title = [self stringForType:kCorePasteboardFlavorType_urld]; |
| 229 if (!title && [types containsObject:kCorePasteboardFlavorType_urln]) | 229 if (!title && [types containsObject:kCorePasteboardFlavorType_urln]) |
| 230 title = [self stringForType:kCorePasteboardFlavorType_urln]; | 230 title = [self stringForType:kCorePasteboardFlavorType_urln]; |
| 231 if (!title && [types containsObject:NSStringPboardType]) | 231 if (!title && [types containsObject:NSStringPboardType]) |
| 232 title = [self stringForType:NSStringPboardType]; | 232 title = [self stringForType:NSStringPboardType]; |
| 233 *outTitles = [NSArray arrayWithObject:(title ? title : @"")]; | 233 *outTitles = [NSArray arrayWithObject:(title ? title : @"")]; |
| 234 } else if ([types containsObject:NSStringPboardType]) { | |
| 235 NSString* potentialURLString = [self cleanedStringWithPasteboardString:[self
stringForType:NSStringPboardType]]; | |
| 236 if ([potentialURLString isValidURI]) { | |
| 237 *outUrls = [NSArray arrayWithObject:potentialURLString]; | |
| 238 NSString* title = nil; | |
| 239 if ([types containsObject:kCorePasteboardFlavorType_urld]) | |
| 240 title = [self stringForType:kCorePasteboardFlavorType_urld]; | |
| 241 if (!title && [types containsObject:kCorePasteboardFlavorType_urln]) | |
| 242 title = [self stringForType:kCorePasteboardFlavorType_urln]; | |
| 243 *outTitles = [NSArray arrayWithObject:(title ? title : @"")]; | |
| 244 } else { | |
| 245 // The string doesn't look like a URL - return empty arrays | |
| 246 *outUrls = [NSArray array]; | |
| 247 *outTitles = [NSArray array]; | |
| 248 } | |
| 249 } else { | 234 } else { |
| 250 // We don't recognise any of these formats - return empty arrays | 235 // We don't recognise any of these formats - return empty arrays |
| 251 *outUrls = [NSArray array]; | 236 *outUrls = [NSArray array]; |
| 252 *outTitles = [NSArray array]; | 237 *outTitles = [NSArray array]; |
| 253 } | 238 } |
| 254 } | 239 } |
| 255 | 240 |
| 256 // | 241 // |
| 257 // Indicates if this pasteboard contains URL data that we understand | 242 // Indicates if this pasteboard contains URL data that we understand |
| 258 // Deals with all our URL formats. Only strings that are valid URLs count. | 243 // 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
. | 244 // If this returns YES it is safe to use getURLs:andTitles: to retrieve the data
. |
| 260 // | 245 // |
| 261 // NB: Does not consider our internal bookmark list format, because callers | 246 // 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. | 247 // usually need to deal with this separately because it can include folders etc. |
| 263 // | 248 // |
| 264 - (BOOL) containsURLData | 249 - (BOOL) containsURLData |
| 265 { | 250 { |
| 266 NSArray* types = [self types]; | 251 NSArray* types = [self types]; |
| 267 if ( [types containsObject:kWebURLsWithTitlesPboardType] | 252 return [types containsObject:kWebURLsWithTitlesPboardType] || |
| 268 || [types containsObject:NSURLPboardType] | 253 [types containsObject:NSURLPboardType] || |
| 269 || [types containsObject:NSFilenamesPboardType] ) | 254 [types containsObject:NSFilenamesPboardType]; |
| 270 return YES; | |
| 271 | |
| 272 if ([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 // 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 return [potentialURLString isValidURI]; | |
| 277 } | |
| 278 | |
| 279 return NO; | |
| 280 } | 255 } |
| 281 @end | 256 @end |
| 282 | 257 |
| 283 @implementation NSPasteboard(ChromiumHTMLUtils) | 258 @implementation NSPasteboard(ChromiumHTMLUtils) |
| 284 | 259 |
| 285 // Convert the RTF to HTML via an NSAttributedString. | 260 // Convert the RTF to HTML via an NSAttributedString. |
| 286 - (NSString*)htmlFromRtf { | 261 - (NSString*)htmlFromRtf { |
| 287 if (![[self types] containsObject:NSRTFPboardType]) | 262 if (![[self types] containsObject:NSRTFPboardType]) |
| 288 return @""; | 263 return @""; |
| 289 | 264 |
| 290 NSAttributedString* attributed = | 265 NSAttributedString* attributed = |
| 291 [[[NSAttributedString alloc] | 266 [[[NSAttributedString alloc] |
| 292 initWithRTF:[self dataForType:NSRTFPboardType] | 267 initWithRTF:[self dataForType:NSRTFPboardType] |
| 293 documentAttributes:nil] autorelease]; | 268 documentAttributes:nil] autorelease]; |
| 294 NSDictionary* attributeDict = | 269 NSDictionary* attributeDict = |
| 295 [NSDictionary dictionaryWithObject:NSHTMLTextDocumentType | 270 [NSDictionary dictionaryWithObject:NSHTMLTextDocumentType |
| 296 forKey:NSDocumentTypeDocumentAttribute]; | 271 forKey:NSDocumentTypeDocumentAttribute]; |
| 297 NSData* htmlData = | 272 NSData* htmlData = |
| 298 [attributed dataFromRange:NSMakeRange(0, [attributed length]) | 273 [attributed dataFromRange:NSMakeRange(0, [attributed length]) |
| 299 documentAttributes:attributeDict | 274 documentAttributes:attributeDict |
| 300 error:nil]; | 275 error:nil]; |
| 301 // According to the docs, NSHTMLTextDocumentType is UTF8. | 276 // According to the docs, NSHTMLTextDocumentType is UTF8. |
| 302 return [[[NSString alloc] | 277 return [[[NSString alloc] |
| 303 initWithData:htmlData encoding:NSUTF8StringEncoding] autorelease]; | 278 initWithData:htmlData encoding:NSUTF8StringEncoding] autorelease]; |
| 304 } | 279 } |
| 305 | 280 |
| 306 @end | 281 @end |
| OLD | NEW |