Bug 1087801 - Don't assume the global is a Window in the DOM CSS object. r=bholley, a=lsblakk
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 29 Oct 2014 17:00:48 -0400
changeset 225884 ac59c74b9386
parent 225883 e35984b580fb
child 225885 17d3079dc41f
push id4055
push userryanvm@gmail.com
push date2014-10-31 01:17 +0000
treeherdermozilla-beta@12a8a2d96453 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley, lsblakk
bugs1087801
milestone34.0
Bug 1087801 - Don't assume the global is a Window in the DOM CSS object. r=bholley, a=lsblakk
layout/style/CSS.cpp
--- a/layout/style/CSS.cpp
+++ b/layout/style/CSS.cpp
@@ -8,36 +8,37 @@
 #include "CSS.h"
 
 #include "mozilla/dom/BindingDeclarations.h"
 #include "nsCSSParser.h"
 #include "nsGlobalWindow.h"
 #include "nsIDocument.h"
 #include "nsIURI.h"
 #include "nsStyleUtil.h"
+#include "xpcpublic.h"
 
 namespace mozilla {
 namespace dom {
 
 struct SupportsParsingInfo
 {
   nsIURI* mDocURI;
   nsIURI* mBaseURI;
   nsIPrincipal* mPrincipal;
 };
 
 static nsresult
-GetParsingInfo(nsISupports* aGlobal,
+GetParsingInfo(const GlobalObject& aGlobal,
                SupportsParsingInfo& aInfo)
 {
-  if (!aGlobal) {
+  nsGlobalWindow* win = xpc::WindowOrNull(aGlobal.Get());
+  if (!win) {
     return NS_ERROR_FAILURE;
   }
 
-  nsGlobalWindow* win = nsGlobalWindow::FromSupports(aGlobal);
   nsCOMPtr<nsIDocument> doc = win->GetDoc();
   if (!doc) {
     return NS_ERROR_FAILURE;
   }
 
   aInfo.mDocURI = nsCOMPtr<nsIURI>(doc->GetDocumentURI());
   aInfo.mBaseURI = nsCOMPtr<nsIURI>(doc->GetBaseURI());
   aInfo.mPrincipal = win->GetPrincipal();
@@ -48,17 +49,17 @@ GetParsingInfo(nsISupports* aGlobal,
 CSS::Supports(const GlobalObject& aGlobal,
               const nsAString& aProperty,
               const nsAString& aValue,
               ErrorResult& aRv)
 {
   nsCSSParser parser;
   SupportsParsingInfo info;
 
-  nsresult rv = GetParsingInfo(aGlobal.GetAsSupports(), info);
+  nsresult rv = GetParsingInfo(aGlobal, info);
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return false;
   }
 
   return parser.EvaluateSupportsDeclaration(aProperty, aValue, info.mDocURI,
                                             info.mBaseURI, info.mPrincipal);
 }
@@ -66,17 +67,17 @@ CSS::Supports(const GlobalObject& aGloba
 /* static */ bool
 CSS::Supports(const GlobalObject& aGlobal,
               const nsAString& aCondition,
               ErrorResult& aRv)
 {
   nsCSSParser parser;
   SupportsParsingInfo info;
 
-  nsresult rv = GetParsingInfo(aGlobal.GetAsSupports(), info);
+  nsresult rv = GetParsingInfo(aGlobal, info);
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return false;
   }
 
   return parser.EvaluateSupportsCondition(aCondition, info.mDocURI,
                                           info.mBaseURI, info.mPrincipal);
 }