Bug 757726 - Part 4: Consolidate duplicate code into EnsurePlugins() and EnsureMimeTypes(). r=johns

This commit is contained in:
Chris Peterson 2013-10-20 00:05:05 -07:00
parent 16ac26e186
commit 42e3c14d60
4 changed files with 25 additions and 38 deletions

View File

@ -79,9 +79,7 @@ nsMimeTypeArray::IndexedGetter(uint32_t aIndex, bool &aFound)
{
aFound = false;
if (mMimeTypes.IsEmpty()) {
EnsureMimeTypes();
}
EnsurePluginMimeTypes();
MOZ_ASSERT(mMimeTypes.Length() >= mPluginMimeTypeCount);
@ -99,9 +97,7 @@ nsMimeTypeArray::NamedGetter(const nsAString& aName, bool &aFound)
{
aFound = false;
if (mMimeTypes.IsEmpty()) {
EnsureMimeTypes();
}
EnsurePluginMimeTypes();
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
if (aName.Equals(mMimeTypes[i]->Type())) {
@ -161,9 +157,7 @@ nsMimeTypeArray::NamedGetter(const nsAString& aName, bool &aFound)
uint32_t
nsMimeTypeArray::Length()
{
if (mMimeTypes.IsEmpty()) {
EnsureMimeTypes();
}
EnsurePluginMimeTypes();
MOZ_ASSERT(mMimeTypes.Length() >= mPluginMimeTypeCount);
@ -173,9 +167,7 @@ nsMimeTypeArray::Length()
void
nsMimeTypeArray::GetSupportedNames(nsTArray< nsString >& aRetval)
{
if (mMimeTypes.IsEmpty()) {
EnsureMimeTypes();
}
EnsurePluginMimeTypes();
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
aRetval.AppendElement(mMimeTypes[i]->Type());
@ -183,7 +175,7 @@ nsMimeTypeArray::GetSupportedNames(nsTArray< nsString >& aRetval)
}
void
nsMimeTypeArray::EnsureMimeTypes()
nsMimeTypeArray::EnsurePluginMimeTypes()
{
if (!mMimeTypes.IsEmpty() || !mWindow) {
return;

View File

@ -41,7 +41,7 @@ public:
void GetSupportedNames(nsTArray< nsString >& retval);
protected:
void EnsureMimeTypes();
void EnsurePluginMimeTypes();
void Clear();
nsCOMPtr<nsPIDOMWindow> mWindow;

View File

@ -76,9 +76,7 @@ nsPluginArray::GetMimeTypes(nsTArray<nsRefPtr<nsMimeType> >& aMimeTypes)
return;
}
if (mPlugins.IsEmpty()) {
EnsurePlugins();
}
EnsurePlugins();
for (uint32_t i = 0; i < mPlugins.Length(); ++i) {
nsPluginElement *plugin = mPlugins[i];
@ -154,9 +152,7 @@ nsPluginArray::IndexedGetter(uint32_t aIndex, bool &aFound)
return nullptr;
}
if (mPlugins.IsEmpty()) {
EnsurePlugins();
}
EnsurePlugins();
aFound = aIndex < mPlugins.Length();
@ -182,9 +178,7 @@ nsPluginArray::NamedGetter(const nsAString& aName, bool &aFound)
return nullptr;
}
if (mPlugins.IsEmpty()) {
EnsurePlugins();
}
EnsurePlugins();
for (uint32_t i = 0; i < mPlugins.Length(); ++i) {
nsAutoString pluginName;
@ -208,9 +202,7 @@ nsPluginArray::Length()
return 0;
}
if (mPlugins.IsEmpty()) {
EnsurePlugins();
}
EnsurePlugins();
return mPlugins.Length();
}
@ -253,11 +245,14 @@ nsPluginArray::AllowPlugins() const
void
nsPluginArray::EnsurePlugins()
{
if (!mPlugins.IsEmpty()) {
// We already have an array of plugin elements.
return;
}
nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
if (!mPlugins.IsEmpty() || !pluginHost) {
// We already have an array of plugin elements, or no plugin host
if (!pluginHost) {
// We have no plugin host.
return;
}
@ -330,7 +325,7 @@ nsPluginElement::GetName(nsString& retval) const
nsMimeType*
nsPluginElement::Item(uint32_t aIndex)
{
EnsureMimeTypes();
EnsurePluginMimeTypes();
return mMimeTypes.SafeElementAt(aIndex);
}
@ -345,7 +340,7 @@ nsPluginElement::NamedItem(const nsAString& aName)
nsMimeType*
nsPluginElement::IndexedGetter(uint32_t aIndex, bool &aFound)
{
EnsureMimeTypes();
EnsurePluginMimeTypes();
aFound = aIndex < mMimeTypes.Length();
@ -355,7 +350,7 @@ nsPluginElement::IndexedGetter(uint32_t aIndex, bool &aFound)
nsMimeType*
nsPluginElement::NamedGetter(const nsAString& aName, bool &aFound)
{
EnsureMimeTypes();
EnsurePluginMimeTypes();
aFound = false;
@ -373,7 +368,7 @@ nsPluginElement::NamedGetter(const nsAString& aName, bool &aFound)
uint32_t
nsPluginElement::Length()
{
EnsureMimeTypes();
EnsurePluginMimeTypes();
return mMimeTypes.Length();
}
@ -381,7 +376,7 @@ nsPluginElement::Length()
void
nsPluginElement::GetSupportedNames(nsTArray< nsString >& retval)
{
EnsureMimeTypes();
EnsurePluginMimeTypes();
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
retval.AppendElement(mMimeTypes[i]->Type());
@ -391,13 +386,13 @@ nsPluginElement::GetSupportedNames(nsTArray< nsString >& retval)
nsTArray<nsRefPtr<nsMimeType> >&
nsPluginElement::MimeTypes()
{
EnsureMimeTypes();
EnsurePluginMimeTypes();
return mMimeTypes;
}
void
nsPluginElement::EnsureMimeTypes()
nsPluginElement::EnsurePluginMimeTypes()
{
if (!mMimeTypes.IsEmpty()) {
return;

View File

@ -97,7 +97,7 @@ public:
nsTArray<nsRefPtr<nsMimeType> >& MimeTypes();
protected:
void EnsureMimeTypes();
void EnsurePluginMimeTypes();
nsCOMPtr<nsPIDOMWindow> mWindow;
nsRefPtr<nsPluginTag> mPluginTag;