Commit f7cab62d 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 678b7ca2
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 },
+6 −5
Original line number Diff line number Diff line
@@ -702,6 +702,12 @@ NS_InitXPCOM2(nsIServiceManager** aResult,
    NS_ADDREF(*aResult = nsComponentManagerImpl::gComponentManager);
  }

  // Ensure that XPConnect etc. is started up before we might call
  // into JS. For instance, on Android nsIDirectoryServiceProvider is
  // written in JS.
  nsCOMPtr<nsISupports> componentLoader =
    do_GetService("@mozilla.org/moz/jsloader;1");

  // After autoreg, but before we actually instantiate any components,
  // add any services listed in the "xpcom-directory-providers" category
  // to the directory service.
@@ -710,11 +716,6 @@ NS_InitXPCOM2(nsIServiceManager** aResult,
  // Init SharedThreadPool (which needs the service manager).
  SharedThreadPool::InitStatics();

  // Force layout to spin up so that nsContentUtils is available for cx stack
  // munging.
  nsCOMPtr<nsISupports> componentLoader =
    do_GetService("@mozilla.org/moz/jsloader;1");

  mozilla::ScriptPreloader::GetSingleton();
  mozilla::scache::StartupCache::GetSingleton();
  mozilla::AvailableMemoryTracker::Init();
+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?
Loading