void FrameFetchContext::upgradeInsecureRequest(FetchRequest& fetchRequest)
{
    KURL url = fetchRequest.resourceRequest().url();

    // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational requests, as described in
    // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect
    if (fetchRequest.resourceRequest().frameType() != WebURLRequest::FrameTypeNone)
        fetchRequest.mutableResourceRequest().addHTTPHeaderField("Upgrade-Insecure-Requests", "1");

    // If we don't yet have an |m_document| (because we're loading an iframe, for instance), check the FrameLoader's policy.
    WebInsecureRequestPolicy relevantPolicy = m_document ? m_document->getInsecureRequestPolicy() : frame()->loader().getInsecureRequestPolicy();
    SecurityContext::InsecureNavigationsSet* relevantNavigationSet = m_document ? m_document->insecureNavigationsToUpgrade() : frame()->loader().insecureNavigationsToUpgrade();

    if (url.protocolIs("http") && relevantPolicy & kUpgradeInsecureRequests) {
        // We always upgrade requests that meet any of the following criteria:
        //
        // 1. Are for subresources (including nested frames).
        // 2. Are form submissions.
        // 3. Whose hosts are contained in the document's InsecureNavigationSet.
        const ResourceRequest& request = fetchRequest.resourceRequest();
        if (request.frameType() == WebURLRequest::FrameTypeNone
            || request.frameType() == WebURLRequest::FrameTypeNested
            || request.requestContext() == WebURLRequest::RequestContextForm
            || (!url.host().isNull() && relevantNavigationSet->contains(url.host().impl()->hash())))
        {
            UseCounter::count(m_document, UseCounter::UpgradeInsecureRequestsUpgradedRequest);
            url.setProtocol("https");
            if (url.port() == 80)
                url.setPort(443);
            fetchRequest.mutableResourceRequest().setURL(url);
        }
    }
}
Пример #2
0
static void dnsPrefetchIfNeeded(
    const LinkRelAttribute& relAttribute,
    const KURL& href,
    Document& document,
    const NetworkHintsInterface& networkHintsInterface,
    LinkCaller caller) {
  if (relAttribute.isDNSPrefetch()) {
    UseCounter::count(document, UseCounter::LinkRelDnsPrefetch);
    if (caller == LinkCalledFromHeader)
      UseCounter::count(document, UseCounter::LinkHeaderDnsPrefetch);
    Settings* settings = document.settings();
    // FIXME: The href attribute of the link element can be in "//hostname"
    // form, and we shouldn't attempt to complete that as URL
    // <https://bugs.webkit.org/show_bug.cgi?id=48857>.
    if (settings && settings->dnsPrefetchingEnabled() && href.isValid() &&
        !href.isEmpty()) {
      if (settings->logDnsPrefetchAndPreconnect()) {
        document.addConsoleMessage(ConsoleMessage::create(
            OtherMessageSource, DebugMessageLevel,
            String("DNS prefetch triggered for " + href.host())));
      }
      networkHintsInterface.dnsPrefetchHost(href.host());
    }
  }
}
Пример #3
0
static String originStringFromURL(const KURL& url)
{
    if (url.port())
        return url.protocol() + "://" + url.host() + ':' + String::number(url.port()) + '/';

    return url.protocol() + "://" + url.host() + '/';
}
Пример #4
0
String DOMURLUtilsReadOnly::host(const KURL& kurl) {
  if (kurl.hostEnd() == kurl.pathStart())
    return kurl.host();
  if (isDefaultPortForProtocol(kurl.port(), kurl.protocol()))
    return kurl.host();
  return kurl.host() + ":" + String::number(kurl.port());
}
Пример #5
0
bool protocolHostAndPortAreEqual(const KURL& a, const KURL& b)
{
    if (!a.isValid() || !b.isValid())
        return false;

    return a.protocol() == b.protocol()
           && a.host() == b.host()
           && a.port() == b.port();
}
Пример #6
0
void Browser::doHTTPRequest(const KURL& url)
{
  initHTTPCommunication();

  kdDebug() << "HTTP request \"" << url.path() + url.query() <<  "\" from " << url.host() << endl;

  m_http->setHost(url.host());
  m_http->get(url.path() + url.query());
}
static bool webKitWebSrcStart(WebKitWebSrc* src)
{
    WebKitWebSrcPrivate* priv = src->priv;

    if (!priv->uri) {
        GST_ERROR_OBJECT(src, "No URI provided");
        return false;
    }
    
    KURL url = KURL(KURL(), priv->uri);

    ResourceRequest request(url);
    request.setTargetType(ResourceRequestBase::TargetIsMedia);
    request.setAllowCookies(true);

    NetworkingContext* context = 0;
    if (priv->frame) {
        Document* document = priv->frame->document();
        if (document)
            request.setHTTPReferrer(document->documentURI());

        FrameLoader* loader = priv->frame->loader();
        if (loader) {
            loader->addExtraFieldsToSubresourceRequest(request);
            context = loader->networkingContext();
        }
    }

    // Let Apple web servers know we want to access their nice movie trailers.
    if (!g_ascii_strcasecmp("movies.apple.com", url.host().utf8().data())
        || !g_ascii_strcasecmp("trailers.apple.com", url.host().utf8().data()))
        request.setHTTPUserAgent("Quicktime/7.6.6");

    if (priv->requestedOffset) {
        GOwnPtr<gchar> val;

        val.set(g_strdup_printf("bytes=%" G_GUINT64_FORMAT "-", priv->requestedOffset));
        request.setHTTPHeaderField("Range", val.get());
    }

    if (priv->iradioMode)
        request.setHTTPHeaderField("icy-metadata", "1");

    // Needed to use DLNA streaming servers
    request.setHTTPHeaderField("transferMode.dlna", "Streaming");

    priv->resourceHandle = ResourceHandle::create(context, request, priv->client, false, false);
    if (!priv->resourceHandle) {
        GST_ERROR_OBJECT(src, "Failed to create ResourceHandle");
        return false;
    }

    GST_DEBUG_OBJECT(src, "Started request");

    return true;
}
Пример #8
0
void MrmlPart::contactServer( const KURL& url )
{
    m_job = transferJob( url );

    m_job->addMetaData( MrmlShared::kio_task(), MrmlShared::kio_initialize() );

    QString host = url.host().isEmpty() ?
                   QString::fromLatin1("localhost") : url.host();

    slotSetStatusBar( i18n("Connecting to indexing server at %1...").arg( host ));
}
Пример #9
0
QString Groupwise::soapUrl(const KURL &url)
{
    // FIXME: Get SSL from parameter
    bool useSsl = url.protocol() == "groupwises";

    QString u;
    if(useSsl) u = "https";
    else u = "http";

    u += "://" + url.host() + ":";
    if(url.port())
        u += QString::number(url.port());
    else
    {
        u += "7191";
    }

    // check for a soap path in the URL
    // assume that if a path to soap is included in the URL,
    // it will be at the start of the path, eg.
    // groupwise://host:port/soap2/freebusy
    if(!(url.path().startsWith("/freebusy/") ||
            url.path().startsWith("/calendar/") ||
            url.path().startsWith("/addressbook/")))
    {
        QString soapPath = QString("/") + QStringList::split('/', url.path())[0];
        u += soapPath;
    }
    else
        u += "/soap";

    return u;
}
Пример #10
0
KProtocolProxyFTP::KProtocolProxyFTP () {

    use_proxy = 0;
    int port = 80;

    QString proxyStr;
    QString tmp;
    KURL proxyURL;
    
    // All right. Now read the proxy settings
    // KSimpleConfig prxcnf(KApplication::localconfigdir() + "/kfmrc");
    // Read Only
    KSimpleConfig prxcnf(KApplication::localconfigdir() + "/kfmrc", true );
    prxcnf.setGroup("Browser Settings/Proxy");

    noProxyForStr = prxcnf.readEntry("NoProxyFor");
    
    tmp = prxcnf.readEntry( "UseProxy" );
    if ( tmp == "Yes" ) { // Do we need proxy?
        proxyStr = prxcnf.readEntry( "FTP-Proxy" );
        proxyURL = proxyStr.data();
        // printf( "Using ftp proxy %s on port %d\n", proxyURL.host(), proxyURL.port() );
        port = proxyURL.port();
	if ( port == 0 )
	    port = 80;

	proxy_user = prxcnf.readEntry( "Proxy-User" );
	proxy_pass = prxcnf.readEntry( "Proxy-Pass" );

	init_sockaddr(&proxy_name, proxyURL.host(), port);
	use_proxy = 1;
    }
}
bool UserContentURLPattern::matchesHost(const KURL& test) const
{
    if (test.host() == m_host)
        return true;

    if (!m_matchSubdomains)
        return false;

    // If we're matching subdomains, and we have no host, that means the pattern
    // was <scheme>://*/<whatever>, so we match anything.
    if (!m_host.length())
        return true;

    // Check if the test host is a subdomain of our host.
    return test.host().endsWith(m_host, false);
}
IconURL IconController::defaultURL(IconType iconType)
{
    // Don't return a favicon iconURL unless we're http or https
    KURL documentURL = m_frame->document()->url();
    if (!documentURL.protocolIsInHTTPFamily())
        return IconURL();

    KURL url;
    bool couldSetProtocol = url.setProtocol(documentURL.protocol());
    ASSERT_UNUSED(couldSetProtocol, couldSetProtocol);
    url.setHost(documentURL.host());
    if (documentURL.hasPort())
        url.setPort(documentURL.port());

    if (iconType == Favicon) {
        url.setPath("/favicon.ico");
        return IconURL::defaultIconURL(url, Favicon);
    }
#if ENABLE(TOUCH_ICON_LOADING)
    if (iconType == TouchPrecomposedIcon) {
        url.setPath("/apple-touch-icon-precomposed.png");
        return IconURL::defaultIconURL(url, TouchPrecomposedIcon);
    }
    if (iconType == TouchIcon) {
        url.setPath("/apple-touch-icon.png");
        return IconURL::defaultIconURL(url, TouchIcon);
    }
#endif
    return IconURL();
}
void BlackBerryCookieCache::clearAllCookiesForHost(const String& pageGroup, const KURL& url)
{
    // FIXME: actually, we only need to clear the cookies for which the protocol+host match the url
    String host = url.host().lower();
    if (pageGroup.isEmpty() || host.isEmpty())
        return;

    // Clear all cookie for specified page group name and host.
    PageGroupMap::iterator groupIterator = m_groupMap.find(pageGroup);
    if (groupIterator != m_groupMap.end()) {
        HostMap::iterator hostIterator = groupIterator->second->find(host);
        if (hostIterator != groupIterator->second->end()) {
            ItemMap::iterator itemIterator = hostIterator->second->begin();
            ItemMap::iterator itemIteratorEnd = hostIterator->second->end();
            // Count down memory counter
            for (; itemIterator != itemIteratorEnd; ++itemIterator)
                m_size -= (itemIterator->first.length() + itemIterator->second.cookies.length()) * sizeof(UChar);
            m_size -= hostIterator->first.length() * sizeof(UChar);

            // Delete the host map pointer and remove it
            // from the group map.
            delete hostIterator->second;
            groupIterator->second->remove(hostIterator);
        }
    }
}
Пример #14
0
AtomicURL::AtomicURL( const KURL &url )
{
    if( url.isEmpty() )
        return;

    QString s = url.protocol() + "://";
    QString host = url.host();
    if( url.hasUser() )
    {
        s += url.user();
        host.prepend("@");
    }
    if( url.hasPass() )
        s += ':' + url.pass();
    if( url.port() )
        host += QString(":") + QString::number( url.port() );

    m_beginning = s + host;
    m_directory = url.directory();
    m_filename = url.fileName();
    m_end = url.query();
    if( url.hasRef() )
        m_end += QString("#") + url.ref();
    if (url != this->url())
    {
        debug() << "from: " << url << endl;
        debug() << "to:   " << this->url() << endl;
    }
}
Пример #15
0
bool KManualProxyDlg::isValidURL( const QString& _url, KURL* result ) const
{
    KURL url (_url);
    
    QStringList filters;
    filters << "kshorturifilter" << "localdomainurifilter";
    
    // If the typed URL is malformed, and the filters cannot filter it
    // then it must be an invalid entry.
    if( !(url.isValid() || KURIFilter::self()->filterURI(url, filters)) && 
        !url.hasHost() )
      return false;
      
    QString host (url.host());
    
    // We only check for a relevant subset of characters that are 
    // not allowed in <authority> component of a URL.
    if ( host.contains ('*') || host.contains (' ') || host.contains ('?') )
      return false;
      
    if ( result )
      *result = url;
          
    return true;
}
void FrameFetchContext::upgradeInsecureRequest(FetchRequest& fetchRequest)
{
    KURL url = fetchRequest.resourceRequest().url();

    // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational requests, as described in
    // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect
    if (fetchRequest.resourceRequest().frameType() != WebURLRequest::FrameTypeNone)
        fetchRequest.mutableResourceRequest().addHTTPHeaderField("Upgrade-Insecure-Requests", "1");

    if (m_document && m_document->insecureRequestsPolicy() == SecurityContext::InsecureRequestsUpgrade && url.protocolIs("http")) {
        ASSERT(m_document->insecureNavigationsToUpgrade());

        // We always upgrade requests that meet any of the following criteria:
        //
        // 1. Are for subresources (including nested frames).
        // 2. Are form submissions.
        // 3. Whose hosts are contained in the document's InsecureNavigationSet.
        const ResourceRequest& request = fetchRequest.resourceRequest();
        if (request.frameType() == WebURLRequest::FrameTypeNone
            || request.frameType() == WebURLRequest::FrameTypeNested
            || request.requestContext() == WebURLRequest::RequestContextForm
            || (!url.host().isNull() && m_document->insecureNavigationsToUpgrade()->contains(url.host().impl()->hash())))
        {
            UseCounter::count(m_document, UseCounter::UpgradeInsecureRequestsUpgradedRequest);
            url.setProtocol("https");
            if (url.port() == 80)
                url.setPort(443);
            fetchRequest.mutableResourceRequest().setURL(url);
        }
    }
}
SocketStreamHandle::SocketStreamHandle(const KURL& url, Page* page,
                                       SocketStreamHandleClient* client)
    : SocketStreamHandleBase(url, client)
{
    String host = url.host();
    bool ssl = url.protocolIs("wss");
    int port = url.hasPort() ? url.port() : (ssl ? 443 : 80);

    JNIEnv* env = WebCore_GetJavaEnv();

    static jmethodID mid = env->GetStaticMethodID(
            GetSocketStreamHandleClass(env),
            "fwkCreate",
            "(Ljava/lang/String;IZLcom/sun/webkit/WebPage;J)"
            "Lcom/sun/webkit/network/SocketStreamHandle;");
    ASSERT(mid);

    m_ref = JLObject(env->CallStaticObjectMethod(
            GetSocketStreamHandleClass(env),
            mid,
            (jstring) host.toJavaString(env),
            port,
            bool_to_jbool(ssl),
            (jobject) WebPage::jobjectFromPage(page),
            ptr_to_jlong(this)));
    CheckAndClearException(env);
}
Пример #18
0
bool CookieManager::shouldRejectForSecurityReason(const ParsedCookie* cookie, const KURL& url)
{
    // Check if path attribute is a prefix of the request URI.
    if (!cookie->path().endsWith(url.path()) == -1) {
        LOG_ERROR("Cookie %s is rejected because its path does not math the URL %s\n", cookie->toString().utf8().data(), url.string().utf8().data());
        return true;
    }

    // Check if the domain starts with a dot.
    // FIXME: This check is in fact disabled because the CookieParser prefix the domain if needed and should be removed.
    if (cookie->domain()[0] != '.') {
        LOG_ERROR("Cookie %s is rejected because its domain does not start with a dot.\n", cookie->toString().utf8().data());
        return true;
    }

    // Check if the domain contains an embedded dot.
    int dotPosition = cookie->domain().find(".", 1);
    if (dotPosition == -1 || static_cast<unsigned int>(dotPosition) == cookie->domain().length()) {
        LOG_ERROR("Cookie %s is rejected because its domain does not contain an embedded dot.\n", cookie->toString().utf8().data());
        return true;
    }

    // The request host should domain match the Domain attribute.
    int diffPos = url.host().endsWith(cookie->domain());
    if (diffPos == -1) {
        LOG_ERROR("Cookie %s is rejected because its domain does not domain match the URL %s\n", cookie->toString().utf8().data(), url.string().utf8().data());
        return true;
    }
    // We should check for an embedded dot in the portion of string in the host not in the domain
    // but to match firefox behaviour we do not.

    return false;
}
Пример #19
0
void KSlovar::slotShowBrowser(const KURL &url, const KParts::URLArgs &)
{
  bool selected = false;
  QString id = url.host();
  QListViewItem *current=m_list->firstChild();
  while(current)
  {
    if(static_cast<KSListViewItem*> (current)->getId() == id)
    {
      m_list->setSelected(current, true);
      selected = true;
      break;
    }
    current=current->nextSibling();
  }
  if(!selected)
  {
    m_list->clearSelection();

    m_editPhrase->setEnabled(true);
    m_removePhrase->setEnabled(true);

    if(m_history == false)
    {
      addHistory();
    }

    m_selectedPhrase = id;
    showDictionary();
  }
}
Пример #20
0
String cookies(const Document* /*document*/, const KURL& url)
{
    String rawCookie = cookieJar.get(url.host());
    String urlPath = url.path();
    String resCookie;
    Vector<String> field;
    const int fieldNum = 7;
    int i, len;

    if (rawCookie.length() == 0)
        return resCookie;

    // --- Parse raw cookie ---
    rawCookie.split('\t', true, field);
    len = field.size();

    for (i = 0; i < len; i += fieldNum)
        if (urlPath.startsWith(field[i + 2], false))
            resCookie += "; " + field[i + 5] + "=" + field[i + 6];

    // --- Trim leading separator ---
    if (!resCookie.isEmpty())
        resCookie.remove(0, 2);

    // printf("%s: %s\n%s\n\n", __func__, url.string().utf8().data(), resCookie.utf8().data());
    return resCookie;
}
String BlackBerryCookieCache::cookies(const String& pageGroup, const KURL& url)
{
    String key = url.string().lower();
    String host = url.host().lower();
    if (pageGroup.isEmpty() || key.isEmpty() || host.isEmpty())
        return String();

    // Lookup cookie by page group name, host name and URL in 3 level
    // hash map.
    PageGroupMap::iterator groupIterator = m_groupMap.find(pageGroup);
    if (groupIterator != m_groupMap.end()) {
        HostMap::iterator hostIterator = groupIterator->second->find(host);
        if (hostIterator != groupIterator->second->end()) {
            ItemMap::iterator itemIterator = hostIterator->second->find(key);
            if (itemIterator != hostIterator->second->end() && currentTime() < itemIterator->second.expireTime) {
                log(LogLevelInfo, "URL:%s:cookies:%s hit in cookie cache\n", key.latin1().data(), itemIterator->second.cookies.latin1().data());
                return itemIterator->second.cookies;
            }

            // If the cookies is "expired", just let it be there for quick
            // return of this call. purge will remove "expired" cookies
            // when there isn't enough room.
        }
    }
    log(LogLevelInfo, "URL:%s miss in cookie cache\n", key.latin1().data());
    return String();
}
Пример #22
0
void MetabarFunctions::handleRequest(const KURL &url)
{
    QString function = url.host();
    QStringList params = QStringList::split(',', url.filename());

    if(function == "toggle") {
        if(params.size() == 1) {
            toggle(params.first());
        }
    }

    else if(function == "adjustSize") {
        if(params.size() == 1) {
            adjustSize(params.first());
        }
    }

    else if(function == "show") {
        if(params.size() == 1) {
            show(params.first());
        }
    }

    else if(function == "hide") {
        if(params.size() == 1) {
            hide(params.first());
        }
    }
}
Пример #23
0
void SearchManager::startSearch(KURL const& root, SearchMode const& modo)
{
    canceled_ = false;

    //time_.restart();
    time_.start();

    Q_ASSERT(root.isValid());
    //Q_ASSERT(root.protocol() == "http" || root.protocol() == "https");

    if(root.hasHost() && (domain_.isNull() || domain_.isEmpty()))
    {
        setDomain(root.host() + root.directory());
        kdDebug(23100) << "Domain: " << domain_ << endl;
    }
    root_.setIsRoot(true);
    root_.setDepth(0);
    root_.setOriginalUrl(root.prettyURL());
    root_.setAbsoluteUrl(root);
    root_.setOnlyCheckHeader(false);
    root_.setRootUrl(root);

    search_mode_ = modo;
    if(modo == depth)
        Q_ASSERT(depth_ != -1);
    else if(modo == domain)
        Q_ASSERT(depth_ == -1);
    else
        Q_ASSERT(depth_ != -1);

    searching_ = true;

    //Q_ASSERT(domain_ != QString::null);
    checkRoot();
}
Пример #24
0
void Loader::discoverFeeds(const QByteArray &data)
{
    QString str = QString(data).simplifyWhiteSpace();
    
    QStringList feeds; 
    
    FeedDetectorEntryList list = FeedDetector::extractFromLinkTags(str); 
    
    for (FeedDetectorEntryList::ConstIterator it = list.begin(); it != list.end(); ++it)
    {
        feeds += (*it).url();
    }  
    
    if (list.isEmpty())
        feeds = FeedDetector::extractBruteForce(str);
        
    QString feed = feeds.first();
    QString host = d->url.host();
    KURL testURL;
    // loop through, prefer feeds on same host
    QStringList::Iterator end( feeds.end() );
    for ( QStringList::Iterator it = feeds.begin(); it != end; ++it) 
    {
        testURL=*it;
        if (testURL.host() == host)
        {
            feed = *it;
            break;
        }
    }

    d->discoveredFeedURL = feed.isNull() ? QString() : FeedDetector::fixRelativeURL(feed, d->url); 
}
Пример #25
0
bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicString& crossOriginMode, const String& type, const KURL& href, Document& document)
{
    if (relAttribute.isDNSPrefetch()) {
        Settings* settings = document.settings();
        // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt
        // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=48857>.
        if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && !href.isEmpty())
            prefetchDNS(href.host());
    }

    // FIXME(crbug.com/323096): Should take care of import.
    if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && href.isValid() && document.frame()) {
        if (!m_client->shouldLoadLink())
            return false;
        Resource::Type type = relAttribute.isLinkSubresource() ?  Resource::LinkSubresource : Resource::LinkPrefetch;
        FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), FetchInitiatorTypeNames::link);
        if (!crossOriginMode.isNull())
            linkRequest.setCrossOriginAccessControl(document.securityOrigin(), crossOriginMode);
        setResource(document.fetcher()->fetchLinkResource(type, linkRequest));
    }

    if (const unsigned prerenderRelTypes = prerenderRelTypesFromRelAttribute(relAttribute)) {
        if (!m_prerender) {
            m_prerender = PrerenderHandle::create(document, this, href, prerenderRelTypes);
        } else if (m_prerender->url() != href) {
            m_prerender->cancel();
            m_prerender = PrerenderHandle::create(document, this, href, prerenderRelTypes);
        }
        // TODO(gavinp): Handle changes to rel types of existing prerenders.
    } else if (m_prerender) {
        m_prerender->cancel();
        m_prerender.clear();
    }
    return true;
}
Пример #26
0
static bool shouldTreatAsUniqueOrigin(const KURL& url)
{
    if (!url.isValid())
        return true;

    // FIXME: Do we need to unwrap the URL further?
    KURL innerURL = shouldUseInnerURL(url) ? extractInnerURL(url) : url;

    // FIXME: Check whether innerURL is valid.

    // For edge case URLs that were probably misparsed, make sure that the origin is unique.
    // FIXME: Do we really need to do this? This looks to be a hack around a
    // security bug in CFNetwork that might have been fixed.
    if (schemeRequiresAuthority(innerURL) && innerURL.host().isEmpty())
        return true;

    // SchemeRegistry needs a lower case protocol because it uses HashMaps
    // that assume the scheme has already been canonicalized.
    String protocol = innerURL.protocol().lower();

    if (SchemeRegistry::shouldTreatURLSchemeAsNoAccess(protocol))
        return true;

    // This is the common case.
    return false;
}
static bool isYouTubeUrl(const KURL& url, const String& mimeType)
{
    String host = url.host();
    bool youtube = host.endsWith("youtube.com")
            || host.endsWith("youtube-nocookie.com");
    return youtube && isValidYouTubeVideo(url.path())
            && equalIgnoringCase(mimeType, "application/x-shockwave-flash");
}
Пример #28
0
    bool hostMatches(const KURL& url) const
    {
        const String& host = url.host();
        if (equalIgnoringCase(host, m_host))
            return true;
        return m_hostHasWildcard && host.endsWith("." + m_host, false);

    }
