diff --git a/extensions/layout-debug/src/Makefile.in b/extensions/layout-debug/src/Makefile.in index ed141cbbd5d..17044d833c5 100644 --- a/extensions/layout-debug/src/Makefile.in +++ b/extensions/layout-debug/src/Makefile.in @@ -63,6 +63,7 @@ REQUIRES = xpcom \ pref \ appshell \ appcomps \ + toolkitcomps \ $(NULL) XPIDLSRCS = \ diff --git a/extensions/layout-debug/src/nsDebugFactory.cpp b/extensions/layout-debug/src/nsDebugFactory.cpp index bf65802da3f..8410871a52a 100644 --- a/extensions/layout-debug/src/nsDebugFactory.cpp +++ b/extensions/layout-debug/src/nsDebugFactory.cpp @@ -43,11 +43,49 @@ #include "nsLayoutDebuggingTools.h" #include "nsLayoutDebugCLH.h" #include "nsIGenericFactory.h" +#include "nsICategoryManager.h" +#include "nsIServiceManager.h" NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegressionTester) NS_GENERIC_FACTORY_CONSTRUCTOR(nsLayoutDebuggingTools) NS_GENERIC_FACTORY_CONSTRUCTOR(nsLayoutDebugCLH) +#ifdef MOZ_XUL_APP + +static NS_IMETHODIMP +RegisterCommandLineHandlers(nsIComponentManager* compMgr, nsIFile* path, + const char *location, const char *type, + const nsModuleComponentInfo *info) +{ + nsresult rv; + nsCOMPtr catMan (do_GetService(NS_CATEGORYMANAGER_CONTRACTID)); + NS_ENSURE_TRUE(catMan, NS_ERROR_FAILURE); + + rv = catMan->AddCategoryEntry("command-line-handler", "m-layoutdebug", + "@mozilla.org/commandlinehandler/general-startup;1?type=layoutdebug", + PR_TRUE, PR_TRUE, nsnull); + if (NS_FAILED(rv)) + return NS_ERROR_FAILURE; + + return NS_OK; +} + +static NS_IMETHODIMP +UnregisterCommandLineHandlers(nsIComponentManager* compMgr, nsIFile *path, + const char *location, + const nsModuleComponentInfo *info) +{ + nsCOMPtr catMan (do_GetService(NS_CATEGORYMANAGER_CONTRACTID)); + NS_ENSURE_TRUE(catMan, NS_ERROR_FAILURE); + + catMan->DeleteCategoryEntry("command-line-handler", "m-layoutdebug", + PR_TRUE); + + return NS_OK; +} + +#endif + static const nsModuleComponentInfo components[] = { { "nsRegressionTester", @@ -64,8 +102,13 @@ static const nsModuleComponentInfo components[] = NS_LAYOUTDEBUGCLH_CID, "@mozilla.org/commandlinehandler/general-startup;1?type=layoutdebug", nsLayoutDebugCLHConstructor, +#ifdef MOZ_XUL_APP + RegisterCommandLineHandlers, + UnregisterCommandLineHandlers +#else nsLayoutDebugCLH::RegisterProc, nsLayoutDebugCLH::UnregisterProc +#endif } }; diff --git a/extensions/layout-debug/src/nsLayoutDebugCLH.cpp b/extensions/layout-debug/src/nsLayoutDebugCLH.cpp index 5704cff2cc8..9d33b816e8e 100644 --- a/extensions/layout-debug/src/nsLayoutDebugCLH.cpp +++ b/extensions/layout-debug/src/nsLayoutDebugCLH.cpp @@ -40,6 +40,14 @@ #include "nsLayoutDebugCLH.h" #include "nsString.h" #include "plstr.h" +#include "nsCOMPtr.h" +#include "nsIWindowWatcher.h" +#include "nsIServiceManager.h" +#include "nsIDOMWindow.h" + +#ifdef MOZ_XUL_APP +#include "nsICommandLine.h" +#endif nsLayoutDebugCLH::nsLayoutDebugCLH() { @@ -49,7 +57,41 @@ nsLayoutDebugCLH::~nsLayoutDebugCLH() { } -NS_IMPL_ISUPPORTS1(nsLayoutDebugCLH, nsICmdLineHandler) +NS_IMPL_ISUPPORTS1(nsLayoutDebugCLH, ICOMMANDLINEHANDLER) + +#ifdef MOZ_XUL_APP + +NS_IMETHODIMP +nsLayoutDebugCLH::Handle(nsICommandLine* aCmdLine) +{ + nsresult rv; + PRBool found; + + rv = aCmdLine->HandleFlag(NS_LITERAL_STRING("layoutdebug"), + PR_FALSE, &found); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr wwatch (do_GetService(NS_WINDOWWATCHER_CONTRACTID)); + NS_ENSURE_TRUE(wwatch, NS_ERROR_FAILURE); + + nsCOMPtr opened; + // XXX passing |aCmdLine| here to work around inconsistent + // window watcher behavior (see bug 277798) + wwatch->OpenWindow(nsnull, "chrome://layoutdebug/content/", + "_blank", "chrome,dialog=no,all", aCmdLine, + getter_AddRefs(opened)); + aCmdLine->SetPreventDefault(PR_TRUE); + return NS_OK; +} + +NS_IMETHODIMP +nsLayoutDebugCLH::GetHelpInfo(nsACString& aResult) +{ + aResult.Assign(NS_LITERAL_CSTRING(" -layoutdebug Start with Layout Debugger\n")); + return NS_OK; +} + +#else // !MOZ_XUL_APP CMDLINEHANDLER_IMPL(nsLayoutDebugCLH, "-layoutdebug", "general.startup.layoutdebug", @@ -60,3 +102,5 @@ CMDLINEHANDLER_IMPL(nsLayoutDebugCLH, "-layoutdebug", PR_TRUE, "", PR_TRUE) + +#endif diff --git a/extensions/layout-debug/src/nsLayoutDebugCLH.h b/extensions/layout-debug/src/nsLayoutDebugCLH.h index f76d6e6d8b2..253b748c282 100644 --- a/extensions/layout-debug/src/nsLayoutDebugCLH.h +++ b/extensions/layout-debug/src/nsLayoutDebugCLH.h @@ -40,21 +40,31 @@ #ifndef nsLayoutDebugCLH_h_ #define nsLayoutDebugCLH_h_ +#ifdef MOZ_XUL_APP +#include "nsICommandLineHandler.h" +#define ICOMMANDLINEHANDLER nsICommandLineHandler +#else #include "nsICmdLineHandler.h" +#define ICOMMANDLINEHANDLER nsICmdLineHandler +#endif #define NS_LAYOUTDEBUGCLH_CID \ { 0xa8f52633, 0x5ecf, 0x424a, \ { 0xa1, 0x47, 0x47, 0xc3, 0x22, 0xf7, 0xbc, 0xe2 }} -class nsLayoutDebugCLH : public nsICmdLineHandler +class nsLayoutDebugCLH : public ICOMMANDLINEHANDLER { public: nsLayoutDebugCLH(); virtual ~nsLayoutDebugCLH(); NS_DECL_ISUPPORTS +#ifdef MOZ_XUL_APP + NS_DECL_NSICOMMANDLINEHANDLER +#else NS_DECL_NSICMDLINEHANDLER CMDLINEHANDLER_REGISTERPROC_DECLS +#endif }; #endif /* !defined(nsLayoutDebugCLH_h_) */