Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 // vim:cindent:tabstop=4:expandtab:shiftwidth=4:
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsLayoutDebugCLH.h"
8 #include "nsString.h"
9 #include "plstr.h"
10 #include "nsCOMPtr.h"
11 #include "nsIWindowWatcher.h"
12 #include "nsIServiceManager.h"
13 #include "nsIDOMWindow.h"
14 #include "nsISupportsArray.h"
15 #include "nsISupportsPrimitives.h"
16 #include "nsICommandLine.h"
18 nsLayoutDebugCLH::nsLayoutDebugCLH()
19 {
20 }
22 nsLayoutDebugCLH::~nsLayoutDebugCLH()
23 {
24 }
26 NS_IMPL_ISUPPORTS(nsLayoutDebugCLH, ICOMMANDLINEHANDLER)
28 NS_IMETHODIMP
29 nsLayoutDebugCLH::Handle(nsICommandLine* aCmdLine)
30 {
31 nsresult rv;
33 int32_t idx;
34 rv = aCmdLine->FindFlag(NS_LITERAL_STRING("layoutdebug"), false, &idx);
35 NS_ENSURE_SUCCESS(rv, rv);
36 if (idx < 0)
37 return NS_OK;
39 int32_t length;
40 aCmdLine->GetLength(&length);
42 nsAutoString url;
43 if (idx + 1 < length) {
44 rv = aCmdLine->GetArgument(idx + 1, url);
45 NS_ENSURE_SUCCESS(rv, rv);
46 if (!url.IsEmpty() && url.CharAt(0) == '-')
47 url.Truncate();
48 }
50 aCmdLine->RemoveArguments(idx, idx + !url.IsEmpty());
52 nsCOMPtr<nsISupportsArray> argsArray =
53 do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv);
54 NS_ENSURE_SUCCESS(rv, rv);
56 if (!url.IsEmpty())
57 {
58 nsCOMPtr<nsISupportsString> scriptableURL =
59 do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
60 NS_ENSURE_TRUE(scriptableURL, NS_ERROR_FAILURE);
62 scriptableURL->SetData(url);
63 argsArray->AppendElement(scriptableURL);
64 }
66 nsCOMPtr<nsIWindowWatcher> wwatch =
67 do_GetService(NS_WINDOWWATCHER_CONTRACTID);
68 NS_ENSURE_TRUE(wwatch, NS_ERROR_FAILURE);
70 nsCOMPtr<nsIDOMWindow> opened;
71 wwatch->OpenWindow(nullptr, "chrome://layoutdebug/content/",
72 "_blank", "chrome,dialog=no,all", argsArray,
73 getter_AddRefs(opened));
74 aCmdLine->SetPreventDefault(true);
75 return NS_OK;
76 }
78 NS_IMETHODIMP
79 nsLayoutDebugCLH::GetHelpInfo(nsACString& aResult)
80 {
81 aResult.Assign(NS_LITERAL_CSTRING(" -layoutdebug [<url>] Start with Layout Debugger\n"));
82 return NS_OK;
83 }