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

Unified Diff: Source/WebCore/platform/chromium/ClipboardChromiumMac.cpp

Issue 7054067: Merge 87848 - 2011-06-01 Daniel Cheng <dcheng@chromium.org> (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/782/
Patch Set: Created 9 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/WebCore/platform/chromium/ClipboardChromium.cpp ('k') | Tools/DumpRenderTree/chromium/EventSender.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/platform/chromium/ClipboardChromiumMac.cpp
===================================================================
--- Source/WebCore/platform/chromium/ClipboardChromiumMac.cpp (revision 88116)
+++ Source/WebCore/platform/chromium/ClipboardChromiumMac.cpp (working copy)
@@ -28,14 +28,42 @@
#include "ClipboardChromium.h"
#include "ChromiumDataObject.h"
-#include "NotImplemented.h"
namespace WebCore {
+
+// Filename length and character-set limits vary by filesystem, and there's no
+// real way to tell what filesystem is in use. Since HFS+ is by far the most
+// common, we'll abide by its limits, which are 255 Unicode characters (slightly
+// simplified; really it uses Normalization Form D, but the differences aren't
+// really worth dealing with here.)
+static const unsigned MaxHFSFilenameLength = 255;
+
+
+static bool isInvalidFileCharacter(UChar c)
+{
+ // HFS+ basically allows anything but '/'. For sanity's sake we'll disallow
+ // control characters.
+ return c < ' ' || c == 0x7F || c == '/';
+}
+
String ClipboardChromium::validateFileName(const String& title, ChromiumDataObject* dataObject)
{
- notImplemented();
- return title;
+ // Remove any invalid file system characters, especially "/".
+ String result = title.removeCharacters(isInvalidFileCharacter);
+ String extension = dataObject->fileExtension().removeCharacters(&isInvalidFileCharacter);
+
+ // Remove a ridiculously-long extension.
+ if (extension.length() >= MaxHFSFilenameLength)
+ extension = "";
+
+ // Truncate an overly-long filename.
+ int overflow = result.length() + extension.length() - MaxHFSFilenameLength;
+ if (overflow > 0)
+ result.remove(result.length() - overflow, overflow);
+
+ dataObject->setFileExtension(extension);
+ return result;
}
} // namespace WebCore
« no previous file with comments | « Source/WebCore/platform/chromium/ClipboardChromium.cpp ('k') | Tools/DumpRenderTree/chromium/EventSender.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698