Commit dcae628b authored by ap's avatar ap

http://bugs.webkit.org/show_bug.cgi?id=9673

        Add support for window.atob() and window.btoa()

        Reviewed by Darin.

JavaScriptCore:
        * JavaScriptCore.exp: Export UString::is8Bit().
        * JavaScriptCore.xcodeproj/project.pbxproj: Added StringExtras.h as
        a private header.

WebCore:
        * WebCore.xcodeproj/project.pbxproj: Added Base64.{h,cpp}
        * bindings/js/kjs_window.cpp:
        (KJS::WindowFunc::callAsFunction):
        * bindings/js/kjs_window.h:
        (KJS::Window::):
        * platform/Base64.cpp: Added.
        (base64Encode):
        (base64Decode):
        * platform/Base64.h: Added.
        * ForwardingHeaders/wtf/StringExtras.h: Added.
        * platform/DeprecatedString.cpp: Use strncasecmp from StringExtras.

LayoutTests:
        * fast/dom/Window/atob-btoa-expected.txt: Added.
        * fast/dom/Window/atob-btoa.html: Added.
        * fast/dom/Window/btoa-pnglet-expected.checksum: Added.
        * fast/dom/Window/btoa-pnglet-expected.png: Added.
        * fast/dom/Window/btoa-pnglet-expected.txt: Added.
        * fast/dom/Window/btoa-pnglet.html: Added.
        * fast/dom/Window/window-properties-expected.txt:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@18170 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ec94d76b
