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

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: 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..bd45642999da530679efec4e64e2af605e55a452
--- /dev/null
+++ b/third_party/WebKit/Source/platform/exported/FilePathConversion.cpp
@@ -0,0 +1,30 @@
+// 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();
+
+ // Depending on platforms base::FilePath can be efficiently constructed
+ // from UTF8 or UTF16.
Nico 2016/02/15 16:45:14 After: Windows: - 8bit: - ascii-only: calls Fro
+ String str = webString;
+ if (str.is8Bit()) {
+ StringUTF8Adaptor utf8(str);
+ return base::FilePath::FromUTF8Unsafe(utf8.asStringPiece());
+ }
+ return base::FilePath::FromUTF16Unsafe(
Nico 2016/02/15 16:45:14 does this branch have test coverage?
+ base::StringPiece16(str.characters16(), str.length()));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698