layout/tools/layout-debug/src/nsLayoutDebugCLH.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/tools/layout-debug/src/nsLayoutDebugCLH.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +// vim:cindent:tabstop=4:expandtab:shiftwidth=4:
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "nsLayoutDebugCLH.h"
    1.11 +#include "nsString.h"
    1.12 +#include "plstr.h"
    1.13 +#include "nsCOMPtr.h"
    1.14 +#include "nsIWindowWatcher.h"
    1.15 +#include "nsIServiceManager.h"
    1.16 +#include "nsIDOMWindow.h"
    1.17 +#include "nsISupportsArray.h"
    1.18 +#include "nsISupportsPrimitives.h"
    1.19 +#include "nsICommandLine.h"
    1.20 +
    1.21 +nsLayoutDebugCLH::nsLayoutDebugCLH()
    1.22 +{
    1.23 +}
    1.24 +
    1.25 +nsLayoutDebugCLH::~nsLayoutDebugCLH()
    1.26 +{
    1.27 +}
    1.28 +
    1.29 +NS_IMPL_ISUPPORTS(nsLayoutDebugCLH, ICOMMANDLINEHANDLER)
    1.30 +
    1.31 +NS_IMETHODIMP
    1.32 +nsLayoutDebugCLH::Handle(nsICommandLine* aCmdLine)
    1.33 +{
    1.34 +    nsresult rv;
    1.35 +
    1.36 +    int32_t idx;
    1.37 +    rv = aCmdLine->FindFlag(NS_LITERAL_STRING("layoutdebug"), false, &idx);
    1.38 +    NS_ENSURE_SUCCESS(rv, rv);
    1.39 +    if (idx < 0)
    1.40 +      return NS_OK;
    1.41 +
    1.42 +    int32_t length;
    1.43 +    aCmdLine->GetLength(&length);
    1.44 +
    1.45 +    nsAutoString url;
    1.46 +    if (idx + 1 < length) {
    1.47 +        rv = aCmdLine->GetArgument(idx + 1, url);
    1.48 +        NS_ENSURE_SUCCESS(rv, rv);
    1.49 +        if (!url.IsEmpty() && url.CharAt(0) == '-')
    1.50 +            url.Truncate();
    1.51 +    }
    1.52 +
    1.53 +    aCmdLine->RemoveArguments(idx, idx + !url.IsEmpty());
    1.54 +
    1.55 +    nsCOMPtr<nsISupportsArray> argsArray =
    1.56 +        do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv);
    1.57 +    NS_ENSURE_SUCCESS(rv, rv);
    1.58 +
    1.59 +    if (!url.IsEmpty())
    1.60 +    {
    1.61 +        nsCOMPtr<nsISupportsString> scriptableURL =
    1.62 +            do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
    1.63 +        NS_ENSURE_TRUE(scriptableURL, NS_ERROR_FAILURE);
    1.64 +  
    1.65 +        scriptableURL->SetData(url);
    1.66 +        argsArray->AppendElement(scriptableURL);
    1.67 +    }
    1.68 +
    1.69 +    nsCOMPtr<nsIWindowWatcher> wwatch =
    1.70 +        do_GetService(NS_WINDOWWATCHER_CONTRACTID);
    1.71 +    NS_ENSURE_TRUE(wwatch, NS_ERROR_FAILURE);
    1.72 +
    1.73 +    nsCOMPtr<nsIDOMWindow> opened;
    1.74 +    wwatch->OpenWindow(nullptr, "chrome://layoutdebug/content/",
    1.75 +                       "_blank", "chrome,dialog=no,all", argsArray,
    1.76 +                       getter_AddRefs(opened));
    1.77 +    aCmdLine->SetPreventDefault(true);
    1.78 +    return NS_OK;
    1.79 +}
    1.80 +
    1.81 +NS_IMETHODIMP
    1.82 +nsLayoutDebugCLH::GetHelpInfo(nsACString& aResult)
    1.83 +{
    1.84 +    aResult.Assign(NS_LITERAL_CSTRING("  -layoutdebug [<url>] Start with Layout Debugger\n"));
    1.85 +    return NS_OK;
    1.86 +}
    1.87 +

mercurial