[BlackBerry] Pass URL String's 8-bit buffer directly to platform layer when possible
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Aug 2012 17:19:36 +0000 (17:19 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Aug 2012 17:19:36 +0000 (17:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=93861

Patch by Yong Li <yoli@rim.com> on 2012-08-14
Reviewed by Rob Buis.

PR# 187605.
URL strings and HTTP header strings usually use 8-bit buffers internally. We can
just pass the buffers to platform calls when only Latin1 strings are needed.

* platform/blackberry/ReadOnlyLatin1String.h: Added.
(WebCore):
(ReadOnlyLatin1String): A utility class that uses either WTF::CString or WTF::String's 8-bit buffer.
(WebCore::ReadOnlyLatin1String::ReadOnlyLatin1String): Can only be constructed with WTF::String for now.
(WebCore::ReadOnlyLatin1String::data):
(WebCore::ReadOnlyLatin1String::length):
* platform/network/blackberry/ResourceRequestBlackBerry.cpp:
(WebCore::ResourceRequest::initializePlatformRequest):
* platform/network/blackberry/SocketStreamHandleBlackBerry.cpp:
(WebCore::SocketStreamHandle::SocketStreamHandle):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@125576 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/blackberry/ReadOnlyLatin1String.h [new file with mode: 0644]
Source/WebCore/platform/network/blackberry/ResourceRequestBlackBerry.cpp
Source/WebCore/platform/network/blackberry/SocketStreamHandleBlackBerry.cpp

index d6b83bf..943a030 100644 (file)
@@ -1,3 +1,25 @@
+2012-08-14  Yong Li  <yoli@rim.com>
+
+        [BlackBerry] Pass URL String's 8-bit buffer directly to platform layer when possible
+        https://bugs.webkit.org/show_bug.cgi?id=93861
+
+        Reviewed by Rob Buis.
+
+        PR# 187605.
+        URL strings and HTTP header strings usually use 8-bit buffers internally. We can
+        just pass the buffers to platform calls when only Latin1 strings are needed.
+
+        * platform/blackberry/ReadOnlyLatin1String.h: Added.
+        (WebCore):
+        (ReadOnlyLatin1String): A utility class that uses either WTF::CString or WTF::String's 8-bit buffer.
+        (WebCore::ReadOnlyLatin1String::ReadOnlyLatin1String): Can only be constructed with WTF::String for now.
+        (WebCore::ReadOnlyLatin1String::data):
+        (WebCore::ReadOnlyLatin1String::length):
+        * platform/network/blackberry/ResourceRequestBlackBerry.cpp:
+        (WebCore::ResourceRequest::initializePlatformRequest):
+        * platform/network/blackberry/SocketStreamHandleBlackBerry.cpp:
+        (WebCore::SocketStreamHandle::SocketStreamHandle):
+
 2012-08-14  Christophe Dumez  <christophe.dumez@intel.com>
 
         Fix  LayoutTests/canvas/philip/tests/2d.text.draw.space.collapse.nonspace.html
diff --git a/Source/WebCore/platform/blackberry/ReadOnlyLatin1String.h b/Source/WebCore/platform/blackberry/ReadOnlyLatin1String.h
new file mode 100644 (file)
index 0000000..613dbda
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef ReadOnlyLatin1String_h
+#define ReadOnlyLatin1String_h
+
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class ReadOnlyLatin1String {
+public:
+    explicit ReadOnlyLatin1String(const String& string)
+    {
+        if (string.is8Bit())
+            m_string = string;
+        else {
+            ASSERT(string.containsOnlyLatin1());
+            m_cstring = string.latin1();
+        }
+    }
+
+    const char* data() const { return m_string.isNull() ? m_cstring.data() : reinterpret_cast<const char*>(m_string.characters8()); }
+
+    size_t length() const { return m_string.isNull() ? m_cstring.length() : m_string.length(); }
+
+private:
+    String m_string;
+    CString m_cstring;
+};
+
+} // namespace WebCore
+
+#endif
index 981f342..9f6ffab 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "BlobRegistryImpl.h"
 #include "CookieManager.h"
+#include "ReadOnlyLatin1String.h"
 #include <LocaleHandler.h>
 #include <network/NetworkRequest.h>
 #include <wtf/HashMap.h>
@@ -148,8 +149,10 @@ void ResourceRequest::initializePlatformRequest(NetworkRequest& platformRequest,
     if (isInitial)
         platformRequest.setRequestInitial(timeoutInterval());
     else {
-        platformRequest.setRequestUrl(url().string().utf8().data(),
-                httpMethod().latin1().data(),
+        ReadOnlyLatin1String latin1URL(url().string());
+        ReadOnlyLatin1String latin1HttpMethod(httpMethod());
+        platformRequest.setRequestUrl(latin1URL.data(), latin1URL.length(),
+                latin1HttpMethod.data(), latin1HttpMethod.length(),
                 platformCachePolicyForRequest(*this),
                 platformTargetTypeForRequest(*this),
                 timeoutInterval());
@@ -198,12 +201,19 @@ void ResourceRequest::initializePlatformRequest(NetworkRequest& platformRequest,
             String key = it->first;
             String value = it->second;
             if (!key.isEmpty()) {
-                // We need to check the encoding and encode the cookie's value using latin1 or utf8 to support unicode characters.
-                // We wo't use the old cookies of resourceRequest for new location because these cookies may be changed by redirection.
-                if (!equalIgnoringCase(key, "Cookie"))
-                    platformRequest.addHeader(key.latin1().data(), value.latin1().data());
-                else if (!cookieHeaderMayBeDirty)
-                    platformRequest.addHeader(key.latin1().data(), value.containsOnlyLatin1() ? value.latin1().data() : value.utf8().data());
+                if (equalIgnoringCase(key, "Cookie")) {
+                    // We won't use the old cookies of resourceRequest for new location because these cookies may be changed by redirection.
+                    if (cookieHeaderMayBeDirty)
+                        continue;
+                    // We need to check the encoding and encode the cookie's value using latin1 or utf8 to support unicode data.
+                    if (!value.containsOnlyLatin1()) {
+                        platformRequest.addHeader("Cookie", value.utf8().data());
+                        continue;
+                    }
+                }
+                ReadOnlyLatin1String latin1Key(key);
+                ReadOnlyLatin1String latin1Value(value);
+                platformRequest.addHeader(latin1Key.data(), latin1Key.length(), latin1Value.data(), latin1Value.length());
             }
         }
 
index 90ed528..55a295f 100644 (file)
@@ -39,6 +39,7 @@
 #include "Page.h"
 #include "PageClientBlackBerry.h"
 #include "PageGroup.h"
+#include "ReadOnlyLatin1String.h"
 #include "SocketStreamError.h"
 #include "SocketStreamHandleClient.h"
 
@@ -70,7 +71,8 @@ SocketStreamHandle::SocketStreamHandle(const String& groupName, const KURL& url,
 
     // Open the socket
     BlackBerry::Platform::NetworkRequest request;
-    request.setRequestUrl(url.string().latin1().data(), "CONNECT");
+    ReadOnlyLatin1String latin1URL(url.string());
+    request.setRequestUrl(latin1URL.data(), latin1URL.length(), "CONNECT", 7);
 
     m_socketStream->setRequest(request);