mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bug 820708 - refresh navigator.plugins when a plugin is enabled/disabled r=joshmoz
This commit is contained in:
parent
a5c94fa139
commit
c969101464
@ -37,6 +37,7 @@
|
||||
#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"
|
||||
@ -102,6 +103,10 @@ 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()
|
||||
@ -118,6 +123,7 @@ NS_INTERFACE_MAP_BEGIN(Navigator)
|
||||
NS_INTERFACE_MAP_ENTRY(nsINavigatorBattery)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorDesktopNotification)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorSms)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
||||
#ifdef MOZ_MEDIA_NAVIGATOR
|
||||
NS_INTERFACE_MAP_ENTRY(nsINavigatorUserMedia)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorUserMedia)
|
||||
@ -152,6 +158,12 @@ Navigator::Invalidate()
|
||||
{
|
||||
mWindow = nullptr;
|
||||
|
||||
nsCOMPtr<nsIObserverService> obsService =
|
||||
mozilla::services::GetObserverService();
|
||||
if (obsService) {
|
||||
obsService->RemoveObserver(this, "plugin-info-updated");
|
||||
}
|
||||
|
||||
if (mPlugins) {
|
||||
mPlugins->Invalidate();
|
||||
mPlugins = nullptr;
|
||||
@ -248,6 +260,19 @@ 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
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "nsINavigatorBattery.h"
|
||||
#include "nsIDOMNavigatorSms.h"
|
||||
#include "nsIDOMNavigatorNetwork.h"
|
||||
#include "nsIObserver.h"
|
||||
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
||||
#include "nsINavigatorAudioChannelManager.h"
|
||||
#endif
|
||||
@ -96,6 +97,7 @@ class Navigator : public nsIDOMNavigator
|
||||
, public nsIDOMNavigatorDesktopNotification
|
||||
, public nsINavigatorBattery
|
||||
, public nsIDOMMozNavigatorSms
|
||||
, public nsIObserver
|
||||
#ifdef MOZ_MEDIA_NAVIGATOR
|
||||
, public nsINavigatorUserMedia
|
||||
, public nsIDOMNavigatorUserMedia
|
||||
@ -132,6 +134,7 @@ public:
|
||||
NS_DECL_NSIDOMNAVIGATORDESKTOPNOTIFICATION
|
||||
NS_DECL_NSINAVIGATORBATTERY
|
||||
NS_DECL_NSIDOMMOZNAVIGATORSMS
|
||||
NS_DECL_NSIOBSERVER
|
||||
#ifdef MOZ_MEDIA_NAVIGATOR
|
||||
NS_DECL_NSINAVIGATORUSERMEDIA
|
||||
NS_DECL_NSIDOMNAVIGATORUSERMEDIA
|
||||
|
@ -186,8 +186,16 @@ nsPluginArray::Refresh(bool aReloadDocuments)
|
||||
// NS_ERROR_PLUGINS_PLUGINSNOTCHANGED on reloading plugins indicates
|
||||
// that plugins did not change and was not reloaded
|
||||
bool pluginsNotChanged = false;
|
||||
if(mPluginHost)
|
||||
pluginsNotChanged = (NS_ERROR_PLUGINS_PLUGINSNOTCHANGED == mPluginHost->ReloadPlugins(aReloadDocuments));
|
||||
uint32_t currentPluginCount = 0;
|
||||
if(mPluginHost) {
|
||||
res = GetLength(¤tPluginCount);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsresult reloadResult = mPluginHost->ReloadPlugins(aReloadDocuments);
|
||||
// currentPluginCount is as reported by nsPluginHost. mPluginCount is
|
||||
// essentially a cache of this value, and may be out of date.
|
||||
pluginsNotChanged = (reloadResult == NS_ERROR_PLUGINS_PLUGINSNOTCHANGED &&
|
||||
currentPluginCount == mPluginCount);
|
||||
}
|
||||
|
||||
// no need to reload the page if plugins have not been changed
|
||||
// in fact, if we do reload we can hit recursive load problem, see bug 93351
|
||||
|
@ -2383,6 +2383,11 @@ nsPluginHost::UpdatePluginInfo(nsPluginTag* aPluginTag)
|
||||
RegisterWithCategoryManager(aPluginTag->mMimeTypes[i], shouldRegister);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> obsService =
|
||||
mozilla::services::GetObserverService();
|
||||
if (obsService)
|
||||
obsService->NotifyObservers(nullptr, "plugin-info-updated", nullptr);
|
||||
|
||||
// Reload instances if needed
|
||||
if (aPluginTag->IsEnabled()) {
|
||||
return NS_OK;
|
||||
|
@ -101,6 +101,7 @@ MOCHITEST_CHROME_FILES = \
|
||||
test_npruntime.xul \
|
||||
test_wmode.xul \
|
||||
test_bug479979.xul \
|
||||
test_refresh_navigator_plugins.html \
|
||||
$(NULL)
|
||||
|
||||
ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
||||
|
@ -0,0 +1,62 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- bug 820708 -->
|
||||
<html>
|
||||
<head>
|
||||
<meta><charset="utf-8"/>
|
||||
<title>Test Refreshing navigator.plugins (bug 820708)</title>
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script class="testbody" type="application/javascript">
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
var pluginHost = Components.classes["@mozilla.org/plugin/host;1"]
|
||||
.getService(Components.interfaces.nsIPluginHost);
|
||||
var pluginTags = pluginHost.getPluginTags();
|
||||
var nextTest = null;
|
||||
var obsService = Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
var observer = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
if (aTopic == "plugin-info-updated") {
|
||||
SimpleTest.executeSoon(nextTest);
|
||||
}
|
||||
}
|
||||
};
|
||||
obsService.addObserver(observer, "plugin-info-updated", false);
|
||||
|
||||
var navTestPlugin = navigator.plugins.namedItem("Test Plug-in");
|
||||
ok(navTestPlugin, "navigator.plugins should have Test Plug-in");
|
||||
var tagTestPlugin = null;
|
||||
for (var plugin of pluginTags) {
|
||||
if (plugin.name == navTestPlugin.name) {
|
||||
tagTestPlugin = plugin;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ok(tagTestPlugin, "plugin tags should have Test Plug-in");
|
||||
var mimeType = tagTestPlugin.getMimeTypes()[0];
|
||||
ok(mimeType, "should have a MIME type for Test Plug-in");
|
||||
ok(navigator.mimeTypes[mimeType.type], "navigator.mimeTypes should have an entry for '" + mimeType.type + "'");
|
||||
|
||||
nextTest = testPart2;
|
||||
tagTestPlugin.disabled = true;
|
||||
|
||||
function testPart2() {
|
||||
var navTestPlugin = navigator.plugins.namedItem("Test Plug-in");
|
||||
ok(!navTestPlugin, "now navigator.plugins should not have Test Plug-in");
|
||||
ok(!navigator.mimeTypes[mimeType.type], "now navigator.mimeTypes should not have an entry for '" + mimeType.type + "'");
|
||||
|
||||
nextTest = testPart3;
|
||||
tagTestPlugin.disabled = false;
|
||||
}
|
||||
|
||||
function testPart3() {
|
||||
ok(navTestPlugin, "now navigator.plugins should have Test Plug-in again");
|
||||
ok(navigator.mimeTypes[mimeType.type], "now navigator.mimeTypes should have an entry for '" + mimeType.type + "' again");
|
||||
obsService.removeObserver(observer, "plugin-info-updated");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user