mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-24 10:45:42 +00:00
More new X Remote work. This code is now in better shape than the original. Not part of the build.
This commit is contained in:
parent
0a93bb62fa
commit
7794d6c4eb
@ -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
|
||||
|
116
xpfe/components/xremote/src/XRemoteContentListener.cpp
Normal file
116
xpfe/components/xremote/src/XRemoteContentListener.cpp
Normal file
@ -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
|
||||
* <blizzard@mozilla.org>. 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);
|
||||
}
|
39
xpfe/components/xremote/src/XRemoteContentListener.h
Normal file
39
xpfe/components/xremote/src/XRemoteContentListener.h
Normal file
@ -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
|
||||
* <blizzard@mozilla.org>. Portions created by Christopher Blizzard
|
||||
* are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include <nsIURIContentListener.h>
|
||||
#include <nsIInterfaceRequestor.h>
|
||||
#include <nsCOMPtr.h>
|
||||
|
||||
class XRemoteContentListener : public nsIURIContentListener,
|
||||
public nsIInterfaceRequestor
|
||||
{
|
||||
public:
|
||||
XRemoteContentListener();
|
||||
virtual ~XRemoteContentListener();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIURICONTENTLISTENER
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
|
||||
private:
|
||||
|
||||
nsCOMPtr<nsISupports> mLoadCookie;
|
||||
};
|
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "XRemoteService.h"
|
||||
#include "XRemoteContentListener.h"
|
||||
|
||||
#include <nsIGenericFactory.h>
|
||||
#include <nsIWebNavigation.h>
|
||||
@ -35,8 +36,13 @@
|
||||
#include <nsIWindowWatcher.h>
|
||||
#include <nsISupportsPrimitives.h>
|
||||
#include <nsIInterfaceRequestor.h>
|
||||
#include <nsIInterfaceRequestorUtils.h>
|
||||
#include <nsIDocShellTreeItem.h>
|
||||
#include <nsIDocShellTreeOwner.h>
|
||||
#include <nsIURILoader.h>
|
||||
#include <nsCURILoader.h>
|
||||
#include <nsIURI.h>
|
||||
#include <nsNetUtil.h>
|
||||
|
||||
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,6 +534,8 @@ XRemoteService::OpenURL(nsCString &aArgument,
|
||||
FindLastInList(aArgument, lastArgument, &index);
|
||||
if (lastArgument.EqualsIgnoreCase("new-window")) {
|
||||
aArgument.Truncate(index);
|
||||
// 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
|
||||
@ -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<nsIURILoader> 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<nsISupports> listenerRef;
|
||||
listenerRef = do_QueryInterface(NS_STATIC_CAST(nsIURIContentListener *,
|
||||
listener));
|
||||
// now the listenerref is the only reference
|
||||
NS_RELEASE(listener);
|
||||
|
||||
// create our uri object
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), url);
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// open a channel
|
||||
nsCOMPtr<nsIChannel> 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.
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user