Commit eefa2cf0 authored by Andrew McCreight's avatar Andrew McCreight
Browse files

Bug 1497707, part 4 - Only support loading JS files in the component manager r=froydnj

JS is the only file extension actually supported, and there are a few
layers of cruft that can be eliminated if we specialize it.

This eliminates one XPCOM registration of the JS component loader.

Depends on D8170

Differential Revision: https://phabricator.services.mozilla.com/D8171

--HG--
extra : moz-landing-system : lando
parent be89d903
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -39,8 +39,5 @@ NS_DEFINE_NAMED_CID(MOZ_JSSUBSCRIPTLOADER_CID);
  { MOZJSCOMPONENTLOADER_CONTRACTID, &kMOZJSCOMPONENTLOADER_CID },            \
  { MOZJSSUBSCRIPTLOADER_CONTRACTID, &kMOZ_JSSUBSCRIPTLOADER_CID },

#define XPCONNECT_CATEGORIES \
  { "module-loader", "js", MOZJSCOMPONENTLOADER_CONTRACTID },

nsresult xpcModuleCtor();
void xpcModuleDtor();
+0 −1
Original line number Diff line number Diff line
@@ -668,7 +668,6 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
};

static const mozilla::Module::CategoryEntry kLayoutCategories[] = {
  XPCONNECT_CATEGORIES
  { "content-policy", NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID, NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID },
  { "content-policy", NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID, NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID },
  { "content-policy", "CSPService", CSPSERVICE_CONTRACTID },
+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ LOCAL_INCLUDES += [
    '../build',
    '../ds',
    '/chrome',
    '/js/xpconnect/loader',
    '/modules/libjar',
]

+7 −36
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include "ManifestParser.h"
#include "nsNetUtil.h"
#include "mozilla/Services.h"
#include "mozJSComponentLoader.h"

#include "mozilla/GenericFactory.h"
#include "nsSupportsPrimitives.h"
@@ -773,19 +774,6 @@ nsComponentManagerImpl::RereadChromeManifests(bool aChromeOnly)
  }
}

bool
nsComponentManagerImpl::KnownModule::EnsureLoader()
{
  if (!mLoader) {
    nsCString extension;
    mFile.GetURIString(extension);
    CutExtension(extension);
    mLoader =
      nsComponentManagerImpl::gComponentManager->LoaderForExtension(extension);
  }
  return !!mLoader;
}

bool
nsComponentManagerImpl::KnownModule::Load()
{
@@ -793,11 +781,15 @@ nsComponentManagerImpl::KnownModule::Load()
    return false;
  }
  if (!mModule) {
    if (!EnsureLoader()) {
    nsCString extension;
    mFile.GetURIString(extension);
    CutExtension(extension);
    if (!extension.Equals("js")) {
      return false;
    }

    mModule = mLoader->LoadModule(mFile);
    RefPtr<mozJSComponentLoader> loader = mozJSComponentLoader::GetOrCreate();
    mModule = loader->LoadModule(mFile);

    if (!mModule) {
      mFailed = true;
@@ -844,7 +836,6 @@ nsresult nsComponentManagerImpl::Shutdown(void)
  // Release all cached factories
  mContractIDs.Clear();
  mFactories.Clear(); // XXX release the objects, don't just clear
  mLoaderMap.Clear();
  mKnownModules.Clear();
  mKnownStaticModules.Clear();

@@ -1521,23 +1512,6 @@ nsComponentManagerImpl::GetServiceByContractID(const char* aContractID,
  return NS_OK;
}

already_AddRefed<mozilla::ModuleLoader>
nsComponentManagerImpl::LoaderForExtension(const nsACString& aExt)
{
  nsCOMPtr<mozilla::ModuleLoader> loader = mLoaderMap.Get(aExt);
  if (!loader) {
    loader = do_GetServiceFromCategory(NS_LITERAL_CSTRING("module-loader"),
                                       aExt);
    if (!loader) {
      return nullptr;
    }

    mLoaderMap.Put(aExt, loader);
  }

  return loader.forget();
}

NS_IMETHODIMP
nsComponentManagerImpl::RegisterFactory(const nsCID& aClass,
                                        const char* aName,
@@ -1746,8 +1720,6 @@ nsComponentManagerImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
{
  size_t n = aMallocSizeOf(this);

  n += mLoaderMap.ShallowSizeOfExcludingThis(aMallocSizeOf);

  n += mFactories.ShallowSizeOfExcludingThis(aMallocSizeOf);
  for (auto iter = mFactories.ConstIter(); !iter.Done(); iter.Next()) {
    n += iter.Data()->SizeOfIncludingThis(aMallocSizeOf);
@@ -1774,7 +1746,6 @@ nsComponentManagerImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)

  // Measurement of the following members may be added later if DMD finds it is
  // worthwhile:
  // - mLoaderMap's keys and values
  // - mMon
  // - sModuleLocations' entries
  // - mKnownStaticModules' entries?
+0 −6
Original line number Diff line number Diff line
@@ -142,9 +142,6 @@ public:

  nsresult FreeServices();

  already_AddRefed<mozilla::ModuleLoader> LoaderForExtension(const nsACString& aExt);
  nsInterfaceHashtable<nsCStringHashKey, mozilla::ModuleLoader> mLoaderMap;

  already_AddRefed<nsIFactory> FindFactory(const nsCID& aClass);
  already_AddRefed<nsIFactory> FindFactory(const char* aContractID,
                                           uint32_t aContractIDLen);
@@ -196,7 +193,6 @@ public:
    explicit KnownModule(mozilla::FileLocation& aFile)
      : mModule(nullptr)
      , mFile(aFile)
      , mLoader(nullptr)
      , mLoaded(false)
      , mFailed(false)
    {
@@ -209,7 +205,6 @@ public:
      }
    }

    bool EnsureLoader();
    bool Load();

    const mozilla::Module* Module() const { return mModule; }
@@ -223,7 +218,6 @@ public:
  private:
    const mozilla::Module* mModule;
    mozilla::FileLocation mFile;
    nsCOMPtr<mozilla::ModuleLoader> mLoader;
    bool mLoaded;
    bool mFailed;
  };