Bug 1491560 - Remove the XPCOM registration for nsCommandLine; r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D5944
This commit is contained in:
Ehsan Akhgari
2018-09-15 05:00:49 -04:00
parent 8c6e3d874c
commit f9231bc798
15 changed files with 90 additions and 109 deletions

View File

@@ -720,6 +720,9 @@ interface nsIXPCComponents_Utils : nsISupports
/* Create a spellchecker object. */
nsIEditorSpellCheck createSpellChecker();
/* Create a commandline object. */
nsISupports createCommandLine();
};
/**

View File

@@ -42,6 +42,7 @@
#include "nsScriptError.h"
#include "GeckoProfiler.h"
#include "mozilla/EditorSpellCheck.h"
#include "nsCommandLine.h"
using namespace mozilla;
using namespace JS;
@@ -3221,6 +3222,15 @@ nsXPCComponents_Utils::CreateSpellChecker(nsIEditorSpellCheck** aSpellChecker)
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::CreateCommandLine(nsISupports** aCommandLine)
{
NS_ENSURE_ARG_POINTER(aCommandLine);
nsCOMPtr<nsISupports> commandLine = new nsCommandLine();
commandLine.forget(aCommandLine);
return NS_OK;
}
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/

View File

@@ -149,7 +149,7 @@ function run_test() {
attribute: "callback"
});
let cmdline = Cc["@mozilla.org/toolkit/command-line;1"].createInstance(Ci.nsICommandLine);
let cmdline = Cu.createCommandLine();
test_twice(cmdline, {});
test_twice(Object.getPrototypeOf(cmdline), {

View File

@@ -20,6 +20,10 @@ XPIDL_SOURCES += [
XPIDL_MODULE = 'commandlines'
EXPORTS += [
'nsCommandLine.h',
]
SOURCES += [
'nsCommandLine.cpp',
]

View File

@@ -2,7 +2,7 @@
* 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 "nsICommandLineRunner.h"
#include "nsCommandLine.h"
#include "nsICategoryManager.h"
#include "nsICommandLineHandler.h"
@@ -14,15 +14,11 @@
#include "nsISimpleEnumerator.h"
#include "mozilla/SimpleEnumerator.h"
#include "nsCOMPtr.h"
#include "mozilla/ModuleUtils.h"
#include "nsISupportsImpl.h"
#include "nsNativeCharsetUtils.h"
#include "nsNetUtil.h"
#include "nsIFileProtocolHandler.h"
#include "nsIURI.h"
#include "nsUnicharUtils.h"
#include "nsTArray.h"
#include "nsTextFormatter.h"
#include "nsXPCOMCID.h"
#include "plstr.h"
@@ -47,37 +43,6 @@
using mozilla::SimpleEnumerator;
class nsCommandLine final : public nsICommandLineRunner
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICOMMANDLINE
NS_DECL_NSICOMMANDLINERUNNER
nsCommandLine();
protected:
~nsCommandLine() = default;
typedef nsresult (*EnumerateHandlersCallback)(nsICommandLineHandler* aHandler,
nsICommandLine* aThis,
void *aClosure);
typedef nsresult (*EnumerateValidatorsCallback)(nsICommandLineValidator* aValidator,
nsICommandLine* aThis,
void *aClosure);
void appendArg(const char* arg);
MOZ_MUST_USE nsresult resolveShortcutURL(nsIFile* aFile, nsACString& outURL);
nsresult EnumerateHandlers(EnumerateHandlersCallback aCallback, void *aClosure);
nsresult EnumerateValidators(EnumerateValidatorsCallback aCallback, void *aClosure);
nsTArray<nsString> mArgs;
uint32_t mState;
nsCOMPtr<nsIFile> mWorkingDir;
nsCOMPtr<nsIDOMWindow> mWindowContext;
bool mPreventDefault;
};
nsCommandLine::nsCommandLine() :
mState(STATE_INITIAL_LAUNCH),
mPreventDefault(false)
@@ -617,25 +582,3 @@ nsCommandLine::GetHelpText(nsACString& aResult)
return NS_OK;
}
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCommandLine)
NS_DEFINE_NAMED_CID(NS_COMMANDLINE_CID);
static const mozilla::Module::CIDEntry kCommandLineCIDs[] = {
{ &kNS_COMMANDLINE_CID, false, nullptr, nsCommandLineConstructor },
{ nullptr }
};
static const mozilla::Module::ContractIDEntry kCommandLineContracts[] = {
{ "@mozilla.org/toolkit/command-line;1", &kNS_COMMANDLINE_CID },
{ nullptr }
};
static const mozilla::Module kCommandLineModule = {
mozilla::Module::kVersion,
kCommandLineCIDs,
kCommandLineContracts
};
NSMODULE_DEFN(CommandLineModule) = &kCommandLineModule;

View File

@@ -0,0 +1,50 @@
/* 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/. */
#ifndef nsCommandLine_h
#define nsCommandLine_h
#include "nsICommandLineRunner.h"
#include "nsCOMPtr.h"
#include "nsISupportsImpl.h"
#include "nsTArray.h"
class nsICommandLineHandler;
class nsICommandLineValidator;
class nsIDOMWindow;
class nsIFile;
class nsCommandLine final : public nsICommandLineRunner
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICOMMANDLINE
NS_DECL_NSICOMMANDLINERUNNER
nsCommandLine();
protected:
~nsCommandLine() = default;
typedef nsresult (*EnumerateHandlersCallback)(nsICommandLineHandler* aHandler,
nsICommandLine* aThis,
void *aClosure);
typedef nsresult (*EnumerateValidatorsCallback)(nsICommandLineValidator* aValidator,
nsICommandLine* aThis,
void *aClosure);
void appendArg(const char* arg);
MOZ_MUST_USE nsresult resolveShortcutURL(nsIFile* aFile, nsACString& outURL);
nsresult EnumerateHandlers(EnumerateHandlersCallback aCallback, void *aClosure);
nsresult EnumerateValidators(EnumerateValidatorsCallback aCallback, void *aClosure);
nsTArray<nsString> mArgs;
uint32_t mState;
nsCOMPtr<nsIFile> mWorkingDir;
nsCOMPtr<nsIDOMWindow> mWindowContext;
bool mPreventDefault;
};
#endif

