[SCM] WebKit Debian packaging branch, webkit-1.3, updated. upstream/1.3.7-4207-g178b198

paroga at webkit.org paroga at webkit.org
Sun Feb 20 23:40:23 UTC 2011


The following commit has been merged in the webkit-1.3 branch:
commit 75d8ffb2cd7f70735b267f45a01f166fc80364c5
Author: paroga at webkit.org <paroga at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sun Jan 23 23:17:26 2011 +0000

    2011-01-23  Patrick Gansterer  <paroga at webkit.org>
    
            Reviewed by David Kilzer.
    
            Add an overload to base64Encode with String output
            https://bugs.webkit.org/show_bug.cgi?id=50122
    
            This change removes duplicated code.
    
            * inspector/InspectorResourceAgent.cpp:
            (WebCore::InspectorResourceAgent::resourceContentBase64):
            * page/DOMWindow.cpp:
            (WebCore::DOMWindow::btoa):
            * platform/graphics/skia/FontCustomPlatformData.cpp:
            (WebCore::createUniqueFontName):
            * platform/graphics/win/FontCustomPlatformData.cpp:
            (WebCore::createUniqueFontName):
            * platform/graphics/wince/FontCustomPlatformData.cpp:
            (WebCore::createUniqueFontName):
            * platform/network/cf/ResourceHandleCFNet.cpp:
            (WebCore::encodeBasicAuthorization):
            * platform/network/mac/ResourceHandleMac.mm:
            (WebCore::encodeBasicAuthorization):
            * platform/text/Base64.cpp:
            (WebCore::base64Encode):
            * platform/text/Base64.h:
            (WebCore::base64Encode):
            * platform/wince/KeygenWinCE.cpp:
            (WebCore::WebCore::signedPublicKeyAndChallengeString):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76472 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 9d9d26d..322d7ec 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -2,6 +2,36 @@
 
         Reviewed by David Kilzer.
 
+        Add an overload to base64Encode with String output
+        https://bugs.webkit.org/show_bug.cgi?id=50122
+
+        This change removes duplicated code.
+
+        * inspector/InspectorResourceAgent.cpp:
+        (WebCore::InspectorResourceAgent::resourceContentBase64):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::btoa):
+        * platform/graphics/skia/FontCustomPlatformData.cpp:
+        (WebCore::createUniqueFontName):
+        * platform/graphics/win/FontCustomPlatformData.cpp:
+        (WebCore::createUniqueFontName):
+        * platform/graphics/wince/FontCustomPlatformData.cpp:
+        (WebCore::createUniqueFontName):
+        * platform/network/cf/ResourceHandleCFNet.cpp:
+        (WebCore::encodeBasicAuthorization):
+        * platform/network/mac/ResourceHandleMac.mm:
+        (WebCore::encodeBasicAuthorization):
+        * platform/text/Base64.cpp:
+        (WebCore::base64Encode):
+        * platform/text/Base64.h:
+        (WebCore::base64Encode):
+        * platform/wince/KeygenWinCE.cpp:
+        (WebCore::WebCore::signedPublicKeyAndChallengeString):
+
+2011-01-23  Patrick Gansterer  <paroga at webkit.org>
+
+        Reviewed by David Kilzer.
+
         Add String::containsOnlyLatin1()
         https://bugs.webkit.org/show_bug.cgi?id=52979
 
diff --git a/Source/WebCore/inspector/InspectorResourceAgent.cpp b/Source/WebCore/inspector/InspectorResourceAgent.cpp
index 029c79d..16d2b66 100644
--- a/Source/WebCore/inspector/InspectorResourceAgent.cpp
+++ b/Source/WebCore/inspector/InspectorResourceAgent.cpp
@@ -95,7 +95,6 @@ bool InspectorResourceAgent::resourceContent(Frame* frame, const KURL& url, Stri
 
 bool InspectorResourceAgent::resourceContentBase64(Frame* frame, const KURL& url, String* result)
 {
-    Vector<char> out;
     String textEncodingName;
     RefPtr<SharedBuffer> data = InspectorResourceAgent::resourceData(frame, url, &textEncodingName);
     if (!data) {
@@ -103,8 +102,7 @@ bool InspectorResourceAgent::resourceContentBase64(Frame* frame, const KURL& url
         return false;
     }
 
-    base64Encode(data->buffer(), out);
-    *result = String(out.data(), out.size());
+    *result = base64Encode(data->buffer());
     return true;
 }
 
diff --git a/Source/WebCore/page/DOMWindow.cpp b/Source/WebCore/page/DOMWindow.cpp
index 5492386..572e559 100644
--- a/Source/WebCore/page/DOMWindow.cpp
+++ b/Source/WebCore/page/DOMWindow.cpp
@@ -974,13 +974,7 @@ String DOMWindow::btoa(const String& stringToEncode, ExceptionCode& ec)
         return String();
     }
 
-    Vector<char> in;
-    in.append(stringToEncode.characters(), stringToEncode.length());
-    Vector<char> out;
-
-    base64Encode(in, out);
-
-    return String(out.data(), out.size());
+    return base64Encode(stringToEncode.latin1());
 }
 
 String DOMWindow::atob(const String& encodedString, ExceptionCode& ec)
