Title: [95176] trunk/Source/WebCore
Revision
95176
Author
yu...@chromium.org
Date
2011-09-15 00:41:02 -0700 (Thu, 15 Sep 2011)

Log Message

ThreadableWebSocketChannelClientWrapper shouldn't have a String in it.
https://bugs.webkit.org/show_bug.cgi?id=67908

Reviewed by David Levin.

Replace a String member variable in ThreadableWebSocketChannelClientWrapper with Vector<UChar>.

ThreadableWebSocketChannelClientWrapper is derived from ThreadSafeRefCounted. It may be
destroyed on different threads, which will affect String's refcounting. Therefore, classes
derived from ThreadSafeRefCounted must not have a String member variable.

No change in functionality, thus no new tests. WebSocket worker tests
(tests under http/tests/websocket/tests/{hixie76,hybi}/workers/) should keep passing.

* websockets/ThreadableWebSocketChannelClientWrapper.cpp:
(WebCore::ThreadableWebSocketChannelClientWrapper::ThreadableWebSocketChannelClientWrapper):
(WebCore::ThreadableWebSocketChannelClientWrapper::subprotocol):
Create a String from Vector<UChar>. Note that String constructor taking an empty vector returns
a null string, not an empty string. We want an empty string in that case, so I had to add
special-case handling for an empty vector.
(WebCore::ThreadableWebSocketChannelClientWrapper::setSubprotocol):
Copy the content of the given String into Vector.
* websockets/ThreadableWebSocketChannelClientWrapper.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (95175 => 95176)


--- trunk/Source/WebCore/ChangeLog	2011-09-15 07:11:43 UTC (rev 95175)
+++ trunk/Source/WebCore/ChangeLog	2011-09-15 07:41:02 UTC (rev 95176)
@@ -1,3 +1,29 @@
+2011-09-15  Yuta Kitamura  <yu...@chromium.org>
+
+        ThreadableWebSocketChannelClientWrapper shouldn't have a String in it.
+        https://bugs.webkit.org/show_bug.cgi?id=67908
+
+        Reviewed by David Levin.
+
+        Replace a String member variable in ThreadableWebSocketChannelClientWrapper with Vector<UChar>.
+
+        ThreadableWebSocketChannelClientWrapper is derived from ThreadSafeRefCounted. It may be
+        destroyed on different threads, which will affect String's refcounting. Therefore, classes
+        derived from ThreadSafeRefCounted must not have a String member variable.
+
+        No change in functionality, thus no new tests. WebSocket worker tests
+        (tests under http/tests/websocket/tests/{hixie76,hybi}/workers/) should keep passing.
+
+        * websockets/ThreadableWebSocketChannelClientWrapper.cpp:
+        (WebCore::ThreadableWebSocketChannelClientWrapper::ThreadableWebSocketChannelClientWrapper):
+        (WebCore::ThreadableWebSocketChannelClientWrapper::subprotocol):
+        Create a String from Vector<UChar>. Note that String constructor taking an empty vector returns
+        a null string, not an empty string. We want an empty string in that case, so I had to add
+        special-case handling for an empty vector.
+        (WebCore::ThreadableWebSocketChannelClientWrapper::setSubprotocol):
+        Copy the content of the given String into Vector.
+        * websockets/ThreadableWebSocketChannelClientWrapper.h:
+
 2011-09-14  Matthew Delaney  <mdela...@apple.com>
 
         Use isAcceleratedContext() on the GraphicsContext instead of flags in ImageBuffer

Modified: trunk/Source/WebCore/websockets/ThreadableWebSocketChannelClientWrapper.cpp (95175 => 95176)


--- trunk/Source/WebCore/websockets/ThreadableWebSocketChannelClientWrapper.cpp	2011-09-15 07:11:43 UTC (rev 95175)
+++ trunk/Source/WebCore/websockets/ThreadableWebSocketChannelClientWrapper.cpp	2011-09-15 07:41:02 UTC (rev 95176)
@@ -44,7 +44,6 @@
     : m_client(client)
     , m_syncMethodDone(false)
     , m_useHixie76Protocol(true)
-    , m_subprotocol("")
     , m_sendRequestResult(false)
     , m_bufferedAmount(0)
     , m_suspended(false)
@@ -83,12 +82,17 @@
 
 String ThreadableWebSocketChannelClientWrapper::subprotocol() const
 {
-    return m_subprotocol;
+    if (m_subprotocol.isEmpty())
+        return String("");
+    return String(m_subprotocol);
 }
 
 void ThreadableWebSocketChannelClientWrapper::setSubprotocol(const String& subprotocol)
 {
-    m_subprotocol = subprotocol;
+    unsigned length = subprotocol.length();
+    m_subprotocol.resize(length);
+    if (length)
+        memcpy(m_subprotocol.data(), subprotocol.characters(), sizeof(UChar) * length);
 }
 
 bool ThreadableWebSocketChannelClientWrapper::sendRequestResult() const

Modified: trunk/Source/WebCore/websockets/ThreadableWebSocketChannelClientWrapper.h (95175 => 95176)


--- trunk/Source/WebCore/websockets/ThreadableWebSocketChannelClientWrapper.h	2011-09-15 07:11:43 UTC (rev 95175)
+++ trunk/Source/WebCore/websockets/ThreadableWebSocketChannelClientWrapper.h	2011-09-15 07:41:02 UTC (rev 95176)
@@ -93,7 +93,7 @@
     WebSocketChannelClient* m_client;
     bool m_syncMethodDone;
     bool m_useHixie76Protocol;
-    String m_subprotocol;
+    Vector<UChar> m_subprotocol; // ThreadSafeRefCounted must not have a String member variable.
     bool m_sendRequestResult;
     unsigned long m_bufferedAmount;
     bool m_suspended;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to