void MixedContentChecker::handleCertificateError(LocalFrame* frame, const ResourceResponse& response, WebURLRequest::FrameType frameType, WebURLRequest::RequestContext requestContext)
{
    Frame* effectiveFrame = effectiveFrameForFrameType(frame, frameType);
    if (frameType == WebURLRequest::FrameTypeTopLevel || !effectiveFrame)
        return;

    // TODO(estark): handle remote frames, perhaps by omitting security info when the effective frame is remote.
    if (!effectiveFrame->isLocalFrame())
        return;

    LocalFrame* localEffectiveFrame = toLocalFrame(effectiveFrame);

    // Use the current local frame's client; the embedder doesn't
    // distinguish mixed content signals from different frames on the
    // same page.
    FrameLoaderClient* client = frame->loader().client();
    ContextType contextType = MixedContentChecker::contextTypeFromContext(requestContext, effectiveFrame);
    if (contextType == ContextTypeBlockable) {
        client->didRunContentWithCertificateErrors(response.url(), response.getSecurityInfo(), mainResourceUrlForFrame(effectiveFrame), localEffectiveFrame->loader().documentLoader()->response().getSecurityInfo());
    } else {
        // contextTypeFromContext() never returns NotMixedContent (it
        // computes the type of mixed content, given that the content is
        // mixed).
        ASSERT(contextType != ContextTypeNotMixedContent);
        client->didDisplayContentWithCertificateErrors(response.url(), response.getSecurityInfo(), mainResourceUrlForFrame(effectiveFrame), localEffectiveFrame->loader().documentLoader()->response().getSecurityInfo());
    }
}
WebMixedContent::ContextType MixedContentChecker::contextTypeForInspector(
    LocalFrame* frame,
    const ResourceRequest& request) {
  Frame* effectiveFrame =
      effectiveFrameForFrameType(frame, request.frameType());

  Frame* mixedFrame = inWhichFrameIsContentMixed(
      effectiveFrame, request.frameType(), request.url());
  if (!mixedFrame)
    return WebMixedContent::ContextType::NotMixedContent;

  // See comment in shouldBlockFetch() about loading the main resource of a
  // subframe.
  if (request.frameType() == WebURLRequest::FrameTypeNested &&
      !SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(
          request.url().protocol())) {
    return WebMixedContent::ContextType::OptionallyBlockable;
  }

  bool strictMixedContentCheckingForPlugin =
      mixedFrame->settings() &&
      mixedFrame->settings()->strictMixedContentCheckingForPlugin();
  return WebMixedContent::contextTypeFromRequestContext(
      request.requestContext(), strictMixedContentCheckingForPlugin);
}
void MixedContentChecker::handleCertificateError(
    LocalFrame* frame,
    const ResourceResponse& response,
    WebURLRequest::FrameType frameType,
    WebURLRequest::RequestContext requestContext) {
  Frame* effectiveFrame = effectiveFrameForFrameType(frame, frameType);
  if (frameType == WebURLRequest::FrameTypeTopLevel || !effectiveFrame)
    return;

  // Use the current local frame's client; the embedder doesn't distinguish
  // mixed content signals from different frames on the same page.
  FrameLoaderClient* client = frame->loader().client();
  bool strictMixedContentCheckingForPlugin =
      effectiveFrame->settings() &&
      effectiveFrame->settings()->strictMixedContentCheckingForPlugin();
  WebMixedContent::ContextType contextType =
      WebMixedContent::contextTypeFromRequestContext(
          requestContext, strictMixedContentCheckingForPlugin);
  if (contextType == WebMixedContent::ContextType::Blockable) {
    client->didRunContentWithCertificateErrors(response.url());
  } else {
    // contextTypeFromRequestContext() never returns NotMixedContent (it
    // computes the type of mixed content, given that the content is mixed).
    DCHECK_NE(contextType, WebMixedContent::ContextType::NotMixedContent);
    client->didDisplayContentWithCertificateErrors(response.url());
  }
}
MixedContentChecker::ContextType MixedContentChecker::contextTypeForInspector(LocalFrame* frame, const ResourceRequest& request)
{
    Frame* effectiveFrame = effectiveFrameForFrameType(frame, request.frameType());

    Frame* mixedFrame = inWhichFrameIsContentMixed(effectiveFrame, request.frameType(), request.url());
    if (!mixedFrame)
        return ContextTypeNotMixedContent;

    // See comment in shouldBlockFetch() about loading the main resource of a subframe.
    if (request.frameType() == WebURLRequest::FrameTypeNested && !SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(request.url().protocol())) {
        return ContextTypeOptionallyBlockable;
    }

    return contextTypeFromContext(request.requestContext(), mixedFrame);
}
void MixedContentChecker::handleCertificateError(LocalFrame* frame, const ResourceRequest& request, const ResourceResponse& response)
{
    WebURLRequest::FrameType frameType = request.frameType();
    LocalFrame* effectiveFrame = effectiveFrameForFrameType(frame, frameType);
    if (frameType == WebURLRequest::FrameTypeTopLevel || !effectiveFrame)
        return;

    FrameLoaderClient* client = effectiveFrame->loader().client();
    WebURLRequest::RequestContext requestContext = request.requestContext();
    ContextType contextType = MixedContentChecker::contextTypeFromContext(requestContext, frame);
    if (contextType == ContextTypeBlockable) {
        client->didRunContentWithCertificateErrors(response.url(), response.getSecurityInfo(), effectiveFrame->document()->url(), effectiveFrame->loader().documentLoader()->response().getSecurityInfo());
    } else {
        // contextTypeFromContext() never returns NotMixedContent (it
        // computes the type of mixed content, given that the content is
        // mixed).
        ASSERT(contextType != ContextTypeNotMixedContent);
        client->didDisplayContentWithCertificateErrors(response.url(), response.getSecurityInfo(), effectiveFrame->document()->url(), effectiveFrame->loader().documentLoader()->response().getSecurityInfo());
    }
}
// static
bool MixedContentChecker::shouldBlockFetch(LocalFrame* frame, WebURLRequest::RequestContext requestContext, WebURLRequest::FrameType frameType, const KURL& url, MixedContentChecker::ReportingStatus reportingStatus)
{
    Frame* effectiveFrame = effectiveFrameForFrameType(frame, frameType);
    Frame* mixedFrame = inWhichFrameIsContentMixed(effectiveFrame, frameType, url);
    if (!mixedFrame)
        return false;

    MixedContentChecker::count(mixedFrame, requestContext);

    Settings* settings = mixedFrame->settings();
    // Use the current local frame's client; the embedder doesn't
    // distinguish mixed content signals from different frames on the
    // same page.
    FrameLoaderClient* client = frame->loader().client();
    SecurityOrigin* securityOrigin = mixedFrame->securityContext()->getSecurityOrigin();
    bool allowed = false;

    // If we're in strict mode, we'll automagically fail everything, and intentionally skip
    // the client checks in order to prevent degrading the site's security UI.
    bool strictMode = mixedFrame->securityContext()->shouldEnforceStrictMixedContentChecking() || settings->strictMixedContentChecking();

    ContextType contextType = contextTypeFromContext(requestContext, mixedFrame);

    // If we're loading the main resource of a subframe, we need to take a close look at the loaded URL.
    // If we're dealing with a CORS-enabled scheme, then block mixed frames as active content. Otherwise,
    // treat frames as passive content.
    //
    // FIXME: Remove this temporary hack once we have a reasonable API for launching external applications
    // via URLs. http://crbug.com/318788 and https://crbug.com/393481
    if (frameType == WebURLRequest::FrameTypeNested && !SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(url.protocol()))
        contextType = ContextTypeOptionallyBlockable;

    switch (contextType) {
    case ContextTypeOptionallyBlockable:
        allowed = !strictMode && client->allowDisplayingInsecureContent(settings && settings->allowDisplayOfInsecureContent(), url);
        if (allowed)
            client->didDisplayInsecureContent();
        break;

    case ContextTypeBlockable: {
        // Strictly block subresources that are mixed with respect to
        // their subframes, unless all insecure content is allowed. This
        // is to avoid the following situation: https://a.com embeds
        // https://b.com, which loads a script over insecure HTTP. The
        // user opts to allow the insecure content, thinking that they are
        // allowing an insecure script to run on https://a.com and not
        // realizing that they are in fact allowing an insecure script on
        // https://b.com.
        if (!settings->allowRunningOfInsecureContent() && requestIsSubframeSubresource(effectiveFrame, frameType) && isMixedContent(frame->securityContext()->getSecurityOrigin(), url)) {
            UseCounter::count(mixedFrame, UseCounter::BlockableMixedContentInSubframeBlocked);
            allowed = false;
            break;
        }

        bool shouldAskEmbedder = !strictMode && settings && (!settings->strictlyBlockBlockableMixedContent() || settings->allowRunningOfInsecureContent());
        allowed = shouldAskEmbedder && client->allowRunningInsecureContent(settings && settings->allowRunningOfInsecureContent(), securityOrigin, url);
        if (allowed) {
            client->didRunInsecureContent(securityOrigin, url);
            UseCounter::count(mixedFrame, UseCounter::MixedContentBlockableAllowed);
        }
        break;
    }

    case ContextTypeShouldBeBlockable:
        allowed = !strictMode;
        if (allowed)
            client->didDisplayInsecureContent();
        break;
    case ContextTypeNotMixedContent:
        ASSERT_NOT_REACHED();
        break;
    };

    if (reportingStatus == SendReport)
        logToConsoleAboutFetch(frame, mainResourceUrlForFrame(mixedFrame), url, requestContext, allowed);
    return !allowed;
}