Bug 1323777, make GetDisplayMode more null-safe, r=bdahl
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -298,18 +298,25 @@ GetScan(nsPresContext* aPresContext, con
// feature is never present.
aResult.Reset();
}
static void
GetDisplayMode(nsPresContext* aPresContext, const nsMediaFeature*,
nsCSSValue& aResult)
{
- nsCOMPtr<nsISupports> container = aPresContext->GetRootPresContext()->
- Document()->GetContainer();
+ nsCOMPtr<nsISupports> container;
+ if (aPresContext) {
+ // Calling GetRootPresContext() can be slow, so make sure to call it
+ // just once.
+ nsRootPresContext* root = aPresContext->GetRootPresContext();
+ if (root && root->Document()) {
+ container = root->Document()->GetContainer();
+ }
+ }
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(container);
if (!baseWindow) {
aResult.SetIntValue(NS_STYLE_DISPLAY_MODE_BROWSER, eCSSUnit_Enumerated);
return;
}
nsCOMPtr<nsIWidget> mainWidget;
baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
int32_t displayMode;