Title: [133631] trunk/Source/WebCore
Revision
133631
Author
[email protected]
Date
2012-11-06 10:15:44 -0800 (Tue, 06 Nov 2012)

Log Message

canonicalizedTitle() shouldn't convert 8 bit title strings to 16 bit
https://bugs.webkit.org/show_bug.cgi?id=101105

Reviewed by Darin Adler.

Turned canonicalizedTitle() into a templated function based on character type.
Changed call in updateTitle() to check the bitness of the title string to call
the right template flavor of canonicalizedTitle().
Made supporting changes by adding displayBufferModifiedByEncoding(LChar*, ...)
and made TextEncoding::displayBuffer() a templated function as well.

No new tests needed, as functionality is unchanged.

* dom/Document.cpp:
(WebCore::canonicalizedTitle):
(WebCore::Document::updateTitle):
(WebCore::Document::displayBufferModifiedByEncodingInternal):
* dom/Document.h:
(WebCore::Document::displayBufferModifiedByEncoding):
* platform/text/TextEncoding.h:
(TextEncoding):
(WebCore::TextEncoding::displayBuffer):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (133630 => 133631)


--- trunk/Source/WebCore/ChangeLog	2012-11-06 18:15:04 UTC (rev 133630)
+++ trunk/Source/WebCore/ChangeLog	2012-11-06 18:15:44 UTC (rev 133631)
@@ -1,3 +1,28 @@
+2012-11-06  Michael Saboff  <[email protected]>
+
+        canonicalizedTitle() shouldn't convert 8 bit title strings to 16 bit
+        https://bugs.webkit.org/show_bug.cgi?id=101105
+
+        Reviewed by Darin Adler.
+
+        Turned canonicalizedTitle() into a templated function based on character type.
+        Changed call in updateTitle() to check the bitness of the title string to call
+        the right template flavor of canonicalizedTitle().
+        Made supporting changes by adding displayBufferModifiedByEncoding(LChar*, ...)
+        and made TextEncoding::displayBuffer() a templated function as well.
+
+        No new tests needed, as functionality is unchanged.
+
+        * dom/Document.cpp:
+        (WebCore::canonicalizedTitle):
+        (WebCore::Document::updateTitle):
+        (WebCore::Document::displayBufferModifiedByEncodingInternal):
+        * dom/Document.h:
+        (WebCore::Document::displayBufferModifiedByEncoding):
+        * platform/text/TextEncoding.h:
+        (TextEncoding):
+        (WebCore::TextEncoding::displayBuffer):
+
 2012-11-05  Simon Fraser  <[email protected]>
 
         Fix RenderGeometryMap assertion when layers are scrolled during layout

Modified: trunk/Source/WebCore/dom/Document.cpp (133630 => 133631)


--- trunk/Source/WebCore/dom/Document.cpp	2012-11-06 18:15:04 UTC (rev 133630)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-11-06 18:15:44 UTC (rev 133631)
@@ -1496,19 +1496,20 @@
  *  2. Trim leading and trailing spaces
  *  3. Collapse internal whitespace.
  */
