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

Unified Diff: third_party/WebKit/Source/platform/exported/FilePathConversion.cpp

Issue 1686263008: Add utility method for WebString to base::FilePath conversion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase! Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/exported/FilePathConversion.cpp
diff --git a/third_party/WebKit/Source/platform/exported/FilePathConversion.cpp b/third_party/WebKit/Source/platform/exported/FilePathConversion.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e518e595f2f330b1c56fa1ecb0a2d0ef6cf5b521
--- /dev/null
+++ b/third_party/WebKit/Source/platform/exported/FilePathConversion.cpp
@@ -0,0 +1,35 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "public/platform/FilePathConversion.h"
+
+#include "base/files/file_path.h"
+#include "public/platform/WebString.h"
+#include "wtf/text/StringUTF8Adaptor.h"
+#include "wtf/text/WTFString.h"
+
+namespace blink {
+
+base::FilePath WebStringToFilePath(const WebString& webString)
+{
+ if (webString.isEmpty())
+ return base::FilePath();
+
+ String str = webString;
+ if (!str.is8Bit()) {
+ return base::FilePath::FromUTF16Unsafe(
+ base::StringPiece16(str.characters16(), str.length()));
+ }
+
+#if OS(POSIX)
+ StringUTF8Adaptor utf8(str);
+ return base::FilePath::FromUTF8Unsafe(utf8.asStringPiece());
+#else
+ const LChar* data8 = str.characters8();
+ return base::FilePath::FromUTF16Unsafe(
+ base::string16(data8, data8 + str.length()));
+#endif
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698