Bug 1323777, make GetDisplayMode more null-safe, r=bdahl
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 25 Jan 2017 23:32:50 +0200
changeset 466639 581720c25bf0f91392e45d106a4baf96e88575f9
parent 466362 924e975566a5ab2b1556abea45aaa34608fbed44
child 466640 65fb78694c3a51dafac29cb886cfc2bdb8b4a301
push id42948
push userbmo:gasolin@mozilla.com
push dateThu, 26 Jan 2017 07:49:21 +0000
reviewersbdahl
bugs1323777
milestone54.0a1
Bug 1323777, make GetDisplayMode more null-safe, r=bdahl
layout/style/nsMediaFeatures.cpp
--- 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;