2006-12-11 Alexey Proskuryakov <ap@webkit.org>
Reviewed by Darin.
http://bugs.webkit.org/show_bug.cgi?id=9673
Add support for window.atob() and window.btoa()
* JavaScriptCore.exp: Export UString::is8Bit().
* JavaScriptCore.xcodeproj/project.pbxproj: Added StringExtras.h as
a private header.
2006-12-11 Darin Adler <darin@apple.com>
Reviewed by Brady.
......
......@@ -252,6 +252,7 @@ __ZNK3KJS7JSValue9toIntegerEPNS_9ExecStateE
__ZNK3KJS7UString10UTF8StringEv
__ZNK3KJS7UString14toStrictUInt32EPb
__ZNK3KJS7UString5asciiEv
__ZNK3KJS7UString6is8BitEv
__ZNK3KJS7UString8toUInt32EPb
__ZNK3KJS8JSObject11hasPropertyEPNS_9ExecStateERKNS_10IdentifierE
__ZNK3KJS8JSObject12defaultValueEPNS_9ExecStateENS_6JSTypeE
......
......@@ -262,6 +262,7 @@
BCF655590A2049710038A194 /* MathExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = BCF6553B0A2048DE0038A194 /* MathExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
D212022A0AD4310D00ED79B6 /* DateMath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D21202280AD4310C00ED79B6 /* DateMath.cpp */; };
D212022B0AD4310D00ED79B6 /* DateMath.h in Headers */ = {isa = PBXBuildFile; fileRef = D21202290AD4310C00ED79B6 /* DateMath.h */; };
E11D51760B2E798D0056C188 /* StringExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = E11D51750B2E798D0056C188 /* StringExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
E195679609E7CF1200B89D13 /* UnicodeIcu.h in Headers */ = {isa = PBXBuildFile; fileRef = E195678F09E7CF1200B89D13 /* UnicodeIcu.h */; settings = {ATTRIBUTES = (Private, ); }; };
E195679809E7CF1200B89D13 /* Unicode.h in Headers */ = {isa = PBXBuildFile; fileRef = E195679409E7CF1200B89D13 /* Unicode.h */; settings = {ATTRIBUTES = (Private, ); }; };
/* End PBXBuildFile section */
......@@ -285,23 +286,6 @@
};
/* End PBXBuildRule section */
/* Begin PBXBuildStyle section */
BC4C649B0B2A359400E57352 /* Development */ = {
isa = PBXBuildStyle;
buildSettings = {
COPY_PHASE_STRIP = NO;
};
name = Development;
};
BC4C649C0B2A359400E57352 /* Deployment */ = {
isa = PBXBuildStyle;
buildSettings = {
COPY_PHASE_STRIP = YES;
};
name = Deployment;
};
/* End PBXBuildStyle section */
/* Begin PBXContainerItemProxy section */
141211350A48796100480255 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
......@@ -554,6 +538,7 @@
BCF6553B0A2048DE0038A194 /* MathExtras.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MathExtras.h; sourceTree = "<group>"; };
D21202280AD4310C00ED79B6 /* DateMath.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DateMath.cpp; sourceTree = "<group>"; };
D21202290AD4310C00ED79B6 /* DateMath.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DateMath.h; sourceTree = "<group>"; };
E11D51750B2E798D0056C188 /* StringExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringExtras.h; sourceTree = "<group>"; };
E195678F09E7CF1200B89D13 /* UnicodeIcu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnicodeIcu.h; sourceTree = "<group>"; };
E195679409E7CF1200B89D13 /* Unicode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Unicode.h; sourceTree = "<group>"; };
F5BB2BC5030F772101FCFE1D /* completion.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = completion.h; sourceTree = "<group>"; tabWidth = 8; };
......@@ -856,6 +841,7 @@
6580F795094070560082C219 /* PassRefPtr.h */,
65D6D87E09B5A32E0002E4D7 /* Platform.h */,
65C647B3093EF8D60022C380 /* RefPtr.h */,
E11D51750B2E798D0056C188 /* StringExtras.h */,
6541BD6E08E80A17002CBEE7 /* TCPageMap.h */,
6541BD6F08E80A17002CBEE7 /* TCSpinLock.h */,
6541BD7008E80A17002CBEE7 /* TCSystemAlloc.cpp */,
......@@ -1161,6 +1147,7 @@
65C7A1740A8EAACB00FA37EA /* JSWrapperObject.h in Headers */,
93B6A0DF0AA64DA40076DE27 /* GetPtr.h in Headers */,
D212022B0AD4310D00ED79B6 /* DateMath.h in Headers */,
E11D51760B2E798D0056C188 /* StringExtras.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
2006-12-11 Alexey Proskuryakov <ap@nypop.com>
http://bugs.webkit.org/show_bug.cgi?id=9673
Add support for window.atob() and window.btoa()
Reviewed by Darin.
* fast/dom/Window/atob-btoa-expected.txt: Added.
* fast/dom/Window/atob-btoa.html: Added.
* fast/dom/Window/btoa-pnglet-expected.checksum: Added.
* fast/dom/Window/btoa-pnglet-expected.png: Added.
* fast/dom/Window/btoa-pnglet-expected.txt: Added.
* fast/dom/Window/btoa-pnglet.html: Added.
* fast/dom/Window/window-properties-expected.txt:
2006-12-11 Darin Adler <darin@apple.com>
* fast/frames/iframe-option-crash-expected.txt: Updated results for this test.
PASS window.atob("YQ==") is "a"
PASS window.atob("YWI=") is "ab"
PASS window.atob("YWJj") is "abc"
PASS window.atob("YWJjZA==") is "abcd"
PASS window.atob("YWJjZGU=") is "abcde"
PASS window.atob("YWJjZGVm") is "abcdef"
PASS window.btoa("a") is "YQ=="
PASS window.btoa("ab") is "YWI="
PASS window.btoa("abc") is "YWJj"
PASS window.btoa("abcd") is "YWJjZA=="
PASS window.btoa("abcde") is "YWJjZGU="
PASS window.btoa("abcdef") is "YWJjZGVm"
PASS typeof window.btoa is "function"
PASS window.btoa() threw exception SyntaxError: Not enough arguments.
PASS window.btoa("") is ""
PASS window.btoa(null) is ""
PASS window.btoa(window) is "W29iamVjdCBXaW5kb3dd"
PASS window.btoa("éé") is "6ek="
PASS window.btoa("\u0080\u0081") is "gIE="
PASS window.btoa("тест") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
PASS window.btoa is 0
PASS typeof window.btoa is "number"
PASS typeof window.atob is "function"
PASS window.atob() threw exception SyntaxError: Not enough arguments.
PASS window.atob("") is ""
PASS window.atob(null) is ""
PASS window.atob(" YQ==") threw exception Error: Cannot decode base64.
PASS window.atob("YQ==\u000a") threw exception Error: Cannot decode base64.
PASS window.atob("6ek=") is "éé"
PASS window.atob("6ek") is "éé"
PASS window.atob("gIE=") is "€"
PASS window.atob("тест") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
PASS window.atob("z") threw exception Error: Cannot decode base64.
PASS window.atob("zz") is "Ï"
PASS window.atob("zzz") is "Ï<"
PASS window.atob("zzzz") is "Ï<ó"
PASS window.atob("zzzzz") threw exception Error: Cannot decode base64.
PASS window.atob("=") threw exception Error: Cannot decode base64.
PASS window.atob("==") threw exception Error: Cannot decode base64.
PASS window.atob("===") threw exception Error: Cannot decode base64.
PASS window.atob("====") threw exception Error: Cannot decode base64.
PASS window.atob("=====") threw exception Error: Cannot decode base64.
PASS window.atob is 0
PASS typeof window.atob is "number"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../../js/resources/js-test-style.css">
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
shouldBe('window.atob("YQ==")', '"a"');
shouldBe('window.atob("YWI=")', '"ab"');
shouldBe('window.atob("YWJj")', '"abc"');
shouldBe('window.atob("YWJjZA==")', '"abcd"');
shouldBe('window.atob("YWJjZGU=")', '"abcde"');
shouldBe('window.atob("YWJjZGVm")', '"abcdef"');
shouldBe('window.btoa("a")', '"YQ=="');
shouldBe('window.btoa("ab")', '"YWI="');
shouldBe('window.btoa("abc")', '"YWJj"');
shouldBe('window.btoa("abcd")', '"YWJjZA=="');
shouldBe('window.btoa("abcde")', '"YWJjZGU="');
shouldBe('window.btoa("abcdef")', '"YWJjZGVm"');
shouldBe('typeof window.btoa', '"function"');
shouldThrow('window.btoa()');
shouldBe('window.btoa("")', '""');
shouldBe('window.btoa(null)', '""');
shouldBe('window.btoa(window)', '"W29iamVjdCBXaW5kb3dd"'); // "[object Window]"
shouldBe('window.btoa("éé")', '"6ek="');
shouldBe('window.btoa("\\u0080\\u0081")', '"gIE="');
shouldThrow('window.btoa("тест")');
window.btoa = 0;
shouldBe('window.btoa', '0');
shouldBe('typeof window.btoa', '"number"');
shouldBe('typeof window.atob', '"function"');
shouldThrow('window.atob()');
shouldBe('window.atob("")', '""');
shouldBe('window.atob(null)', '""');
shouldThrow('window.atob(" YQ==")');
shouldThrow('window.atob("YQ==\\u000a")');
shouldBe('window.atob("6ek=")', '"éé"');
shouldBe('window.atob("6ek")', '"éé"');
shouldBe('window.atob("gIE=")', '"\u0080\u0081"');
shouldThrow('window.atob("тест")');
shouldThrow('window.atob("z")');
shouldBe('window.atob("zz")', '"Ï"');
shouldBe('window.atob("zzz")', '\u003C"');
shouldBe('window.atob("zzzz")', '\u003Có"');
shouldThrow('window.atob("zzzzz")');
shouldThrow('window.atob("=")');
shouldThrow('window.atob("==")');
shouldThrow('window.atob("===")');
shouldThrow('window.atob("====")');
shouldThrow('window.atob("=====")');
window.atob = 0;
shouldBe('window.atob', '0');
shouldBe('typeof window.atob', '"number"');
successfullyParsed = true;
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>
40e68cf2b802e976b46b19f94ff19a55
\ No newline at end of file
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderBlock {P} at (0,0) size 784x18
RenderText {#text} at (0,0) size 216x18
text run at (0,0) width 216: "Should see a light green rectangle:"
RenderBlock {DIV} at (0,34) size 784x100
RenderImage {IMG} at (0,0) size 100x100
This diff is collapsed.
......@@ -535,28 +535,13 @@ window.XSLTProcessor.prototype.transformToFragment [function]
window.addEventListener [function]
window.alert [function]
window.appleScriptController [object RuntimeObject]
window.atob [function]
window.blur [function]
window.btoa [function]
window.captureEvents [function]
window.clearInterval [function]
window.clearTimeout [function]
window.clientInformation [object Navigator]
window.clientInformation.appCodeName [string]
window.clientInformation.appName [string]
window.clientInformation.appVersion [string]
window.clientInformation.cookieEnabled [boolean]
window.clientInformation.javaEnabled [function]
window.clientInformation.language [string]
window.clientInformation.mimeTypes [object MimeTypeArray]
window.clientInformation.mimeTypes.length [number]
window.clientInformation.platform [string]
window.clientInformation.plugins [object PluginArray]
window.clientInformation.plugins.length [number]
window.clientInformation.plugins.refresh [function]
window.clientInformation.product [string]
window.clientInformation.productSub [string]
window.clientInformation.userAgent [string]
window.clientInformation.vendor [string]
window.clientInformation.vendorSub [string]
window.clientInformation [printed above as window.navigator]
window.close [function]
window.closed [boolean]
window.confirm [function]
......@@ -1617,7 +1602,24 @@ window.moveBy [function]
window.moveTo [function]
window.name [string]
window.navigationController [object RuntimeObject]
window.navigator [printed above as window.clientInformation]
window.navigator [object Navigator]
window.navigator.appCodeName [string]
window.navigator.appName [string]
window.navigator.appVersion [string]
window.navigator.cookieEnabled [boolean]
window.navigator.javaEnabled [function]
window.navigator.language [string]
window.navigator.mimeTypes [object MimeTypeArray]
window.navigator.mimeTypes.length [number]
window.navigator.platform [string]
window.navigator.plugins [object PluginArray]
window.navigator.plugins.length [number]
window.navigator.plugins.refresh [function]
window.navigator.product [string]
window.navigator.productSub [string]
window.navigator.userAgent [string]
window.navigator.vendor [string]
window.navigator.vendorSub [string]
window.objCPlugin [object RuntimeObject]
window.objCPluginFunction [function]
window.offscreenBuffering [boolean]
......
2006-12-11 Alexey Proskuryakov <ap@nypop.com>
Reviewed by Darin.
http://bugs.webkit.org/show_bug.cgi?id=9673
Add support for window.atob() and window.btoa()
* WebCore.xcodeproj/project.pbxproj: Added Base64.{h,cpp}
* bindings/js/kjs_window.cpp:
(KJS::WindowFunc::callAsFunction):
* bindings/js/kjs_window.h:
(KJS::Window::):
* platform/Base64.cpp: Added.
(base64Encode):
(base64Decode):
* platform/Base64.h: Added.
* ForwardingHeaders/wtf/StringExtras.h: Added.
* platform/DeprecatedString.cpp: Use strncasecmp from StringExtras.
2006-12-11 Darin Adler <darin@apple.com>
Reviewed by Brady.
#import <JavaScriptCore/StringExtras.h>
......@@ -2792,6 +2792,8 @@
DB23C2CC0A508D29002489EB /* IndentOutdentCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = DB23C2CA0A508D29002489EB /* IndentOutdentCommand.h */; };
DD763BB20992C2C900740B8E /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = DD763BB10992C2C900740B8E /* libxml2.dylib */; };
DD7CDF250A23CF9800069928 /* CSSUnknownRule.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E6CCE0A1989CA007FB8C5 /* CSSUnknownRule.h */; };
E11D51930B2E7A5F0056C188 /* Base64.h in Headers */ = {isa = PBXBuildFile; fileRef = E11D51910B2E7A5F0056C188 /* Base64.h */; };
E11D51940B2E7A5F0056C188 /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E11D51920B2E7A5F0056C188 /* Base64.cpp */; };
E14842DE0A674934007E4D39 /* TextCodecICU.h in Headers */ = {isa = PBXBuildFile; fileRef = E14842DD0A674934007E4D39 /* TextCodecICU.h */; };
E14842FF0A674A31007E4D39 /* TextCodecICU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E14842FE0A674A31007E4D39 /* TextCodecICU.cpp */; };
E148432F0A674FC2007E4D39 /* TextCodecMac.h in Headers */ = {isa = PBXBuildFile; fileRef = E148432E0A674FC2007E4D39 /* TextCodecMac.h */; };
......@@ -5889,6 +5891,8 @@
DB23C2C90A508D29002489EB /* IndentOutdentCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IndentOutdentCommand.cpp; sourceTree = "<group>"; };
DB23C2CA0A508D29002489EB /* IndentOutdentCommand.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = IndentOutdentCommand.h; sourceTree = "<group>"; };
DD763BB10992C2C900740B8E /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = /usr/lib/libxml2.dylib; sourceTree = "<absolute>"; };
E11D51910B2E7A5F0056C188 /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base64.h; sourceTree = "<group>"; };
E11D51920B2E7A5F0056C188 /* Base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Base64.cpp; sourceTree = "<group>"; };
E14842DD0A674934007E4D39 /* TextCodecICU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextCodecICU.h; sourceTree = "<group>"; };
E14842FE0A674A31007E4D39 /* TextCodecICU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextCodecICU.cpp; sourceTree = "<group>"; };
E148432E0A674FC2007E4D39 /* TextCodecMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = TextCodecMac.h; path = mac/TextCodecMac.h; sourceTree = "<group>"; };
......@@ -8801,6 +8805,8 @@
93CD4FD70995F9EA007ECC97 /* AtomicString.cpp */,
93CD4FD80995F9EA007ECC97 /* AtomicString.h */,
93CD4FD90995F9EA007ECC97 /* AtomicStringImpl.h */,
E11D51910B2E7A5F0056C188 /* Base64.h */,
E11D51920B2E7A5F0056C188 /* Base64.cpp */,
65F5382009B2B55700F3DC4A /* character-sets.txt */,
9326DC0A09DAD5BE00AFC847 /* CharsetData.h */,
BCC8CFCA0986CD2400140BF2 /* ColorData.gperf */,
......@@ -10837,6 +10843,7 @@
BC18C5D00B2A886F0018461D /* TextBreakIterator.h in Headers */,
AA4C3A770B2B1679002334A2 /* StyleElement.h in Headers */,
93E241FF0B2B4E4000C732A1 /* HTMLFrameOwnerElement.h in Headers */,
E11D51930B2E7A5F0056C188 /* Base64.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -12156,6 +12163,7 @@
BC18C5D10B2A886F0018461D /* TextBreakIteratorICU.cpp in Sources */,
AA4C3A760B2B1679002334A2 /* StyleElement.cpp in Sources */,
93E2425F0B2B509500C732A1 /* HTMLFrameOwnerElement.cpp in Sources */,
E11D51940B2E7A5F0056C188 /* Base64.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -4,6 +4,7 @@
* Copyright (C) 2000 Harri Porten (porten@kde.org)
* Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
* Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
* Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -23,12 +24,14 @@
#include "config.h"
#include "kjs_window.h"
#include "Base64.h"
#include "Chrome.h"
#include "CString.h"
#include "DOMWindow.h"
#include "Element.h"
#include "EventListener.h"
#include "EventNames.h"
#include "ExceptionCode.h"
#include "FloatRect.h"
#include "Frame.h"
#include "FrameLoadRequest.h"
......@@ -220,6 +223,8 @@ const ClassInfo Window::info = { "Window", 0, &WindowTable, 0 };
/*
@begin WindowTable 103
atob Window::AToB DontDelete|Function 1
btoa Window::BToA DontDelete|Function 1
closed Window::Closed DontDelete|ReadOnly
crypto Window::Crypto DontDelete|ReadOnly
defaultStatus Window::DefaultStatus DontDelete
......@@ -1535,6 +1540,30 @@ JSValue *WindowFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const Li
frame->runJavaScriptAlert(str);
exec->dynamicInterpreter()->resumeTimeoutCheck();
return jsUndefined();
case Window::AToB:
case Window::BToA: {
if (args.size() < 1)
return throwError(exec, SyntaxError, "Not enough arguments");
if (v->isNull())
return jsString();
if (!s.is8Bit()) {
setDOMException(exec, INVALID_CHARACTER_ERR);
return jsUndefined();
}
Vector<char> in(s.size());
for (int i = 0; i < s.size(); ++i)
in[i] = static_cast<char>(s.data()[i].unicode());
Vector<char> out;
if (id == Window::AToB) {
if (!base64Decode(in, out))
return throwError(exec, GeneralError, "Cannot decode base64");
} else
base64Encode(in, out);
return jsString(String(out.data(), out.size()));
}
case Window::Confirm: {
if (frame && frame->document())
frame->document()->updateRendering();
......
......@@ -155,7 +155,7 @@ namespace KJS {
UnprotectedListenersMap jsUnprotectedHTMLEventListeners;
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
enum { Closed, Crypto, DefaultStatus, Status, DOMException, Frames, History_, Event_, InnerHeight,
enum { AToB, BToA, Closed, Crypto, DefaultStatus, Status, DOMException, Frames, History_, Event_, InnerHeight,
InnerWidth, Length, Location_, Locationbar, Name, Navigator_, ClientInformation,
Menubar, OffscreenBuffering, Opener, OuterHeight, OuterWidth, PageXOffset, PageYOffset,
Parent, Personalbar, ScreenX, ScreenY, Scrollbars, Scroll, ScrollBy,
......
/*
Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org>
Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (LGPL)
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
This code is based on the java implementation in HTTPClient
package by Ronald Tschalär Copyright (C) 1996-1999.
*/
#include "config.h"
#include "Base64.h"
#include <wtf/platform.h>
#include <wtf/StringExtras.h>
static const char base64EncMap[64] =
{
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E,
0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33,
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F
};
static const char base64DecMap[128] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F,
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00
};
void base64Encode(const Vector<char>& in, Vector<char>& out, bool insertLFs)
{
// clear out the output buffer
out.clear();
if (in.isEmpty())
return;
unsigned sidx = 0;
unsigned didx = 0;
const char* data = in.data();
const unsigned len = in.size();
unsigned out_len = ((len + 2) / 3) * 4;
// Deal with the 76 characters or less per
// line limit specified in RFC 2045 on a
// pre request basis.
insertLFs = (insertLFs && out_len > 76);
if (insertLFs)
out_len += ((out_len - 1) / 76);
int count = 0;
out.resize(out_len);
// 3-byte to 4-byte conversion + 0-63 to ascii printable conversion
if (len > 1) {
while (sidx < len - 2) {
if (insertLFs) {
if (count && (count % 76) == 0)
out[didx++] = '\n';
count += 4;
}
out[didx++] = base64EncMap[(data[sidx] >> 2) & 077];
out[didx++] = base64EncMap[(data[sidx + 1] >> 4) & 017 | (data[sidx] << 4) & 077];
out[didx++] = base64EncMap[(data[sidx + 2] >> 6) & 003 | (data[sidx + 1] << 2) & 077];
out[didx++] = base64EncMap[data[sidx + 2] & 077];
sidx += 3;
}
}
if (sidx < len) {
if (insertLFs && (count > 0) && (count % 76) == 0)
out[didx++] = '\n';
out[didx++] = base64EncMap[(data[sidx] >> 2) & 077];
if (sidx < len - 1) {
out[didx++] = base64EncMap[(data[sidx + 1] >> 4) & 017 | (data[sidx] << 4) & 077];
out[didx++] = base64EncMap[(data[sidx + 1] << 2) & 077];
} else
out[didx++] = base64EncMap[(data[sidx] << 4) & 077];
}
// Add padding
while (didx < out.size()) {
out[didx] = '=';
didx++;
}
}
bool base64Decode(const Vector<char>& in, Vector<char>& out)
{
out.clear();
if (in.isEmpty())
return true;
unsigned len = in.size();
const char* data = in.data();
while (len && data[len-1] == '=')
--len;
out.resize(len);
for (unsigned idx = 0; idx < len; idx++) {
unsigned char ch = data[idx];
if ((ch > 47 && ch < 58) || (ch > 64 && ch < 91) || (ch > 96 && ch < 123) || ch == '+' || ch == '/' || ch == '=')
out[idx] = base64DecMap[ch];
else
return false;
}
// 4-byte to 3-byte conversion
unsigned outLen = len - ((len + 3) / 4);
if (!outLen || ((outLen + 2) / 3) * 4 < len)
return false;
unsigned sidx = 0;
unsigned didx = 0;
if (outLen > 1) {
while (didx < outLen - 2) {
out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003));
out[didx + 1] = (((out[sidx + 1] << 4) & 255) | ((out[sidx + 2] >> 2) & 017));
out[didx + 2] = (((out[sidx + 2] << 6) & 255) | (out[sidx + 3] & 077));
sidx += 4;
didx += 3;
}
}
if (didx < outLen)
out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003));
if (++didx < outLen)
out[didx] = (((out[sidx + 1] << 4) & 255) | ((out[sidx + 2] >> 2) & 017));
if (outLen < out.size())
out.resize(outLen);
return true;
}
/*
* Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT