Fixing bug 855611. Convert navigator.plugins and navigator.mimeTypes to use new DOM bindings. r=peterv@propagandism.org.

This commit is contained in:
Johnny Stenback 2013-07-09 06:58:21 -07:00
Родитель 5c1fe496e8
Коммит fb568a43de
26 изменённых файлов: 760 добавлений и 1220 удалений

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

@ -159,15 +159,14 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(Navigator)
NS_IMPL_CYCLE_COLLECTING_RELEASE(Navigator)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Navigator)
// mMimeTypes isn't cycle collected
tmp->Invalidate();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
// mMimeTypes isn't cycle collected
// mPlugins isn't cycle collected
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPlugins)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMimeTypes)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGeolocation)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotification)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryManager)
@ -212,6 +211,8 @@ Navigator::Invalidate()
mPlugins = nullptr;
}
mMimeTypes = nullptr;
// If there is a page transition, make sure delete the geolocation object.
if (mGeolocation) {
mGeolocation->Shutdown();
@ -482,11 +483,12 @@ Navigator::GetProductSub(nsAString& aProductSub)
}
NS_IMETHODIMP
Navigator::GetMimeTypes(nsIDOMMimeTypeArray** aMimeTypes)
Navigator::GetMimeTypes(nsISupports** aMimeTypes)
{
if (!mMimeTypes) {
NS_ENSURE_STATE(mWindow);
mMimeTypes = new nsMimeTypeArray(this);
nsWeakPtr win = do_GetWeakReference(mWindow);
mMimeTypes = new nsMimeTypeArray(win);
}
NS_ADDREF(*aMimeTypes = mMimeTypes);
@ -495,16 +497,16 @@ Navigator::GetMimeTypes(nsIDOMMimeTypeArray** aMimeTypes)
}
NS_IMETHODIMP
Navigator::GetPlugins(nsIDOMPluginArray** aPlugins)
Navigator::GetPlugins(nsISupports** aPlugins)
{
if (!mPlugins) {
NS_ENSURE_STATE(mWindow);
mPlugins = new nsPluginArray(this, mWindow->GetDocShell());
nsWeakPtr win = do_GetWeakReference(mWindow);
mPlugins = new nsPluginArray(win);
mPlugins->Init();
}
NS_ADDREF(*aPlugins = mPlugins);
NS_ADDREF(*aPlugins = static_cast<nsIObserver*>(mPlugins.get()));
return NS_OK;
}
@ -618,31 +620,16 @@ Navigator::JavaEnabled(bool* aReturn)
if (!mMimeTypes) {
NS_ENSURE_STATE(mWindow);
mMimeTypes = new nsMimeTypeArray(this);
nsWeakPtr win = do_GetWeakReference(mWindow);
mMimeTypes = new nsMimeTypeArray(win);
}
RefreshMIMEArray();
uint32_t count;
mMimeTypes->GetLength(&count);
for (uint32_t i = 0; i < count; i++) {
nsresult rv;
nsIDOMMimeType* type = mMimeTypes->GetItemAt(i, &rv);
nsMimeType *mimeType =
mMimeTypes->NamedItem(NS_LITERAL_STRING("application/x-java-vm"));
if (NS_FAILED(rv) || !type) {
continue;
}
nsAutoString mimeString;
if (NS_FAILED(type->GetType(mimeString))) {
continue;
}
if (mimeString.EqualsLiteral("application/x-java-vm")) {
*aReturn = true;
break;
}
}
*aReturn = mimeType && mimeType->GetEnabledPlugin();
return NS_OK;
}

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

@ -83,10 +83,6 @@
#include "nsJSEnvironment.h"
// DOM base includes
#include "nsIDOMPluginArray.h"
#include "nsIDOMPlugin.h"
#include "nsIDOMMimeTypeArray.h"
#include "nsIDOMMimeType.h"
#include "nsIDOMLocation.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
@ -210,9 +206,6 @@
#include "nsIDOMNavigatorGeolocation.h"
#include "Navigator.h"
#include "nsPluginArray.h"
#include "nsMimeTypeArray.h"
#include "nsIEventListenerService.h"
#include "nsIMessageManager.h"
#include "mozilla/dom/Element.h"
@ -449,14 +442,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
DOM_DEFAULT_SCRIPTABLE_FLAGS |
nsIXPCScriptable::WANT_PRECREATE |
nsIXPCScriptable::WANT_NEWRESOLVE)
NS_DEFINE_CLASSINFO_DATA(Plugin, nsPluginSH,
ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(PluginArray, nsPluginArraySH,
ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MimeType, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MimeTypeArray, nsMimeTypeArraySH,
ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(History, nsHistorySH,
ARRAY_SCRIPTABLE_FLAGS |
nsIXPCScriptable::WANT_PRECREATE)
@ -1332,22 +1317,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(Plugin, nsIDOMPlugin)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMPlugin)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(PluginArray, nsIDOMPluginArray)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMPluginArray)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MimeType, nsIDOMMimeType)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMimeType)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MimeTypeArray, nsIDOMMimeTypeArray)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMimeTypeArray)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(History, nsIDOMHistory)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMHistory)
DOM_CLASSINFO_MAP_END
@ -5417,69 +5386,6 @@ nsHTMLDocumentSH::CallToGetPropMapper(JSContext *cx, unsigned argc, jsval *vp)
return ::JS_GetUCProperty(cx, self, chars, length, vp);
}
// Plugin helper
nsISupports*
nsPluginSH::GetItemAt(nsISupports *aNative, uint32_t aIndex,
nsWrapperCache **aCache, nsresult *aResult)
{
nsPluginElement* plugin = nsPluginElement::FromSupports(aNative);
return plugin->GetItemAt(aIndex, aResult);
}
nsISupports*
nsPluginSH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsWrapperCache **aCache, nsresult *aResult)
{
nsPluginElement* plugin = nsPluginElement::FromSupports(aNative);
return plugin->GetNamedItem(aName, aResult);
}
// PluginArray helper
nsISupports*
nsPluginArraySH::GetItemAt(nsISupports *aNative, uint32_t aIndex,
nsWrapperCache **aCache, nsresult *aResult)
{
nsPluginArray* array = nsPluginArray::FromSupports(aNative);
return array->GetItemAt(aIndex, aResult);
}
nsISupports*
nsPluginArraySH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsWrapperCache **aCache, nsresult *aResult)
{
nsPluginArray* array = nsPluginArray::FromSupports(aNative);
return array->GetNamedItem(aName, aResult);
}
// MimeTypeArray helper
nsISupports*
nsMimeTypeArraySH::GetItemAt(nsISupports *aNative, uint32_t aIndex,
nsWrapperCache **aCache, nsresult *aResult)
{
nsMimeTypeArray* array = nsMimeTypeArray::FromSupports(aNative);
return array->GetItemAt(aIndex, aResult);
}
nsISupports*
nsMimeTypeArraySH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsWrapperCache **aCache, nsresult *aResult)
{
nsMimeTypeArray* array = nsMimeTypeArray::FromSupports(aNative);
return array->GetNamedItem(aName, aResult);
}
// StringArray helper
NS_IMETHODIMP

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

@ -525,96 +525,6 @@ public:
};
// Plugin helper
class nsPluginSH : public nsNamedArraySH
{
protected:
nsPluginSH(nsDOMClassInfoData* aData) : nsNamedArraySH(aData)
{
}
virtual ~nsPluginSH()
{
}
virtual nsISupports* GetItemAt(nsISupports *aNative, uint32_t aIndex,
nsWrapperCache **aCache, nsresult *aResult) MOZ_OVERRIDE;
// Override nsNamedArraySH::GetNamedItem()
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsWrapperCache **cache,
nsresult *aResult) MOZ_OVERRIDE;
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsPluginSH(aData);
}
};
// PluginArray helper
class nsPluginArraySH : public nsNamedArraySH
{
protected:
nsPluginArraySH(nsDOMClassInfoData* aData) : nsNamedArraySH(aData)
{
}
virtual ~nsPluginArraySH()
{
}
virtual nsISupports* GetItemAt(nsISupports *aNative, uint32_t aIndex,
nsWrapperCache **aCache, nsresult *aResult) MOZ_OVERRIDE;
// Override nsNamedArraySH::GetNamedItem()
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsWrapperCache **cache,
nsresult *aResult) MOZ_OVERRIDE;
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsPluginArraySH(aData);
}
};
// MimeTypeArray helper
class nsMimeTypeArraySH : public nsNamedArraySH
{
protected:
nsMimeTypeArraySH(nsDOMClassInfoData* aData) : nsNamedArraySH(aData)
{
}
virtual ~nsMimeTypeArraySH()
{
}
virtual nsISupports* GetItemAt(nsISupports *aNative, uint32_t aIndex,
nsWrapperCache **aCache, nsresult *aResult) MOZ_OVERRIDE;
// Override nsNamedArraySH::GetNamedItem()
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsWrapperCache **cache,
nsresult *aResult) MOZ_OVERRIDE;
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsMimeTypeArraySH(aData);
}
};
// String array helper
class nsStringArraySH : public nsGenericArraySH

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