Пример #29
0
/**
 * Set raw cookies from cookieJar hash for given url (required).
**/
void setCookieJar(const KURL& url, const String& rawCookie)
{
    if (!url || url.isEmpty())
        return;

    cookieJar.set(url.host(), rawCookie);
    setCookieJarStatus(COOKIE_JAR_NEW);
}
bool BlackBerryCookieCache::setCookies(const String& pageGroup, const KURL& url, const String& cookies)
{
    String key = url.string().lower();
    String host = url.host().lower();
    if (pageGroup.isEmpty() || key.isEmpty() || host.isEmpty())
        return false;

    int maxRequiredSize = (host.length() + key.length() + cookies.length()) * sizeof(UChar);

    // Just purge storage when there isn't enough room.
    // For simplicity, we use maximum required size here.
    if (m_size + maxRequiredSize > m_capacity) {
        purgeStorage();
        if (m_size + maxRequiredSize > m_capacity)
            return false;
    }

    // Add a host map for specified page group name if there isn't suitable one.
    PageGroupMap::iterator groupIterator = m_groupMap.find(pageGroup);
    if (groupIterator == m_groupMap.end()) {
        HostMap* map = new HostMap;
        pair<PageGroupMap::iterator, bool> result = m_groupMap.add(pageGroup, map);
        if (result.second)
            groupIterator = result.first;
        else {
            delete map;
            return false;
        }
    }

    ASSERT(groupIterator != m_groupMap.end());

    // Add a item map for speicified host map if there isn't suitable one.
    HostMap::iterator hostIterator = groupIterator->second->find(host);
    if (hostIterator == groupIterator->second->end()) {
        ItemMap* map = new ItemMap;
        pair<HostMap::iterator, bool> result = groupIterator->second->add(host, map);
        if (result.second)
            hostIterator = result.first;
        else {
            delete map;
            return false;
        }
    } else {
        // There is a entry for the host, no need to count host length.
        maxRequiredSize -= host.length() * sizeof(UChar);
    }

    ASSERT(hostIterator != groupIterator->second->end());

    BlackBerryCookieCacheItem item;
    item.cookies = cookies;
    item.expireTime = currentTime() + cookieCacheExpireTime;
    m_size += maxRequiredSize;
    hostIterator->second->set(key, item);

    return true;
}