diff --git a/Source/WebCore/platform/graphics/skia/FontCustomPlatformData.cpp b/Source/WebCore/platform/graphics/skia/FontCustomPlatformData.cpp
index 0b31dfa..b6427b0 100644
--- a/Source/WebCore/platform/graphics/skia/FontCustomPlatformData.cpp
+++ b/Source/WebCore/platform/graphics/skia/FontCustomPlatformData.cpp
@@ -114,13 +114,12 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, b
 // not allow access from CSS.
 static String createUniqueFontName()
 {
-    Vector<char> fontUuid(sizeof(GUID));
-    CoCreateGuid(reinterpret_cast<GUID*>(fontUuid.data()));
+    GUID fontUuid;
+    CoCreateGuid(&fontUuid);
 
-    Vector<char> fontNameVector;
-    base64Encode(fontUuid, fontNameVector);
-    ASSERT(fontNameVector.size() < LF_FACESIZE);
-    return String(fontNameVector.data(), fontNameVector.size());
+    String fontName = base64Encode(reinterpret_cast<char*>(&fontUuid), sizeof(fontUuid));
+    ASSERT(fontName.length() < LF_FACESIZE);
+    return fontName;
 }
 #endif
 
diff --git a/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp b/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp
index 9cae99b..1bb2050 100644
--- a/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp
+++ b/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp
@@ -154,13 +154,12 @@ static unsigned long WINAPIV readEmbedProc(void* stream, void* buffer, unsigned
 // not allow access from CSS.
 static String createUniqueFontName()
 {
-    Vector<char> fontUuid(sizeof(GUID));
-    CoCreateGuid(reinterpret_cast<GUID*>(fontUuid.data()));
+    GUID fontUuid;
+    CoCreateGuid(&fontUuid);
 
-    Vector<char> fontNameVector;
-    base64Encode(fontUuid, fontNameVector);
-    ASSERT(fontNameVector.size() < LF_FACESIZE);
-    return String(fontNameVector.data(), fontNameVector.size());
+    String fontName = base64Encode(reinterpret_cast<char*>(&fontUuid), sizeof(fontUuid));
+    ASSERT(fontName.length() < LF_FACESIZE);
+    return fontName;
 }
 
 FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
diff --git a/Source/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp b/Source/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp
index f61ae8e..424b64a 100644
--- a/Source/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp
+++ b/Source/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp
@@ -59,16 +59,14 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, b
 // not allow access from CSS.
 static String createUniqueFontName()
 {
-    Vector<char> fontUuid(sizeof(GUID));
+    GUID fontUuid;
 
-    unsigned int* ptr = reinterpret_cast<unsigned int*>(fontUuid.data());
+    unsigned int* ptr = reinterpret_cast<unsigned int*>(&fontUuid);
     for (int i = 0; i < sizeof(GUID) / sizeof(int) ; ++i)
         *(ptr + i) = static_cast<unsigned int>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0));
 
-    Vector<char> fontNameVector;
-    base64Encode(fontUuid, fontNameVector);
-    ASSERT(fontNameVector.size() < LF_FACESIZE);
-    String fontName(fontNameVector.data(), fontNameVector.size());
+    String fontName = base64Encode(reinterpret_cast<char*>(&fontUuid), sizeof(fontUuid));
+    ASSERT(fontName.length() < LF_FACESIZE);
     return fontName.replace('/', '_');
 }
 
diff --git a/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp b/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp
index 66ae5a0..52b100f 100644
--- a/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp
+++ b/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp
@@ -126,12 +126,7 @@ static void setDefaultMIMEType(CFURLResponseRef response)
 
 static String encodeBasicAuthorization(const String& user, const String& password)
 {
-    CString unencodedString = (user + ":" + password).utf8();
-    Vector<char> unencoded(unencodedString.length());
-    std::copy(unencodedString.data(), unencodedString.data() + unencodedString.length(), unencoded.begin());
-    Vector<char> encoded;
-    base64Encode(unencoded, encoded);
-    return String(encoded.data(), encoded.size());
+    return base64Encode((user + ":" + password).utf8());
 }
 
 CFURLRequestRef willSendRequest(CFURLConnectionRef conn, CFURLRequestRef cfRequest, CFURLResponseRef cfRedirectResponse, const void* clientInfo)
