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

Side by Side Diff: third_party/WebKit/Source/platform/clipboard/ClipboardUtilitiesWin.cpp

Issue 2674953003: Only generate suggested filenames when actually dragging an image. (Closed)
Patch Set: rebase Created 3 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. 3 * Copyright (C) 2009 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 15 matching lines...) Expand all
26 26
27 #include "platform/clipboard/ClipboardUtilities.h" 27 #include "platform/clipboard/ClipboardUtilities.h"
28 28
29 #include "wtf/text/StringBuilder.h" 29 #include "wtf/text/StringBuilder.h"
30 #include "wtf/text/WTFString.h" 30 #include "wtf/text/WTFString.h"
31 31
32 #include <shlwapi.h> 32 #include <shlwapi.h>
33 33
34 namespace blink { 34 namespace blink {
35 35
36 // FAT32 and NTFS both limit filenames to a maximum of 255 characters.
37 static const unsigned maxFilenameLength = 255;
38
39 // Returns true if the specified character is not valid in a file name. This
40 // is intended for use with removeCharacters.
41 static bool isInvalidFileCharacter(UChar c) {
42 return !(PathGetCharType(c) & (GCT_LFNCHAR | GCT_SHORTCHAR));
43 }
44
45 void replaceNewlinesWithWindowsStyleNewlines(String& str) { 36 void replaceNewlinesWithWindowsStyleNewlines(String& str) {
46 DEFINE_STATIC_LOCAL(String, windowsNewline, ("\r\n")); 37 DEFINE_STATIC_LOCAL(String, windowsNewline, ("\r\n"));
47 StringBuilder result; 38 StringBuilder result;
48 for (unsigned index = 0; index < str.length(); ++index) { 39 for (unsigned index = 0; index < str.length(); ++index) {
49 if (str[index] != '\n' || (index > 0 && str[index - 1] == '\r')) 40 if (str[index] != '\n' || (index > 0 && str[index - 1] == '\r'))
50 result.append(str[index]); 41 result.append(str[index]);
51 else 42 else
52 result.append(windowsNewline); 43 result.append(windowsNewline);
53 } 44 }
54 str = result.toString(); 45 str = result.toString();
55 } 46 }
56 47
57 void validateFilename(String& name, String& extension) {
58 // Remove any invalid file system characters.
59 name = name.removeCharacters(&isInvalidFileCharacter);
60 extension = extension.removeCharacters(&isInvalidFileCharacter);
61
62 if (extension.length() >= maxFilenameLength)
63 extension = String();
64
65 // Truncate overly-long filenames, reserving one character for a dot.
66 name.truncate(maxFilenameLength - extension.length() - 1);
67 }
68
69 } // namespace blink 48 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698