bug 856777 - observe plugin-info-updated in nsPluginArray, not Navigator r=khuey

This commit is contained in:
David Keeler 2013-04-10 13:59:45 -07:00
parent 25dcf8cff7
commit 201dfe5cf1
4 changed files with 43 additions and 31 deletions

View File

@ -38,7 +38,6 @@
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/StaticPtr.h"
#include "Connection.h"
#include "nsIObserverService.h"
#ifdef MOZ_B2G_RIL
#include "MobileConnection.h"
#include "mozilla/dom/CellBroadcast.h"
@ -104,10 +103,6 @@ Navigator::Navigator(nsPIDOMWindow* aWindow)
{
NS_ASSERTION(aWindow->IsInnerWindow(),
"Navigator must get an inner window!");
nsCOMPtr<nsIObserverService> obsService =
mozilla::services::GetObserverService();
if (obsService)
obsService->AddObserver(this, "plugin-info-updated", false);
}
Navigator::~Navigator()
@ -125,7 +120,6 @@ NS_INTERFACE_MAP_BEGIN(Navigator)
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorDesktopNotification)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorSms)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorMobileMessage)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
#ifdef MOZ_MEDIA_NAVIGATOR
NS_INTERFACE_MAP_ENTRY(nsINavigatorUserMedia)
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorUserMedia)
@ -161,12 +155,6 @@ Navigator::Invalidate()
{
mWindow = nullptr;
nsCOMPtr<nsIObserverService> obsService =
mozilla::services::GetObserverService();
if (obsService) {
obsService->RemoveObserver(this, "plugin-info-updated");
}
if (mPlugins) {
mPlugins->Invalidate();
mPlugins = nullptr;
@ -268,20 +256,6 @@ Navigator::GetWindow()
return win;
}
//*****************************************************************************
// Navigator::nsIObserver
//*****************************************************************************
NS_IMETHODIMP
Navigator::Observe(nsISupports *aSubject, const char *aTopic,
const PRUnichar *aData) {
if (!nsCRT::strcmp(aTopic, "plugin-info-updated") && mPlugins) {
mPlugins->Refresh(false);
}
return NS_OK;
}
//*****************************************************************************
// Navigator::nsIDOMNavigator
//*****************************************************************************
@ -479,6 +453,7 @@ Navigator::GetPlugins(nsIDOMPluginArray** aPlugins)
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
mPlugins = new nsPluginArray(this, win ? win->GetDocShell() : nullptr);
mPlugins->Init();
}
NS_ADDREF(*aPlugins = mPlugins);

View File

@ -16,7 +16,6 @@
#include "nsIDOMNavigatorSms.h"
#include "nsIDOMNavigatorMobileMessage.h"
#include "nsIDOMNavigatorNetwork.h"
#include "nsIObserver.h"
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
#include "nsINavigatorAudioChannelManager.h"
#endif
@ -98,7 +97,6 @@ class Navigator : public nsIDOMNavigator
, public nsINavigatorBattery
, public nsIDOMMozNavigatorSms
, public nsIDOMMozNavigatorMobileMessage
, public nsIObserver
#ifdef MOZ_MEDIA_NAVIGATOR
, public nsINavigatorUserMedia
, public nsIDOMNavigatorUserMedia
@ -137,7 +135,6 @@ public:
NS_DECL_NSINAVIGATORBATTERY
NS_DECL_NSIDOMMOZNAVIGATORSMS
NS_DECL_NSIDOMMOZNAVIGATORMOBILEMESSAGE
NS_DECL_NSIOBSERVER
#ifdef MOZ_MEDIA_NAVIGATOR
NS_DECL_NSINAVIGATORUSERMEDIA
NS_DECL_NSIDOMNAVIGATORUSERMEDIA

View File

@ -17,6 +17,9 @@
#include "nsPluginHost.h"
#include "nsIContentViewer.h"
#include "nsIDocument.h"
#include "nsIObserverService.h"
#include "nsIWeakReference.h"
#include "mozilla/Services.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -31,6 +34,16 @@ nsPluginArray::nsPluginArray(Navigator* navigator,
{
}
void
nsPluginArray::Init()
{
nsCOMPtr<nsIObserverService> obsService =
mozilla::services::GetObserverService();
if (obsService) {
obsService->AddObserver(this, "plugin-info-updated", true);
}
}
nsPluginArray::~nsPluginArray()
{
if (mPluginArray != nullptr) {
@ -47,6 +60,8 @@ DOMCI_DATA(PluginArray, nsPluginArray)
NS_INTERFACE_MAP_BEGIN(nsPluginArray)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMPluginArray)
NS_INTERFACE_MAP_ENTRY(nsIDOMPluginArray)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(PluginArray)
NS_INTERFACE_MAP_END
@ -166,6 +181,12 @@ nsPluginArray::Invalidate()
{
mDocShell = nullptr;
mNavigator = nullptr;
nsCOMPtr<nsIObserverService> obsService =
mozilla::services::GetObserverService();
if (obsService) {
obsService->RemoveObserver(this, "plugin-info-updated");
}
}
NS_IMETHODIMP
@ -256,7 +277,15 @@ nsPluginArray::GetPlugins()
return rv;
}
//
NS_IMETHODIMP
nsPluginArray::Observe(nsISupports *aSubject, const char *aTopic,
const PRUnichar *aData) {
if (!nsCRT::strcmp(aTopic, "plugin-info-updated")) {
Refresh(false);
}
return NS_OK;
}
nsPluginElement::nsPluginElement(nsIDOMPlugin* plugin)
{

View File

@ -12,6 +12,7 @@
#include "nsIPluginHost.h"
#include "nsIURL.h"
#include "nsWeakReference.h"
#include "nsIObserver.h"
namespace mozilla {
namespace dom {
@ -24,6 +25,8 @@ class nsIDocShell;
// NB: Due to weak references, Navigator has intimate knowledge of our
// internals.
class nsPluginArray : public nsIDOMPluginArray
, public nsIObserver
, public nsSupportsWeakReference
{
public:
nsPluginArray(mozilla::dom::Navigator* navigator, nsIDocShell *aDocShell);
@ -33,6 +36,14 @@ public:
// nsIDOMPluginArray
NS_DECL_NSIDOMPLUGINARRAY
// nsIObserver
NS_DECL_NSIOBSERVER
// nsPluginArray registers itself as an observer with a weak reference.
// This can't be done in the constructor, because at that point its
// refcount is 0 (and it gets destroyed upon registration). So, Init()
// must be called after construction.
void Init();
nsresult GetPluginHost(nsIPluginHost** aPluginHost);
@ -53,7 +64,7 @@ public:
}
#endif
return static_cast<nsPluginArray*>(aSupports);
return static_cast<nsPluginArray*>(static_cast<nsIDOMPluginArray*>(aSupports));
}
private: