mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-12 10:40:12 +00:00
First Checked In.
This commit is contained in:
parent
b952773b92
commit
b546b154cf
247
dom/src/base/nsMimeTypeArray.cpp
Normal file
247
dom/src/base/nsMimeTypeArray.cpp
Normal file
@ -0,0 +1,247 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsMimeTypeArray.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIDOMNavigator.h"
|
||||
#include "nsIDOMPluginArray.h"
|
||||
#include "nsIDOMPlugin.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
MimeTypeArrayImpl::MimeTypeArrayImpl(nsIDOMNavigator* navigator)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mScriptObject = nsnull;
|
||||
mNavigator = navigator;
|
||||
mMimeTypeCount = 0;
|
||||
mMimeTypeArray = nsnull;
|
||||
}
|
||||
|
||||
MimeTypeArrayImpl::~MimeTypeArrayImpl()
|
||||
{
|
||||
if (mMimeTypeArray != nsnull) {
|
||||
for (int i = 0; i < mMimeTypeCount; i++) {
|
||||
NS_IF_RELEASE(mMimeTypeArray[i]);
|
||||
}
|
||||
delete[] mMimeTypeArray;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(MimeTypeArrayImpl)
|
||||
NS_IMPL_RELEASE(MimeTypeArrayImpl)
|
||||
|
||||
NS_IMETHODIMP MimeTypeArrayImpl::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsIScriptObjectOwner::GetIID())) {
|
||||
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIDOMMimeTypeArray::GetIID())) {
|
||||
*aInstancePtrResult = (void*) ((nsIDOMMimeTypeArray*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MimeTypeArrayImpl::SetScriptObject(void *aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MimeTypeArrayImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
|
||||
nsresult res = NS_OK;
|
||||
if (nsnull == mScriptObject) {
|
||||
res = NS_NewScriptMimeTypeArray(aContext, (nsISupports*)(nsIDOMMimeTypeArray*)this, mNavigator, &mScriptObject);
|
||||
}
|
||||
|
||||
*aScriptObject = mScriptObject;
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MimeTypeArrayImpl::GetLength(PRUint32* aLength)
|
||||
{
|
||||
if (mMimeTypeArray == nsnull) {
|
||||
nsresult rv = GetMimeTypes();
|
||||
if (rv != NS_OK)
|
||||
return rv;
|
||||
}
|
||||
*aLength = mMimeTypeCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MimeTypeArrayImpl::Item(PRUint32 aIndex, nsIDOMMimeType** aReturn)
|
||||
{
|
||||
if (mMimeTypeArray == nsnull) {
|
||||
nsresult rv = GetMimeTypes();
|
||||
if (rv != NS_OK)
|
||||
return rv;
|
||||
}
|
||||
if (aIndex >= 0 && aIndex < mMimeTypeCount) {
|
||||
*aReturn = mMimeTypeArray[aIndex];
|
||||
NS_IF_ADDREF(*aReturn);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MimeTypeArrayImpl::NamedItem(const nsString& aName, nsIDOMMimeType** aReturn)
|
||||
{
|
||||
*aReturn = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult MimeTypeArrayImpl::GetMimeTypes()
|
||||
{
|
||||
nsIDOMPluginArray* pluginArray = nsnull;
|
||||
nsresult rv = mNavigator->GetPlugins(&pluginArray);
|
||||
if (rv == NS_OK) {
|
||||
// count up all possible MimeTypes, and collect them here. Later, we'll remove
|
||||
// duplicates.
|
||||
mMimeTypeCount = 0;
|
||||
PRUint32 pluginCount = 0;
|
||||
rv = pluginArray->GetLength(&pluginCount);
|
||||
if (rv == NS_OK) {
|
||||
for (PRUint32 i = 0; i < pluginCount; i++) {
|
||||
nsIDOMPlugin* plugin = nsnull;
|
||||
if (pluginArray->Item(i, &plugin) == NS_OK) {
|
||||
PRUint32 mimeTypeCount = 0;
|
||||
if (plugin->GetLength(&mimeTypeCount) == NS_OK)
|
||||
mMimeTypeCount += mimeTypeCount;
|
||||
NS_RELEASE(plugin);
|
||||
}
|
||||
}
|
||||
// now we know how many there are, start gathering them.
|
||||
mMimeTypeArray = new nsIDOMMimeType*[mMimeTypeCount];
|
||||
if (mMimeTypeArray == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
PRUint32 mimeTypeIndex = 0;
|
||||
for (PRUint32 i = 0; i < pluginCount; i++) {
|
||||
nsIDOMPlugin* plugin = nsnull;
|
||||
if (pluginArray->Item(i, &plugin) == NS_OK) {
|
||||
PRUint32 mimeTypeCount = 0;
|
||||
if (plugin->GetLength(&mimeTypeCount) == NS_OK) {
|
||||
for (PRUint32 j = 0; j < mimeTypeCount; j++)
|
||||
plugin->Item(j, &mMimeTypeArray[mimeTypeIndex++]);
|
||||
}
|
||||
NS_RELEASE(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_RELEASE(pluginArray);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
MimeTypeElementImpl::MimeTypeElementImpl(nsIDOMPlugin* aPlugin, nsIDOMMimeType* aMimeType)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mScriptObject = nsnull;
|
||||
mPlugin = aPlugin;
|
||||
mMimeType = aMimeType;
|
||||
}
|
||||
|
||||
MimeTypeElementImpl::~MimeTypeElementImpl()
|
||||
{
|
||||
NS_IF_RELEASE(mMimeType);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(MimeTypeElementImpl)
|
||||
NS_IMPL_RELEASE(MimeTypeElementImpl)
|
||||
|
||||
NS_IMETHODIMP MimeTypeElementImpl::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsIScriptObjectOwner::GetIID())) {
|
||||
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIDOMMimeType::GetIID())) {
|
||||
*aInstancePtrResult = (void*) ((nsIDOMMimeType*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MimeTypeElementImpl::SetScriptObject(void *aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MimeTypeElementImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
|
||||
nsresult res = NS_OK;
|
||||
if (nsnull == mScriptObject) {
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
res = NS_NewScriptMimeType(aContext, (nsISupports*)(nsIDOMMimeType*)this, global, &mScriptObject);
|
||||
NS_IF_RELEASE(global);
|
||||
}
|
||||
|
||||
*aScriptObject = mScriptObject;
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MimeTypeElementImpl::GetDescription(nsString& aDescription)
|
||||
{
|
||||
return mMimeType->GetDescription(aDescription);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MimeTypeElementImpl::GetEnabledPlugin(nsIDOMPlugin** aEnabledPlugin)
|
||||
{
|
||||
*aEnabledPlugin = mPlugin;
|
||||
NS_IF_ADDREF(mPlugin);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MimeTypeElementImpl::GetSuffixes(nsString& aSuffixes)
|
||||
{
|
||||
return mMimeType->GetSuffixes(aSuffixes);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MimeTypeElementImpl::GetType(nsString& aType)
|
||||
{
|
||||
return mMimeType->GetType(aType);
|
||||
}
|
73
dom/src/base/nsMimeTypeArray.h
Normal file
73
dom/src/base/nsMimeTypeArray.h
Normal file
@ -0,0 +1,73 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsMimeTypeArray_h___
|
||||
#define nsMimeTypeArray_h___
|
||||
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMMimeTypeArray.h"
|
||||
#include "nsIDOMMimeType.h"
|
||||
|
||||
class nsIDOMNavigator;
|
||||
|
||||
class MimeTypeArrayImpl : public nsIScriptObjectOwner, public nsIDOMMimeTypeArray {
|
||||
public:
|
||||
MimeTypeArrayImpl(nsIDOMNavigator* navigator);
|
||||
virtual ~MimeTypeArrayImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
NS_IMETHOD GetLength(PRUint32* aLength);
|
||||
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMMimeType** aReturn);
|
||||
NS_IMETHOD NamedItem(const nsString& aName, nsIDOMMimeType** aReturn);
|
||||
|
||||
private:
|
||||
nsresult GetMimeTypes();
|
||||
|
||||
protected:
|
||||
void *mScriptObject;
|
||||
nsIDOMNavigator* mNavigator;
|
||||
PRUint32 mMimeTypeCount;
|
||||
nsIDOMMimeType** mMimeTypeArray;
|
||||
};
|
||||
|
||||
class MimeTypeElementImpl : public nsIScriptObjectOwner, public nsIDOMMimeType {
|
||||
public:
|
||||
MimeTypeElementImpl(nsIDOMPlugin* aPlugin, nsIDOMMimeType* aMimeType);
|
||||
virtual ~MimeTypeElementImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
NS_IMETHOD GetDescription(nsString& aDescription);
|
||||
NS_IMETHOD GetEnabledPlugin(nsIDOMPlugin** aEnabledPlugin);
|
||||
NS_IMETHOD GetSuffixes(nsString& aSuffixes);
|
||||
NS_IMETHOD GetType(nsString& aType);
|
||||
|
||||
protected:
|
||||
void *mScriptObject;
|
||||
nsIDOMPlugin* mPlugin;
|
||||
nsIDOMMimeType* mMimeType;
|
||||
};
|
||||
|
||||
#endif /* nsMimeTypeArray_h___ */
|
325
dom/src/base/nsPluginArray.cpp
Normal file
325
dom/src/base/nsPluginArray.cpp
Normal file
@ -0,0 +1,325 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsPluginArray.h"
|
||||
#include "nsMimeTypeArray.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIDOMNavigator.h"
|
||||
#include "nsIDOMMimeType.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPluginHost.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
|
||||
|
||||
PluginArrayImpl::PluginArrayImpl(nsIDOMNavigator* navigator)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mScriptObject = nsnull;
|
||||
mNavigator = navigator; // don't ADDREF here, needed for parent of script object.
|
||||
|
||||
if (nsServiceManager::GetService(kPluginManagerCID, nsIPluginHost::GetIID(), (nsISupports**)&mPluginHost) != NS_OK)
|
||||
mPluginHost = nsnull;
|
||||
|
||||
mPluginCount = 0;
|
||||
mPluginArray = nsnull;
|
||||
}
|
||||
|
||||
PluginArrayImpl::~PluginArrayImpl()
|
||||
{
|
||||
if (mPluginHost != nsnull)
|
||||
nsServiceManager::ReleaseService(kPluginManagerCID, mPluginHost);
|
||||
|
||||
if (mPluginArray != nsnull) {
|
||||
for (int i = 0; i < mPluginCount; i++) {
|
||||
NS_IF_RELEASE(mPluginArray[i]);
|
||||
}
|
||||
delete[] mPluginArray;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(PluginArrayImpl)
|
||||
NS_IMPL_RELEASE(PluginArrayImpl)
|
||||
|
||||
NS_IMETHODIMP PluginArrayImpl::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsIScriptObjectOwner::GetIID())) {
|
||||
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIDOMPluginArray::GetIID())) {
|
||||
*aInstancePtrResult = (void*) ((nsIDOMPluginArray*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginArrayImpl::SetScriptObject(void *aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginArrayImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
|
||||
nsresult res = NS_OK;
|
||||
if (nsnull == mScriptObject) {
|
||||
res = NS_NewScriptPluginArray(aContext, (nsISupports*)(nsIDOMPluginArray*)this, mNavigator, &mScriptObject);
|
||||
}
|
||||
|
||||
*aScriptObject = mScriptObject;
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginArrayImpl::GetLength(PRUint32* aLength)
|
||||
{
|
||||
return mPluginHost->GetPluginCount(aLength);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginArrayImpl::Item(PRUint32 aIndex, nsIDOMPlugin** aReturn)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aReturn, "null arg");
|
||||
|
||||
if (mPluginArray == nsnull) {
|
||||
nsresult rv = GetPlugins();
|
||||
if (rv != NS_OK)
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (aIndex >= 0 && aIndex < mPluginCount) {
|
||||
*aReturn = mPluginArray[aIndex];
|
||||
NS_IF_ADDREF(*aReturn);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginArrayImpl::NamedItem(const nsString& aName, nsIDOMPlugin** aReturn)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aReturn, "null arg");
|
||||
|
||||
if (mPluginArray == nsnull) {
|
||||
nsresult rv = GetPlugins();
|
||||
if (rv != NS_OK)
|
||||
return rv;
|
||||
}
|
||||
|
||||
*aReturn = nsnull;
|
||||
|
||||
for (int i = 0; i < mPluginCount; i++) {
|
||||
nsString pluginName;
|
||||
nsIDOMPlugin* plugin = mPluginArray[i];
|
||||
if (plugin->GetName(pluginName) == NS_OK) {
|
||||
if (pluginName == aName) {
|
||||
*aReturn = plugin;
|
||||
NS_IF_ADDREF(plugin);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginArrayImpl::Refresh(PRBool aReloadDocuments)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult PluginArrayImpl::GetPlugins()
|
||||
{
|
||||
nsresult rv = mPluginHost->GetPluginCount(&mPluginCount);
|
||||
if (rv == NS_OK) {
|
||||
mPluginArray = new nsIDOMPlugin*[mPluginCount];
|
||||
if (mPluginArray != nsnull) {
|
||||
rv = mPluginHost->GetPlugins(mPluginCount, mPluginArray);
|
||||
if (rv == NS_OK) {
|
||||
// need to wrap each of these with a PluginElementImpl, which is scriptable.
|
||||
for (int i = 0; i < mPluginCount; i++) {
|
||||
nsIDOMPlugin* wrapper = new PluginElementImpl(mPluginArray[i]);
|
||||
NS_IF_ADDREF(wrapper);
|
||||
mPluginArray[i] = wrapper;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
PluginElementImpl::PluginElementImpl(nsIDOMPlugin* plugin)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mScriptObject = nsnull;
|
||||
mPlugin = plugin; // don't AddRef, see PluginArrayImpl::Item.
|
||||
mMimeTypeCount = 0;
|
||||
mMimeTypeArray = nsnull;
|
||||
}
|
||||
|
||||
PluginElementImpl::~PluginElementImpl()
|
||||
{
|
||||
NS_IF_RELEASE(mPlugin);
|
||||
|
||||
if (mMimeTypeArray != nsnull) {
|
||||
for (int i = 0; i < mMimeTypeCount; i++)
|
||||
NS_IF_RELEASE(mMimeTypeArray[i]);
|
||||
delete[] mMimeTypeArray;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(PluginElementImpl)
|
||||
NS_IMPL_RELEASE(PluginElementImpl)
|
||||
|
||||
NS_IMETHODIMP PluginElementImpl::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsIScriptObjectOwner::GetIID())) {
|
||||
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIDOMPlugin::GetIID())) {
|
||||
*aInstancePtrResult = (void*) ((nsIDOMPlugin*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginElementImpl::SetScriptObject(void *aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginElementImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
|
||||
nsresult res = NS_OK;
|
||||
if (nsnull == mScriptObject) {
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
res = NS_NewScriptPlugin(aContext, (nsISupports*)(nsIDOMPlugin*)this, global, &mScriptObject);
|
||||
NS_IF_RELEASE(global);
|
||||
}
|
||||
|
||||
*aScriptObject = mScriptObject;
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginElementImpl::GetDescription(nsString& aDescription)
|
||||
{
|
||||
return mPlugin->GetDescription(aDescription);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginElementImpl::GetFilename(nsString& aFilename)
|
||||
{
|
||||
return mPlugin->GetFilename(aFilename);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginElementImpl::GetName(nsString& aName)
|
||||
{
|
||||
return mPlugin->GetName(aName);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginElementImpl::GetLength(PRUint32* aLength)
|
||||
{
|
||||
return mPlugin->GetLength(aLength);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginElementImpl::Item(PRUint32 aIndex, nsIDOMMimeType** aReturn)
|
||||
{
|
||||
if (mMimeTypeArray == nsnull) {
|
||||
nsresult rv = GetMimeTypes();
|
||||
if (rv != NS_OK)
|
||||
return rv;
|
||||
}
|
||||
if (aIndex >= 0 && aIndex < mMimeTypeCount) {
|
||||
nsIDOMMimeType* mimeType = mMimeTypeArray[aIndex];
|
||||
NS_IF_ADDREF(mimeType);
|
||||
*aReturn = mimeType;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP PluginElementImpl::NamedItem(const nsString& aName, nsIDOMMimeType** aReturn)
|
||||
{
|
||||
if (mMimeTypeArray == nsnull) {
|
||||
nsresult rv = GetMimeTypes();
|
||||
if (rv != NS_OK)
|
||||
return rv;
|
||||
}
|
||||
for (int i = 0; i < mMimeTypeCount; i++) {
|
||||
nsString type;
|
||||
nsIDOMMimeType* mimeType = mMimeTypeArray[i];
|
||||
if (mimeType->GetType(type) == NS_OK) {
|
||||
if (type == aName) {
|
||||
*aReturn = mimeType;
|
||||
NS_ADDREF(mimeType);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult PluginElementImpl::GetMimeTypes()
|
||||
{
|
||||
nsresult rv = mPlugin->GetLength(&mMimeTypeCount);
|
||||
if (rv == NS_OK) {
|
||||
mMimeTypeArray = new nsIDOMMimeType*[mMimeTypeCount];
|
||||
if (mMimeTypeArray == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
for (int i = 0; i < mMimeTypeCount; i++) {
|
||||
nsIDOMMimeType* mimeType = nsnull;
|
||||
rv = mPlugin->Item(i, &mimeType);
|
||||
if (rv != NS_OK)
|
||||
break;
|
||||
mimeType = new MimeTypeElementImpl(this, mimeType);
|
||||
NS_IF_ADDREF(mimeType);
|
||||
mMimeTypeArray[i] = mimeType;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
82
dom/src/base/nsPluginArray.h
Normal file
82
dom/src/base/nsPluginArray.h
Normal file
@ -0,0 +1,82 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsPluginArray_h___
|
||||
#define nsPluginArray_h___
|
||||
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMPluginArray.h"
|
||||
#include "nsIDOMPlugin.h"
|
||||
|
||||
class nsIDOMNavigator;
|
||||
class nsIPluginHost;
|
||||
|
||||
class PluginArrayImpl : public nsIScriptObjectOwner, public nsIDOMPluginArray {
|
||||
public:
|
||||
PluginArrayImpl(nsIDOMNavigator* navigator);
|
||||
virtual ~PluginArrayImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
NS_IMETHOD GetLength(PRUint32* aLength);
|
||||
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMPlugin** aReturn);
|
||||
NS_IMETHOD NamedItem(const nsString& aName, nsIDOMPlugin** aReturn);
|
||||
NS_IMETHOD Refresh(PRBool aReloadDocuments);
|
||||
|
||||
private:
|
||||
nsresult GetPlugins();
|
||||
|
||||
protected:
|
||||
void *mScriptObject;
|
||||
nsIDOMNavigator* mNavigator;
|
||||
nsIPluginHost* mPluginHost;
|
||||
PRUint32 mPluginCount;
|
||||
nsIDOMPlugin** mPluginArray;
|
||||
};
|
||||
|
||||
class PluginElementImpl : public nsIScriptObjectOwner, public nsIDOMPlugin {
|
||||
public:
|
||||
PluginElementImpl(nsIDOMPlugin* plugin);
|
||||
virtual ~PluginElementImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
NS_IMETHOD GetDescription(nsString& aDescription);
|
||||
NS_IMETHOD GetFilename(nsString& aFilename);
|
||||
NS_IMETHOD GetName(nsString& aName);
|
||||
NS_IMETHOD GetLength(PRUint32* aLength);
|
||||
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMMimeType** aReturn);
|
||||
NS_IMETHOD NamedItem(const nsString& aName, nsIDOMMimeType** aReturn);
|
||||
|
||||
private:
|
||||
nsresult GetMimeTypes();
|
||||
|
||||
protected:
|
||||
void *mScriptObject;
|
||||
nsIDOMPlugin* mPlugin;
|
||||
PRUint32 mMimeTypeCount;
|
||||
nsIDOMMimeType** mMimeTypeArray;
|
||||
};
|
||||
|
||||
#endif /* nsPluginArray_h___ */
|
Loading…
x
Reference in New Issue
Block a user