| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * Copyright (C) 2013 Samsung Electronics. All rights reserved. | 4 * Copyright (C) 2013 Samsung Electronics. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
| 8 * met: | 8 * met: |
| 9 * | 9 * |
| 10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 */ | 31 */ |
| 32 | 32 |
| 33 #include "config.h" | 33 #include "config.h" |
| 34 #include "core/frame/DOMWindowBase64.h" | 34 #include "core/frame/DOMWindowBase64.h" |
| 35 | 35 |
| 36 #include "bindings/v8/ExceptionState.h" | 36 #include "bindings/v8/ExceptionState.h" |
| 37 #include "core/dom/ExceptionCode.h" | 37 #include "core/dom/ExceptionCode.h" |
| 38 #include "core/html/parser/HTMLParserIdioms.h" |
| 38 #include "wtf/text/Base64.h" | 39 #include "wtf/text/Base64.h" |
| 39 | 40 |
| 40 namespace WebCore { | 41 namespace WebCore { |
| 41 | 42 |
| 42 namespace DOMWindowBase64 { | 43 namespace DOMWindowBase64 { |
| 43 | 44 |
| 44 String btoa(void*, const String& stringToEncode, ExceptionState& es) | 45 String btoa(void*, const String& stringToEncode, ExceptionState& es) |
| 45 { | 46 { |
| 46 if (stringToEncode.isNull()) | 47 if (stringToEncode.isNull()) |
| 47 return String(); | 48 return String(); |
| 48 | 49 |
| 49 if (!stringToEncode.containsOnlyLatin1()) { | 50 if (!stringToEncode.containsOnlyLatin1()) { |
| 50 es.throwDOMException(InvalidCharacterError, "'btoa' failed: The string t
o be encoded contains characters outside of the Latin1 range."); | 51 es.throwDOMException(InvalidCharacterError, "'btoa' failed: The string t
o be encoded contains characters outside of the Latin1 range."); |
| 51 return String(); | 52 return String(); |
| 52 } | 53 } |
| 53 | 54 |
| 54 return base64Encode(stringToEncode.latin1()); | 55 return base64Encode(stringToEncode.latin1()); |
| 55 } | 56 } |
| 56 | 57 |
| 57 String atob(void*, const String& encodedString, ExceptionState& es) | 58 String atob(void*, const String& encodedString, ExceptionState& es) |
| 58 { | 59 { |
| 59 if (encodedString.isNull()) | 60 if (encodedString.isNull()) |
| 60 return String(); | 61 return String(); |
| 61 | 62 |
| 62 if (!encodedString.containsOnlyLatin1()) { | 63 if (!encodedString.containsOnlyLatin1()) { |
| 63 es.throwDOMException(InvalidCharacterError, "'atob' failed: The string t
o be decoded contains characters outside of the Latin1 range."); | 64 es.throwDOMException(InvalidCharacterError, "'atob' failed: The string t
o be decoded contains characters outside of the Latin1 range."); |
| 64 return String(); | 65 return String(); |
| 65 } | 66 } |
| 66 | |
| 67 Vector<char> out; | 67 Vector<char> out; |
| 68 if (!base64Decode(encodedString, out, Base64FailOnInvalidCharacterOrExcessPa
dding)) { | 68 if (!base64Decode(encodedString, out, isHTMLSpace<UChar>, Base64ValidatePadd
ing)) { |
| 69 es.throwDOMException(InvalidCharacterError, "'atob' failed: The string t
o be decoded is not correctly encoded."); | 69 es.throwDOMException(InvalidCharacterError, "'atob' failed: The string t
o be decoded is not correctly encoded."); |
| 70 return String(); | 70 return String(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 return String(out.data(), out.size()); | 73 return String(out.data(), out.size()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace DOMWindowBase64 | 76 } // namespace DOMWindowBase64 |
| 77 | 77 |
| 78 } // namespace WebCore | 78 } // namespace WebCore |
| OLD | NEW |