Fix bug 584512.
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 12 Aug 2010 21:05:05 -0700
changeset 50373 fe1b3c35fa9d45c694c57db70b1824c45646ba89
parent 50372 11ca949a6affc516fffee5acb96e83f645b1a42a
child 50374 173fb265a91cc78a2a558f9983c822fe3ac35248
push idunknown
push userunknown
push dateunknown
bugs584512
milestone2.0b4pre
Fix bug 584512.
dom/base/nsGlobalWindow.cpp
dom/base/nsMimeTypeArray.cpp
dom/base/nsMimeTypeArray.h
dom/base/nsPluginArray.cpp
dom/base/nsPluginArray.h
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -9781,16 +9781,20 @@ NS_NewScriptGlobalObject(PRBool aIsChrom
 
 nsNavigator::nsNavigator(nsIDocShell *aDocShell)
   : mDocShell(aDocShell)
 {
 }
 
 nsNavigator::~nsNavigator()
 {
+  if (mMimeTypes)
+    mMimeTypes->Invalidate();
+  if (mPlugins)
+    mPlugins->Invalidate();
 }
 
 //*****************************************************************************
 //    nsNavigator::nsISupports
 //*****************************************************************************
 
 
 DOMCI_DATA(Navigator, nsNavigator)
@@ -10205,18 +10209,25 @@ nsNavigator::TaintEnabled(PRBool *aRetur
 }
 
 void
 nsNavigator::LoadingNewDocument()
 {
   // Release these so that they will be recreated for the
   // new document (if requested).  The plugins or mime types
   // arrays may have changed.  See bug 150087.
-  mMimeTypes = nsnull;
-  mPlugins = nsnull;
+  if (mMimeTypes) {
+    mMimeTypes->Invalidate();
+    mMimeTypes = nsnull;
+  }
+
+  if (mPlugins) {
+    mPlugins->Invalidate();
+    mPlugins = nsnull;
+  }
 
   if (mGeolocation)
   {
     mGeolocation->Shutdown();
     mGeolocation = nsnull;
   }
 }
 
--- a/dom/base/nsMimeTypeArray.cpp
+++ b/dom/base/nsMimeTypeArray.cpp
@@ -1,9 +1,10 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 sw=2 et tw=79: */
 /* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
@@ -222,16 +223,20 @@ nsresult nsMimeTypeArray::Refresh()
   return GetMimeTypes();
 }
 
 nsresult nsMimeTypeArray::GetMimeTypes()
 {
   NS_PRECONDITION(!mInited && mPluginMimeTypeCount==0,
                       "already initialized");
 
+  if (!mNavigator) {
+    return NS_ERROR_NOT_AVAILABLE;
+  }
+
   nsIDOMPluginArray* pluginArray = nsnull;
   nsresult rv = mNavigator->GetPlugins(&pluginArray);
   if (rv == NS_OK) {
     // count up all possible MimeTypes, and collect them here. Later,
     // we'll remove duplicates.
     PRUint32 pluginMimeTypeCount = 0;
     PRUint32 pluginCount = 0;
     rv = pluginArray->GetLength(&pluginCount);
--- a/dom/base/nsMimeTypeArray.h
+++ b/dom/base/nsMimeTypeArray.h
@@ -1,9 +1,10 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 sw=2 et tw=79: */
 /* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
@@ -41,16 +42,18 @@
 #include "nsIDOMMimeTypeArray.h"
 #include "nsIDOMMimeType.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsCOMArray.h"
 
 class nsIDOMNavigator;
 
+// NB: Due to weak references, nsNavigator has intimate knowledge of our
+// members.
 class nsMimeTypeArray : public nsIDOMMimeTypeArray
 {
 public:
   nsMimeTypeArray(nsIDOMNavigator* navigator);
   virtual ~nsMimeTypeArray();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMMIMETYPEARRAY
@@ -72,16 +75,23 @@ public:
       NS_ASSERTION(array_qi == static_cast<nsIDOMMimeTypeArray*>(aSupports),
                    "Uh, fix QI!");
     }
 #endif
 
     return static_cast<nsMimeTypeArray*>(aSupports);
   }
 
+  void Invalidate()
+  {
+    // NB: This will cause GetMimeTypes to fail from now on.
+    mNavigator = nsnull;
+    Clear();
+  }
+
 private:
   nsresult GetMimeTypes();
   void     Clear();
 
 protected:
   nsIDOMNavigator* mNavigator;
   // Number of mimetypes handled by plugins.
   PRUint32 mPluginMimeTypeCount;
--- a/dom/base/nsPluginArray.cpp
+++ b/dom/base/nsPluginArray.cpp
@@ -184,21 +184,28 @@ nsPluginArray::GetPluginHost(nsIPluginHo
 
   *aPluginHost = mPluginHost;
   NS_IF_ADDREF(*aPluginHost);
 
   return rv;
 }
 
 void
-nsPluginArray::SetDocShell(nsIDocShell* aDocShell)
+nsPluginArray::SetDocShell(nsIDocShell *aDocShell)
 {
   mDocShell = aDocShell;
 }
 
+void
+nsPluginArray::Invalidate()
+{
+  mDocShell = nsnull;
+  mNavigator = nsnull;
+}
+
 NS_IMETHODIMP
 nsPluginArray::Refresh(PRBool aReloadDocuments)
 {
   nsresult res = NS_OK;
   if (!AllowPlugins())
     return NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA;
 
   if (!mPluginHost) {
--- a/dom/base/nsPluginArray.h
+++ b/dom/base/nsPluginArray.h
@@ -42,16 +42,18 @@
 #include "nsIDOMPlugin.h"
 #include "nsIPluginHost.h"
 #include "nsIURL.h"
 
 class nsNavigator;
 class nsIDocShell;
 class nsIPluginHost;
 
+// NB: Due to weak references, nsNavigator has intimate knowledge of our
+// internals.
 class nsPluginArray : public nsIDOMPluginArray
 {
 public:
   nsPluginArray(nsNavigator* navigator, nsIDocShell *aDocShell);
   virtual ~nsPluginArray();
 
   NS_DECL_ISUPPORTS
 
@@ -80,17 +82,18 @@ public:
     return static_cast<nsPluginArray*>(aSupports);
   }
 
 private:
   nsresult GetPlugins();
   PRBool AllowPlugins();
 
 public:
-  void SetDocShell(nsIDocShell* aDocShell);
+  void SetDocShell(nsIDocShell *aDocShell);
+  void Invalidate();
 
 protected:
   nsNavigator* mNavigator;
   nsCOMPtr<nsIPluginHost> mPluginHost;
   PRUint32 mPluginCount;
   nsIDOMPlugin** mPluginArray;
   nsIDocShell* mDocShell; // weak reference
 };