+template <typename CharacterType>
 static inline StringWithDirection canonicalizedTitle(Document* document, const StringWithDirection& titleWithDirection)
 {
     const String& title = titleWithDirection.string();
-    const UChar* characters = title.characters();
+    const CharacterType* characters = title.getCharacters<CharacterType>();
     unsigned length = title.length();
     unsigned i;
 
-    StringBuffer<UChar> buffer(length);
+    StringBuffer<CharacterType> buffer(length);
     unsigned builderIndex = 0;
 
     // Skip leading spaces and leading characters that would convert to spaces
     for (i = 0; i < length; ++i) {
-        UChar c = characters[i];
+        CharacterType c = characters[i];
         if (!(c <= 0x20 || c == 0x7F))
             break;
     }
@@ -1519,7 +1520,7 @@
     // Replace control characters with spaces, and backslashes with currency symbols, and collapse whitespace.
     bool previousCharWasWS = false;
     for (; i < length; ++i) {
-        UChar c = characters[i];
+        CharacterType c = characters[i];
         if (c <= 0x20 || c == 0x7F || (WTF::Unicode::category(c) & (WTF::Unicode::Separator_Line | WTF::Unicode::Separator_Paragraph))) {
             if (previousCharWasWS)
                 continue;
@@ -1555,7 +1556,15 @@
         return;
 
     m_rawTitle = title;
-    m_title = canonicalizedTitle(this, m_rawTitle);
+
+    if (m_rawTitle.string().isEmpty())
+        m_title = StringWithDirection();
+    else {
+        if (m_rawTitle.string().is8Bit())
+            m_title = canonicalizedTitle<LChar>(this, m_rawTitle);
+        else
+            m_title = canonicalizedTitle<UChar>(this, m_rawTitle);
+    }
     if (Frame* f = frame())
         f->loader()->setTitle(m_title);
 }
@@ -4992,12 +5001,17 @@
     return str;
 }
 
-void Document::displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const
+template <typename CharacterType>
+void Document::displayBufferModifiedByEncodingInternal(CharacterType* buffer, unsigned len) const
 {
     if (m_decoder)
         m_decoder->encoding().displayBuffer(buffer, len);
 }
 
+// Generate definitions for both character types
+template void Document::displayBufferModifiedByEncodingInternal<LChar>(LChar*, unsigned) const;
+template void Document::displayBufferModifiedByEncodingInternal<UChar>(UChar*, unsigned) const;
+
 void Document::enqueuePageshowEvent(PageshowEventPersistence persisted)
 {
     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=36334 Pageshow event needs to fire asynchronously.

Modified: trunk/Source/WebCore/dom/Document.h (133630 => 133631)


--- trunk/Source/WebCore/dom/Document.h	2012-11-06 18:15:04 UTC (rev 133630)
+++ trunk/Source/WebCore/dom/Document.h	2012-11-06 18:15:44 UTC (rev 133631)
@@ -981,7 +981,14 @@
 
     String displayStringModifiedByEncoding(const String&) const;
     PassRefPtr<StringImpl> displayStringModifiedByEncoding(PassRefPtr<StringImpl>) const;
-    void displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const;
+    void displayBufferModifiedByEncoding(LChar* buffer, unsigned len) const
+    {
+        displayBufferModifiedByEncodingInternal(buffer, len);
+    }
+    void displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const
+    {
+        displayBufferModifiedByEncodingInternal(buffer, len);
+    }
 
     // Quirk for the benefit of Apple's Dictionary application.
     void setFrameElementsShouldIgnoreScrolling(bool ignore) { m_frameElementsShouldIgnoreScrolling = ignore; }
@@ -1207,6 +1214,9 @@
     void pendingTasksTimerFired(Timer<Document>*);
 
     static void didReceiveTask(void*);
+    
+    template <typename CharacterType>
+    void displayBufferModifiedByEncodingInternal(CharacterType*, unsigned) const;
 
 #if ENABLE(PAGE_VISIBILITY_API)
     PageVisibilityState visibilityState() const;

Modified: trunk/Source/WebCore/platform/text/TextEncoding.h (133630 => 133631)


--- trunk/Source/WebCore/platform/text/TextEncoding.h	2012-11-06 18:15:04 UTC (rev 133630)
+++ trunk/Source/WebCore/platform/text/TextEncoding.h	2012-11-06 18:15:44 UTC (rev 133631)
@@ -50,7 +50,8 @@
                 return str;
             return str->replace('\\', m_backslashAsCurrencySymbol);
         }
-        void displayBuffer(UChar* characters, unsigned len) const
+        template <typename CharacterType>
+        void displayBuffer(CharacterType* characters, unsigned len) const
         {
             if (m_backslashAsCurrencySymbol == '\\')
                 return;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to