Bug 1323777 - Make GetDisplayMode more null-safe. r=bdahl, a=gchang
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 25 Jan 2017 23:32:50 +0200
changeset 375972 bd48d1daf4c229ce5b7e554aea75de5a1fff7e08
parent 375971 4895917438eb538cc2371fb203b992d20fc9fab2
child 375973 66bd19aeb873560c559abe5f1f380647ea50b2d7
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbdahl, gchang
bugs1323777
milestone53.0a2
Bug 1323777 - Make GetDisplayMode more null-safe. r=bdahl, a=gchang
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;