Changeset 85056 in webkit


Ignore:
Timestamp:
Apr 27, 2011 9:22:48 AM (13 years ago)
Author:
Darin Adler
Message:

2011-04-27 Darin Adler <Darin Adler>

Reviewed by Sam Weinig.

Somehow about:blank gets into the icon database
https://bugs.webkit.org/show_bug.cgi?id=58067
rdar://problem/6751446

Implemented the policy Brady suggested, where only http and https URLs can
be associated with and icon, guarding both on the way in to the database,
and on the way out.

  • loader/icon/IconDatabase.cpp: (WebCore::pageCanHaveIcon): Added. (WebCore::IconDatabase::synchronousIconForPageURL): Call pageCanHaveIcon instead of just checking for an empty URL. (WebCore::IconDatabase::synchronousIconURLForPageURL): Ditto. (WebCore::IconDatabase::retainIconForPageURL): Ditto. (WebCore::IconDatabase::releaseIconForPageURL): Ditto. (WebCore::IconDatabase::setIconURLForPageURL): Ditto. (WebCore::IconDatabase::getOrCreatePageURLRecord): Ditto. (WebCore::IconDatabase::importIconURLForPageURL): Broke assertion into two separate assertions and added a third. (WebCore::IconDatabase::performURLImport): Call pageCanHaveIcon.
  • platform/KURL.cpp: Sorted includes. Moved a FIXME to the top of the file. (WebCore::isLetterMatchIgnoringCase): Renamed matchLetter to this name, overloaded it to work on both UChar and char, and added an assertion to it. Also moved this to the top of the file and made the UChar version usable in the shared code used even by Google. (WebCore::KURL::invalidate): Updated for name change. (WebCore::KURL::protocolIs): Use isLetterMatchIgnoringCase instead of toASCIILower since it's faster. (WebCore::KURL::parse): Updated for name changes. (WebCore::protocolIs):Use isLetterMatchIgnoringCase instead of toASCIILower since it's faster. (WebCore::protocolIsInHTTPFamily): Added.
  • platform/KURL.h: Tweaked formatting. Renamed protocolInHTTPFamily to protocolIsInHTTPFamily and added a version that works on a string. Kept the old name as an inline function so we don't have to rename all the cal sites now.
  • platform/KURLGoogle.cpp: Renamed as above. (WebCore::KURLGooglePrivate::KURLGooglePrivate): Updated for rename. (WebCore::KURLGooglePrivate::setUtf8): Ditto. (WebCore::KURLGooglePrivate::setAscii): Ditto. (WebCore::KURLGooglePrivate::initProtocolIsInHTTPFamily): Ditto. (WebCore::KURLGooglePrivate::copyTo): Ditto. (WebCore::KURL::KURL): Ditto. (WebCore::KURL::protocolIsInHTTPFamily): Ditto. (WebCore::KURL::invalidate): Ditto.
  • platform/KURLGooglePrivate.h: Ditto.
  • WebCore.exp.in: Updated for above changes.
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r85054 r85056  
     12011-04-27  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Somehow about:blank gets into the icon database
     6        https://bugs.webkit.org/show_bug.cgi?id=58067
     7        rdar://problem/6751446
     8
     9        Implemented the policy Brady suggested, where only http and https URLs can
     10        be associated with and icon, guarding both on the way in to the database,
     11        and on the way out.
     12
     13        * loader/icon/IconDatabase.cpp:
     14        (WebCore::pageCanHaveIcon): Added.
     15        (WebCore::IconDatabase::synchronousIconForPageURL): Call pageCanHaveIcon
     16        instead of just checking for an empty URL.
     17        (WebCore::IconDatabase::synchronousIconURLForPageURL): Ditto.
     18        (WebCore::IconDatabase::retainIconForPageURL): Ditto.
     19        (WebCore::IconDatabase::releaseIconForPageURL): Ditto.
     20        (WebCore::IconDatabase::setIconURLForPageURL): Ditto.
     21        (WebCore::IconDatabase::getOrCreatePageURLRecord): Ditto.
     22        (WebCore::IconDatabase::importIconURLForPageURL): Broke assertion into
     23        two separate assertions and added a third.
     24        (WebCore::IconDatabase::performURLImport): Call pageCanHaveIcon.
     25
     26        * platform/KURL.cpp: Sorted includes. Moved a FIXME to the top of the file.
     27        (WebCore::isLetterMatchIgnoringCase): Renamed matchLetter to this name,
     28        overloaded it to work on both UChar and char, and added an assertion to it.
     29        Also moved this to the top of the file and made the UChar version usable
     30        in the shared code used even by Google.
     31        (WebCore::KURL::invalidate): Updated for name change.
     32        (WebCore::KURL::protocolIs): Use isLetterMatchIgnoringCase instead of
     33        toASCIILower since it's faster.
     34        (WebCore::KURL::parse): Updated for name changes.
     35        (WebCore::protocolIs):Use isLetterMatchIgnoringCase instead of toASCIILower
     36        since it's faster.
     37        (WebCore::protocolIsInHTTPFamily): Added.
     38
     39        * platform/KURL.h: Tweaked formatting. Renamed protocolInHTTPFamily
     40        to protocolIsInHTTPFamily and added a version that works on a string.
     41        Kept the old name as an inline function so we don't have to rename
     42        all the cal sites now.
     43
     44        * platform/KURLGoogle.cpp: Renamed as above.
     45        (WebCore::KURLGooglePrivate::KURLGooglePrivate): Updated for rename.
     46        (WebCore::KURLGooglePrivate::setUtf8): Ditto.
     47        (WebCore::KURLGooglePrivate::setAscii): Ditto.
     48        (WebCore::KURLGooglePrivate::initProtocolIsInHTTPFamily): Ditto.
     49        (WebCore::KURLGooglePrivate::copyTo): Ditto.
     50        (WebCore::KURL::KURL): Ditto.
     51        (WebCore::KURL::protocolIsInHTTPFamily): Ditto.
     52        (WebCore::KURL::invalidate): Ditto.
     53        * platform/KURLGooglePrivate.h: Ditto.
     54
     55        * WebCore.exp.in: Updated for above changes.
     56
    1572011-04-27  Yury Semikhatsky  <yurys@chromium.org>
    258
  • trunk/Source/WebCore/WebCore.exp.in

    r85036 r85056  
    11911191__ZNK7WebCore4Font5widthERKNS_7TextRunEPN3WTF7HashSetIPKNS_14SimpleFontDataENS4_7PtrHashIS8_EENS4_10HashTraitsIS8_EEEEPNS_13GlyphOverflowE
    11921192__ZNK7WebCore4Font8drawTextEPNS_15GraphicsContextERKNS_7TextRunERKNS_10FloatPointEii
     1193__ZNK7WebCore4KURL10protocolIsEPKc
    11931194__ZNK7WebCore4KURL11createCFURLEv
    11941195__ZNK7WebCore4KURL11isLocalFileEv
     
    16021603__ZN7WebCore17HTMLPlugInElement11getNPObjectEv
    16031604__ZNK7WebCore14SecurityOrigin9canAccessEPKS0_
    1604 __ZNK7WebCore4KURL10protocolIsEPKc
    16051605__ZNK7WebCore4KURL7hasPathEv
    16061606__ZNK7WebCore4KURL9prettyURLEv
  • trunk/Source/WebCore/loader/icon/IconDatabase.cpp

    r84801 r85056  
    100100}
    101101
     102static inline bool pageCanHaveIcon(const String& pageURL)
     103{
     104    return protocolIsInHTTPFamily(pageURL);
     105}
     106
    102107// ************************
    103108// *** Main Thread Only ***
     
    219224    // We should go our of our way to only copy it if we have to store it
    220225   
    221     if (!isOpen() || pageURLOriginal.isEmpty())
     226    if (!isOpen() || !pageCanHaveIcon(pageURLOriginal))
    222227        return defaultIcon(size);
    223228
     
    306311    // Also, in the case we have a real answer for the caller, we must deep copy that as well
    307312   
    308     if (!isOpen() || pageURLOriginal.isEmpty())
     313    if (!isOpen() || !pageCanHaveIcon(pageURLOriginal))
    309314        return String();
    310315       
     
    396401    // Cannot do anything with pageURLOriginal that would end up storing it without deep copying first
    397402   
    398     if (!isEnabled() || pageURLOriginal.isEmpty())
     403    if (!isEnabled() || !pageCanHaveIcon(pageURLOriginal))
    399404        return;
    400405       
     
    440445    // Cannot do anything with pageURLOriginal that would end up storing it without deep copying first
    441446   
    442     if (!isEnabled() || pageURLOriginal.isEmpty())
     447    if (!isEnabled() || !pageCanHaveIcon(pageURLOriginal))
    443448        return;
    444449   
     
    575580    ASSERT(!iconURLOriginal.isEmpty());
    576581       
    577     if (!isOpen() || pageURLOriginal.isEmpty())
     582    if (!isOpen() || !pageCanHaveIcon(pageURLOriginal))
    578583        return;
    579584   
     
    885890    ASSERT(!m_urlAndIconLock.tryLock());
    886891
    887     if (pageURL.isEmpty())
     892    if (!pageCanHaveIcon(pageURL))
    888893        return 0;
    889894
     
    921926   
    922927    // This function is only for setting actual existing url mappings so assert that neither of these URLs are empty
    923     ASSERT(!iconURL.isEmpty() && !pageURL.isEmpty());
     928    ASSERT(!iconURL.isEmpty());
     929    ASSERT(!pageURL.isEmpty());
     930    ASSERT(pageCanHaveIcon(pageURL));
    924931   
    925932    setIconURLForPageURLInSQLDatabase(iconURL, pageURL);   
     
    12281235            // If database cleanup *is* allowed, we don't want to bother pulling in a page url from disk that noone is actually interested
    12291236            // in - we'll prune it later instead!
    1230             if (!pageRecord && databaseCleanupCounter && !pageURL.isEmpty()) {
     1237            if (!pageRecord && databaseCleanupCounter && pageCanHaveIcon(pageURL)) {
    12311238                pageRecord = new PageURLRecord(pageURL);
    12321239                m_pageURLToRecordMap.set(pageURL, pageRecord);
  • trunk/Source/WebCore/platform/KURL.cpp

    r84762 r85056  
    11/*
    2  * Copyright (C) 2004, 2007, 2008 Apple Inc. All rights reserved.
     2 * Copyright (C) 2004, 2007, 2008, 2011 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525
    2626#include "config.h"
    27 
    2827#include "KURL.h"
    2928
    3029#include "TextEncoding.h"
    31 #include <wtf/text/CString.h>
     30#include <stdio.h>
    3231#include <wtf/HashMap.h>
    3332#include <wtf/HexNumber.h>
    3433#include <wtf/StdLibExtras.h>
     34#include <wtf/text/CString.h>
    3535#include <wtf/text/StringHash.h>
    3636
     
    4444#endif
    4545
    46 #include <stdio.h>
     46// FIXME: This file makes too much use of the + operator on String.
     47// We either have to optimize that operator so it doesn't involve
     48// so many allocations, or change this to use StringBuffer instead.
    4749
    4850using namespace std;
     
    5759static const unsigned invalidPortNumber = 0xFFFF;
    5860
     61static inline bool isLetterMatchIgnoringCase(UChar character, char lowercaseLetter)
     62{
     63    ASSERT(isASCIILower(lowercaseLetter));
     64    return (character | 0x20) == lowercaseLetter;
     65}
     66
    5967#if !USE(GOOGLEURL)
    6068
    61 // FIXME: This file makes too much use of the + operator on String.
    62 // We either have to optimize that operator so it doesn't involve
    63 // so many allocations, or change this to use Vector<UChar> instead.
     69static inline bool isLetterMatchIgnoringCase(char character, char lowercaseLetter)
     70{
     71    ASSERT(isASCIILower(lowercaseLetter));
     72    return (character | 0x20) == lowercaseLetter;
     73}
    6474
    6575enum URLCharacterClasses {
     
    296306{
    297307    m_isValid = false;
    298     m_protocolInHTTPFamily = false;
     308    m_protocolIsInHTTPFamily = false;
    299309    m_schemeEnd = 0;
    300310    m_userStart = 0;
     
    693703    // Do the comparison without making a new string object.
    694704    for (int i = 0; i < m_schemeEnd; ++i) {
    695         if (!protocol[i] || toASCIILower(m_string[i]) != protocol[i])
     705        if (!protocol[i] || !isLetterMatchIgnoringCase(m_string[i], protocol[i]))
    696706            return false;
    697707    }
     
    10861096}
    10871097
    1088 static inline bool matchLetter(char c, char lowercaseLetter)
    1089 {
    1090     return (c | 0x20) == lowercaseLetter;
    1091 }
    1092 
    10931098void KURL::parse(const String& string)
    10941099{
     
    11941199
    11951200    bool isFile = schemeEnd == 4
    1196         && matchLetter(url[0], 'f')
    1197         && matchLetter(url[1], 'i')
    1198         && matchLetter(url[2], 'l')
    1199         && matchLetter(url[3], 'e');
    1200 
    1201     m_protocolInHTTPFamily = matchLetter(url[0], 'h')
    1202         && matchLetter(url[1], 't')
    1203         && matchLetter(url[2], 't')
    1204         && matchLetter(url[3], 'p')
    1205         && (url[4] == ':' || (matchLetter(url[4], 's') && url[5] == ':'));
     1201        && isLetterMatchIgnoringCase(url[0], 'f')
     1202        && isLetterMatchIgnoringCase(url[1], 'i')
     1203        && isLetterMatchIgnoringCase(url[2], 'l')
     1204        && isLetterMatchIgnoringCase(url[3], 'e');
     1205
     1206    m_protocolIsInHTTPFamily = isLetterMatchIgnoringCase(url[0], 'h')
     1207        && isLetterMatchIgnoringCase(url[1], 't')
     1208        && isLetterMatchIgnoringCase(url[2], 't')
     1209        && isLetterMatchIgnoringCase(url[3], 'p')
     1210        && (url[4] == ':' || (isLetterMatchIgnoringCase(url[4], 's') && url[5] == ':'));
    12061211
    12071212    if ((hierarchical && hasSecondSlash) || isNonFileHierarchicalScheme(url, schemeEnd)) {
     
    12901295        }
    12911296
    1292         if (userStart == portEnd && !m_protocolInHTTPFamily && !isFile) {
     1297        if (userStart == portEnd && !m_protocolIsInHTTPFamily && !isFile) {
    12931298            // No authority found, which means that this is not a net_path, but rather an abs_path whose first two
    12941299            // path segments are empty. For file, http and https only, an empty authority is allowed.
     
    13451350
    13461351    bool hostIsLocalHost = portEnd - userStart == 9
    1347         && matchLetter(url[userStart], 'l')
    1348         && matchLetter(url[userStart+1], 'o')
    1349         && matchLetter(url[userStart+2], 'c')
    1350         && matchLetter(url[userStart+3], 'a')
    1351         && matchLetter(url[userStart+4], 'l')
    1352         && matchLetter(url[userStart+5], 'h')
    1353         && matchLetter(url[userStart+6], 'o')
    1354         && matchLetter(url[userStart+7], 's')
    1355         && matchLetter(url[userStart+8], 't');
     1352        && isLetterMatchIgnoringCase(url[userStart], 'l')
     1353        && isLetterMatchIgnoringCase(url[userStart+1], 'o')
     1354        && isLetterMatchIgnoringCase(url[userStart+2], 'c')
     1355        && isLetterMatchIgnoringCase(url[userStart+3], 'a')
     1356        && isLetterMatchIgnoringCase(url[userStart+4], 'l')
     1357        && isLetterMatchIgnoringCase(url[userStart+5], 'h')
     1358        && isLetterMatchIgnoringCase(url[userStart+6], 'o')
     1359        && isLetterMatchIgnoringCase(url[userStart+7], 's')
     1360        && isLetterMatchIgnoringCase(url[userStart+8], 't');
    13561361
    13571362    // File URLs need a host part unless it is just file:// or file://localhost
     
    14171422    // For canonicalization, ensure we have a '/' for no path.
    14181423    // Do this only for URL with protocol http or https.
    1419     if (m_protocolInHTTPFamily && pathEnd == pathStart)
     1424    if (m_protocolIsInHTTPFamily && pathEnd == pathStart)
    14201425        *p++ = '/';
    14211426
     
    17741779        if (!protocol[i])
    17751780            return url[i] == ':';
    1776         if (toASCIILower(url[i]) != protocol[i])
     1781        if (!isLetterMatchIgnoringCase(url[i], protocol[i]))
    17771782            return false;
    17781783    }
     
    19661971}
    19671972
    1968 }
     1973bool protocolIsInHTTPFamily(const String& url)
     1974{
     1975    unsigned length = url.length();
     1976    const UChar* characters = url.characters();
     1977    return length > 4
     1978        && isLetterMatchIgnoringCase(characters[0], 'h')
     1979        && isLetterMatchIgnoringCase(characters[1], 't')
     1980        && isLetterMatchIgnoringCase(characters[2], 't')
     1981        && isLetterMatchIgnoringCase(characters[3], 'p')
     1982        && (characters[4] == ':'
     1983            || (isLetterMatchIgnoringCase(characters[4], 's') && length > 5 && characters[5] == ':'));
     1984}
     1985
     1986}
  • trunk/Source/WebCore/platform/KURL.h

    r83671 r85056  
    11/*
    2  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
     2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    9494    KURL(const KURL& base, const String& relative, const TextEncoding&);
    9595
    96 
    97 #if USE(GOOGLEURL)
    98     // For conversions for other structures that have already parsed and
     96#if USE(GOOGLEURL)
     97    // For conversions from other structures that have already parsed and
    9998    // canonicalized the URL. The input must be exactly what KURL would have
    10099    // done with the same input.
    101     KURL(const CString& canonicalSpec,
    102          const url_parse::Parsed& parsed, bool isValid);
     100    KURL(const CString& canonicalSpec, const url_parse::Parsed&, bool isValid);
    103101#endif
    104102
     
    160158    bool protocolIs(const char*) const;
    161159    bool protocolIsData() const { return protocolIs("data"); }
    162     bool protocolInHTTPFamily() const;
     160    bool protocolIsInHTTPFamily() const;
    163161    bool isLocalFile() const;
    164162
     
    197195    unsigned pathEnd() const;
    198196    unsigned pathAfterLastSlash() const;
     197
    199198    operator const String&() const { return string(); }
    200199
     
    226225    void print() const;
    227226#endif
     227
     228    // FIXME: Remove this after changing all callers to use protocolIsInHTTPFamily.
     229    bool protocolInHTTPFamily() const { return protocolIsInHTTPFamily(); }
    228230
    229231private:
     
    248250    String m_string;
    249251    bool m_isValid : 1;
    250     bool m_protocolInHTTPFamily : 1;
     252    bool m_protocolIsInHTTPFamily : 1;
    251253
    252254    int m_schemeEnd;
     
    281283
    282284bool protocolIs(const String& url, const char* protocol);
     285bool protocolIsInHTTPFamily(const String& url);
    283286bool protocolIsJavaScript(const String& url);
    284287
     
    355358}
    356359
    357 inline bool KURL::protocolInHTTPFamily() const
    358 {
    359     return m_protocolInHTTPFamily;
     360inline bool KURL::protocolIsInHTTPFamily() const
     361{
     362    return m_protocolIsInHTTPFamily;
    360363}
    361364
  • trunk/Source/WebCore/platform/KURLGoogle.cpp

    r83671 r85056  
    155155KURLGooglePrivate::KURLGooglePrivate()
    156156    : m_isValid(false)
    157     , m_protocolInHTTPFamily(false)
     157    , m_protocolIsInHTTPFamily(false)
    158158    , m_utf8IsASCII(true)
    159159    , m_stringIsValid(false)
     
    163163KURLGooglePrivate::KURLGooglePrivate(const url_parse::Parsed& parsed, bool isValid)
    164164    : m_isValid(isValid)
    165     , m_protocolInHTTPFamily(false)
     165    , m_protocolIsInHTTPFamily(false)
    166166    , m_parsed(parsed)
    167167    , m_utf8IsASCII(true)
     
    197197    m_utf8 = str;
    198198    m_stringIsValid = false;
    199     initProtocolInHTTPFamily();
     199    initProtocolIsInHTTPFamily();
    200200}
    201201
     
    205205    m_utf8IsASCII = true;
    206206    m_stringIsValid = false;
    207     initProtocolInHTTPFamily();
     207    initProtocolIsInHTTPFamily();
    208208}
    209209
     
    259259}
    260260
    261 void KURLGooglePrivate::initProtocolInHTTPFamily()
     261void KURLGooglePrivate::initProtocolIsInHTTPFamily()
    262262{
    263263    if (!m_isValid) {
    264         m_protocolInHTTPFamily = false;
     264        m_protocolIsInHTTPFamily = false;
    265265        return;
    266266    }
     
    268268    const char* scheme = m_utf8.data() + m_parsed.scheme.begin;
    269269    if (m_parsed.scheme.len == 4)
    270         m_protocolInHTTPFamily = lowerCaseEqualsASCII(scheme, scheme + 4, "http");
     270        m_protocolIsInHTTPFamily = lowerCaseEqualsASCII(scheme, scheme + 4, "http");
    271271    else if (m_parsed.scheme.len == 5)
    272         m_protocolInHTTPFamily = lowerCaseEqualsASCII(scheme, scheme + 5, "https");
     272        m_protocolIsInHTTPFamily = lowerCaseEqualsASCII(scheme, scheme + 5, "https");
    273273    else
    274         m_protocolInHTTPFamily = false;
     274        m_protocolIsInHTTPFamily = false;
    275275}
    276276
     
    278278{
    279279    dest->m_isValid = m_isValid;
    280     dest->m_protocolInHTTPFamily = m_protocolInHTTPFamily;
     280    dest->m_protocolIsInHTTPFamily = m_protocolIsInHTTPFamily;
    281281    dest->m_parsed = m_parsed;
    282282
     
    371371        // empty string, which is what init() will create.
    372372        m_url.m_isValid = false;
    373         m_url.m_protocolInHTTPFamily = false;
     373        m_url.m_protocolIsInHTTPFamily = false;
    374374    }
    375375}
     
    444444}
    445445
    446 bool KURL::protocolInHTTPFamily() const
    447 {
    448     return m_url.m_protocolInHTTPFamily;
     446bool KURL::protocolIsInHTTPFamily() const
     447{
     448    return m_url.m_protocolIsInHTTPFamily;
    449449}
    450450
     
    884884    // initialized) string and parsed structure would be a waste of time.
    885885    m_url.m_isValid = false;
    886     m_url.m_protocolInHTTPFamily = false;
     886    m_url.m_protocolIsInHTTPFamily = false;
    887887}
    888888
  • trunk/Source/WebCore/platform/KURLGooglePrivate.h

    r83671 r85056  
    9292
    9393        bool m_isValid;
    94         bool m_protocolInHTTPFamily;
     94        bool m_protocolIsInHTTPFamily;
    9595        url_parse::Parsed m_parsed; // Indexes into the UTF-8 version of the string.
    9696
    9797    private:
    98         void initProtocolInHTTPFamily();
     98        void initProtocolIsInHTTPFamily();
    9999
    100100        CString m_utf8;
Note: See TracChangeset for help on using the changeset viewer.