Fixing 143178 -- refreshing plugins before going to the plugin finder sevice, r=peterl, sr=beard

This commit is contained in:
av%netscape.com 2002-05-16 20:47:29 +00:00
Родитель 63666b7227
Коммит c340817b6e
3 изменённых файлов: 60 добавлений и 127 удалений

Просмотреть файл

@ -1,103 +0,0 @@
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsIDocumentLoaderFactory.h"
#include "nsIPluginHost.h"
#include "nsIPluginManager.h"
#include "nsIServiceManager.h"
#include "nsPluginDocLoaderFactory.h"
#include "nsPluginViewer.h"
NS_METHOD
nsPluginDocLoaderFactory::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
{
NS_PRECONDITION(aOuter == nsnull, "no aggregation");
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsPluginDocLoaderFactory* factory = new nsPluginDocLoaderFactory();
if (! factory)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
NS_ADDREF(factory);
rv = factory->QueryInterface(aIID, aResult);
NS_RELEASE(factory);
return rv;
}
NS_IMPL_ISUPPORTS1(nsPluginDocLoaderFactory, nsIDocumentLoaderFactory);
NS_IMETHODIMP
nsPluginDocLoaderFactory::CreateInstance(const char *aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
const char* aContentType,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIStreamListener** aDocListener,
nsIContentViewer** aDocViewer)
{
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
nsCOMPtr<nsIPluginHost> pluginHost = do_GetService(kPluginManagerCID);
if(! pluginHost)
return NS_ERROR_FAILURE;
if (pluginHost->IsPluginEnabledForType(aContentType) != NS_OK)
return NS_ERROR_FAILURE;
return NS_NewPluginContentViewer(aCommand, aDocListener, aDocViewer);
}
NS_IMETHODIMP
nsPluginDocLoaderFactory::CreateInstanceForDocument(nsISupports* aContainer,
nsIDocument* aDocument,
const char *aCommand,
nsIContentViewer** aDocViewerResult)
{
NS_NOTREACHED("how'd I get here?");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsPluginDocLoaderFactory::CreateBlankDocument(nsILoadGroup *aLoadGroup,
nsIDocument **_retval) {
NS_NOTREACHED("how'd I get here?");
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -2736,21 +2736,26 @@ nsresult nsPluginHostImpl::ReloadPlugins(PRBool reloadPages)
nsresult rv = NS_OK;
// this will create the initial plugin list out of cache
// if it was not created yet
LoadPlugins();
// we are re-scanning plugins. New plugins may have been added, also some
// plugins may have been removed, so we should probably shut everything down
// but don't touch running (active and not stopped) plugins
// check if plugins changed, no need to do anything else
// if no changes to plugins have been made
// PR_FALSE instructs not to touch the plugin list, just to
// look for possible changes
PRBool pluginschanged = PR_TRUE;
FindPlugins(PR_FALSE, &pluginschanged);
// if no changed detected, return an appropriate error code
if (!pluginschanged)
return NS_ERROR_PLUGINS_PLUGINSNOTCHANGED;
if(reloadPages) {
// check if plugins changed, no need to refresh and reload
// page if no changes to plugins have been made
// PR_FALSE instructs not to touch the plugin list, just to
// look for possible changes
PRBool pluginschanged = PR_TRUE;
FindPlugins(PR_FALSE, &pluginschanged);
// if no changed detected, return an appropriate error code
if (!pluginschanged)
return NS_ERROR_PLUGINS_PLUGINSNOTCHANGED;
// if we have currently running plugins we should set a flag not to
// unload them from memory, see bug #61388
// and form a list of libs to be unloaded later
@ -2798,17 +2803,6 @@ nsresult nsPluginHostImpl::ReloadPlugins(PRBool reloadPages)
// set flags
mPluginsLoaded = PR_FALSE;
//refresh the component registry first
nsCOMPtr<nsIServiceManager> servManager;
NS_GetServiceManager(getter_AddRefs(servManager));
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servManager);
if (!registrar) {
NS_ASSERTION(0, "No nsIComponentRegistrar from get service");
return NS_ERROR_FAILURE;
}
NS_ASSERTION(registrar, "No nsIComponentRegistrar from get service");
rv = registrar->AutoRegister(nsnull);
// load them again
rv = LoadPlugins();
@ -3781,13 +3775,50 @@ nsresult nsPluginHostImpl::RegisterPluginMimeTypesWithLayout(nsPluginTag * plugi
NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType,
nsIURI *aURL,
nsIPluginInstanceOwner *aOwner)
{
nsresult rv = NS_OK;
rv = TrySetUpPluginInstance(aMimeType, aURL, aOwner);
// if we fail, refresh plugin list just in case the plugin has been
// just added and try to instantiate plugin instance again, see bug 143178
if (NS_FAILED(rv)) {
// we should also make sure not to do this more than once per page
// so if there are a few embed tags with unknown plugins,
// we don't get unnecessary overhead
// let's cache document to decide whether this is the same page or not
nsCOMPtr<nsIDocument> document;
if (aOwner)
aOwner->GetDocument(getter_AddRefs(document));
nsCOMPtr<nsIDocument> currentdocument = do_QueryReferent(mCurrentDocument);
if (document == currentdocument)
return rv;
mCurrentDocument = getter_AddRefs(NS_GetWeakReference(document));
// ReloadPlugins will do the job smartly: nothing will be done
// if no changes detected, in such a case just return
if (NS_ERROR_PLUGINS_PLUGINSNOTCHANGED == ReloadPlugins(PR_FALSE))
return rv;
// other failure return codes may be not fatal, so we can still try
rv = TrySetUpPluginInstance(aMimeType, aURL, aOwner);
}
return rv;
}
NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType,
nsIURI *aURL,
nsIPluginInstanceOwner *aOwner)
{
#ifdef PLUGIN_LOGGING
nsCAutoString urlSpec;
if(aURL != nsnull) (void)aURL->GetSpec(urlSpec);
PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_NORMAL,
("nsPluginHostImpl::SetupPluginInstance Begin mime=%s, owner=%p, url=%s\n",
("nsPluginHostImpl::TrySetupPluginInstance Begin mime=%s, owner=%p, url=%s\n",
aMimeType, aOwner, urlSpec.get()));
PR_LogFlush();
@ -3961,7 +3992,7 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType,
if(aURL != nsnull) (void)aURL->GetSpec(urlSpec2);
PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_BASIC,
("nsPluginHostImpl::SetupPluginInstance Finished mime=%s, rv=%d, owner=%p, url=%s\n",
("nsPluginHostImpl::TrySetupPluginInstance Finished mime=%s, rv=%d, owner=%p, url=%s\n",
aMimeType, result, aOwner, urlSpec2.get()));
PR_LogFlush();

Просмотреть файл

@ -51,6 +51,7 @@
#include "nsPluginsDir.h"
#include "nsVoidArray.h" // array for holding "active" streams
#include "nsIDirectoryService.h"
#include "nsWeakPtr.h"
class ns4xPlugin;
class nsFileSpec;
@ -390,6 +391,9 @@ public:
StopPluginInstance(nsIPluginInstance* aInstance);
private:
NS_IMETHOD
TrySetUpPluginInstance(const char *aMimeType, nsIURI *aURL, nsIPluginInstanceOwner *aOwner);
nsresult
LoadXPCOMPlugins(nsIComponentManager* aComponentManager, nsIFile* aPath);
@ -477,6 +481,7 @@ private:
nsUnusedLibrary *mUnusedLibraries;
nsCOMPtr<nsIDirectoryServiceProvider> mPrivateDirServiceProvider;
nsWeakPtr mCurrentDocument; // weak reference, we use it to id document only
};
#endif