@ -6,10 +6,6 @@
DOMCI_CLASS(Window)
DOMCI_CLASS(Location)
DOMCI_CLASS(Navigator)
DOMCI_CLASS(Plugin)
DOMCI_CLASS(PluginArray)
DOMCI_CLASS(MimeType)
DOMCI_CLASS(MimeTypeArray)
DOMCI_CLASS(History)
DOMCI_CLASS(DOMPrototype)
DOMCI_CLASS(DOMConstructor)

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

@ -1367,7 +1367,11 @@ nsGlobalWindow::CleanUp(bool aIgnoreModalDialog)
NS_RELEASE(mObserver);
}
mNavigator = nullptr;
if (mNavigator) {
mNavigator->Invalidate();
mNavigator = nullptr;
}
mScreen = nullptr;
mMenubar = nullptr;
mToolbar = nullptr;

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

@ -5,332 +5,289 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsMimeTypeArray.h"
#include "nsIScriptGlobalObject.h"
#include "mozilla/dom/MimeTypeArrayBinding.h"
#include "mozilla/dom/MimeTypeBinding.h"
#include "nsIDOMNavigator.h"
#include "nsIDOMPluginArray.h"
#include "nsIDOMPlugin.h"
#include "nsDOMClassInfoID.h"
#include "nsContentUtils.h"
#include "nsPluginArray.h"
#include "nsIMIMEService.h"
#include "nsIMIMEInfo.h"
#include "nsIFile.h"
using namespace mozilla;
using namespace mozilla::dom;
nsMimeTypeArray::nsMimeTypeArray(nsIDOMNavigator* navigator)
: mNavigator(navigator),
mPluginMimeTypeCount(0),
mInited(false)
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsMimeTypeArray)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsMimeTypeArray)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsMimeTypeArray)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsMimeTypeArray,
mMimeTypes)
nsMimeTypeArray::nsMimeTypeArray(nsWeakPtr aWindow)
: mWindow(aWindow),
mPluginMimeTypeCount(0)
{
SetIsDOMBinding();
}
nsMimeTypeArray::~nsMimeTypeArray()
{
Clear();
}
DOMCI_DATA(MimeTypeArray, nsMimeTypeArray)
// QueryInterface implementation for nsMimeTypeArray
NS_INTERFACE_MAP_BEGIN(nsMimeTypeArray)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIDOMMimeTypeArray)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MimeTypeArray)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsMimeTypeArray)
NS_IMPL_RELEASE(nsMimeTypeArray)
NS_IMETHODIMP
nsMimeTypeArray::GetLength(uint32_t* aLength)
JSObject*
nsMimeTypeArray::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
if (!mInited) {
nsresult rv = GetMimeTypes();
if (rv != NS_OK)
return rv;
}
NS_ASSERTION(mPluginMimeTypeCount <= (uint32_t)mMimeTypeArray.Count(),
"The number of total mimetypes should be equal to or higher "
"than the number of plugin mimetypes.");
*aLength = mPluginMimeTypeCount;
return NS_OK;
}
nsIDOMMimeType*
nsMimeTypeArray::GetItemAt(uint32_t aIndex, nsresult *aResult)
{
if (!mInited) {
*aResult = GetMimeTypes();
if (*aResult != NS_OK)
return nullptr;
}
NS_ASSERTION(mPluginMimeTypeCount <= (uint32_t)mMimeTypeArray.Count(),
"The number of total mimetypes should be equal to or higher "
"than the number of plugin mimetypes.");
if (aIndex >= mPluginMimeTypeCount) {
*aResult = NS_ERROR_FAILURE;
return nullptr;
}
*aResult = NS_OK;
return mMimeTypeArray[aIndex];
}
NS_IMETHODIMP
nsMimeTypeArray::Item(uint32_t aIndex, nsIDOMMimeType** aReturn)
{
nsresult rv;
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex, &rv));
return rv;
}
nsIDOMMimeType*
nsMimeTypeArray::GetNamedItem(const nsAString& aName, nsresult* aResult)
{
if (!mInited) {
*aResult = GetMimeTypes();
if (*aResult != NS_OK)
return nullptr;
}
NS_ASSERTION(mPluginMimeTypeCount <= (uint32_t)mMimeTypeArray.Count(),
"The number of total mimetypes should be equal to or higher "
"than the number of plugin mimetypes.");
*aResult = NS_OK;
nsAutoString type;
for (int32_t i = 0; i < mMimeTypeArray.Count(); i++) {
nsIDOMMimeType *mtype = mMimeTypeArray[i];
mtype->GetType(type);
if (type.Equals(aName)) {
return mtype;
}
}
// Now let's check with the MIME service.
nsCOMPtr<nsIMIMEService> mimeSrv = do_GetService("@mozilla.org/mime;1");
if (mimeSrv) {
nsCOMPtr<nsIMIMEInfo> mimeInfo;
mimeSrv->GetFromTypeAndExtension(NS_ConvertUTF16toUTF8(aName), EmptyCString(),
getter_AddRefs(mimeInfo));
if (mimeInfo) {
// Now we check whether we can really claim to support this type
nsHandlerInfoAction action = nsIHandlerInfo::saveToDisk;
mimeInfo->GetPreferredAction(&action);
if (action != nsIMIMEInfo::handleInternally) {
bool hasHelper = false;
mimeInfo->GetHasDefaultHandler(&hasHelper);
if (!hasHelper) {
nsCOMPtr<nsIHandlerApp> helper;
mimeInfo->GetPreferredApplicationHandler(getter_AddRefs(helper));
if (!helper) {
// mime info from the OS may not have a PreferredApplicationHandler
// so just check for an empty default description
nsAutoString defaultDescription;
mimeInfo->GetDefaultDescription(defaultDescription);
if (defaultDescription.IsEmpty()) {
// no support; just leave
return nullptr;
}
}
}
}
// If we got here, we support this type! Say so.
nsCOMPtr<nsIDOMMimeType> helper, entry;
if (!(helper = new nsHelperMimeType(aName)) ||
!(entry = new nsMimeType(nullptr, helper)) ||
!mMimeTypeArray.AppendObject(entry)) {
*aResult = NS_ERROR_OUT_OF_MEMORY;
return nullptr;
}
return entry;
}
}
return nullptr;
}
NS_IMETHODIMP
nsMimeTypeArray::NamedItem(const nsAString& aName, nsIDOMMimeType** aReturn)
{
nsresult rv;
NS_IF_ADDREF(*aReturn = GetNamedItem(aName, &rv));
return rv;
}
void
nsMimeTypeArray::Clear()
{
mInited = false;
mMimeTypeArray.Clear();
mPluginMimeTypeCount = 0;
return MimeTypeArrayBinding::Wrap(aCx, aScope, this);
}
void
nsMimeTypeArray::Refresh()
{
Clear();
GetMimeTypes();
mMimeTypes.Clear();
mPluginMimeTypeCount = 0;
}
nsresult
nsMimeTypeArray::GetMimeTypes()
nsPIDOMWindow *
nsMimeTypeArray::GetParentObject() const
{
NS_PRECONDITION(!mInited && mPluginMimeTypeCount==0,
"already initialized");
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
MOZ_ASSERT(win);
return win;
}
if (!mNavigator) {
return NS_ERROR_NOT_AVAILABLE;
nsMimeType*
nsMimeTypeArray::Item(uint32_t aIndex)
{
bool unused;
return IndexedGetter(aIndex, unused);
}
nsMimeType*
nsMimeTypeArray::NamedItem(const nsAString& aName)
{
bool unused;
return NamedGetter(aName, unused);
}
nsMimeType*
nsMimeTypeArray::IndexedGetter(uint32_t aIndex, bool &aFound)
{
aFound = false;
if (mMimeTypes.IsEmpty()) {
EnsureMimeTypes();
}
nsIDOMPluginArray* pluginArray = nullptr;
nsresult rv = mNavigator->GetPlugins(&pluginArray);
if (rv == NS_OK) {
// count up all possible MimeTypes, and collect them here. Later,
// we'll remove duplicates.
uint32_t pluginMimeTypeCount = 0;
uint32_t pluginCount = 0;
rv = pluginArray->GetLength(&pluginCount);
if (rv == NS_OK) {
uint32_t i;
for (i = 0; i < pluginCount; i++) {
nsCOMPtr<nsIDOMPlugin> plugin;
if (NS_SUCCEEDED(pluginArray->Item(i, getter_AddRefs(plugin))) &&
plugin) {
uint32_t mimeTypeCount = 0;
if (plugin->GetLength(&mimeTypeCount) == NS_OK)
pluginMimeTypeCount += mimeTypeCount;
}
}
// now we know how many there are, start gathering them.
mMimeTypeArray.SetCapacity(pluginMimeTypeCount);
MOZ_ASSERT(mMimeTypes.Length() >= mPluginMimeTypeCount);
mPluginMimeTypeCount = pluginMimeTypeCount;
mInited = true;
if (aIndex >= mPluginMimeTypeCount) {
return nullptr;
}
uint32_t k;
for (k = 0; k < pluginCount; k++) {
nsCOMPtr<nsIDOMPlugin> plugin;
if (NS_SUCCEEDED(pluginArray->Item(k, getter_AddRefs(plugin))) &&
plugin) {
uint32_t mimeTypeCount = 0;
if (plugin->GetLength(&mimeTypeCount) == NS_OK) {
nsCOMPtr<nsIDOMMimeType> item;
for (uint32_t j = 0; j < mimeTypeCount; j++) {
plugin->Item(j, getter_AddRefs(item));
mMimeTypeArray.AppendObject(item);
}
}
aFound = true;
return mMimeTypes[aIndex];
}
nsMimeType*
nsMimeTypeArray::NamedGetter(const nsAString& aName, bool &aFound)
{
aFound = false;
if (mMimeTypes.IsEmpty()) {
EnsureMimeTypes();
}
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
if (aName.Equals(mMimeTypes[i]->Type())) {
aFound = true;
return mMimeTypes[i];
}
}
// Now let's check with the MIME service.
nsCOMPtr<nsIMIMEService> mimeSrv = do_GetService("@mozilla.org/mime;1");
if (!mimeSrv) {
return nullptr;
}
nsCOMPtr<nsIMIMEInfo> mimeInfo;
mimeSrv->GetFromTypeAndExtension(NS_ConvertUTF16toUTF8(aName), EmptyCString(),
getter_AddRefs(mimeInfo));
if (!mimeInfo) {
return nullptr;
}
// Now we check whether we can really claim to support this type
nsHandlerInfoAction action = nsIHandlerInfo::saveToDisk;
mimeInfo->GetPreferredAction(&action);
if (action != nsIMIMEInfo::handleInternally) {
bool hasHelper = false;
mimeInfo->GetHasDefaultHandler(&hasHelper);
if (!hasHelper) {
nsCOMPtr<nsIHandlerApp> helper;
mimeInfo->GetPreferredApplicationHandler(getter_AddRefs(helper));
if (!helper) {
// mime info from the OS may not have a PreferredApplicationHandler
// so just check for an empty default description
nsAutoString defaultDescription;
mimeInfo->GetDefaultDescription(defaultDescription);
if (defaultDescription.IsEmpty()) {
// no support; just leave
return nullptr;
}
}
}
NS_RELEASE(pluginArray);
}
return rv;
// If we got here, we support this type! Say so.
aFound = true;
nsMimeType *mt = new nsMimeType(mWindow, aName);
mMimeTypes.AppendElement(mt);
return mt;
}
nsMimeType::nsMimeType(nsIDOMPlugin* aPlugin, nsIDOMMimeType* aMimeType)
uint32_t
nsMimeTypeArray::Length()
{
mPlugin = aPlugin;
mMimeType = aMimeType;
if (mMimeTypes.IsEmpty()) {
EnsureMimeTypes();
}
MOZ_ASSERT(mMimeTypes.Length() >= mPluginMimeTypeCount);
return mPluginMimeTypeCount;
}
void
nsMimeTypeArray::GetSupportedNames(nsTArray< nsString >& aRetval)
{
if (mMimeTypes.IsEmpty()) {
EnsureMimeTypes();
}
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
aRetval.AppendElement(mMimeTypes[i]->Type());
}
}
void
nsMimeTypeArray::EnsureMimeTypes()
{
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
if (!mMimeTypes.IsEmpty() || !win) {
return;
}
nsCOMPtr<nsIDOMNavigator> navigator;
win->GetNavigator(getter_AddRefs(navigator));
if (!navigator) {
return;
}
nsCOMPtr<nsISupports> pluginsSupports;
navigator->GetPlugins(getter_AddRefs(pluginsSupports));
nsCOMPtr<nsIObserver> pluginsObserver(do_QueryInterface(pluginsSupports));
nsPluginArray *pluginArray =
static_cast<nsPluginArray*>(pluginsObserver.get());
nsTArray<nsRefPtr<nsPluginElement> > plugins;
pluginArray->GetPlugins(plugins);
for (uint32_t i = 0; i < plugins.Length(); ++i) {
nsPluginElement *plugin = plugins[i];
mMimeTypes.AppendElements(plugin->MimeTypes());
}
mPluginMimeTypeCount = mMimeTypes.Length();
}
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsMimeType, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsMimeType, Release)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(nsMimeType)
nsMimeType::nsMimeType(nsWeakPtr aWindow, nsPluginElement* aPluginElement,
uint32_t aPluginTagMimeIndex, const nsAString& aType)
: mWindow(aWindow),
mPluginElement(aPluginElement),
mPluginTagMimeIndex(aPluginTagMimeIndex),
mType(aType)
{
SetIsDOMBinding();
}
nsMimeType::nsMimeType(nsWeakPtr aWindow, const nsAString& aType)
: mWindow(aWindow),
mPluginElement(nullptr),
mPluginTagMimeIndex(0),
mType(aType)
{
SetIsDOMBinding();
}
nsMimeType::~nsMimeType()
{
}
DOMCI_DATA(MimeType, nsMimeType)
// QueryInterface implementation for nsMimeType
NS_INTERFACE_MAP_BEGIN(nsMimeType)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIDOMMimeType)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MimeType)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsMimeType)
NS_IMPL_RELEASE(nsMimeType)
NS_IMETHODIMP
nsMimeType::GetDescription(nsAString& aDescription)
nsPIDOMWindow *
nsMimeType::GetParentObject() const
{
return mMimeType->GetDescription(aDescription);
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
MOZ_ASSERT(win);
return win;
}
NS_IMETHODIMP
nsMimeType::GetEnabledPlugin(nsIDOMPlugin** aEnabledPlugin)
JSObject*
nsMimeType::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
nsAutoString type;
GetType(type);
*aEnabledPlugin = mPlugin;
NS_IF_ADDREF(*aEnabledPlugin);
return NS_OK;
return MimeTypeBinding::Wrap(aCx, aScope, this);
}
NS_IMETHODIMP
nsMimeType::GetSuffixes(nsAString& aSuffixes)
void
nsMimeType::GetDescription(nsString& retval) const
{
return mMimeType->GetSuffixes(aSuffixes);
retval.Truncate();
if (mPluginElement) {
CopyUTF8toUTF16(mPluginElement->PluginTag()->
mMimeDescriptions[mPluginTagMimeIndex], retval);
}
}
NS_IMETHODIMP
nsMimeType::GetType(nsAString& aType)
nsPluginElement*
nsMimeType::GetEnabledPlugin() const
{
return mMimeType->GetType(aType);
return (mPluginElement && mPluginElement->PluginTag()->IsEnabled()) ?
mPluginElement : nullptr;
}
// QueryInterface implementation for nsHelperMimeType
NS_IMPL_ISUPPORTS1(nsHelperMimeType, nsIDOMMimeType)
NS_IMETHODIMP
nsHelperMimeType::GetDescription(nsAString& aDescription)
void
nsMimeType::GetSuffixes(nsString& retval) const
{
aDescription.Truncate();
return NS_OK;
retval.Truncate();
if (mPluginElement) {
CopyUTF8toUTF16(mPluginElement->PluginTag()->
mExtensions[mPluginTagMimeIndex], retval);
}
}
NS_IMETHODIMP
nsHelperMimeType::GetEnabledPlugin(nsIDOMPlugin** aEnabledPlugin)
void
nsMimeType::GetType(nsString& aRetval) const
{
*aEnabledPlugin = nullptr;
return NS_OK;
aRetval = mType;
}
NS_IMETHODIMP
nsHelperMimeType::GetSuffixes(nsAString& aSuffixes)
{
aSuffixes.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsHelperMimeType::GetType(nsAString& aType)
{
aType = mType;
return NS_OK;
}

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

@ -7,102 +7,94 @@
#ifndef nsMimeTypeArray_h___
#define nsMimeTypeArray_h___
#include "nsIDOMMimeTypeArray.h"
#include "nsIDOMMimeType.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsCOMArray.h"
#include "nsTArray.h"
#include "nsWeakReference.h"
#include "nsWrapperCache.h"
class nsIDOMNavigator;
class nsPIDOMWindow;
class nsPluginElement;
class nsMimeType;
// NB: Due to weak references, nsNavigator has intimate knowledge of our
// members.
class nsMimeTypeArray : public nsIDOMMimeTypeArray
class nsMimeTypeArray MOZ_FINAL : public nsISupports,
public nsWrapperCache
{
public:
nsMimeTypeArray(nsIDOMNavigator* navigator);
nsMimeTypeArray(nsWeakPtr aWindow);
virtual ~nsMimeTypeArray();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMMIMETYPEARRAY
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsMimeTypeArray)
nsPIDOMWindow* GetParentObject() const;
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
void Refresh();
nsIDOMMimeType* GetItemAt(uint32_t aIndex, nsresult* aResult);
nsIDOMMimeType* GetNamedItem(const nsAString& aName, nsresult* aResult);
// MimeTypeArray WebIDL methods
nsMimeType* Item(uint32_t index);
nsMimeType* NamedItem(const nsAString& name);
nsMimeType* IndexedGetter(uint32_t index, bool &found);
nsMimeType* NamedGetter(const nsAString& name, bool &found);
uint32_t Length();
void GetSupportedNames(nsTArray< nsString >& retval);
static nsMimeTypeArray* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsIDOMMimeTypeArray> array_qi = do_QueryInterface(aSupports);
protected:
void EnsureMimeTypes();
void Clear();
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMMimeTypeArray pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(array_qi == static_cast<nsIDOMMimeTypeArray*>(aSupports),
"Uh, fix QI!");
}
#endif
nsWeakPtr mWindow;
return static_cast<nsMimeTypeArray*>(aSupports);
}
// mMimeTypes contains all mime types handled by plugins followed by
// any other mime types that we handle internally and have been
// looked up before.
nsTArray<nsRefPtr<nsMimeType> > mMimeTypes;
// mPluginMimeTypeCount is the number of plugin mime types that we
// have in mMimeTypes. The plugin mime types are always at the
// beginning of the list.
uint32_t mPluginMimeTypeCount;
};
class nsMimeType MOZ_FINAL : public nsWrapperCache
{
public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsMimeType)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(nsMimeType)
nsMimeType(nsWeakPtr aWindow, nsPluginElement* aPluginElement,
uint32_t aPluginTagMimeIndex, const nsAString& aMimeType);
nsMimeType(nsWeakPtr aWindow, const nsAString& aMimeType);
virtual ~nsMimeType();
nsPIDOMWindow* GetParentObject() const;
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
void Invalidate()
{
// NB: This will cause GetMimeTypes to fail from now on.
mNavigator = nullptr;
Clear();
mPluginElement = nullptr;
}
private:
nsresult GetMimeTypes();
void Clear();
const nsString& Type() const
{
return mType;
}
// MimeType WebIDL methods
void GetDescription(nsString& retval) const;
nsPluginElement *GetEnabledPlugin() const;
void GetSuffixes(nsString& retval) const;
void GetType(nsString& retval) const;
protected:
nsIDOMNavigator* mNavigator;
// Number of mimetypes handled by plugins.
uint32_t mPluginMimeTypeCount;
// mMimeTypeArray contains all mimetypes handled by plugins
// (mPluginMimeTypeCount) and any mimetypes that we handle internally and
// have been looked up before. The number of items in mMimeTypeArray should
// thus always be equal to or higher than mPluginMimeTypeCount.
nsCOMArray<nsIDOMMimeType> mMimeTypeArray;
bool mInited;
};
nsWeakPtr mWindow;
class nsMimeType : public nsIDOMMimeType
{
public:
nsMimeType(nsIDOMPlugin* aPlugin, nsIDOMMimeType* aMimeType);
virtual ~nsMimeType();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMMIMETYPE
void DetachPlugin() { mPlugin = nullptr; }
protected:
nsIDOMPlugin* mPlugin;
nsCOMPtr<nsIDOMMimeType> mMimeType;
};
class nsHelperMimeType : public nsIDOMMimeType
{
public:
nsHelperMimeType(const nsAString& aType)
: mType(aType)
{
}
virtual ~nsHelperMimeType()
{
}
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMMIMETYPE
private:
// Weak pointer to the active plugin, if any.
nsPluginElement *mPluginElement;
uint32_t mPluginTagMimeIndex;
nsString mType;
};

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

