Bug 1323777 - Make GetDisplayMode more null-safe. r=bdahl, a=jcristau
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 25 Jan 2017 23:32:50 +0200
changeset 366928 405ee5de06739ed6cf90e38b4f006e8dc47bfbd7
parent 366927 f67c25a9d2a909969bcba04b9a0c263415cfeddd
child 366929 cd797ef148c3e3b2a153d0ace89c4d5bcbab8267
push id6891
push userryanvm@gmail.com
push dateTue, 07 Feb 2017 17:32:45 +0000
treeherdermozilla-beta@be5204c4c3ee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbdahl, jcristau
bugs1323777
milestone52.0
Bug 1323777 - Make GetDisplayMode more null-safe. r=bdahl, a=jcristau
layout/style/nsMediaFeatures.cpp
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -312,18 +312,25 @@ GetScan(nsPresContext* aPresContext, con
   aResult.Reset();
   return NS_OK;
 }
 
 static nsresult
 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 NS_OK;
   }
   nsCOMPtr<nsIWidget> mainWidget;
   baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
   int32_t displayMode;