diff --git a/Source/WebCore/platform/network/mac/ResourceHandleMac.mm b/Source/WebCore/platform/network/mac/ResourceHandleMac.mm
index 84b656c..2d687c0 100644
--- a/Source/WebCore/platform/network/mac/ResourceHandleMac.mm
+++ b/Source/WebCore/platform/network/mac/ResourceHandleMac.mm
@@ -164,12 +164,7 @@ public:
 #ifndef BUILDING_ON_TIGER
 static String encodeBasicAuthorization(const String& user, const String& password)
 {
-    CString unencodedString = (user + ":" + password).utf8();
-    Vector<char> unencoded(unencodedString.length());
-    std::copy(unencodedString.data(), unencodedString.data() + unencodedString.length(), unencoded.begin());
-    Vector<char> encoded;
-    base64Encode(unencoded, encoded);
-    return String(encoded.data(), encoded.size());
+    return base64Encode((user + ":" + password).utf8());
 }
 #endif
 
diff --git a/Source/WebCore/platform/text/Base64.cpp b/Source/WebCore/platform/text/Base64.cpp
index 98b537a..bf706f6 100644
--- a/Source/WebCore/platform/text/Base64.cpp
+++ b/Source/WebCore/platform/text/Base64.cpp
@@ -60,9 +60,11 @@ static const char base64DecMap[128] = {
     0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00
 };
 
-void base64Encode(const Vector<char>& in, Vector<char>& out, bool insertLFs)
+String base64Encode(const char* data, unsigned length, bool insertLFs)
 {
-    base64Encode(in.data(), in.size(), out, insertLFs);
+    Vector<char> result;
+    base64Encode(data, length, result, insertLFs);
+    return String(result.data(), result.size());
 }
 
 void base64Encode(const char* data, unsigned len, Vector<char>& out, bool insertLFs)
diff --git a/Source/WebCore/platform/text/Base64.h b/Source/WebCore/platform/text/Base64.h
index 211bd3c..70855de 100644
--- a/Source/WebCore/platform/text/Base64.h
+++ b/Source/WebCore/platform/text/Base64.h
@@ -27,20 +27,45 @@
 #ifndef Base64_h
 #define Base64_h
 
-#include <wtf/Forward.h>
 #include <wtf/Vector.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
 enum Base64DecodePolicy { FailOnInvalidCharacter, IgnoreWhitespace, IgnoreInvalidCharacters };
 
-void base64Encode(const Vector<char>&, Vector<char>&, bool insertLFs = false);
 void base64Encode(const char*, unsigned, Vector<char>&, bool insertLFs = false);
+void base64Encode(const Vector<char>&, Vector<char>&, bool insertLFs = false);
+void base64Encode(const CString&, Vector<char>&, bool insertLFs = false);
+String base64Encode(const char*, unsigned, bool insertLFs = false);
+String base64Encode(const Vector<char>&, bool insertLFs = false);
+String base64Encode(const CString&, bool insertLFs = false);
 
 bool base64Decode(const String&, Vector<char>&, Base64DecodePolicy = FailOnInvalidCharacter);
 bool base64Decode(const Vector<char>&, Vector<char>&, Base64DecodePolicy = FailOnInvalidCharacter);
 bool base64Decode(const char*, unsigned, Vector<char>&, Base64DecodePolicy = FailOnInvalidCharacter);
 
+inline void base64Encode(const Vector<char>& in, Vector<char>& out, bool insertLFs)
+{
+    base64Encode(in.data(), in.size(), out, insertLFs);
 }
 
+inline void base64Encode(const CString& in, Vector<char>& out, bool insertLFs)
+{
+    base64Encode(in.data(), in.length(), out, insertLFs);
+}
+
+inline String base64Encode(const Vector<char>& in, bool insertLFs)
+{
+    return base64Encode(in.data(), in.size(), insertLFs);
+}
+
+inline String base64Encode(const CString& in, bool insertLFs)
+{
+    return base64Encode(in.data(), in.length(), insertLFs);
+}
+
+} // namespace WebCore
+
 #endif // Base64_h
diff --git a/Source/WebCore/platform/wince/KeygenWinCE.cpp b/Source/WebCore/platform/wince/KeygenWinCE.cpp
index 0c1b3c6..8537f44 100644
--- a/Source/WebCore/platform/wince/KeygenWinCE.cpp
+++ b/Source/WebCore/platform/wince/KeygenWinCE.cpp
@@ -80,10 +80,7 @@ String WebCore::signedPublicKeyAndChallengeString(unsigned index, const String&
         if (!CryptSignAndEncodeCertificate(hContext, AT_KEYEXCHANGE, X509_ASN_ENCODING, X509_KEYGEN_REQUEST_TO_BE_SIGNED, &requestInfo, &signAlgo, 0, reinterpret_cast<LPBYTE>(binary.data()), &dwEncodedLength))
             break;
 
-        Vector<char> base64;
-        base64Encode(binary, base64);
-        keyString = String(base64.data(), base64.size());
-
+        keyString = base64Encode(binary);
     } while(0);
 
     if (pPubInfo)

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list