зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1569077 - Part 1: Refactor layout debugger command line handling. r=dbaron
Differential Revision: https://phabricator.services.mozilla.com/D39467 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
adb9edf389
Коммит
7ce6716163
|
@ -22,41 +22,84 @@ nsLayoutDebugCLH::~nsLayoutDebugCLH() {}
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsLayoutDebugCLH, ICOMMANDLINEHANDLER)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLayoutDebugCLH::Handle(nsICommandLine* aCmdLine) {
|
||||
nsresult rv;
|
||||
static nsresult HandleFlagWithOptionalArgument(nsICommandLine* aCmdLine,
|
||||
const nsAString& aName,
|
||||
const nsAString& aDefaultValue,
|
||||
nsAString& aValue,
|
||||
bool& aFlagPresent) {
|
||||
aValue = EmptyString();
|
||||
aFlagPresent = false;
|
||||
|
||||
nsresult rv;
|
||||
int32_t idx;
|
||||
rv = aCmdLine->FindFlag(NS_LITERAL_STRING("layoutdebug"), false, &idx);
|
||||
|
||||
rv = aCmdLine->FindFlag(aName, false, &idx);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (idx < 0) return NS_OK;
|
||||
|
||||
aFlagPresent = true;
|
||||
|
||||
int32_t length;
|
||||
aCmdLine->GetLength(&length);
|
||||
|
||||
nsAutoString url;
|
||||
bool argPresent = false;
|
||||
|
||||
if (idx + 1 < length) {
|
||||
rv = aCmdLine->GetArgument(idx + 1, url);
|
||||
rv = aCmdLine->GetArgument(idx + 1, aValue);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!url.IsEmpty() && url.CharAt(0) == '-') url.Truncate();
|
||||
|
||||
if (!aValue.IsEmpty() && aValue.CharAt(0) == '-') {
|
||||
aValue = EmptyString();
|
||||
} else {
|
||||
argPresent = true;
|
||||
}
|
||||
}
|
||||
|
||||
aCmdLine->RemoveArguments(idx, idx + !url.IsEmpty());
|
||||
if (!argPresent) {
|
||||
aValue = aDefaultValue;
|
||||
}
|
||||
|
||||
return aCmdLine->RemoveArguments(idx, idx + argPresent);
|
||||
}
|
||||
|
||||
static nsresult AppendArg(nsIMutableArray* aArray, const nsAString& aString) {
|
||||
nsCOMPtr<nsISupportsString> s =
|
||||
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
|
||||
NS_ENSURE_TRUE(s, NS_ERROR_FAILURE);
|
||||
s->SetData(aString);
|
||||
return aArray->AppendElement(s);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLayoutDebugCLH::Handle(nsICommandLine* aCmdLine) {
|
||||
nsresult rv;
|
||||
bool flagPresent;
|
||||
|
||||
nsString url;
|
||||
|
||||
rv =
|
||||
HandleFlagWithOptionalArgument(aCmdLine, NS_LITERAL_STRING("layoutdebug"),
|
||||
EmptyString(), url, flagPresent);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!flagPresent) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMutableArray> argsArray = nsArray::Create();
|
||||
|
||||
if (!url.IsEmpty()) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsAutoCString resolvedSpec;
|
||||
|
||||
rv = aCmdLine->ResolveURI(url, getter_AddRefs(uri));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsISupportsString> scriptableURL =
|
||||
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
|
||||
NS_ENSURE_TRUE(scriptableURL, NS_ERROR_FAILURE);
|
||||
nsAutoCString resolvedSpec;
|
||||
|
||||
rv = uri->GetSpec(resolvedSpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
scriptableURL->SetData(NS_ConvertUTF8toUTF16(resolvedSpec));
|
||||
argsArray->AppendElement(scriptableURL);
|
||||
|
||||
rv = AppendArg(argsArray, NS_ConvertUTF8toUTF16(resolvedSpec));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWindowWatcher> wwatch =
|
||||
|
|
Загрузка…
Ссылка в новой задаче