Bug 1323777, make GetDisplayMode more null-safe, r=bdahl
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 25 Jan 2017 23:32:50 +0200
changeset 331038 581720c25bf0f91392e45d106a4baf96e88575f9
parent 331037 924e975566a5ab2b1556abea45aaa34608fbed44
child 331039 65fb78694c3a51dafac29cb886cfc2bdb8b4a301
push id86155
push useropettay@mozilla.com
push dateWed, 25 Jan 2017 22:05:48 +0000
treeherdermozilla-inbound@021414da3a4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbdahl
bugs1323777
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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;