OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "public/platform/URLConversion.h" |
| 6 |
| 7 #include "public/platform/WebString.h" |
| 8 #include "url/gurl.h" |
| 9 #include "wtf/text/StringUTF8Adaptor.h" |
| 10 #include "wtf/text/WTFString.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 GURL WebStringToGURL(const WebString& webString) |
| 15 { |
| 16 if (webString.isEmpty()) |
| 17 return GURL(); |
| 18 |
| 19 String str = webString; |
| 20 if (str.is8Bit()) { |
| 21 // Ensure the (possibly Latin-1) 8-bit string is UTF-8 for GURL. |
| 22 StringUTF8Adaptor utf8(str); |
| 23 return GURL(utf8.asStringPiece()); |
| 24 } |
| 25 |
| 26 // GURL can consume UTF-16 directly. |
| 27 return GURL(base::StringPiece16(str.characters16(), str.length())); |
| 28 } |
| 29 |
| 30 } // namespace blink |
OLD | NEW |