Index: Source/core/page/DOMWindowBase64.cpp |
diff --git a/Source/modules/webmidi/MIDIOutput.cpp b/Source/core/page/DOMWindowBase64.cpp |
similarity index 62% |
copy from Source/modules/webmidi/MIDIOutput.cpp |
copy to Source/core/page/DOMWindowBase64.cpp |
index e9066f0561fc600d24a8c1dd0fe59623522c6950..1e88852bd3738310d518d7a029d27416a4d7420b 100644 |
--- a/Source/modules/webmidi/MIDIOutput.cpp |
+++ b/Source/core/page/DOMWindowBase64.cpp |
@@ -1,5 +1,7 @@ |
/* |
- * Copyright (C) 2013 Google Inc. All rights reserved. |
+ * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. |
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
+ * Copyright (C) 2013 Samsung Electronics. All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions are |
@@ -29,32 +31,42 @@ |
*/ |
#include "config.h" |
-#include "modules/webmidi/MIDIOutput.h" |
+#include "DOMWindowBase64.h" |
+ |
+#include "wtf/text/Base64.h" |
namespace WebCore { |
-PassRefPtr<MIDIOutput> MIDIOutput::create(ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version) |
+String DOMWindowBase64::btoa(const String& stringToEncode, ExceptionCode& ec) const |
{ |
- return adoptRef(new MIDIOutput(context, id, manufacturer, name, version)); |
-} |
+ if (stringToEncode.isNull()) |
+ return String(); |
-MIDIOutput::MIDIOutput(ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version) |
- : MIDIPort(context, id, manufacturer, name, MIDIPortTypeOutput, version) |
-{ |
- ScriptWrappable::init(this); |
-} |
+ if (!stringToEncode.containsOnlyLatin1()) { |
+ ec = InvalidCharacterError; |
+ return String(); |
+ } |
-void MIDIOutput::send(Uint8Array* data, double timestamp) |
-{ |
- // FIXME: Implement MIDI protocol validation here. System exclusive |
- // messages must be checked at the same time. |
- // Actual sending operation will be implemented in core/platform/midi. |
+ return base64Encode(stringToEncode.latin1()); |
} |
-void MIDIOutput::send(Vector<unsigned>, double timestamp) |
+String DOMWindowBase64::atob(const String& encodedString, ExceptionCode& ec) const |
{ |
- // FIXME: Ditto. Implementation will be shared between these two send |
- // functions. |
+ if (encodedString.isNull()) |
+ return String(); |
+ |
+ if (!encodedString.containsOnlyLatin1()) { |
+ ec = InvalidCharacterError; |
+ return String(); |
+ } |
+ |
+ Vector<char> out; |
+ if (!base64Decode(encodedString, out, Base64FailOnInvalidCharacter)) { |
+ ec = InvalidCharacterError; |
+ return String(); |
+ } |
+ |
+ return String(out.data(), out.size()); |
} |
} // namespace WebCore |