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); }
// static void MixedContentChecker::count(Frame* frame, WebURLRequest::RequestContext requestContext) { UseCounter::count(frame, UseCounter::MixedContentPresent); // Roll blockable content up into a single counter, count unblocked types individually so we // can determine when they can be safely moved to the blockable category: ContextType contextType = contextTypeFromContext(requestContext, frame); if (contextType == ContextTypeBlockable) { UseCounter::count(frame, UseCounter::MixedContentBlockable); return; } UseCounter::Feature feature; switch (requestContext) { case WebURLRequest::RequestContextAudio: feature = UseCounter::MixedContentAudio; break; case WebURLRequest::RequestContextDownload: feature = UseCounter::MixedContentDownload; break; case WebURLRequest::RequestContextFavicon: feature = UseCounter::MixedContentFavicon; break; case WebURLRequest::RequestContextImage: feature = UseCounter::MixedContentImage; break; case WebURLRequest::RequestContextInternal: feature = UseCounter::MixedContentInternal; break; case WebURLRequest::RequestContextPlugin: feature = UseCounter::MixedContentPlugin; break; case WebURLRequest::RequestContextPrefetch: feature = UseCounter::MixedContentPrefetch; break; case WebURLRequest::RequestContextVideo: feature = UseCounter::MixedContentVideo; break; default: ASSERT_NOT_REACHED(); return; } UseCounter::count(frame, feature); }
// 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; }
// static bool MixedContentChecker::shouldBlockFetch(LocalFrame* frame, WebURLRequest::RequestContext requestContext, WebURLRequest::FrameType frameType, const KURL& url, MixedContentChecker::ReportingStatus reportingStatus) { LocalFrame* mixedFrame = inWhichFrameIsContentMixed(frame, frameType, url); if (!mixedFrame) return false; MixedContentChecker::count(mixedFrame, requestContext); Settings* settings = mixedFrame->settings(); FrameLoaderClient* client = mixedFrame->loader().client(); SecurityOrigin* securityOrigin = mixedFrame->document()->securityOrigin(); 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 in subframes, unless all insecure // content is allowed. if (!settings->allowRunningOfInsecureContent() && requestIsSubframeSubresource(frame, frameType)) { 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, url, requestContext, allowed); return !allowed; }