Ejemplo n.º 1
0
void LinkLoader::notifyFinished(Resource* resource)
{
    ASSERT(this->resource() == resource);

    triggerEvents(resource);
    clearResource();
}
Ejemplo n.º 2
0
void ProcessingInstruction::removedFrom(ContainerNode* insertionPoint) {
  CharacterData::removedFrom(insertionPoint);
  if (!insertionPoint->isConnected())
    return;

  // No need to remove XSLStyleSheet from StyleEngine.
  if (!DocumentXSLT::processingInstructionRemovedFromDocument(document(),
                                                              this)) {
    document().styleEngine().removeStyleSheetCandidateNode(*this,
                                                           *insertionPoint);
  }

  if (m_sheet) {
    DCHECK_EQ(m_sheet->ownerNode(), this);
    clearSheet();
  }

  // No need to remove pending sheets.
  clearResource();

  // TODO([email protected]): resolverChanged() can be removed once stylesheet
  // updates are async. https://crbug.com/567021
  // If we're in document teardown, then we don't need to do any notification of
  // our sheet's removal.
  if (document().isActive())
    document().styleEngine().resolverChanged(FullStyleUpdate);
}
Ejemplo n.º 3
0
void MainResourceLoader::cancel(const ResourceError& error)
{
    RefPtr<MainResourceLoader> protect(this);
    ResourceError resourceError = error.isNull() ? frameLoader()->cancelledError(request()) : error;

    m_dataLoadTimer.stop();

    if (m_waitingForContentPolicy) {
        frameLoader()->policyChecker()->cancelCheck();
        ASSERT(m_waitingForContentPolicy);
        m_waitingForContentPolicy = false;
        deref(); // balances ref in responseReceived
    }

    if (loader())
        loader()->cancel(resourceError);

    clearResource();
    receivedError(resourceError);

#if USE(CONTENT_FILTERING)
    if (m_filter) {
        wkFilterRelease(m_filter);
        m_filter = 0;
    }
#endif
}
Ejemplo n.º 4
0
MainResourceLoader::~MainResourceLoader()
{
    clearResource();
#if USE(CONTENT_FILTERING)
    ASSERT(!m_filter);
#endif
}
Ejemplo n.º 5
0
MainResourceLoader::~MainResourceLoader()
{
    clearResource();
#if PLATFORM(MAC) && !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
    ASSERT(!m_filter);
#endif
}
DocumentThreadableLoader::~DocumentThreadableLoader()
{
    m_client = nullptr;

    // TODO(oilpan): Remove this once DocumentThreadableLoader is once again a ResourceOwner.
    clearResource();
}
Ejemplo n.º 7
0
void MainResourceLoader::cancel(const ResourceError& error)
{
    RefPtr<MainResourceLoader> protect(this);
    ResourceError resourceError = error.isNull() ? frameLoader()->cancelledError(request()) : error;

    m_dataLoadTimer.stop();

    if (m_waitingForContentPolicy) {
        frameLoader()->policyChecker()->cancelCheck();
        ASSERT(m_waitingForContentPolicy);
        m_waitingForContentPolicy = false;
        deref(); // balances ref in responseReceived
    }

    if (loader())
        loader()->cancel(resourceError);

    clearResource();
    receivedError(resourceError);

#if PLATFORM(MAC) && !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
    if (m_filter) {
        wkFilterRelease(m_filter);
        m_filter = 0;
    }
#endif
}
Ejemplo n.º 8
0
void ProcessingInstruction::removedFrom(ContainerNode* insertionPoint)
{
    CharacterData::removedFrom(insertionPoint);
    if (!insertionPoint->inDocument())
        return;

    // No need to remove XSLStyleSheet from StyleEngine.
    if (m_isCSS)
        document().styleEngine()->removeStyleSheetCandidateNode(this);
    else if (m_isXSL)
        document().styleEngine()->removeXSLStyleSheet(this);

    RefPtrWillBeRawPtr<StyleSheet> removedSheet = m_sheet;
    if (m_sheet) {
        ASSERT(m_sheet->ownerNode() == this);
        clearSheet();
    }

    // No need to remove pending sheets.
    clearResource();

    // If we're in document teardown, then we don't need to do any notification of our sheet's removal.
    if (document().isActive())
        document().removedStyleSheet(removedSheet.get());
}
Ejemplo n.º 9
0
void ProcessingInstruction::process(const String& href, const String& charset)
{
    if (href.length() > 1 && href[0] == '#') {
        m_localHref = href.substring(1);
        // We need to make a synthetic XSLStyleSheet that is embedded.
        // It needs to be able to kick off import/include loads that
        // can hang off some parent sheet.
        if (m_isXSL) {
            KURL finalURL(ParsedURLString, m_localHref);
            m_sheet = XSLStyleSheet::createEmbedded(this, finalURL);
            m_loading = false;
        }
        return;
    }

    clearResource();

    String url = document().completeURL(href).string();

    ResourcePtr<StyleSheetResource> resource;
    FetchRequest request(ResourceRequest(document().completeURL(href)), FetchInitiatorTypeNames::processinginstruction);
    if (m_isXSL) {
        resource = document().fetcher()->fetchXSLStyleSheet(request);
    } else {
        request.setCharset(charset.isEmpty() ? document().charset() : charset);
        resource = document().fetcher()->fetchCSSStyleSheet(request);
    }

    if (resource) {
        m_loading = true;
        document().styleEngine()->addPendingSheet();
        setResource(resource);
    }
}
Ejemplo n.º 10
0
void HTMLImportChild::didFinishLoading()
{
    clearResource();
    stateWillChange();
    if (m_customElementMicrotaskStep)
        CustomElementMicrotaskDispatcher::instance().importDidFinish(m_customElementMicrotaskStep.get());
}
void DocumentThreadableLoader::loadFallbackRequestForServiceWorker()
{
    clearResource();
    ResourceRequest fallbackRequest(m_fallbackRequestForServiceWorker);
    m_fallbackRequestForServiceWorker = ResourceRequest();
    dispatchInitialRequest(fallbackRequest);
    // |this| may be dead here in async mode.
}
Ejemplo n.º 12
0
void HTMLImportLoader::didFinishLoading()
{
    for (size_t i = 0; i < m_imports.size(); ++i)
        m_imports[i]->didFinishLoading();

    clearResource();

    ASSERT(!m_document || !m_document->parsing());
}
Ejemplo n.º 13
0
void DocumentThreadableLoader::redirectReceived(CachedResource* resource, ResourceRequest& request, const ResourceResponse& redirectResponse)
{
    ASSERT(m_client);
    ASSERT_UNUSED(resource, resource == m_resource);

    Ref<DocumentThreadableLoader> protectedThis(*this);
    if (!isAllowedByContentSecurityPolicy(request.url(), !redirectResponse.isNull())) {
        m_client->didFailRedirectCheck();
        request = ResourceRequest();
        return;
    }

    // Allow same origin requests to continue after allowing clients to audit the redirect.
    if (isAllowedRedirect(request.url()))
        return;

    // When using access control, only simple cross origin requests are allowed to redirect. The new request URL must have a supported
    // scheme and not contain the userinfo production. In addition, the redirect response must pass the access control check if the
    // original request was not same-origin.
    if (m_options.crossOriginRequestPolicy == UseAccessControl) {
        bool allowRedirect = false;
        if (m_simpleRequest) {
            String accessControlErrorDescription;
            allowRedirect = isValidCrossOriginRedirectionURL(request.url())
                            && (m_sameOriginRequest || passesAccessControlCheck(redirectResponse, m_options.allowCredentials(), securityOrigin(), accessControlErrorDescription));
        }

        if (allowRedirect) {
            if (m_resource)
                clearResource();

            RefPtr<SecurityOrigin> originalOrigin = SecurityOrigin::createFromString(redirectResponse.url());
            RefPtr<SecurityOrigin> requestOrigin = SecurityOrigin::createFromString(request.url());
            // If the original request wasn't same-origin, then if the request URL origin is not same origin with the original URL origin,
            // set the source origin to a globally unique identifier. (If the original request was same-origin, the origin of the new request
            // should be the original URL origin.)
            if (!m_sameOriginRequest && !originalOrigin->isSameSchemeHostPort(requestOrigin.get()))
                m_options.securityOrigin = SecurityOrigin::createUnique();
            // Force any subsequent request to use these checks.
            m_sameOriginRequest = false;

            // Since the request is no longer same-origin, if the user didn't request credentials in
            // the first place, update our state so we neither request them nor expect they must be allowed.
            if (m_options.credentialRequest() == ClientDidNotRequestCredentials)
                m_options.setAllowCredentials(DoNotAllowStoredCredentials);

            cleanRedirectedRequestForAccessControl(request);

            makeCrossOriginAccessRequest(request);
            return;
        }
    }

    m_client->didFailRedirectCheck();
    request = ResourceRequest();
}
void DocumentThreadableLoader::cancel()
{
    if (m_client) {
        ResourceError error(errorDomainWebKitInternal, 0, m_resource->url(), "Load cancelled");
        error.setIsCancellation(true);
        didFail(error);
    }
    clearResource();
    m_client = 0;
}
void DocumentThreadableLoader::preflightSuccess()
{
    OwnPtr<ResourceRequest> actualRequest;
    actualRequest.swap(m_actualRequest);

    actualRequest->setHTTPOrigin(securityOrigin()->toAtomicString());

    clearResource();

    loadRequest(*actualRequest);
}
Ejemplo n.º 16
0
void HTMLImportLoader::dispose()
{
    m_controller = nullptr;
    if (m_document) {
        if (m_document->parser())
            m_document->parser()->removeClient(this);
        m_document->setImportsController(nullptr);
        m_document.clear();
    }
    clearResource();
}
void DocumentThreadableLoader::clear()
{
    m_client = 0;

    if (!m_async)
        return;

    m_timeoutTimer.stop();
    m_requestStartedSeconds = 0.0;
    clearResource();
}
Ejemplo n.º 18
0
void LinkLoader::notifyFinished(Resource* resource)
{
    ASSERT(this->resource() == resource);

    if (resource->errorOccurred())
        m_linkLoadingErrorTimer.startOneShot(0, FROM_HERE);
    else
        m_linkLoadTimer.startOneShot(0, FROM_HERE);

    clearResource();
}
Ejemplo n.º 19
0
void DocumentThreadableLoader::preflightSuccess()
{
    std::unique_ptr<ResourceRequest> actualRequest;
    actualRequest.swap(m_actualRequest);

    actualRequest->setHTTPOrigin(securityOrigin()->toString());

    clearResource();

    // It should be ok to skip the security check since we already asked about the preflight request.
    loadRequest(*actualRequest, SkipSecurityCheck);
}
Ejemplo n.º 20
0
void WorkletScriptLoader::notifyFinished(Resource* resource) {
  DCHECK(this->resource() == resource);

  m_host->notifyFinished(this);
  if (resource->errorOccurred()) {
    m_resolver->reject(DOMException::create(NetworkError));
  } else {
    DCHECK(resource->isLoaded());
    m_resolver->resolve();
  }
  clearResource();
}
Ejemplo n.º 21
0
void MainResourceLoader::continueAfterNavigationPolicy(const ResourceRequest& request, bool shouldContinue)
{
    if (!shouldContinue)
        stopLoadingForPolicyChange();
    else if (m_substituteData.isValid()) {
        // A redirect resulted in loading substitute data.
        ASSERT(documentLoader()->timing()->redirectCount());
        clearResource();
        handleSubstituteDataLoadSoon(request);
    }

    deref(); // balances ref in willSendRequest
}
Ejemplo n.º 22
0
void DocumentThreadableLoader::cancel()
{
    RefPtr<DocumentThreadableLoader> protect(this);

    // Cancel can re-enter and m_resource might be null here as a result.
    if (m_client && m_resource) {
        ResourceError error(errorDomainWebKitInternal, 0, m_resource->url(), "Load cancelled");
        error.setIsCancellation(true);
        didFail(error);
    }
    clearResource();
    m_client = 0;
}
void DocumentThreadableLoader::loadActualRequest()
{
    ResourceRequest actualRequest = m_actualRequest;
    ResourceLoaderOptions actualOptions = m_actualOptions;
    m_actualRequest = ResourceRequest();
    m_actualOptions = ResourceLoaderOptions();

    actualRequest.setHTTPOrigin(securityOrigin());

    clearResource();

    loadRequest(actualRequest, actualOptions);
}
Ejemplo n.º 24
0
void DocumentThreadableLoader::redirectReceived(CachedResource* resource, ResourceRequest& request, const ResourceResponse& redirectResponse)
{
    ASSERT(m_client);
    ASSERT_UNUSED(resource, resource == m_resource);

    RefPtr<DocumentThreadableLoader> protect(this);
    // Allow same origin requests to continue after allowing clients to audit the redirect.
    if (isAllowedRedirect(request.url())) {
        if (m_client->isDocumentThreadableLoaderClient())
            static_cast<DocumentThreadableLoaderClient*>(m_client)->willSendRequest(request, redirectResponse);
        return;
    }

    // When using access control, only simple cross origin requests are allowed to redirect. The new request URL must have a supported
    // scheme and not contain the userinfo production. In addition, the redirect response must pass the access control check.
    if (m_options.crossOriginRequestPolicy == UseAccessControl) {
        bool allowRedirect = false;
        if (m_simpleRequest) {
            String accessControlErrorDescription;
            allowRedirect = SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(request.url().protocol())
                            && request.url().user().isEmpty()
                            && request.url().pass().isEmpty()
                            && passesAccessControlCheck(redirectResponse, m_options.allowCredentials, securityOrigin(), accessControlErrorDescription);
        }

        if (allowRedirect) {
            if (m_resource)
                clearResource();

            RefPtr<SecurityOrigin> originalOrigin = SecurityOrigin::createFromString(redirectResponse.url());
            RefPtr<SecurityOrigin> requestOrigin = SecurityOrigin::createFromString(request.url());
            // If the request URL origin is not same origin with the original URL origin, set source origin to a globally unique identifier.
            if (!originalOrigin->isSameSchemeHostPort(requestOrigin.get()))
                m_options.securityOrigin = SecurityOrigin::createUnique();
            // Force any subsequent requests to use these checks.
            m_sameOriginRequest = false;

            // Remove any headers that may have been added by the network layer that cause access control to fail.
            request.clearHTTPContentType();
            request.clearHTTPReferrer();
            request.clearHTTPOrigin();
            request.clearHTTPUserAgent();
            request.clearHTTPAccept();
            makeCrossOriginAccessRequest(request);
            return;
        }
    }

    m_client->didFailRedirectCheck();
    request = ResourceRequest();
}
Ejemplo n.º 25
0
void DocumentThreadableLoader::cancel()
{
    Ref<DocumentThreadableLoader> protectedThis(*this);

    // Cancel can re-enter and m_resource might be null here as a result.
    if (m_client && m_resource) {
        // FIXME: This error is sent to the client in didFail(), so it should not be an internal one. Use FrameLoaderClient::cancelledError() instead.
        ResourceError error(errorDomainWebKitInternal, 0, m_resource->url(), "Load cancelled");
        error.setIsCancellation(true);
        didFail(m_resource->identifier(), error);
    }
    clearResource();
    m_client = nullptr;
}
Ejemplo n.º 26
0
void ProcessingInstruction::parseStyleSheet(const String& sheet) {
  if (m_isCSS)
    toCSSStyleSheet(m_sheet.get())->contents()->parseString(sheet);
  else if (m_isXSL)
    toXSLStyleSheet(m_sheet.get())->parseString(sheet);

  clearResource();
  m_loading = false;

  if (m_isCSS)
    toCSSStyleSheet(m_sheet.get())->contents()->checkLoaded();
  else if (m_isXSL)
    toXSLStyleSheet(m_sheet.get())->checkLoaded();
}
Ejemplo n.º 27
0
bool TextTrackLoader::redirectReceived(Resource* resource,
                                       const ResourceRequest& request,
                                       const ResourceResponse&) {
  DCHECK_EQ(this->resource(), resource);
  if (resource->options().corsEnabled == IsCORSEnabled ||
      document().getSecurityOrigin()->canRequestNoSuborigin(request.url()))
    return true;

  corsPolicyPreventedLoad(document().getSecurityOrigin(), request.url());
  if (!m_cueLoadTimer.isActive())
    m_cueLoadTimer.startOneShot(0, BLINK_FROM_HERE);
  clearResource();
  return false;
}
void DocumentThreadableLoader::cancelWithError(const ResourceError& error)
{
    RefPtr<DocumentThreadableLoader> protect(this);

    // Cancel can re-enter and m_resource might be null here as a result.
    if (m_client && resource()) {
        ResourceError errorForCallback = error;
        if (errorForCallback.isNull()) {
            // FIXME: This error is sent to the client in didFail(), so it should not be an internal one. Use FrameLoaderClient::cancelledError() instead.
            errorForCallback = ResourceError(errorDomainBlinkInternal, 0, resource()->url().string(), "Load cancelled");
            errorForCallback.setIsCancellation(true);
        }
        m_client->didFail(errorForCallback);
    }
    clearResource();
    m_client = 0;
}
Ejemplo n.º 29
0
void DocumentThreadableLoader::loadActualRequest() {
  ResourceRequest actualRequest = m_actualRequest;
  ResourceLoaderOptions actualOptions = m_actualOptions;
  m_actualRequest = ResourceRequest();
  m_actualOptions = ResourceLoaderOptions();

  clearResource();

  // Explicitly set the SkipServiceWorker flag here. Even if the page was not
  // controlled by a SW when the preflight request was sent, a new SW may be
  // controlling the page now by calling clients.claim(). We should not send
  // the actual request to the SW. https://crbug.com/604583
  actualRequest.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All);

  prepareCrossOriginRequest(actualRequest);
  loadRequest(actualRequest, actualOptions);
}
Ejemplo n.º 30
0
void MainResourceLoader::continueAfterNavigationPolicy(const ResourceRequest& request, bool shouldContinue)
{
    if (!shouldContinue)
        stopLoadingForPolicyChange();
    else if (m_substituteData.isValid()) {
        // A redirect resulted in loading substitute data.
        ASSERT(documentLoader()->timing()->redirectCount());

        // We need to remove our reference to the CachedResource in favor of a SubstituteData load.
        // This will probably trigger the cancellation of the CachedResource's underlying ResourceLoader, though there is a
        // small chance that the resource is being loaded by a different Frame, preventing the ResourceLoader from being cancelled.
        // If the ResourceLoader is indeed cancelled, it would normally send resource load callbacks.
        // However, from an API perspective, this isn't a cancellation. Therefore, sever our relationship with the network load via clearResource(),
        // but prevent the ResourceLoader from sending ResourceLoadNotifier callbacks.
        RefPtr<ResourceLoader> resourceLoader = loader();
        ASSERT(resourceLoader->shouldSendResourceLoadCallbacks());
        resourceLoader->setSendCallbackPolicy(DoNotSendCallbacks);
        clearResource();
        resourceLoader->setSendCallbackPolicy(SendCallbacks);
        handleSubstituteDataLoadSoon(request);
    }

    deref(); // balances ref in willSendRequest
}