michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: // vim:cindent:tabstop=4:expandtab:shiftwidth=4: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsLayoutDebugCLH.h" michael@0: #include "nsString.h" michael@0: #include "plstr.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIWindowWatcher.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsIDOMWindow.h" michael@0: #include "nsISupportsArray.h" michael@0: #include "nsISupportsPrimitives.h" michael@0: #include "nsICommandLine.h" michael@0: michael@0: nsLayoutDebugCLH::nsLayoutDebugCLH() michael@0: { michael@0: } michael@0: michael@0: nsLayoutDebugCLH::~nsLayoutDebugCLH() michael@0: { michael@0: } michael@0: michael@0: NS_IMPL_ISUPPORTS(nsLayoutDebugCLH, ICOMMANDLINEHANDLER) michael@0: michael@0: NS_IMETHODIMP michael@0: nsLayoutDebugCLH::Handle(nsICommandLine* aCmdLine) michael@0: { michael@0: nsresult rv; michael@0: michael@0: int32_t idx; michael@0: rv = aCmdLine->FindFlag(NS_LITERAL_STRING("layoutdebug"), false, &idx); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: if (idx < 0) michael@0: return NS_OK; michael@0: michael@0: int32_t length; michael@0: aCmdLine->GetLength(&length); michael@0: michael@0: nsAutoString url; michael@0: if (idx + 1 < length) { michael@0: rv = aCmdLine->GetArgument(idx + 1, url); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: if (!url.IsEmpty() && url.CharAt(0) == '-') michael@0: url.Truncate(); michael@0: } michael@0: michael@0: aCmdLine->RemoveArguments(idx, idx + !url.IsEmpty()); michael@0: michael@0: nsCOMPtr argsArray = michael@0: do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: if (!url.IsEmpty()) michael@0: { michael@0: nsCOMPtr scriptableURL = michael@0: do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID); michael@0: NS_ENSURE_TRUE(scriptableURL, NS_ERROR_FAILURE); michael@0: michael@0: scriptableURL->SetData(url); michael@0: argsArray->AppendElement(scriptableURL); michael@0: } michael@0: michael@0: nsCOMPtr wwatch = michael@0: do_GetService(NS_WINDOWWATCHER_CONTRACTID); michael@0: NS_ENSURE_TRUE(wwatch, NS_ERROR_FAILURE); michael@0: michael@0: nsCOMPtr opened; michael@0: wwatch->OpenWindow(nullptr, "chrome://layoutdebug/content/", michael@0: "_blank", "chrome,dialog=no,all", argsArray, michael@0: getter_AddRefs(opened)); michael@0: aCmdLine->SetPreventDefault(true); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsLayoutDebugCLH::GetHelpInfo(nsACString& aResult) michael@0: { michael@0: aResult.Assign(NS_LITERAL_CSTRING(" -layoutdebug [] Start with Layout Debugger\n")); michael@0: return NS_OK; michael@0: } michael@0: