diff --git a/xpfe/components/xremote/src/Makefile.in b/xpfe/components/xremote/src/Makefile.in index c35ead73d95c..1cd2bd790bc1 100644 --- a/xpfe/components/xremote/src/Makefile.in +++ b/xpfe/components/xremote/src/Makefile.in @@ -29,7 +29,12 @@ MODULE = xremoteservice LIBRARY_NAME = xremoteservice EXPORT_LIBRARY = 1 IS_COMPONENT = 1 +REQUIRES = xpcom string dom widget layout uriloader docshell \ + pref windowwatcher necko -CPPSRCS = XRemoteService.cpp +CPPSRCS = \ + XRemoteService.cpp \ + XRemoteContentListener.cpp \ + $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/xpfe/components/xremote/src/XRemoteContentListener.cpp b/xpfe/components/xremote/src/XRemoteContentListener.cpp new file mode 100644 index 000000000000..2ada7b3f25dd --- /dev/null +++ b/xpfe/components/xremote/src/XRemoteContentListener.cpp @@ -0,0 +1,116 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Christopher Blizzard + * . Portions created by Christopher Blizzard + * are Copyright (C) Christopher Blizzard. All Rights Reserved. + * + * Contributor(s): + */ + +#include "XRemoteContentListener.h" + +XRemoteContentListener::XRemoteContentListener() +{ + NS_INIT_ISUPPORTS(); +} + +XRemoteContentListener::~XRemoteContentListener() +{ +} + +NS_IMPL_ISUPPORTS2(XRemoteContentListener, + nsIURIContentListener, + nsIInterfaceRequestor) + +// nsIURIContentListener + +NS_IMETHODIMP +XRemoteContentListener::OnStartURIOpen(nsIURI *aURI, PRBool *_retval) +{ + return NS_OK; +} + +NS_IMETHODIMP +XRemoteContentListener::GetProtocolHandler(nsIURI *aURI, + nsIProtocolHandler **_retval) +{ + *_retval = nsnull; + return NS_OK; +} + +NS_IMETHODIMP +XRemoteContentListener::DoContent(const char *aContentType, + nsURILoadCommand aCommand, + nsIRequest *request, + nsIStreamListener **aContentHandler, + PRBool *_retval) +{ + NS_NOTREACHED("XRemoteContentListener::DoContent"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +XRemoteContentListener::IsPreferred(const char *aContentType, + nsURILoadCommand aCommand, + char **aDesiredContentType, + PRBool *_retval) +{ + return NS_OK; +} + +NS_IMETHODIMP +XRemoteContentListener::CanHandleContent(const char *aContentType, + nsURILoadCommand aCommand, + char **aDesiredContentType, + PRBool *_retval) +{ + NS_NOTREACHED("XRemoteContentListener::CanHandleContent"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +XRemoteContentListener::GetLoadCookie(nsISupports * *aLoadCookie) +{ + *aLoadCookie = mLoadCookie; + NS_IF_ADDREF(*aLoadCookie); + return NS_OK; +} + +NS_IMETHODIMP +XRemoteContentListener::SetLoadCookie(nsISupports * aLoadCookie) +{ + mLoadCookie = aLoadCookie; + return NS_OK; +} + +NS_IMETHODIMP +XRemoteContentListener::GetParentContentListener(nsIURIContentListener * *aParentContentListener) +{ + *aParentContentListener = nsnull; + return NS_OK; +} + +NS_IMETHODIMP +XRemoteContentListener::SetParentContentListener(nsIURIContentListener * aParentContentListener) +{ + return NS_OK; +} + +// nsIInterfaceRequestor +NS_IMETHODIMP +XRemoteContentListener::GetInterface(const nsIID & uuid, void * *result) +{ + NS_ENSURE_ARG_POINTER(result); + return QueryInterface(uuid, result); +} diff --git a/xpfe/components/xremote/src/XRemoteContentListener.h b/xpfe/components/xremote/src/XRemoteContentListener.h new file mode 100644 index 000000000000..a3477a245987 --- /dev/null +++ b/xpfe/components/xremote/src/XRemoteContentListener.h @@ -0,0 +1,39 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Christopher Blizzard + * . Portions created by Christopher Blizzard + * are Copyright (C) Christopher Blizzard. All Rights Reserved. + * + * Contributor(s): + */ + +#include +#include +#include + +class XRemoteContentListener : public nsIURIContentListener, + public nsIInterfaceRequestor +{ + public: + XRemoteContentListener(); + virtual ~XRemoteContentListener(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIURICONTENTLISTENER + NS_DECL_NSIINTERFACEREQUESTOR + + private: + + nsCOMPtr mLoadCookie; +}; diff --git a/xpfe/components/xremote/src/XRemoteService.cpp b/xpfe/components/xremote/src/XRemoteService.cpp index 811bdfd2bc68..8b2fe3b2fc92 100644 --- a/xpfe/components/xremote/src/XRemoteService.cpp +++ b/xpfe/components/xremote/src/XRemoteService.cpp @@ -19,6 +19,7 @@ */ #include "XRemoteService.h" +#include "XRemoteContentListener.h" #include #include @@ -35,8 +36,13 @@ #include #include #include +#include #include #include +#include +#include +#include +#include NS_DEFINE_CID(kWindowCID, NS_WINDOW_CID); @@ -170,7 +176,7 @@ XRemoteService::ParseCommand(nsIWidget *aWidget, rv = OpenURLDialog(domWindow); } else { - rv = OpenURL(argument, domWindow); + rv = OpenURL(argument, domWindow, PR_TRUE); } } @@ -186,7 +192,30 @@ XRemoteService::ParseCommand(nsIWidget *aWidget, */ else if (action.Equals("saveas")) { - // XXX save files + if (argument.Length() == 0) { + rv = NS_ERROR_NOT_IMPLEMENTED; + } + else { + // check to see if it has a type on it + index = 0; + FindLastInList(argument, lastArgument, &index); + if (lastArgument.EqualsIgnoreCase("html")) { + argument.Truncate(index); + rv = NS_ERROR_NOT_IMPLEMENTED; + } + else if (lastArgument.EqualsIgnoreCase("text", PR_TRUE)) { + argument.Truncate(index); + rv = NS_ERROR_NOT_IMPLEMENTED; + } + else if (lastArgument.EqualsIgnoreCase("postscript", PR_TRUE)) { + argument.Truncate(index); + rv = NS_ERROR_NOT_IMPLEMENTED; + } + else { + rv = NS_ERROR_NOT_IMPLEMENTED; + } + } + } /* @@ -202,7 +231,7 @@ XRemoteService::ParseCommand(nsIWidget *aWidget, // and openurl should work fine. nsCString tempArg("mailto:"); tempArg.Append(argument); - rv = OpenURL(tempArg, domWindow); + rv = OpenURL(tempArg, domWindow, PR_FALSE); } /* @@ -216,7 +245,21 @@ XRemoteService::ParseCommand(nsIWidget *aWidget, */ else if (action.Equals("addbookmark")) { - // XXX bookmarks + if (argument.Length() == 0) { + rv = NS_ERROR_NOT_IMPLEMENTED; + } + else { + index = 0; + FindLastInList(argument, lastArgument, &index); + if (!lastArgument.IsEmpty()) { + nsCString title(lastArgument); + argument.Truncate(index); + rv = NS_ERROR_NOT_IMPLEMENTED; + } + else { + rv = NS_ERROR_NOT_IMPLEMENTED; + } + } } // bad command @@ -481,7 +524,8 @@ XRemoteService::GetBrowserLocation(char **_retval) nsresult XRemoteService::OpenURL(nsCString &aArgument, - nsIDOMWindowInternal *aParent) + nsIDOMWindowInternal *aParent, + PRBool aOpenBrowser) { // see if there's a new window argument on the end nsCString lastArgument; @@ -490,7 +534,9 @@ XRemoteService::OpenURL(nsCString &aArgument, FindLastInList(aArgument, lastArgument, &index); if (lastArgument.EqualsIgnoreCase("new-window")) { aArgument.Truncate(index); - newWindow = PR_TRUE; + // only open new windows if it's OK to do so + if (aOpenBrowser) + newWindow = PR_TRUE; // recheck for a possible noraise argument since it might have // been before the new-window argument FindLastInList(aArgument, lastArgument, &index); @@ -498,15 +544,16 @@ XRemoteService::OpenURL(nsCString &aArgument, aArgument.Truncate(index); } + // if someone told us to open a new browser when we could and + // there's no parent then open a new window. + if (aOpenBrowser && !aParent) + newWindow = PR_TRUE; + // try to fixup the argument passed in nsString url; url.AssignWithConversion(aArgument); - // if there's no parent passed in then this is a new window - if (!aParent) - newWindow = PR_TRUE; - nsresult rv = NS_OK; if (newWindow) { @@ -528,6 +575,44 @@ XRemoteService::OpenURL(nsCString &aArgument, arg, getter_AddRefs(window)); } + // if no new window flag was set but there's no parent then we have + // to pass everything off to the uri loader + else if (!aParent) { + nsCOMPtr loader; + loader = do_GetService(NS_URI_LOADER_CONTRACTID); + if (!loader) + return NS_ERROR_FAILURE; + + XRemoteContentListener *listener; + listener = new XRemoteContentListener(); + if (!listener) + return NS_ERROR_FAILURE; + + // we own it + NS_ADDREF(listener); + nsCOMPtr listenerRef; + listenerRef = do_QueryInterface(NS_STATIC_CAST(nsIURIContentListener *, + listener)); + // now the listenerref is the only reference + NS_RELEASE(listener); + + // create our uri object + nsCOMPtr uri; + rv = NS_NewURI(getter_AddRefs(uri), url); + if (NS_FAILED(rv)) + return NS_ERROR_FAILURE; + + // open a channel + nsCOMPtr channel; + rv = NS_OpenURI(getter_AddRefs(channel), uri); + if (NS_FAILED(rv)) + return NS_ERROR_FAILURE; + + // load it + rv = loader->OpenURI(channel, nsIURILoader::viewUserClick, + listenerRef); + } + else { // find the primary content shell for the window that we've been // asked to load into. diff --git a/xpfe/components/xremote/src/XRemoteService.h b/xpfe/components/xremote/src/XRemoteService.h index 1092d459d45b..d5682ce31f8a 100644 --- a/xpfe/components/xremote/src/XRemoteService.h +++ b/xpfe/components/xremote/src/XRemoteService.h @@ -66,7 +66,8 @@ class XRemoteService : public nsIXRemoteService { // remote command handlers nsresult OpenURL(nsCString &aArgument, - nsIDOMWindowInternal *aParent); + nsIDOMWindowInternal *aParent, + PRBool aOpenBrowser); nsresult OpenURLDialog(nsIDOMWindowInternal *aParent);