2001-09-26 02:43:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-04-20 23:18:51 +04:00
|
|
|
|
|
|
|
#include "nsPluginArray.h"
|
|
|
|
#include "nsMimeTypeArray.h"
|
2011-11-02 17:44:16 +04:00
|
|
|
#include "Navigator.h"
|
1999-04-20 23:18:51 +04:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIDOMNavigator.h"
|
|
|
|
#include "nsIDOMMimeType.h"
|
|
|
|
#include "nsIPluginHost.h"
|
2001-01-24 01:29:41 +03:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
2011-10-03 23:11:31 +04:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2011-05-21 17:28:54 +04:00
|
|
|
#include "nsPluginHost.h"
|
2012-08-20 22:34:32 +04:00
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIDocument.h"
|
2013-04-11 00:59:45 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIWeakReference.h"
|
|
|
|
#include "mozilla/Services.h"
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
nsPluginArray::nsPluginArray(Navigator* navigator,
|
2004-12-10 22:48:22 +03:00
|
|
|
nsIDocShell *aDocShell)
|
2011-12-01 12:28:16 +04:00
|
|
|
: mNavigator(navigator),
|
|
|
|
mPluginHost(do_GetService(MOZ_PLUGIN_HOST_CONTRACTID)),
|
|
|
|
mPluginCount(0),
|
2012-07-30 18:20:58 +04:00
|
|
|
mPluginArray(nullptr),
|
2011-12-01 12:28:16 +04:00
|
|
|
mDocShell(do_GetWeakReference(aDocShell))
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-11 00:59:45 +04:00
|
|
|
void
|
|
|
|
nsPluginArray::Init()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsService) {
|
|
|
|
obsService->AddObserver(this, "plugin-info-updated", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-10 22:48:22 +03:00
|
|
|
nsPluginArray::~nsPluginArray()
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if (mPluginArray != nullptr) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mPluginCount; i++) {
|
2000-11-29 05:26:11 +03:00
|
|
|
NS_IF_RELEASE(mPluginArray[i]);
|
|
|
|
}
|
|
|
|
delete[] mPluginArray;
|
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2010-01-12 16:08:43 +03:00
|
|
|
DOMCI_DATA(PluginArray, nsPluginArray)
|
|
|
|
|
2004-12-10 22:48:22 +03:00
|
|
|
// QueryInterface implementation for nsPluginArray
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsPluginArray)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMPluginArray)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMPluginArray)
|
2013-04-11 00:59:45 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(PluginArray)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2004-12-10 22:48:22 +03:00
|
|
|
NS_IMPL_ADDREF(nsPluginArray)
|
|
|
|
NS_IMPL_RELEASE(nsPluginArray)
|
2000-11-29 05:26:11 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPluginArray::GetLength(uint32_t* aLength)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2011-05-21 17:28:54 +04:00
|
|
|
nsPluginHost *pluginHost = static_cast<nsPluginHost*>(mPluginHost.get());
|
|
|
|
if (AllowPlugins() && pluginHost)
|
|
|
|
return pluginHost->GetPluginCount(aLength);
|
2005-01-17 10:57:04 +03:00
|
|
|
|
|
|
|
*aLength = 0;
|
|
|
|
return NS_OK;
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2006-03-21 08:31:59 +03:00
|
|
|
nsPluginArray::AllowPlugins()
|
|
|
|
{
|
2011-12-01 12:28:16 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShell);
|
|
|
|
|
2012-08-20 22:34:32 +04:00
|
|
|
if (!docShell) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-03-21 08:31:59 +03:00
|
|
|
|
2012-08-20 22:34:32 +04:00
|
|
|
return docShell->PluginsAllowedInCurrentDoc();
|
2006-03-21 08:31:59 +03:00
|
|
|
}
|
|
|
|
|
2008-10-22 18:31:14 +04:00
|
|
|
nsIDOMPlugin*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPluginArray::GetItemAt(uint32_t aIndex, nsresult* aResult)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2008-10-22 18:31:14 +04:00
|
|
|
*aResult = NS_OK;
|
2006-03-21 08:31:59 +03:00
|
|
|
|
|
|
|
if (!AllowPlugins())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2000-11-29 05:26:11 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (mPluginArray == nullptr) {
|
2008-10-22 18:31:14 +04:00
|
|
|
*aResult = GetPlugins();
|
|
|
|
if (*aResult != NS_OK)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return aIndex < mPluginCount ? mPluginArray[aIndex] : nullptr;
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
2000-11-29 05:26:11 +03:00
|
|
|
|
2008-10-22 18:31:14 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPluginArray::Item(uint32_t aIndex, nsIDOMPlugin** aReturn)
|
2008-10-22 18:31:14 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex, &rv));
|
|
|
|
|
|
|
|
return rv;
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2008-11-01 00:40:35 +03:00
|
|
|
nsIDOMPlugin*
|
|
|
|
nsPluginArray::GetNamedItem(const nsAString& aName, nsresult* aResult)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2008-11-01 00:40:35 +03:00
|
|
|
*aResult = NS_OK;
|
2006-03-21 08:31:59 +03:00
|
|
|
|
|
|
|
if (!AllowPlugins())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2000-11-29 05:26:11 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (mPluginArray == nullptr) {
|
2008-11-01 00:40:35 +03:00
|
|
|
*aResult = GetPlugins();
|
|
|
|
if (*aResult != NS_OK)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mPluginCount; i++) {
|
2000-11-29 05:26:11 +03:00
|
|
|
nsAutoString pluginName;
|
|
|
|
nsIDOMPlugin* plugin = mPluginArray[i];
|
2008-11-01 00:40:35 +03:00
|
|
|
if (plugin->GetName(pluginName) == NS_OK && pluginName.Equals(aName)) {
|
|
|
|
return plugin;
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-11-01 00:40:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginArray::NamedItem(const nsAString& aName, nsIDOMPlugin** aReturn)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != aReturn, "null arg");
|
2008-11-01 00:40:35 +03:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aReturn = GetNamedItem(aName, &rv));
|
|
|
|
|
|
|
|
return rv;
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2001-04-05 02:12:26 +04:00
|
|
|
nsresult
|
2004-12-10 22:48:22 +03:00
|
|
|
nsPluginArray::GetPluginHost(nsIPluginHost** aPluginHost)
|
2001-04-05 02:12:26 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPluginHost);
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!mPluginHost) {
|
2009-06-26 01:06:54 +04:00
|
|
|
mPluginHost = do_GetService(MOZ_PLUGIN_HOST_CONTRACTID, &rv);
|
2001-04-05 02:12:26 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aPluginHost = mPluginHost;
|
|
|
|
NS_IF_ADDREF(*aPluginHost);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-08-13 08:05:05 +04:00
|
|
|
void
|
|
|
|
nsPluginArray::Invalidate()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocShell = nullptr;
|
|
|
|
mNavigator = nullptr;
|
2013-04-11 00:59:45 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsService) {
|
|
|
|
obsService->RemoveObserver(this, "plugin-info-updated");
|
|
|
|
}
|
2010-08-13 08:05:05 +04:00
|
|
|
}
|
|
|
|
|
2000-11-29 05:26:11 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsPluginArray::Refresh(bool aReloadDocuments)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2000-12-22 03:08:31 +03:00
|
|
|
nsresult res = NS_OK;
|
2006-03-21 08:31:59 +03:00
|
|
|
if (!AllowPlugins())
|
|
|
|
return NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA;
|
2000-12-22 03:08:31 +03:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
if (!mPluginHost) {
|
2009-06-26 01:06:54 +04:00
|
|
|
mPluginHost = do_GetService(MOZ_PLUGIN_HOST_CONTRACTID, &res);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(NS_FAILED(res)) {
|
2000-12-22 03:08:31 +03:00
|
|
|
return res;
|
2001-01-24 01:29:41 +03:00
|
|
|
}
|
2000-12-22 03:08:31 +03:00
|
|
|
|
2002-02-12 02:09:38 +03:00
|
|
|
// NS_ERROR_PLUGINS_PLUGINSNOTCHANGED on reloading plugins indicates
|
|
|
|
// that plugins did not change and was not reloaded
|
2011-09-29 10:19:26 +04:00
|
|
|
bool pluginsNotChanged = false;
|
2012-12-21 04:53:21 +04:00
|
|
|
uint32_t currentPluginCount = 0;
|
|
|
|
if(mPluginHost) {
|
|
|
|
res = GetLength(¤tPluginCount);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
2013-04-24 00:02:12 +04:00
|
|
|
nsresult reloadResult = mPluginHost->ReloadPlugins();
|
2012-12-21 04:53:21 +04:00
|
|
|
// 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);
|
|
|
|
}
|
2002-02-12 02:09:38 +03:00
|
|
|
|
|
|
|
// 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
|
|
|
|
if(pluginsNotChanged)
|
|
|
|
return res;
|
2000-12-22 03:08:31 +03:00
|
|
|
|
2011-12-01 12:28:16 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryReferent(mDocShell);
|
2002-05-17 00:41:26 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (mPluginArray != nullptr) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mPluginCount; i++)
|
2002-05-17 00:41:26 +04:00
|
|
|
NS_IF_RELEASE(mPluginArray[i]);
|
|
|
|
|
|
|
|
delete[] mPluginArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPluginCount = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
mPluginArray = nullptr;
|
2002-05-17 00:41:26 +04:00
|
|
|
|
2001-07-23 09:36:52 +04:00
|
|
|
if (mNavigator)
|
|
|
|
mNavigator->RefreshMIMEArray();
|
|
|
|
|
2002-02-12 02:09:38 +03:00
|
|
|
if (aReloadDocuments && webNav)
|
2001-08-10 05:12:05 +04:00
|
|
|
webNav->Reload(nsIWebNavigation::LOAD_FLAGS_NONE);
|
2001-01-24 01:29:41 +03:00
|
|
|
|
2000-12-22 03:08:31 +03:00
|
|
|
return res;
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2000-11-29 05:26:11 +03:00
|
|
|
nsresult
|
2004-12-10 22:48:22 +03:00
|
|
|
nsPluginArray::GetPlugins()
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2000-12-01 00:10:55 +03:00
|
|
|
nsresult rv = GetLength(&mPluginCount);
|
2005-01-17 10:57:04 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-11-29 05:26:11 +03:00
|
|
|
mPluginArray = new nsIDOMPlugin*[mPluginCount];
|
2005-01-17 10:57:04 +03:00
|
|
|
if (!mPluginArray)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (!mPluginCount)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-05-21 17:28:54 +04:00
|
|
|
nsPluginHost *pluginHost = static_cast<nsPluginHost*>(mPluginHost.get());
|
|
|
|
rv = pluginHost->GetPlugins(mPluginCount, mPluginArray);
|
2005-01-17 10:57:04 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// need to wrap each of these with a nsPluginElement, which
|
|
|
|
// is scriptable.
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mPluginCount; i++) {
|
2005-01-17 11:36:44 +03:00
|
|
|
nsIDOMPlugin* wrapper = new nsPluginElement(mPluginArray[i]);
|
2005-01-17 10:57:04 +03:00
|
|
|
NS_IF_ADDREF(wrapper);
|
|
|
|
mPluginArray[i] = wrapper;
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
|
|
|
} else {
|
2005-01-17 10:57:04 +03:00
|
|
|
/* XXX this code is all broken. If GetPlugins fails, there's no contract
|
|
|
|
* explaining what should happen. Instead of deleting elements in an
|
|
|
|
* array of random pointers, we mark the array as 0 length.
|
|
|
|
*/
|
|
|
|
mPluginCount = 0;
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2013-04-11 00:59:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginArray::Observe(nsISupports *aSubject, const char *aTopic,
|
|
|
|
const PRUnichar *aData) {
|
|
|
|
if (!nsCRT::strcmp(aTopic, "plugin-info-updated")) {
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2004-12-10 22:48:22 +03:00
|
|
|
nsPluginElement::nsPluginElement(nsIDOMPlugin* plugin)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2004-12-10 22:48:22 +03:00
|
|
|
mPlugin = plugin; // don't AddRef, see nsPluginArray::Item.
|
2000-11-29 05:26:11 +03:00
|
|
|
mMimeTypeCount = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
mMimeTypeArray = nullptr;
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2004-12-10 22:48:22 +03:00
|
|
|
nsPluginElement::~nsPluginElement()
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2000-11-29 05:26:11 +03:00
|
|
|
NS_IF_RELEASE(mPlugin);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (mMimeTypeArray != nullptr) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mMimeTypeCount; i++) {
|
2010-02-11 14:03:47 +03:00
|
|
|
nsMimeType* mt = static_cast<nsMimeType*>(mMimeTypeArray[i]);
|
|
|
|
if (mt) {
|
|
|
|
mt->DetachPlugin();
|
|
|
|
NS_RELEASE(mt);
|
|
|
|
}
|
|
|
|
}
|
2000-11-29 05:26:11 +03:00
|
|
|
delete[] mMimeTypeArray;
|
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-12 16:08:43 +03:00
|
|
|
DOMCI_DATA(Plugin, nsPluginElement)
|
|
|
|
|
2004-12-10 22:48:22 +03:00
|
|
|
// QueryInterface implementation for nsPluginElement
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsPluginElement)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMPlugin)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Plugin)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
2004-12-10 22:48:22 +03:00
|
|
|
NS_IMPL_ADDREF(nsPluginElement)
|
|
|
|
NS_IMPL_RELEASE(nsPluginElement)
|
2000-11-29 05:26:11 +03:00
|
|
|
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2000-11-29 05:26:11 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsPluginElement::GetDescription(nsAString& aDescription)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2000-11-29 05:26:11 +03:00
|
|
|
return mPlugin->GetDescription(aDescription);
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2000-11-29 05:26:11 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsPluginElement::GetFilename(nsAString& aFilename)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2000-11-29 05:26:11 +03:00
|
|
|
return mPlugin->GetFilename(aFilename);
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2009-04-22 23:13:10 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginElement::GetVersion(nsAString& aVersion)
|
|
|
|
{
|
|
|
|
return mPlugin->GetVersion(aVersion);
|
|
|
|
}
|
|
|
|
|
2000-11-29 05:26:11 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsPluginElement::GetName(nsAString& aName)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2000-11-29 05:26:11 +03:00
|
|
|
return mPlugin->GetName(aName);
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2000-11-29 05:26:11 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPluginElement::GetLength(uint32_t* aLength)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2000-11-29 05:26:11 +03:00
|
|
|
return mPlugin->GetLength(aLength);
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2008-10-22 18:31:14 +04:00
|
|
|
nsIDOMMimeType*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPluginElement::GetItemAt(uint32_t aIndex, nsresult *aResult)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if (mMimeTypeArray == nullptr) {
|
2008-10-22 18:31:14 +04:00
|
|
|
*aResult = GetMimeTypes();
|
|
|
|
if (*aResult != NS_OK)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
2008-10-22 18:31:14 +04:00
|
|
|
|
|
|
|
if (aIndex >= mMimeTypeCount) {
|
|
|
|
*aResult = NS_ERROR_FAILURE;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
2008-10-22 18:31:14 +04:00
|
|
|
|
|
|
|
*aResult = NS_OK;
|
|
|
|
|
|
|
|
return mMimeTypeArray[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPluginElement::Item(uint32_t aIndex, nsIDOMMimeType** aReturn)
|
2008-10-22 18:31:14 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex, &rv));
|
|
|
|
|
|
|
|
return rv;
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2008-11-01 00:40:35 +03:00
|
|
|
nsIDOMMimeType*
|
|
|
|
nsPluginElement::GetNamedItem(const nsAString& aName, nsresult *aResult)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if (mMimeTypeArray == nullptr) {
|
2008-11-01 00:40:35 +03:00
|
|
|
*aResult = GetMimeTypes();
|
|
|
|
if (*aResult != NS_OK)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
|
|
|
|
2008-11-01 00:40:35 +03:00
|
|
|
*aResult = NS_OK;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mMimeTypeCount; i++) {
|
2000-11-29 05:26:11 +03:00
|
|
|
nsAutoString type;
|
|
|
|
nsIDOMMimeType* mimeType = mMimeTypeArray[i];
|
2008-11-01 00:40:35 +03:00
|
|
|
if (mimeType->GetType(type) == NS_OK && type.Equals(aName)) {
|
|
|
|
return mimeType;
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-11-01 00:40:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginElement::NamedItem(const nsAString& aName, nsIDOMMimeType** aReturn)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aReturn = GetNamedItem(aName, &rv));
|
|
|
|
|
|
|
|
return rv;
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2000-11-29 05:26:11 +03:00
|
|
|
nsresult
|
2004-12-10 22:48:22 +03:00
|
|
|
nsPluginElement::GetMimeTypes()
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2000-11-29 05:26:11 +03:00
|
|
|
nsresult rv = mPlugin->GetLength(&mMimeTypeCount);
|
|
|
|
if (rv == NS_OK) {
|
|
|
|
mMimeTypeArray = new nsIDOMMimeType*[mMimeTypeCount];
|
2012-07-30 18:20:58 +04:00
|
|
|
if (mMimeTypeArray == nullptr)
|
2000-11-29 05:26:11 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mMimeTypeCount; i++) {
|
2003-02-27 02:54:55 +03:00
|
|
|
nsCOMPtr<nsIDOMMimeType> mimeType;
|
|
|
|
rv = mPlugin->Item(i, getter_AddRefs(mimeType));
|
2000-11-29 05:26:11 +03:00
|
|
|
if (rv != NS_OK)
|
|
|
|
break;
|
2004-12-10 22:48:22 +03:00
|
|
|
mimeType = new nsMimeType(this, mimeType);
|
2003-02-27 02:54:55 +03:00
|
|
|
NS_IF_ADDREF(mMimeTypeArray[i] = mimeType);
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|