@ -4,34 +4,29 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsPluginArray.h"
#include "nsContentUtils.h"
#include "mozilla/dom/PluginArrayBinding.h"
#include "mozilla/dom/PluginBinding.h"
#include "nsMimeTypeArray.h"
#include "Navigator.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMNavigator.h"
#include "nsIDOMMimeType.h"
#include "nsIPluginHost.h"
#include "nsIDocShell.h"
#include "nsIWebNavigation.h"
#include "nsDOMClassInfoID.h"
#include "nsError.h"
#include "nsPluginHost.h"
#include "nsIContentViewer.h"
#include "nsIDocument.h"
#include "nsPluginTags.h"
#include "nsIObserverService.h"
#include "nsIWeakReference.h"
#include "mozilla/Services.h"
#include "nsWeakReference.h"
#include "nsIInterfaceRequestorUtils.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
using namespace mozilla::dom;
nsPluginArray::nsPluginArray(Navigator* navigator,
nsIDocShell *aDocShell)
: mNavigator(navigator),
mPluginHost(do_GetService(MOZ_PLUGIN_HOST_CONTRACTID)),
mPluginCount(0),
mPluginArray(nullptr),
mDocShell(do_GetWeakReference(aDocShell))
nsPluginArray::nsPluginArray(nsWeakPtr aWindow)
: mWindow(aWindow)
{
SetIsDOMBinding();
}
void
@ -46,142 +41,132 @@ nsPluginArray::Init()
nsPluginArray::~nsPluginArray()
{
if (mPluginArray != nullptr) {
for (uint32_t i = 0; i < mPluginCount; i++) {
NS_IF_RELEASE(mPluginArray[i]);
}
delete[] mPluginArray;
}
}
DOMCI_DATA(PluginArray, nsPluginArray)
nsPIDOMWindow*
nsPluginArray::GetParentObject() const
{
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
MOZ_ASSERT(win);
return win;
}
// QueryInterface implementation for nsPluginArray
NS_INTERFACE_MAP_BEGIN(nsPluginArray)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMPluginArray)
NS_INTERFACE_MAP_ENTRY(nsIDOMPluginArray)
JSObject*
nsPluginArray::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return PluginArrayBinding::Wrap(aCx, aScope, this);
}
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPluginArray)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPluginArray)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPluginArray)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(PluginArray)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsPluginArray)
NS_IMPL_RELEASE(nsPluginArray)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsPluginArray,
mPlugins)
NS_IMETHODIMP
nsPluginArray::GetLength(uint32_t* aLength)
void
nsPluginArray::GetPlugins(nsTArray<nsRefPtr<nsPluginElement> >& aPlugins)
{
nsPluginHost *pluginHost = static_cast<nsPluginHost*>(mPluginHost.get());
if (AllowPlugins() && pluginHost)
return pluginHost->GetPluginCount(aLength);
*aLength = 0;
return NS_OK;
}
aPlugins.Clear();
bool
nsPluginArray::AllowPlugins()
{
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShell);
if (!docShell) {
return false;
if (!AllowPlugins()) {
return;
}
return docShell->PluginsAllowedInCurrentDoc();
}
nsIDOMPlugin*
nsPluginArray::GetItemAt(uint32_t aIndex, nsresult* aResult)
{
*aResult = NS_OK;
if (!AllowPlugins())
return nullptr;
if (mPluginArray == nullptr) {
*aResult = GetPlugins();
if (*aResult != NS_OK)
return nullptr;
if (mPlugins.IsEmpty()) {
EnsurePlugins();
}
return aIndex < mPluginCount ? mPluginArray[aIndex] : nullptr;
aPlugins = mPlugins;
}
NS_IMETHODIMP
nsPluginArray::Item(uint32_t aIndex, nsIDOMPlugin** aReturn)
nsPluginElement*
nsPluginArray::Item(uint32_t aIndex)
{
nsresult rv;
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex, &rv));
return rv;
bool unused;
return IndexedGetter(aIndex, unused);
}
nsIDOMPlugin*
nsPluginArray::GetNamedItem(const nsAString& aName, nsresult* aResult)
nsPluginElement*
nsPluginArray::NamedItem(const nsAString& aName)
{
*aResult = NS_OK;
bool unused;
return NamedGetter(aName, unused);
}
if (!AllowPlugins())
return nullptr;
void
nsPluginArray::Refresh(bool aReloadDocuments)
{
nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
if (mPluginArray == nullptr) {
*aResult = GetPlugins();
if (*aResult != NS_OK)
return nullptr;
if(!AllowPlugins() || !pluginHost) {
return;
}
for (uint32_t i = 0; i < mPluginCount; i++) {
nsAutoString pluginName;
nsIDOMPlugin* plugin = mPluginArray[i];
if (plugin->GetName(pluginName) == NS_OK && pluginName.Equals(aName)) {
return plugin;
// NS_ERROR_PLUGINS_PLUGINSNOTCHANGED on reloading plugins indicates
// that plugins did not change and was not reloaded
if (pluginHost->ReloadPlugins() ==
NS_ERROR_PLUGINS_PLUGINSNOTCHANGED) {
nsTArray<nsRefPtr<nsPluginTag> > newPluginTags;
pluginHost->GetPlugins(newPluginTags);
// Check if the number of plugins we know about are different from
// the number of plugin tags the plugin host knows about. If the
// lengths are different, we refresh. This is safe because we're
// notified for every plugin enabling/disabling event that
// happens, and therefore the lengths will be in sync only when
// the both arrays contain the same plugin tags (though as
// different types).
if (newPluginTags.Length() == mPlugins.Length()) {
return;
}
}
return nullptr;
}
mPlugins.Clear();
NS_IMETHODIMP
nsPluginArray::NamedItem(const nsAString& aName, nsIDOMPlugin** aReturn)
{
NS_PRECONDITION(nullptr != aReturn, "null arg");
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
nsresult rv;
nsCOMPtr<nsIDOMNavigator> navigator;
win->GetNavigator(getter_AddRefs(navigator));
NS_IF_ADDREF(*aReturn = GetNamedItem(aName, &rv));
return rv;
}
nsresult
nsPluginArray::GetPluginHost(nsIPluginHost** aPluginHost)
{
NS_ENSURE_ARG_POINTER(aPluginHost);
nsresult rv = NS_OK;
if (!mPluginHost) {
mPluginHost = do_GetService(MOZ_PLUGIN_HOST_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
return rv;
}
if (!navigator) {
return;
}
*aPluginHost = mPluginHost;
NS_IF_ADDREF(*aPluginHost);
static_cast<mozilla::dom::Navigator*>(navigator.get())->RefreshMIMEArray();
return rv;
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(win);
if (aReloadDocuments && webNav) {
webNav->Reload(nsIWebNavigation::LOAD_FLAGS_NONE);
}
}
nsPluginElement*
nsPluginArray::IndexedGetter(uint32_t aIndex, bool &aFound)
{
aFound = false;
if (!AllowPlugins()) {
return nullptr;
}
if (mPlugins.IsEmpty()) {
EnsurePlugins();
}
aFound = aIndex < mPlugins.Length();
return aFound ? mPlugins[aIndex] : nullptr;
}
void
nsPluginArray::Invalidate()
{
mDocShell = nullptr;
mNavigator = nullptr;
nsCOMPtr<nsIObserverService> obsService =
mozilla::services::GetObserverService();
if (obsService) {
@ -189,92 +174,63 @@ nsPluginArray::Invalidate()
}
}
NS_IMETHODIMP
nsPluginArray::Refresh(bool aReloadDocuments)
nsPluginElement*
nsPluginArray::NamedGetter(const nsAString& aName, bool &aFound)
{
nsresult res = NS_OK;
if (!AllowPlugins())
return NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA;
aFound = false;
if (!mPluginHost) {
mPluginHost = do_GetService(MOZ_PLUGIN_HOST_CONTRACTID, &res);
if (!AllowPlugins()) {
return nullptr;
}
if(NS_FAILED(res)) {
return res;
if (mPlugins.IsEmpty()) {
EnsurePlugins();
}
// NS_ERROR_PLUGINS_PLUGINSNOTCHANGED on reloading plugins indicates
// that plugins did not change and was not reloaded
bool pluginsNotChanged = false;
uint32_t currentPluginCount = 0;
if(mPluginHost) {
res = GetLength(&currentPluginCount);
NS_ENSURE_SUCCESS(res, res);
nsresult reloadResult = mPluginHost->ReloadPlugins();
// 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);
}
for (uint32_t i = 0; i < mPlugins.Length(); ++i) {
nsAutoString pluginName;
nsPluginElement* plugin = mPlugins[i];
plugin->GetName(pluginName);
// 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;
if (pluginName.Equals(aName)) {
aFound = true;
nsCOMPtr<nsIWebNavigation> webNav = do_QueryReferent(mDocShell);
if (mPluginArray != nullptr) {
for (uint32_t i = 0; i < mPluginCount; i++)
NS_IF_RELEASE(mPluginArray[i]);
delete[] mPluginArray;
}
mPluginCount = 0;
mPluginArray = nullptr;
if (mNavigator)
mNavigator->RefreshMIMEArray();
if (aReloadDocuments && webNav)
webNav->Reload(nsIWebNavigation::LOAD_FLAGS_NONE);
return res;
}
nsresult
nsPluginArray::GetPlugins()
{
nsresult rv = GetLength(&mPluginCount);
if (NS_SUCCEEDED(rv)) {
mPluginArray = new nsIDOMPlugin*[mPluginCount];
if (!mPluginArray)
return NS_ERROR_OUT_OF_MEMORY;
if (!mPluginCount)
return NS_OK;
nsPluginHost *pluginHost = static_cast<nsPluginHost*>(mPluginHost.get());
rv = pluginHost->GetPlugins(mPluginCount, mPluginArray);
if (NS_SUCCEEDED(rv)) {
// need to wrap each of these with a nsPluginElement, which
// is scriptable.
for (uint32_t i = 0; i < mPluginCount; i++) {
nsIDOMPlugin* wrapper = new nsPluginElement(mPluginArray[i]);
NS_IF_ADDREF(wrapper);
mPluginArray[i] = wrapper;
}
} else {
/* 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;
return plugin;
}
}
return rv;
return nullptr;
}
uint32_t
nsPluginArray::Length()
{
if (!AllowPlugins()) {
return 0;
}
if (mPlugins.IsEmpty()) {
EnsurePlugins();
}
return mPlugins.Length();
}
void
nsPluginArray::GetSupportedNames(nsTArray< nsString >& aRetval)
{
aRetval.Clear();
if (!AllowPlugins()) {
return;
}
for (uint32_t i = 0; i < mPlugins.Length(); ++i) {
nsAutoString pluginName;
mPlugins[i]->GetName(pluginName);
aRetval.AppendElement(pluginName);
}
}
NS_IMETHODIMP
@ -287,151 +243,179 @@ nsPluginArray::Observe(nsISupports *aSubject, const char *aTopic,
return NS_OK;
}
nsPluginElement::nsPluginElement(nsIDOMPlugin* plugin)
bool
nsPluginArray::AllowPlugins() const
{
mPlugin = plugin; // don't AddRef, see nsPluginArray::Item.
mMimeTypeCount = 0;
mMimeTypeArray = nullptr;
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(win);
return docShell && docShell->PluginsAllowedInCurrentDoc();
}
void
nsPluginArray::EnsurePlugins()
{
nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
if (!mPlugins.IsEmpty() || !pluginHost) {
// We already have an array of plugin elements, or no plugin host
return;
}
nsTArray<nsRefPtr<nsPluginTag> > pluginTags;
pluginHost->GetPlugins(pluginTags);
// need to wrap each of these with a nsPluginElement, which is
// scriptable.
for (uint32_t i = 0; i < pluginTags.Length(); ++i) {
mPlugins.AppendElement(new nsPluginElement(mWindow, pluginTags[i]));
}
}
// nsPluginElement implementation.
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPluginElement)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPluginElement)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPluginElement)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsPluginElement,
mMimeTypes)
nsPluginElement::nsPluginElement(nsWeakPtr aWindow,
nsPluginTag* aPluginTag)
: mWindow(aWindow),
mPluginTag(aPluginTag)
{
SetIsDOMBinding();
}
nsPluginElement::~nsPluginElement()
{
NS_IF_RELEASE(mPlugin);
if (mMimeTypeArray != nullptr) {
for (uint32_t i = 0; i < mMimeTypeCount; i++) {
nsMimeType* mt = static_cast<nsMimeType*>(mMimeTypeArray[i]);
if (mt) {
mt->DetachPlugin();
NS_RELEASE(mt);
}
}
delete[] mMimeTypeArray;
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
mMimeTypes[i]->Invalidate();
}
}
DOMCI_DATA(Plugin, nsPluginElement)
// QueryInterface implementation for nsPluginElement
NS_INTERFACE_MAP_BEGIN(nsPluginElement)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIDOMPlugin)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Plugin)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsPluginElement)
NS_IMPL_RELEASE(nsPluginElement)
NS_IMETHODIMP
nsPluginElement::GetDescription(nsAString& aDescription)
nsPIDOMWindow*
nsPluginElement::GetParentObject() const
{
return mPlugin->GetDescription(aDescription);
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
MOZ_ASSERT(win);
return win;
}
NS_IMETHODIMP
nsPluginElement::GetFilename(nsAString& aFilename)
JSObject*
nsPluginElement::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return mPlugin->GetFilename(aFilename);
return PluginBinding::Wrap(aCx, aScope, this);
}
NS_IMETHODIMP
nsPluginElement::GetVersion(nsAString& aVersion)
void
nsPluginElement::GetDescription(nsString& retval) const
{
return mPlugin->GetVersion(aVersion);
CopyUTF8toUTF16(mPluginTag->mDescription, retval);
}
NS_IMETHODIMP
nsPluginElement::GetName(nsAString& aName)
void
nsPluginElement::GetFilename(nsString& retval) const
{
return mPlugin->GetName(aName);
CopyUTF8toUTF16(mPluginTag->mFileName, retval);
}
NS_IMETHODIMP
nsPluginElement::GetLength(uint32_t* aLength)
void
nsPluginElement::GetVersion(nsString& retval) const
{
return mPlugin->GetLength(aLength);
CopyUTF8toUTF16(mPluginTag->mVersion, retval);
}
nsIDOMMimeType*
nsPluginElement::GetItemAt(uint32_t aIndex, nsresult *aResult)
void
nsPluginElement::GetName(nsString& retval) const
{
if (mMimeTypeArray == nullptr) {
*aResult = GetMimeTypes();
if (*aResult != NS_OK)
return nullptr;
}
if (aIndex >= mMimeTypeCount) {
*aResult = NS_ERROR_FAILURE;
return nullptr;
}
*aResult = NS_OK;
return mMimeTypeArray[aIndex];
CopyUTF8toUTF16(mPluginTag->mName, retval);
}
NS_IMETHODIMP
nsPluginElement::Item(uint32_t aIndex, nsIDOMMimeType** aReturn)
nsMimeType*
nsPluginElement::Item(uint32_t aIndex)
{
nsresult rv;
EnsureMimeTypes();
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex, &rv));
return rv;
return mMimeTypes.SafeElementAt(aIndex);
}
nsIDOMMimeType*
nsPluginElement::GetNamedItem(const nsAString& aName, nsresult *aResult)
nsMimeType*
nsPluginElement::NamedItem(const nsAString& aName)
{
if (mMimeTypeArray == nullptr) {
*aResult = GetMimeTypes();
if (*aResult != NS_OK)
return nullptr;
}
bool unused;
return NamedGetter(aName, unused);
}
*aResult = NS_OK;
for (uint32_t i = 0; i < mMimeTypeCount; i++) {
nsAutoString type;
nsIDOMMimeType* mimeType = mMimeTypeArray[i];
if (mimeType->GetType(type) == NS_OK && type.Equals(aName)) {
return mimeType;
nsMimeType*
nsPluginElement::IndexedGetter(uint32_t aIndex, bool &aFound)
{
EnsureMimeTypes();
aFound = aIndex < mMimeTypes.Length();
return aFound ? mMimeTypes[aIndex] : nullptr;
}
nsMimeType*
nsPluginElement::NamedGetter(const nsAString& aName, bool &aFound)
{
EnsureMimeTypes();
aFound = false;
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
if (mMimeTypes[i]->Type().Equals(aName)) {
aFound = true;
return mMimeTypes[i];
}
}
return nullptr;
}
NS_IMETHODIMP
nsPluginElement::NamedItem(const nsAString& aName, nsIDOMMimeType** aReturn)
uint32_t
nsPluginElement::Length()
{
nsresult rv;
EnsureMimeTypes();
NS_IF_ADDREF(*aReturn = GetNamedItem(aName, &rv));
return rv;
return mMimeTypes.Length();
}
nsresult
nsPluginElement::GetMimeTypes()
void
nsPluginElement::GetSupportedNames(nsTArray< nsString >& retval)
{
nsresult rv = mPlugin->GetLength(&mMimeTypeCount);
if (rv == NS_OK) {
mMimeTypeArray = new nsIDOMMimeType*[mMimeTypeCount];
if (mMimeTypeArray == nullptr)
return NS_ERROR_OUT_OF_MEMORY;
for (uint32_t i = 0; i < mMimeTypeCount; i++) {
nsCOMPtr<nsIDOMMimeType> mimeType;
rv = mPlugin->Item(i, getter_AddRefs(mimeType));
if (rv != NS_OK)
break;
mimeType = new nsMimeType(this, mimeType);
NS_IF_ADDREF(mMimeTypeArray[i] = mimeType);
}
EnsureMimeTypes();
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
retval.AppendElement(mMimeTypes[i]->Type());
}
}
nsTArray<nsRefPtr<nsMimeType> >&
nsPluginElement::MimeTypes()
{
EnsureMimeTypes();
return mMimeTypes;
}
void
nsPluginElement::EnsureMimeTypes()
{
if (!mMimeTypes.IsEmpty()) {
return;
}
for (uint32_t i = 0; i < mPluginTag->mMimeTypes.Length(); ++i) {
NS_ConvertUTF8toUTF16 type(mPluginTag->mMimeTypes[i]);
mMimeTypes.AppendElement(new nsMimeType(mWindow, this, i, type));
}
return rv;
}

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

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 sw=2 et tw=79: */
/* 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/. */
@ -6,118 +7,105 @@
#ifndef nsPluginArray_h___
#define nsPluginArray_h___
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsIDOMPluginArray.h"
#include "nsIDOMPlugin.h"
#include "nsIPluginHost.h"
#include "nsIURL.h"
#include "nsTArray.h"
#include "nsWeakReference.h"
#include "nsIObserver.h"
#include "nsWrapperCache.h"
#include "nsPluginTags.h"
namespace mozilla {
namespace dom {
class Navigator;
} // namespace dom
} // namespace mozilla
class nsPIDOMWindow;
class nsPluginElement;
class nsMimeType;
class nsPluginTag;
class nsIDocShell;
// NB: Due to weak references, Navigator has intimate knowledge of our
// internals.
class nsPluginArray : public nsIDOMPluginArray
, public nsIObserver
, public nsSupportsWeakReference
class nsPluginArray MOZ_FINAL : public nsIObserver,
public nsSupportsWeakReference,
public nsWrapperCache
{
public:
nsPluginArray(mozilla::dom::Navigator* navigator, nsIDocShell *aDocShell);
virtual ~nsPluginArray();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsPluginArray,
nsIObserver)
NS_DECL_ISUPPORTS
// nsIDOMPluginArray
NS_DECL_NSIDOMPLUGINARRAY
// nsIObserver
NS_DECL_NSIOBSERVER
nsPluginArray(nsWeakPtr aWindow);
virtual ~nsPluginArray();
nsPIDOMWindow* GetParentObject() const;
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
// 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);
nsIDOMPlugin* GetItemAt(uint32_t aIndex, nsresult* aResult);
nsIDOMPlugin* GetNamedItem(const nsAString& aName, nsresult* aResult);
static nsPluginArray* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsIDOMPluginArray> array_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMPluginArray pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(array_qi == static_cast<nsIDOMPluginArray*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<nsPluginArray*>(static_cast<nsIDOMPluginArray*>(aSupports));
}
private:
nsresult GetPlugins();
bool AllowPlugins();
public:
void Invalidate();
protected:
mozilla::dom::Navigator* mNavigator;
nsCOMPtr<nsIPluginHost> mPluginHost;
uint32_t mPluginCount;
nsIDOMPlugin** mPluginArray;
nsWeakPtr mDocShell;
};
void GetPlugins(nsTArray<nsRefPtr<nsPluginElement> >& aPlugins);
class nsPluginElement : public nsIDOMPlugin
{
public:
nsPluginElement(nsIDOMPlugin* plugin);
virtual ~nsPluginElement();
// PluginArray WebIDL methods
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMPLUGIN
nsIDOMMimeType* GetItemAt(uint32_t aIndex, nsresult* aResult);
nsIDOMMimeType* GetNamedItem(const nsAString& aName, nsresult* aResult);
static nsPluginElement* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsIDOMPlugin> plugin_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMPlugin pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(plugin_qi == static_cast<nsIDOMPlugin*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<nsPluginElement*>(aSupports);
}
nsPluginElement* Item(uint32_t aIndex);
nsPluginElement* NamedItem(const nsAString& aName);
void Refresh(bool aReloadDocuments);
nsPluginElement* IndexedGetter(uint32_t aIndex, bool &aFound);
nsPluginElement* NamedGetter(const nsAString& aName, bool &aFound);
uint32_t Length();
void GetSupportedNames(nsTArray< nsString >& aRetval);
private:
nsresult GetMimeTypes();
bool AllowPlugins() const;
void EnsurePlugins();
nsWeakPtr mWindow;
nsTArray<nsRefPtr<nsPluginElement> > mPlugins;
};
class nsPluginElement MOZ_FINAL : public nsISupports,
public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsPluginElement)
nsPluginElement(nsWeakPtr aWindow, nsPluginTag* aPluginTag);
virtual ~nsPluginElement();
nsPIDOMWindow* GetParentObject() const;
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
nsPluginTag* PluginTag() const
{
return mPluginTag;
}
// Plugin WebIDL methods
void GetDescription(nsString& retval) const;
void GetFilename(nsString& retval) const;
void GetVersion(nsString& retval) const;
void GetName(nsString& retval) const;
nsMimeType* Item(uint32_t index);
nsMimeType* NamedItem(const nsAString& name);
nsMimeType* IndexedGetter(uint32_t index, bool &found);
nsMimeType* NamedGetter(const nsAString& name, bool &found);
uint32_t Length();
void GetSupportedNames(nsTArray< nsString >& retval);
nsTArray<nsRefPtr<nsMimeType> >& MimeTypes();
protected:
nsIDOMPlugin* mPlugin;
uint32_t mMimeTypeCount;
nsIDOMMimeType** mMimeTypeArray;
void EnsureMimeTypes();
nsWeakPtr mWindow;
nsRefPtr<nsPluginTag> mPluginTag;
nsTArray<nsRefPtr<nsMimeType> > mMimeTypes;
};
#endif /* nsPluginArray_h___ */

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

@ -1376,6 +1376,29 @@ DOMInterfaces = {
'resultNotAddRefed': [ 'controllers', 'style' ]
},
'Plugin': {
'headerFile' : 'nsPluginArray.h',
'nativeType': 'nsPluginElement',
'resultNotAddRefed': [ 'item', 'namedItem' ]
},
'PluginArray': {
'nativeType': 'nsPluginArray',
'resultNotAddRefed': [ 'item', 'namedItem' ]
},
'MimeType': {
'headerFile' : 'nsMimeTypeArray.h',
'nativeType': 'nsMimeType',
'nativeOwnership': 'refcounted',
'resultNotAddRefed': [ 'enabledPlugin' ]
},
'MimeTypeArray': {
'nativeType': 'nsMimeTypeArray',
'resultNotAddRefed': [ 'item', 'namedItem' ]
},
####################################
# Test Interfaces of various sorts #
####################################

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

@ -44,10 +44,6 @@ interface nsIDOMMediaList;
// Base
interface nsIDOMWindow;
interface nsIDOMWindowCollection;
interface nsIDOMPlugin;
interface nsIDOMPluginArray;
interface nsIDOMMimeType;
interface nsIDOMMimeTypeArray;
interface nsIDOMNavigator;
interface nsIDOMScreen;
interface nsIDOMHistory;

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

@ -23,13 +23,9 @@ XPIDL_SOURCES += [
'nsIDOMJSWindow.idl',
'nsIDOMLocation.idl',
'nsIDOMMediaQueryList.idl',
'nsIDOMMimeType.idl',
'nsIDOMMimeTypeArray.idl',
'nsIDOMModalContentWindow.idl',
'nsIDOMNavigator.idl',
'nsIDOMPkcs11.idl',
'nsIDOMPlugin.idl',
'nsIDOMPluginArray.idl',
'nsIDOMScreen.idl',
'nsIDOMWindow.idl',
'nsIDOMWindowCollection.idl',

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

@ -1,15 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "domstubs.idl"
[scriptable, uuid(f6134682-f28b-11d2-8360-c90899049c3c)]
interface nsIDOMMimeType : nsISupports
{
readonly attribute DOMString description;
readonly attribute nsIDOMPlugin enabledPlugin;
readonly attribute DOMString suffixes;
readonly attribute DOMString type;
};

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

@ -1,15 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "domstubs.idl"
[scriptable, uuid(f6134683-f28b-11d2-8360-c90899049c3c)]
interface nsIDOMMimeTypeArray : nsISupports
{
readonly attribute unsigned long length;
nsIDOMMimeType item(in unsigned long index);
nsIDOMMimeType namedItem(in DOMString name);
};

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

@ -7,21 +7,21 @@
interface nsIIdleObserver;
[scriptable, uuid(b0ccf251-d793-48a1-94aa-cf840fe6639d)]
[scriptable, uuid(be8930d7-7543-45bd-8ba3-5678450c543a)]
interface nsIDOMNavigator : nsISupports
{
readonly attribute DOMString appCodeName;
readonly attribute DOMString appName;
readonly attribute DOMString appVersion;
readonly attribute DOMString language;
readonly attribute nsIDOMMimeTypeArray mimeTypes;
readonly attribute nsISupports mimeTypes;
readonly attribute DOMString platform;
readonly attribute DOMString oscpu;
readonly attribute DOMString vendor;
readonly attribute DOMString vendorSub;
readonly attribute DOMString product;
readonly attribute DOMString productSub;
readonly attribute nsIDOMPluginArray plugins;
readonly attribute nsISupports plugins;
readonly attribute DOMString userAgent;
readonly attribute boolean cookieEnabled;
readonly attribute boolean onLine;

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

@ -1,19 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "domstubs.idl"
[scriptable, uuid(ff69a292-c74d-4ef5-9d0f-86112fff2d5b)]
interface nsIDOMPlugin : nsISupports
{
readonly attribute DOMString description;
readonly attribute DOMString filename;
readonly attribute DOMString version;
readonly attribute DOMString name;
readonly attribute unsigned long length;
nsIDOMMimeType item(in unsigned long index);
nsIDOMMimeType namedItem(in DOMString name);
};

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

@ -1,17 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "domstubs.idl"
[scriptable, uuid(f6134680-f28b-11d2-8360-c90899049c3c)]
interface nsIDOMPluginArray : nsISupports
{
readonly attribute unsigned long length;
nsIDOMPlugin item(in unsigned long index);
nsIDOMPlugin namedItem(in DOMString name);
void refresh([optional] in boolean reloadDocuments);
};

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

@ -12,7 +12,6 @@
#include <stdio.h>
#include "prio.h"
#include "prmem.h"
#include "nsIComponentManager.h"
#include "nsNPAPIPlugin.h"
#include "nsNPAPIPluginStreamListener.h"
#include "nsNPAPIPluginInstance.h"
@ -23,7 +22,6 @@
#include "nsIObserverService.h"
#include "nsIHttpProtocolHandler.h"
#include "nsIHttpChannel.h"
#include "nsIHttpChannelInternal.h"
#include "nsIUploadChannel.h"
#include "nsIByteRangeRequest.h"
#include "nsIStreamListener.h"
@ -38,17 +36,11 @@
#if defined(XP_MACOSX)
#include "nsILocalFileMac.h"
#endif
#include "nsIInputStream.h"
#include "nsIIOService.h"
#include "nsIURL.h"
#include "nsIChannel.h"
#include "nsISeekableStream.h"
#include "nsNetUtil.h"
#include "nsIProgressEventSink.h"
#include "nsIDocument.h"
#include "nsICachingChannel.h"
#include "nsHashtable.h"
#include "nsIProxyInfo.h"
#include "nsPluginLogging.h"
#include "nsIScriptChannel.h"
#include "nsIBlocklistService.h"
@ -71,44 +63,20 @@
#include "nsIWindowWatcher.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIPrincipal.h"
#include "nsNetCID.h"
#include "nsIDOMPlugin.h"
#include "nsIDOMMimeType.h"
#include "nsMimeTypes.h"
#include "prprf.h"
#include "nsThreadUtils.h"
#include "nsIInputStreamTee.h"
#include "nsIInterfaceInfoManager.h"
#include "xptinfo.h"
#include "nsIMIMEService.h"
#include "nsCExternalHandlerService.h"
#include "nsIFileChannel.h"
#include "nsICharsetConverterManager.h"
#include "nsIPlatformCharset.h"
#include "nsIDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsXULAppAPI.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsPluginDirServiceProvider.h"
#include "nsError.h"
#include "nsUnicharUtils.h"
#include "nsPluginManifestLineReader.h"
#include "nsIWeakReferenceUtils.h"
#include "nsIDOMElement.h"
#include "nsIDOMHTMLObjectElement.h"
#include "nsIDOMHTMLEmbedElement.h"
#include "nsIPresShell.h"
#include "nsIWebNavigation.h"
#include "nsIDocShell.h"
#include "nsPluginNativeWindow.h"
#include "nsIScriptSecurityManager.h"
#include "nsIContentPolicy.h"
@ -1159,105 +1127,20 @@ nsPluginHost::IsPluginEnabledForExtension(const char* aExtension,
return NS_ERROR_FAILURE;
}
class DOMPluginImpl : public nsIDOMPlugin {
public:
NS_DECL_ISUPPORTS
DOMPluginImpl(nsPluginTag* aPluginTag) : mPluginTag(aPluginTag)
{
}
virtual ~DOMPluginImpl() {
}
NS_METHOD GetDescription(nsAString& aDescription)
{
CopyUTF8toUTF16(mPluginTag.mDescription, aDescription);
return NS_OK;
}
NS_METHOD GetFilename(nsAString& aFilename)
{
CopyUTF8toUTF16(mPluginTag.mFileName, aFilename);
return NS_OK;
}
NS_METHOD GetVersion(nsAString& aVersion)
{
CopyUTF8toUTF16(mPluginTag.mVersion, aVersion);
return NS_OK;
}
NS_METHOD GetName(nsAString& aName)
{
CopyUTF8toUTF16(mPluginTag.mName, aName);
return NS_OK;
}
NS_METHOD GetLength(uint32_t* aLength)
{
*aLength = mPluginTag.mMimeTypes.Length();
return NS_OK;
}
NS_METHOD Item(uint32_t aIndex, nsIDOMMimeType** aReturn)
{
nsIDOMMimeType* mimeType = new DOMMimeTypeImpl(&mPluginTag, aIndex);
NS_IF_ADDREF(mimeType);
*aReturn = mimeType;
return NS_OK;
}
NS_METHOD NamedItem(const nsAString& aName, nsIDOMMimeType** aReturn)
{
for (int i = mPluginTag.mMimeTypes.Length() - 1; i >= 0; --i) {
if (aName.Equals(NS_ConvertUTF8toUTF16(mPluginTag.mMimeTypes[i])))
return Item(i, aReturn);
}
return NS_OK;
}
private:
nsPluginTag mPluginTag;
};
NS_IMPL_ISUPPORTS1(DOMPluginImpl, nsIDOMPlugin)
nsresult
nsPluginHost::GetPluginCount(uint32_t* aPluginCount)
void
nsPluginHost::GetPlugins(nsTArray<nsRefPtr<nsPluginTag> >& aPluginArray)
{
LoadPlugins();
aPluginArray.Clear();
uint32_t count = 0;
LoadPlugins();
nsPluginTag* plugin = mPlugins;
while (plugin != nullptr) {
if (plugin->IsActive()) {
++count;
if (plugin->IsEnabled()) {
aPluginArray.AppendElement(plugin);
}
plugin = plugin->mNext;
}
*aPluginCount = count;
return NS_OK;
}
nsresult
nsPluginHost::GetPlugins(uint32_t aPluginCount, nsIDOMPlugin** aPluginArray)
{
LoadPlugins();
nsPluginTag* plugin = mPlugins;
for (uint32_t i = 0; i < aPluginCount && plugin; plugin = plugin->mNext) {
if (plugin->IsActive()) {
nsIDOMPlugin* domPlugin = new DOMPluginImpl(plugin);
NS_IF_ADDREF(domPlugin);
aPluginArray[i++] = domPlugin;
}
}
return NS_OK;
}
NS_IMETHODIMP
@ -2769,9 +2652,6 @@ nsPluginHost::ReadPluginInfo()
if (heapalloced)
delete [] heapalloced;
if (!tag)
continue;
// Import flags from registry into prefs for old registry versions
if (hasValidFlags && !pluginStateImported) {
tag->ImportFlagsToPrefs(tagflag);

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

@ -83,8 +83,7 @@ public:
nsresult IsPluginEnabledForExtension(const char* aExtension, const char* &aMimeType);
nsresult GetPluginCount(uint32_t* aPluginCount);
nsresult GetPlugins(uint32_t aPluginCount, nsIDOMPlugin** aPluginArray);
void GetPlugins(nsTArray<nsRefPtr<nsPluginTag> >& aPluginArray);
nsresult GetURL(nsISupports* pluginInst,
const char* url,

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

@ -15,7 +15,6 @@
#include "nsIUnicodeDecoder.h"
#include "nsIPlatformCharset.h"
#include "nsICharsetConverterManager.h"
#include "nsIDOMMimeType.h"
#include "nsPluginLogging.h"
#include "nsNPAPIPlugin.h"
#include "mozilla/TimeStamp.h"
@ -63,29 +62,8 @@ GetStatePrefNameForPlugin(nsPluginTag* aTag)
return MakePrefNameForPlugin("state", aTag);
}
NS_IMPL_ISUPPORTS1(DOMMimeTypeImpl, nsIDOMMimeType)
/* nsPluginTag */
nsPluginTag::nsPluginTag(nsPluginTag* aPluginTag)
: mName(aPluginTag->mName),
mDescription(aPluginTag->mDescription),
mMimeTypes(aPluginTag->mMimeTypes),
mMimeDescriptions(aPluginTag->mMimeDescriptions),
mExtensions(aPluginTag->mExtensions),
mLibrary(nullptr),
mIsJavaPlugin(aPluginTag->mIsJavaPlugin),
mIsFlashPlugin(aPluginTag->mIsFlashPlugin),
mFileName(aPluginTag->mFileName),
mFullPath(aPluginTag->mFullPath),
mVersion(aPluginTag->mVersion),
mLastModifiedTime(0),
mNiceFileName(),
mCachedBlocklistState(nsIBlocklistService::STATE_NOT_BLOCKED),
mCachedBlocklistStateValid(false)
{
}
nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo)
: mName(aPluginInfo->fName),
mDescription(aPluginInfo->fDescription),

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

@ -14,7 +14,6 @@
#include "nsIPluginTag.h"
#include "nsNPAPIPluginInstance.h"
#include "nsITimer.h"
#include "nsIDOMMimeType.h"
class nsPluginHost;
struct PRLibrary;
@ -36,7 +35,6 @@ public:
ePluginState_MaxValue = 3,
};
nsPluginTag(nsPluginTag* aPluginTag);
nsPluginTag(nsPluginInfo* aPluginInfo);
nsPluginTag(const char* aName,
const char* aDescription,
@ -101,50 +99,4 @@ private:
nsresult EnsureMembersAreUTF8();
};
class DOMMimeTypeImpl : public nsIDOMMimeType {
public:
NS_DECL_ISUPPORTS
DOMMimeTypeImpl(nsPluginTag* aTag, uint32_t aMimeTypeIndex)
{
if (!aTag)
return;
CopyUTF8toUTF16(aTag->mMimeDescriptions[aMimeTypeIndex], mDescription);
CopyUTF8toUTF16(aTag->mExtensions[aMimeTypeIndex], mSuffixes);
CopyUTF8toUTF16(aTag->mMimeTypes[aMimeTypeIndex], mType);
}
virtual ~DOMMimeTypeImpl() {
}
NS_METHOD GetDescription(nsAString& aDescription) MOZ_OVERRIDE
{
aDescription.Assign(mDescription);
return NS_OK;
}
NS_METHOD GetEnabledPlugin(nsIDOMPlugin** aEnabledPlugin) MOZ_OVERRIDE
{
// this has to be implemented by the DOM version.
*aEnabledPlugin = nullptr;
return NS_OK;
}
NS_METHOD GetSuffixes(nsAString& aSuffixes) MOZ_OVERRIDE
{
aSuffixes.Assign(mSuffixes);
return NS_OK;
}
NS_METHOD GetType(nsAString& aType) MOZ_OVERRIDE
{
aType.Assign(mType);
return NS_OK;
}
private:
nsString mDescription;
nsString mSuffixes;
nsString mType;
};
#endif // nsPluginTags_h_

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

@ -0,0 +1,12 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
interface MimeType {
readonly attribute DOMString description;
readonly attribute Plugin? enabledPlugin;
readonly attribute DOMString suffixes;
readonly attribute DOMString type;
};

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

@ -0,0 +1,12 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
interface MimeTypeArray {
readonly attribute unsigned long length;
getter MimeType? item(unsigned long index);
getter MimeType? namedItem(DOMString name);
};

16
dom/webidl/Plugin.webidl Normal file
Просмотреть файл

@ -0,0 +1,16 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
interface Plugin {
readonly attribute DOMString description;
readonly attribute DOMString filename;
readonly attribute DOMString version;
readonly attribute DOMString name;
readonly attribute unsigned long length;
getter MimeType? item(unsigned long index);
getter MimeType? namedItem(DOMString name);
};

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

@ -0,0 +1,14 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
interface PluginArray {
readonly attribute unsigned long length;
getter Plugin? item(unsigned long index);
getter Plugin? namedItem(DOMString name);
void refresh(optional boolean reloadDocuments = false);
};

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

@ -368,6 +368,10 @@ webidl_files = \
XULCommandEvent.webidl \
XULDocument.webidl \
XULElement.webidl \
Plugin.webidl \
PluginArray.webidl \
MimeType.webidl \
MimeTypeArray.webidl \
$(NULL)
ifdef MOZ_AUDIO_CHANNEL_MANAGER