Chromium Code Reviews| 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 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/mac/mac_logging.h" | 9 #include "base/mac/mac_logging.h" |
| 10 #include "chrome/browser/search/search.h" | 10 #include "chrome/browser/search/search.h" |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 | 715 |
| 716 // Returns if there is already a file |name| at dir NSURL |base|. | 716 // Returns if there is already a file |name| at dir NSURL |base|. |
| 717 static BOOL FileAlreadyExists(NSURL* base, NSString* name) { | 717 static BOOL FileAlreadyExists(NSURL* base, NSString* name) { |
| 718 NSString* path = PathWithBaseURLAndName(base, name); | 718 NSString* path = PathWithBaseURLAndName(base, name); |
| 719 DCHECK([path hasSuffix:name]); | 719 DCHECK([path hasSuffix:name]); |
| 720 return [[NSFileManager defaultManager] fileExistsAtPath:path]; | 720 return [[NSFileManager defaultManager] fileExistsAtPath:path]; |
| 721 } | 721 } |
| 722 | 722 |
| 723 // Takes a destination URL, a suggested file name, & an extension (eg .webloc). | 723 // Takes a destination URL, a suggested file name, & an extension (eg .webloc). |
| 724 // Returns the complete file name with extension you should use. | 724 // Returns the complete file name with extension you should use. |
| 725 // The name returned will not contain /, : or ?, will not be longer than | 725 // The name returned will not contain /, : or ?, will not start with a dot, |
| 726 // kMaxNameLength + length of extension, and will not be a file name that | 726 // will not be longer than kMaxNameLength + length of extension, and will not |
| 727 // already exists in that directory. If necessary it will try appending a space | 727 // be a file name that already exists in that directory. If necessary it will |
| 728 // and a number to the name (but before the extension) trying numbers up to and | 728 // try appending a space and a number to the name (but before the extension) |
| 729 // including kMaxIndex. | 729 // trying numbers up to and including kMaxIndex. |
| 730 // If the function gives up it returns nil. | 730 // If the function gives up it returns nil. |
| 731 static NSString* UnusedLegalNameForNewDropFile(NSURL* saveLocation, | 731 static NSString* UnusedLegalNameForNewDropFile(NSURL* saveLocation, |
| 732 NSString *fileName, | 732 NSString *fileName, |
| 733 NSString *extension) { | 733 NSString *extension) { |
| 734 int number = 1; | 734 int number = 1; |
| 735 const int kMaxIndex = 20; | 735 const int kMaxIndex = 20; |
| 736 const unsigned kMaxNameLength = 64; // Arbitrary. | 736 const unsigned kMaxNameLength = 64; // Arbitrary. |
| 737 | 737 |
| 738 NSString* filteredName = [fileName stringByReplacingOccurrencesOfString:@"/" | 738 NSString* filteredName = [fileName stringByReplacingOccurrencesOfString:@"/" |
| 739 withString:@"-"]; | 739 withString:@"-"]; |
| 740 filteredName = [filteredName stringByReplacingOccurrencesOfString:@":" | 740 filteredName = [filteredName stringByReplacingOccurrencesOfString:@":" |
| 741 withString:@"-"]; | 741 withString:@"-"]; |
| 742 filteredName = [filteredName stringByReplacingOccurrencesOfString:@"?" | 742 filteredName = [filteredName stringByReplacingOccurrencesOfString:@"?" |
| 743 withString:@"-"]; | 743 withString:@"-"]; |
| 744 filteredName = [filteredName stringByReplacingOccurrencesOfString:@"." | |
| 745 withString:@"-" options:0 range:NSMakeRange(0,1)]; | |
|
Scott Hess - ex-Googler
2015/06/09 20:37:29
http://google-styleguide.googlecode.com/svn/trunk/
| |
| 744 | 746 |
| 745 if ([filteredName length] > kMaxNameLength) | 747 if ([filteredName length] > kMaxNameLength) |
| 746 filteredName = [filteredName substringToIndex:kMaxNameLength]; | 748 filteredName = [filteredName substringToIndex:kMaxNameLength]; |
| 747 | 749 |
| 748 NSString* candidateName = [filteredName stringByAppendingString:extension]; | 750 NSString* candidateName = [filteredName stringByAppendingString:extension]; |
| 749 | 751 |
| 750 while (FileAlreadyExists(saveLocation, candidateName)) { | 752 while (FileAlreadyExists(saveLocation, candidateName)) { |
| 751 if (number > kMaxIndex) | 753 if (number > kMaxIndex) |
| 752 return nil; | 754 return nil; |
| 753 else | 755 else |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 focusEvent_.reset([event retain]); | 865 focusEvent_.reset([event retain]); |
| 864 return; | 866 return; |
| 865 } | 867 } |
| 866 } | 868 } |
| 867 | 869 |
| 868 // Handle event immediately. | 870 // Handle event immediately. |
| 869 [self focusNotificationFor:event ofView:controlView]; | 871 [self focusNotificationFor:event ofView:controlView]; |
| 870 } | 872 } |
| 871 | 873 |
| 872 @end | 874 @end |
| OLD | NEW |