bool protocolHostAndPortAreEqual(const KURL& a, const KURL& b)
{
    if (a.parsed().scheme.end() != b.parsed().scheme.end())
        return false;

    int hostStartA = a.hostStart();
    int hostStartB = b.hostStart();
    if (a.hostEnd() - hostStartA != b.hostEnd() - hostStartB)
        return false;

    // Check the scheme
    for (int i = 0; i < a.parsed().scheme.end(); ++i)
        if (a.string()[i] != b.string()[i])
            return false;
    
    // And the host
    for (int i = hostStartA; i < static_cast<int>(a.hostEnd()); ++i)
        if (a.string()[i] != b.string()[i])
            return false;
    
    if (a.port() != b.port())
        return false;

    return true;
}
bool protocolHostAndPortAreEqual(const KURL& a, const KURL& b)
{
    if (a.parsed().scheme.end() != b.parsed().scheme.end())
        return false;

    int hostStartA = a.hostStart();
    int hostLengthA = a.hostEnd() - hostStartA;
    int hostStartB = b.hostStart();
    int hostLengthB = b.hostEnd() - b.hostStart();
    if (hostLengthA != hostLengthB)
        return false;

    // Check the scheme
    for (int i = 0; i < a.parsed().scheme.end(); ++i)
        if (a.string()[i] != b.string()[i])
            return false;
    
    // And the host
    for (int i = 0; i < hostLengthA; ++i)
        if (a.string()[hostStartA + i] != b.string()[hostStartB + i])
            return false;
    
    if (a.port() != b.port())
        return false;

    return true;
}
Exemple #3
0
static bool resolveRelative(const KURL& base, const String& relative, url_canon::RawCanonOutput<2048>* buffer)
{
    // We use these low-level GURL functions to avoid converting back and forth from UTF-8 unnecessarily.
    url_parse::Parsed parsed;
    StringUTF8Adaptor baseUTF8(base.string());
    if (relative.is8Bit()) {
        StringUTF8Adaptor relativeUTF8(relative);
        return url_util::ResolveRelative(baseUTF8.data(), baseUTF8.length(), base.parsed(), relativeUTF8.data(), relativeUTF8.length(), 0, buffer, &parsed);
    }
    return url_util::ResolveRelative(baseUTF8.data(), baseUTF8.length(), base.parsed(), relative.characters16(), relative.length(), 0, buffer, &parsed);
}
LinkHash ChromiumBridge::visitedLinkHash(const KURL& base,
                                         const AtomicString& attributeURL)
{
    // Resolve the relative URL using googleurl and pass the absolute URL up to
    // the embedder. We could create a GURL object from the base and resolve
    // the relative URL that way, but calling the lower-level functions
    // directly saves us the string allocation in most cases.
    url_canon::RawCanonOutput<2048> buffer;
    url_parse::Parsed parsed;

#if USE(GOOGLEURL)
    const CString& cstr = base.utf8String();
    const char* data = cstr.data();
    int length = cstr.length();
    const url_parse::Parsed& srcParsed = base.parsed();
#else
    // When we're not using GoogleURL, first canonicalize it so we can resolve it
    // below.
    url_canon::RawCanonOutput<2048> srcCanon;
    url_parse::Parsed srcParsed;
    String str = base.string();
    if (!url_util::Canonicalize(str.characters(), str.length(), 0, &srcCanon, &srcParsed))
        return 0;
    const char* data = srcCanon.data();
    int length = srcCanon.length();
#endif

    if (!url_util::ResolveRelative(data, length, srcParsed, attributeURL.characters(),
                                   attributeURL.length(), 0, &buffer, &parsed))
        return 0;  // Invalid resolved URL.

    return webKitClient()->visitedLinkHash(buffer.data(), buffer.length());
}