Chromium Code Reviews| 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 |