View File

@@ -1,5 +1,5 @@
function run_test() {
var cmdLine = Cc["@mozilla.org/toolkit/command-line;1"].createInstance(Ci.nsICommandLine);
var cmdLine = Cu.createCommandLine();
try {
cmdLine.getArgument(cmdLine.length);
} catch (e) {}

View File

@@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function run_test() {
var clClass = Cc["@mozilla.org/toolkit/command-line;1"];
var commandLine = clClass.createInstance();
var commandLine = Cu.createCommandLine();
Assert.ok("length" in commandLine);
}

View File

@@ -3,8 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function run_test() {
var clClass = Cc["@mozilla.org/toolkit/command-line;1"];
var commandLine = clClass.createInstance();
var commandLine = Cu.createCommandLine();
var urlFile = do_get_file("../unit/data/test_bug410156.desktop");
var uri = commandLine.resolveURI(urlFile.path);
Assert.equal(uri.spec, "http://www.bug410156.com/");

View File

@@ -3,8 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function run_test() {
var clClass = Cc["@mozilla.org/toolkit/command-line;1"];
var commandLine = clClass.createInstance();
var commandLine = Cu.createCommandLine();
var urlFile = do_get_file("../unit/data/test_bug410156.url");
var uri = commandLine.resolveURI(urlFile.path);
Assert.equal(uri.spec, "http://www.bug410156.com/");

View File

@@ -23,7 +23,7 @@
#include "nsIWeakReference.h"
#include "nsGTKToolkit.h"
#include "nsICommandLineRunner.h"
#include "nsICommandLine.h"
#include "nsCommandLine.h"
#include "nsString.h"
#include "nsIFile.h"
@@ -155,12 +155,7 @@ const char*
nsRemoteService::HandleCommandLine(const char* aBuffer, nsIDOMWindow* aWindow,
uint32_t aTimestamp)
{
nsresult rv;
nsCOMPtr<nsICommandLineRunner> cmdline
(do_CreateInstance("@mozilla.org/toolkit/command-line;1", &rv));
if (NS_FAILED(rv))
return "509 internal error";
nsCOMPtr<nsICommandLineRunner> cmdline(new nsCommandLine());
// the commandline property is constructed as an array of int32_t
// followed by a series of null-terminated strings:
@@ -172,8 +167,8 @@ nsRemoteService::HandleCommandLine(const char* aBuffer, nsIDOMWindow* aWindow,
const char *wd = aBuffer + ((argc + 1) * sizeof(int32_t));
nsCOMPtr<nsIFile> lf;
rv = NS_NewNativeLocalFile(nsDependentCString(wd), true,
getter_AddRefs(lf));
nsresult rv = NS_NewNativeLocalFile(nsDependentCString(wd), true,
getter_AddRefs(lf));
if (NS_FAILED(rv))
return "509 internal error";

View File

@@ -26,12 +26,13 @@
#include "nsObjCExceptions.h"
#include "nsIFile.h"
#include "nsDirectoryServiceDefs.h"
#include "nsICommandLineRunner.h"
#include "nsCommandLine.h"
#include "nsIMacDockSupport.h"
#include "nsIStandaloneNativeMenu.h"
#include "nsILocalFileMac.h"
#include "nsString.h"
#include "nsCommandLineServiceMac.h"
#include "nsCommandLine.h"
class AutoAutoreleasePool {
public:
@@ -207,11 +208,7 @@ ProcessPendingGetURLAppleEvents()
if (NS_FAILED(rv))
return NO;
nsCOMPtr<nsICommandLineRunner> cmdLine(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
if (!cmdLine) {
NS_ERROR("Couldn't create command line!");
return NO;
}
nsCOMPtr<nsICommandLineRunner> cmdLine(new nsCommandLinew());
nsCString filePath;
rv = inFile->GetNativePath(filePath);
@@ -362,11 +359,7 @@ ProcessPendingGetURLAppleEvents()
if (CommandLineServiceMac::AddURLToCurrentCommandLine([urlString UTF8String]))
return;
nsCOMPtr<nsICommandLineRunner> cmdLine(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
if (!cmdLine) {
NS_ERROR("Couldn't create command line!");
return;
}
nsCOMPtr<nsICommandLineRunner> cmdLine(new nsCommandLine());
nsCOMPtr<nsIFile> workingDir;
nsresult rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR, getter_AddRefs(workingDir));
if (NS_FAILED(rv))

View File

@@ -59,7 +59,7 @@
#include "nsIMutableArray.h"
#include "nsICategoryManager.h"
#include "nsIChromeRegistry.h"
#include "nsICommandLineRunner.h"
#include "nsCommandLine.h"
#include "nsIComponentManager.h"
#include "nsIComponentRegistrar.h"
#include "nsIConsoleService.h"
@@ -1595,10 +1595,7 @@ static void DumpArbitraryHelp()
ScopedXPCOMStartup xpcom;
xpcom.Initialize();
nsCOMPtr<nsICommandLineRunner> cmdline
(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
if (!cmdline)
return;
nsCOMPtr<nsICommandLineRunner> cmdline(new nsCommandLine());
nsCString text;
rv = cmdline->GetHelpText(text);
@@ -4673,8 +4670,7 @@ XREMain::XRE_mainRun()
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
if (!mShuttingDown) {
cmdLine = do_CreateInstance("@mozilla.org/toolkit/command-line;1");
NS_ENSURE_TRUE(cmdLine, NS_ERROR_FAILURE);
cmdLine = new nsCommandLine();
rv = cmdLine->Init(gArgc, gArgv, workingDir,
nsICommandLine::STATE_INITIAL_LAUNCH);
@@ -4740,8 +4736,7 @@ XREMain::XRE_mainRun()
#ifdef XP_MACOSX
// we re-initialize the command-line service and do appleevents munging
// after we are sure that we're not restarting
cmdLine = do_CreateInstance("@mozilla.org/toolkit/command-line;1");
NS_ENSURE_TRUE(cmdLine, NS_ERROR_FAILURE);
cmdLine = new nsCommandLine();
CommandLineServiceMac::SetupMacCommandLine(gArgc, gArgv, false);

View File

@@ -15,7 +15,7 @@
#include "nsIAppShellService.h"
#include "nsIAppStartup.h"
#include "nsIBaseWindow.h"
#include "nsICommandLineRunner.h"
#include "nsCommandLine.h"
#include "mozIDOMWindow.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeOwner.h"
@@ -167,9 +167,7 @@ nsNativeAppSupportCocoa::ReOpen()
char* argv[] = { nullptr };
// use an empty command line to make the right kind(s) of window open
nsCOMPtr<nsICommandLineRunner> cmdLine
(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
NS_ENSURE_TRUE(cmdLine, NS_ERROR_FAILURE);
nsCOMPtr<nsICommandLineRunner> cmdLine(new nsCommandLine());
nsresult rv;
rv = cmdLine->Init(0, argv, nullptr,

View File

@@ -10,7 +10,7 @@
#include "nsXULAppAPI.h"
#include "nsString.h"
#include "nsIBrowserDOMWindow.h"
#include "nsICommandLineRunner.h"
#include "nsCommandLine.h"
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
@@ -1236,12 +1236,7 @@ nsNativeAppSupportWin::HandleCommandLine(const char* aCmdLineString,
const char *p;
nsAutoCString arg;
nsCOMPtr<nsICommandLineRunner> cmdLine
(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
if (!cmdLine) {
NS_ERROR("Couldn't create command line!");
return;
}
nsCOMPtr<nsICommandLineRunner> cmdLine(new nsCommandLine());
// Parse command line args according to MS spec
// (see "Parsing C++ Command-Line Arguments" at
@@ -1480,9 +1475,7 @@ nsNativeAppSupportWin::OpenBrowserWindow()
// open a new window if caller requested it or if anything above failed
char* argv[] = { 0 };
nsCOMPtr<nsICommandLineRunner> cmdLine
(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
NS_ENSURE_TRUE(cmdLine, NS_ERROR_FAILURE);
nsCOMPtr<nsICommandLineRunner> cmdLine(new nsCommandLine());
rv = cmdLine->Init(0, argv, nullptr, nsICommandLine::STATE_REMOTE_EXPLICIT);
NS_ENSURE_SUCCESS(rv, rv);