Bug 1384789 - Mark import loop sheet complete. r=heycam
For an import loop sheet, set the URIs and principal, and mark it complete, so
that it can still be properly accessed via CSSOM without errors.
MozReview-Commit-ID: 1oO1LoaPk8V
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -2488,48 +2488,58 @@ Gecko_GetAppUnitsPerPhysicalInch(RawGeck
nsPresContext* presContext = const_cast<nsPresContext*>(aPresContext);
return presContext->DeviceContext()->AppUnitsPerPhysicalInch();
}
ServoStyleSheet*
Gecko_LoadStyleSheet(css::Loader* aLoader,
ServoStyleSheet* aParent,
css::LoaderReusableStyleSheets* aReusableSheets,
- RawGeckoURLExtraData* aBaseURLData,
+ RawGeckoURLExtraData* aURLExtraData,
const uint8_t* aURLString,
uint32_t aURLStringLength,
RawServoMediaListStrong aMediaList)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aLoader, "Should've catched this before");
MOZ_ASSERT(aParent, "Only used for @import, so parent should exist!");
MOZ_ASSERT(aURLString, "Invalid URLs shouldn't be loaded!");
MOZ_ASSERT(aBaseURLData, "Need base URL data");
RefPtr<dom::MediaList> media = new ServoMediaList(aMediaList.Consume());
nsDependentCSubstring urlSpec(reinterpret_cast<const char*>(aURLString),
aURLStringLength);
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), urlSpec, nullptr,
- aBaseURLData->BaseURI());
+ aURLExtraData->BaseURI());
StyleSheet* previousFirstChild = aParent->GetFirstChild();
if (NS_SUCCEEDED(rv)) {
rv = aLoader->LoadChildSheet(aParent, uri, media, nullptr, aReusableSheets);
}
if (NS_FAILED(rv) ||
!aParent->GetFirstChild() ||
aParent->GetFirstChild() == previousFirstChild) {
// Servo and Gecko have different ideas of what a valid URL is, so we might
- // get in here with a URL string that NS_NewURI can't handle. If so,
- // silently do nothing. Eventually we should be able to assert that the
- // NS_NewURI succeeds, here.
+ // get in here with a URL string that NS_NewURI can't handle. We may also
+ // reach here via an import cycle. For the import cycle case, we need some
+ // sheet object per spec, even if its empty. DevTools uses the URI to
+ // realize it has hit an import cycle, so we mark it complete to make the
+ // sheet readable from JS.
RefPtr<ServoStyleSheet> emptySheet =
aParent->CreateEmptyChildSheet(media.forget());
+ // Make a dummy URI if we don't have one because some methods assume
+ // non-null URIs.
+ if (!uri) {
+ NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:invalid"));
+ }
+ emptySheet->SetURIs(uri, uri, uri);
+ emptySheet->SetPrincipal(aURLExtraData->GetPrincipal());
+ emptySheet->SetComplete();
aParent->PrependStyleSheet(emptySheet);
return emptySheet.forget().take();
}
RefPtr<ServoStyleSheet> sheet =
static_cast<ServoStyleSheet*>(aParent->GetFirstChild());
return sheet.forget().take();
}