зеркало из https://github.com/mozilla/gecko-dev.git
Rewrite XRemote code. It sucks less now. Fixes bugs 62250, 66543, 84239, 89911, 90580, 94289, 98764. r=jag, sr=alecf
This commit is contained in:
Родитель
6003c43280
Коммит
87395759c4
|
@ -27,7 +27,7 @@ LIBRARY_NAME = widget_gtk
|
|||
EXPORT_LIBRARY = 1
|
||||
IS_COMPONENT = 1
|
||||
MODULE_NAME = nsWidgetGTKModule
|
||||
REQUIRES = xpcom string layout pref dom appshell timer uconv necko img view util rdf uriloader docshell msgcompose msgbase editor windowwatcher mailnews intl
|
||||
REQUIRES = xpcom string appshell layout pref dom timer uconv necko intl xremoteservice view util
|
||||
|
||||
CSRCS = \
|
||||
keysym2ucs.c
|
||||
|
|
|
@ -21,37 +21,12 @@
|
|||
|
||||
#include <X11/Xatom.h> // for XA_STRING
|
||||
#include <stdlib.h>
|
||||
#include <nsIWidget.h>
|
||||
#include <nsIXRemoteService.h>
|
||||
#include <nsCOMPtr.h>
|
||||
#include <nsIServiceManager.h>
|
||||
#include "nsGtkMozRemoteHelper.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsAppShellCIDs.h"
|
||||
#include "nsIXULWindow.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsIWindowMediator.h"
|
||||
#include "nsIWindowWatcher.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsIURIContentListener.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIURILoader.h"
|
||||
#include "nsCURILoader.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
#ifdef MOZ_MAIL_NEWS
|
||||
|
||||
#include "nsMsgCompCID.h"
|
||||
#include "nsIMsgCompose.h"
|
||||
#include "nsIMsgComposeService.h"
|
||||
|
||||
#endif /* MOZ_MAIL_NEWS */
|
||||
|
||||
#define MOZILLA_VERSION_PROP "_MOZILLA_VERSION"
|
||||
#define MOZILLA_LOCK_PROP "_MOZILLA_LOCK"
|
||||
|
@ -65,131 +40,6 @@ Atom nsGtkMozRemoteHelper::sMozResponseAtom = 0;
|
|||
|
||||
// XXX get this dynamically
|
||||
static char *sRemoteVersion = "5.0";
|
||||
// protocol strings
|
||||
static char *s200ExecutedCommand = "200 executed command:";
|
||||
static char *s500ParseCommand = "500 command not parsable:";
|
||||
static char *s501UnrecognizedCommand = "501 unrecognized command:";
|
||||
// not using this yet...
|
||||
// static char *s502NoWindow = "502 no appropriate window for:";
|
||||
static char *s509InternalError = "509 internal error";
|
||||
|
||||
static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
|
||||
|
||||
class RemoteHelperContentListener : public nsIURIContentListener,
|
||||
public nsIInterfaceRequestor
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIURICONTENTLISTENER
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
|
||||
RemoteHelperContentListener();
|
||||
virtual ~RemoteHelperContentListener();
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsISupports> mLoadCookie;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS2(RemoteHelperContentListener,
|
||||
nsIURIContentListener,
|
||||
nsIInterfaceRequestor)
|
||||
|
||||
RemoteHelperContentListener::RemoteHelperContentListener()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
RemoteHelperContentListener::~RemoteHelperContentListener()
|
||||
{
|
||||
}
|
||||
|
||||
// nsIURIContentListener
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoteHelperContentListener::OnStartURIOpen(nsIURI *aURI,
|
||||
PRBool *aAbortOpen)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoteHelperContentListener::GetProtocolHandler(nsIURI *aURI,
|
||||
nsIProtocolHandler **aProtocolHandler)
|
||||
{
|
||||
*aProtocolHandler = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoteHelperContentListener::DoContent(const char *aContentType,
|
||||
nsURILoadCommand aCommand,
|
||||
nsIRequest *aOpenedRequest,
|
||||
nsIStreamListener **aContentHandler,
|
||||
PRBool *aAbortProcess)
|
||||
{
|
||||
NS_NOTREACHED("RemoteHelperContentListener::DoContent");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoteHelperContentListener::IsPreferred(const char *aContentType,
|
||||
nsURILoadCommand aCommand,
|
||||
char **aDesiredContentType,
|
||||
PRBool *_retval)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoteHelperContentListener::CanHandleContent(const char *aContentType,
|
||||
nsURILoadCommand aCommand,
|
||||
char **aDesiredContentType,
|
||||
PRBool *_retval)
|
||||
{
|
||||
NS_NOTREACHED("RemoteHelperContentListener::CanHandleContent");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoteHelperContentListener::GetLoadCookie(nsISupports * *aLoadCookie)
|
||||
{
|
||||
*aLoadCookie = mLoadCookie;
|
||||
NS_IF_ADDREF(*aLoadCookie);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoteHelperContentListener::SetLoadCookie(nsISupports * aLoadCookie)
|
||||
{
|
||||
mLoadCookie = aLoadCookie;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoteHelperContentListener::GetParentContentListener(nsIURIContentListener * *aParentContentListener)
|
||||
{
|
||||
*aParentContentListener = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RemoteHelperContentListener::SetParentContentListener(nsIURIContentListener * aParentContentListener)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIInterfaceRequestor
|
||||
NS_IMETHODIMP
|
||||
RemoteHelperContentListener::GetInterface(const nsIID & aIID,
|
||||
void * *aInstancePtr)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtr);
|
||||
return QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
nsGtkMozRemoteHelper::nsGtkMozRemoteHelper()
|
||||
{
|
||||
EnsureAtoms();
|
||||
}
|
||||
|
||||
void
|
||||
nsGtkMozRemoteHelper::SetupVersion(GdkWindow *aWindow)
|
||||
|
@ -205,7 +55,9 @@ nsGtkMozRemoteHelper::SetupVersion(GdkWindow *aWindow)
|
|||
}
|
||||
|
||||
gboolean
|
||||
nsGtkMozRemoteHelper::HandlePropertyChange(GtkWidget *aWidget, GdkEventProperty *aEvent)
|
||||
nsGtkMozRemoteHelper::HandlePropertyChange(GtkWidget *aWidget,
|
||||
GdkEventProperty *aEvent,
|
||||
nsIWidget *ansIWidget)
|
||||
{
|
||||
|
||||
EnsureAtoms();
|
||||
|
@ -255,8 +107,14 @@ nsGtkMozRemoteHelper::HandlePropertyChange(GtkWidget *aWidget, GdkEventProperty
|
|||
// giving up since a lot of clients will just hang forever. Hence
|
||||
// using a static string.
|
||||
PRBool freeResponse = PR_TRUE;
|
||||
|
||||
// parse the command
|
||||
ParseCommand(data, &response);
|
||||
nsCOMPtr<nsIXRemoteService> remoteService;
|
||||
remoteService = do_GetService(NS_IXREMOTESERVICE_CONTRACTID);
|
||||
|
||||
if (remoteService)
|
||||
remoteService->ParseCommand(ansIWidget, data, &response);
|
||||
|
||||
if (!response)
|
||||
{
|
||||
response = "500 error parsing command";
|
||||
|
@ -308,576 +166,39 @@ nsGtkMozRemoteHelper::~nsGtkMozRemoteHelper()
|
|||
{
|
||||
}
|
||||
|
||||
void
|
||||
nsGtkMozRemoteHelper::ParseCommand(const char *aCommand, char **aResponse)
|
||||
nsGtkXRemoteWidgetHelper::nsGtkXRemoteWidgetHelper()
|
||||
{
|
||||
PRBool newWindow = PR_FALSE;
|
||||
PRBool raiseWindow = PR_TRUE;
|
||||
nsCString actionString;
|
||||
nsCString commandString;
|
||||
nsCString origString;
|
||||
nsCString lastCommand;
|
||||
PRInt32 begin_command = 0;
|
||||
PRInt32 end_command = 0;
|
||||
PRInt32 commandLen = 0;
|
||||
PRUint32 indexRet = 0;
|
||||
|
||||
if (!aResponse)
|
||||
{
|
||||
// have to just return silently
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure that we return at least a null string
|
||||
*aResponse = 0;
|
||||
|
||||
// check to make sure that we have our command
|
||||
if (!aCommand)
|
||||
{
|
||||
*aResponse = nsCRT::strdup(s509InternalError);
|
||||
return;
|
||||
}
|
||||
// make a copy of the string to work with
|
||||
origString = aCommand;
|
||||
|
||||
// check to make sure that was allocated properly
|
||||
if (origString.IsEmpty())
|
||||
{
|
||||
// hey, this might fail to. but that's ok, the caller will handle
|
||||
// it if it is null anyway.
|
||||
*aResponse = nsCRT::strdup(s509InternalError);
|
||||
return;
|
||||
}
|
||||
|
||||
// should start with a '(' char
|
||||
begin_command = origString.FindChar('(');
|
||||
// make sure that it's there and it's not the first character
|
||||
if (begin_command == kNotFound || begin_command == 0)
|
||||
{
|
||||
*aResponse = BuildResponse(s500ParseCommand, origString.get());
|
||||
return;
|
||||
}
|
||||
|
||||
// should end with a ')' char after the '(' char
|
||||
end_command = origString.RFindChar(')');
|
||||
if (end_command == kNotFound || end_command < begin_command)
|
||||
{
|
||||
*aResponse = BuildResponse(s500ParseCommand, origString.get());
|
||||
return;
|
||||
}
|
||||
|
||||
// trunc the end of command
|
||||
origString.Truncate(end_command);
|
||||
|
||||
// get the action type
|
||||
actionString.Append(origString, begin_command);
|
||||
if (origString.Length() > 0)
|
||||
origString.Cut(0, begin_command + 1);
|
||||
commandString.Append(origString);
|
||||
|
||||
// convert the action to lower case and remove whitespace
|
||||
actionString.Trim(" ", PR_TRUE, PR_TRUE);
|
||||
actionString.ToLowerCase();
|
||||
|
||||
// strip off whitespace from the command
|
||||
commandString.Trim(" ", PR_TRUE, PR_TRUE);
|
||||
|
||||
commandLen = commandString.Length();
|
||||
|
||||
// pop off the "noraise" argument if it exists.
|
||||
|
||||
FindLastInList(commandString, lastCommand, &indexRet);
|
||||
if (lastCommand.EqualsIgnoreCase("noraise"))
|
||||
{
|
||||
commandString.Truncate(indexRet);
|
||||
raiseWindow = PR_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
openURL ( )
|
||||
Prompts for a URL with a dialog box.
|
||||
openURL (URL)
|
||||
Opens the specified document without prompting.
|
||||
openURL (URL, new-window)
|
||||
Create a new window displaying the the specified document.
|
||||
*/
|
||||
|
||||
nsresult rv;
|
||||
|
||||
if (actionString.Equals("openurl"))
|
||||
{
|
||||
if (commandLen == 0)
|
||||
{
|
||||
rv = OpenURLDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
// check to see if we need to open a new window
|
||||
FindLastInList (commandString, lastCommand, &indexRet);
|
||||
if (lastCommand.EqualsIgnoreCase("new-window"))
|
||||
{
|
||||
commandString.Truncate(indexRet);
|
||||
newWindow = PR_TRUE;
|
||||
}
|
||||
// ok, do it
|
||||
rv = OpenURL(commandString.get(), newWindow, raiseWindow);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
openFile ( )
|
||||
Prompts for a file with a dialog box.
|
||||
openFile (File)
|
||||
Opens the specified file without prompting.
|
||||
|
||||
*/
|
||||
|
||||
else if (actionString.Equals("openfile"))
|
||||
{
|
||||
if (commandLen == 0)
|
||||
{
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = OpenFile(commandString.get(), raiseWindow);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
saveAs ( )
|
||||
Prompts for a file with a dialog box (like the menu item).
|
||||
saveAs (Output-File)
|
||||
Writes HTML to the specified file without prompting.
|
||||
saveAs (Output-File, Type)
|
||||
Writes to the specified file with the type specified - the type may be HTML, Text, or PostScript.
|
||||
|
||||
*/
|
||||
|
||||
else if (actionString.Equals("saveas"))
|
||||
{
|
||||
if (commandLen == 0)
|
||||
{
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
// check to see if it has a type on it
|
||||
FindLastInList(commandString, lastCommand, &indexRet);
|
||||
if (lastCommand.EqualsIgnoreCase("html"))
|
||||
{
|
||||
commandString.Truncate(indexRet);
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
else if (lastCommand.EqualsIgnoreCase("text", PR_TRUE))
|
||||
{
|
||||
commandString.Truncate(indexRet);
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
else if (lastCommand.EqualsIgnoreCase("postscript", PR_TRUE))
|
||||
{
|
||||
commandString.Truncate(indexRet);
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
mailto ( )
|
||||
pops up the mail dialog with the To: field empty.
|
||||
mailto (a, b, c)
|
||||
Puts the addresses "a, b, c" in the default To: field.
|
||||
|
||||
*/
|
||||
|
||||
else if (actionString.Equals("mailto"))
|
||||
{
|
||||
// convert it to unicode
|
||||
nsString toList;
|
||||
if (commandLen == 0)
|
||||
{
|
||||
rv = MailTo(nsnull);
|
||||
}
|
||||
else
|
||||
{
|
||||
// convert it to unicode
|
||||
toList.AppendWithConversion(commandString);
|
||||
rv = MailTo(toList.get());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
addBookmark ( )
|
||||
Adds the current document to the bookmark list.
|
||||
addBookmark (URL)
|
||||
Adds the given document to the bookmark list.
|
||||
addBookmark (URL, Title)
|
||||
Adds the given document to the bookmark list, with the given title.
|
||||
*/
|
||||
|
||||
else if (actionString.Equals("addbookmark"))
|
||||
{
|
||||
if (commandLen == 0)
|
||||
{
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
FindLastInList(commandString, lastCommand, &indexRet);
|
||||
if (!lastCommand.IsEmpty())
|
||||
{
|
||||
nsCAutoString title(lastCommand);
|
||||
commandString.Truncate(indexRet);
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
rv = NS_ERROR_FAILURE;
|
||||
*aResponse = BuildResponse(s501UnrecognizedCommand, aCommand);
|
||||
}
|
||||
|
||||
// if we failed and *aResponse isn't already filled in, fill it in
|
||||
// with the generic internal error message
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
if (!*aResponse)
|
||||
{
|
||||
if (rv == NS_ERROR_NOT_IMPLEMENTED)
|
||||
*aResponse = BuildResponse(s501UnrecognizedCommand, aCommand);
|
||||
else
|
||||
*aResponse = nsCRT::strdup(s509InternalError);
|
||||
}
|
||||
}
|
||||
|
||||
// if we got this far everything worked. make sure to use aCommand
|
||||
// since origString might have been messed with.
|
||||
if (!*aResponse)
|
||||
*aResponse = BuildResponse(s200ExecutedCommand, aCommand);
|
||||
return;
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
void
|
||||
nsGtkMozRemoteHelper::FindLastInList(nsCString &aString, nsCString &retString, PRUint32 *aIndexRet)
|
||||
nsGtkXRemoteWidgetHelper::~nsGtkXRemoteWidgetHelper()
|
||||
{
|
||||
// init our return
|
||||
*aIndexRet = 0;
|
||||
// make a copy to work with
|
||||
nsCString tempString = aString;
|
||||
PRInt32 strIndex;
|
||||
// find out of there's a , at the end of the string
|
||||
strIndex = tempString.RFindChar(',');
|
||||
|
||||
// give up now if you can
|
||||
if (strIndex == kNotFound)
|
||||
return;
|
||||
|
||||
// cut the string down to the first ,
|
||||
tempString.Cut(0, strIndex + 1);
|
||||
|
||||
// strip off leading + trailing whitespace
|
||||
|
||||
tempString.Trim(" ", PR_TRUE, PR_TRUE);
|
||||
|
||||
// see if we've reduced it to nothing
|
||||
if (tempString.IsEmpty())
|
||||
return;
|
||||
|
||||
*aIndexRet = strIndex;
|
||||
// otherwise, return it as a new C string
|
||||
retString = tempString;
|
||||
|
||||
}
|
||||
|
||||
char *
|
||||
nsGtkMozRemoteHelper::BuildResponse (const char *aError, const char *aMessage)
|
||||
{
|
||||
nsCString retvalString;
|
||||
char *retval;
|
||||
NS_IMPL_ISUPPORTS1(nsGtkXRemoteWidgetHelper, nsIXRemoteWidgetHelper)
|
||||
|
||||
// check to make sure that we have the minimum for allocating this
|
||||
// buffer
|
||||
if (!aError || !aMessage)
|
||||
return NULL;
|
||||
|
||||
retvalString.Append(aError);
|
||||
retvalString.Append(" ");
|
||||
retvalString.Append(aMessage);
|
||||
|
||||
retval = retvalString.ToNewCString();
|
||||
return retval;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsGtkMozRemoteHelper::OpenURLDialog (void)
|
||||
NS_IMETHODIMP
|
||||
nsGtkXRemoteWidgetHelper::EnableXRemoteCommands(nsIWidget *aWidget)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMWindow> lastWindow;
|
||||
|
||||
// get the last used browser window
|
||||
rv = GetLastBrowserWindow(getter_AddRefs(lastWindow));
|
||||
if (NS_FAILED(rv))
|
||||
// find the native gdk window
|
||||
GdkWindow *window = NS_STATIC_CAST(GdkWindow *,
|
||||
aWidget->GetNativeData(NS_NATIVE_WINDOW));
|
||||
if (!window)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// get the last used browser window
|
||||
// find the toplevel gdk window
|
||||
GdkWindow *temp = window;
|
||||
|
||||
// use it to open the open location dialog
|
||||
rv = OpenXULWindow ("chrome://communicator/content/openLocation.xul",
|
||||
lastWindow,
|
||||
"chrome,modal",
|
||||
"_blank",
|
||||
nsnull);
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
while (temp) {
|
||||
temp = gdk_window_get_parent(window);
|
||||
if (!temp || temp == GDK_ROOT_PARENT())
|
||||
break;
|
||||
window = temp;
|
||||
}
|
||||
|
||||
// ok, found the toplevel window - set up the version information
|
||||
nsGtkMozRemoteHelper::SetupVersion(window);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsGtkMozRemoteHelper::OpenURL (const char *aURL, PRBool aNewWindow, PRBool raiseWindow)
|
||||
{
|
||||
nsresult rv;
|
||||
nsString newURL;
|
||||
nsCString navChromeURL;
|
||||
nsXPIDLCString tempString;
|
||||
nsCOMPtr<nsIPref> prefs(do_GetService("@mozilla.org/preferences;1", &rv));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
prefs->CopyCharPref("browser.chromeURL", getter_Copies(tempString));
|
||||
// make a copy for the auto string
|
||||
if (tempString)
|
||||
navChromeURL = tempString;
|
||||
// default to this
|
||||
if (navChromeURL.IsEmpty())
|
||||
navChromeURL = "chrome://navigator/content/navigator.xul";
|
||||
|
||||
newURL.AssignWithConversion(aURL);
|
||||
|
||||
if (aNewWindow)
|
||||
{
|
||||
rv = OpenXULWindow(navChromeURL, 0,
|
||||
"chrome,all,dialog=no",
|
||||
"_blank", newURL.get());
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
// otherwise, pass it off to the default handler
|
||||
else
|
||||
{
|
||||
// get our uri loader service
|
||||
nsCOMPtr<nsIURILoader> loader (do_GetService(NS_URI_LOADER_CONTRACTID));
|
||||
NS_ENSURE_TRUE(loader, NS_ERROR_FAILURE);
|
||||
|
||||
RemoteHelperContentListener *listener;
|
||||
listener = new RemoteHelperContentListener();
|
||||
if (!listener)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// we own it
|
||||
NS_ADDREF(listener);
|
||||
nsCOMPtr<nsISupports> listenerRef(do_QueryInterface((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), aURL);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
// open a channel
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = NS_OpenURI (getter_AddRefs(channel), uri);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
// load it
|
||||
rv = loader->OpenURI(channel, nsIURILoader::viewUserClick, listenerRef);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsGtkMozRemoteHelper::OpenFileDialog (void)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsGtkMozRemoteHelper::OpenFile (const char *aURL, PRBool raiseWindow)
|
||||
{
|
||||
nsCString newURL;
|
||||
nsresult rv;
|
||||
// check to see if the url starts with a file:/// string
|
||||
if (PL_strncasecmp(aURL, "file:///", 8) != 0)
|
||||
{
|
||||
// ok, we don't have a file:/// url yet. Munge it to where it
|
||||
// looks right.
|
||||
// check for file:/<filename>
|
||||
if (PL_strncasecmp(aURL, "file:/", 6) == 0)
|
||||
{
|
||||
// netlib seems to handle this case properly
|
||||
newURL = aURL;
|
||||
}
|
||||
// ooook. let it fail.
|
||||
else if (PL_strncasecmp(aURL, "file:", 5) == 0)
|
||||
{
|
||||
newURL = aURL;
|
||||
}
|
||||
// doesn't match anything. slap a file: extension on the front
|
||||
// and hope for the best
|
||||
else
|
||||
{
|
||||
newURL.Append("file:");
|
||||
newURL.Append(aURL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newURL = aURL;
|
||||
}
|
||||
// open with the new url
|
||||
rv = OpenURL(newURL, PR_FALSE, raiseWindow);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsGtkMozRemoteHelper::SaveAsDialog (void)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsGtkMozRemoteHelper::SaveAs (const char *aFileName, const char *aType)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsGtkMozRemoteHelper::MailTo (const PRUnichar *aToList)
|
||||
{
|
||||
|
||||
#ifdef MOZ_MAIL_NEWS
|
||||
nsresult rv;
|
||||
// get the messenger compose service
|
||||
nsCOMPtr<nsIMsgComposeService> composeService =
|
||||
do_GetService("@mozilla.org/messengercompose;1", &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
if (aToList)
|
||||
{
|
||||
rv = composeService->OpenComposeWindowWithValues(nsnull,
|
||||
/* msg compose window url */
|
||||
nsIMsgCompType::New,
|
||||
/* new message */
|
||||
nsIMsgCompFormat::Default,
|
||||
/* default of html/plain text */
|
||||
aToList,
|
||||
/* the to: list */
|
||||
nsnull,
|
||||
/* cc: */
|
||||
nsnull,
|
||||
/* bcc: */
|
||||
nsnull,
|
||||
/* newsgroups */
|
||||
nsnull,
|
||||
/* subject */
|
||||
nsnull,
|
||||
/* body */
|
||||
nsnull,
|
||||
/* attachment */
|
||||
nsnull); /* identity */
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = composeService->OpenComposeWindow(nsnull,
|
||||
/* msg compose window url */
|
||||
nsnull,
|
||||
/* original msg uri */
|
||||
nsIMsgCompType::New,
|
||||
/* new msg */
|
||||
nsIMsgCompFormat::Default,
|
||||
/* default of html/plain text */
|
||||
nsnull); /* identity */
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
return NS_OK;
|
||||
#else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif /* MOZ_MAIL_NEWS */
|
||||
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsGtkMozRemoteHelper::AddBookmark (const char *aURL, const char *aTitle)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsGtkMozRemoteHelper::GetLastBrowserWindow (nsIDOMWindow **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
nsresult rv;
|
||||
nsString browserString;
|
||||
nsCOMPtr<nsIDOMWindowInternal> outerWindow;
|
||||
browserString.AssignWithConversion("navigator:browser");
|
||||
|
||||
// get the window mediator service
|
||||
nsCOMPtr<nsIWindowMediator> windowMediator =
|
||||
do_GetService(kWindowMediatorCID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// find the most recently used window
|
||||
rv = windowMediator->GetMostRecentWindow(browserString.get(), getter_AddRefs(outerWindow));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIDOMWindow> domwin(do_QueryInterface(outerWindow));
|
||||
if (!domwin)
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
*_retval = domwin;
|
||||
NS_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsGtkMozRemoteHelper::OpenXULWindow (const char *aChromeURL, nsIDOMWindow *aParent,
|
||||
const char *aWindowFeatures,
|
||||
const char *aName, const PRUnichar *aURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aChromeURL);
|
||||
NS_ENSURE_ARG_POINTER(aWindowFeatures);
|
||||
|
||||
// make sure that we pass a valid name even if there isn't one
|
||||
// passed in.
|
||||
const char *name;
|
||||
const PRUnichar *url;
|
||||
|
||||
static char kEmptyChar[] = { 0 };
|
||||
static PRUnichar kEmptyUnichar[] = { PRUnichar(0) };
|
||||
name = aName ? aName : kEmptyChar;
|
||||
url = aURL ? aURL : kEmptyUnichar;
|
||||
|
||||
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
|
||||
nsCOMPtr<nsISupportsWString> sarg(do_CreateInstance(NS_SUPPORTS_WSTRING_CONTRACTID));
|
||||
if (!wwatch || !sarg)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
sarg->SetData(aURL);
|
||||
nsCOMPtr<nsIDOMWindow> returnedWindow;
|
||||
nsresult rv;
|
||||
rv = wwatch->OpenWindow(aParent, aChromeURL, aName, aWindowFeatures, sarg,
|
||||
getter_AddRefs(returnedWindow));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
#include "nsString.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include <nsString.h>
|
||||
#include <nsIXRemoteWidgetHelper.h>
|
||||
|
||||
#ifndef __nsGtkMozRemoteHelper_h__
|
||||
#define __nsGtkMozRemoteHelper_h__
|
||||
|
@ -36,32 +36,15 @@ public:
|
|||
|
||||
// interaction from the outside world
|
||||
static void SetupVersion (GdkWindow *aWindow);
|
||||
static gboolean HandlePropertyChange (GtkWidget *aWidget, GdkEventProperty *aEvent);
|
||||
static gboolean HandlePropertyChange (GtkWidget *aWidget,
|
||||
GdkEventProperty *aEvent,
|
||||
nsIWidget *ansIWidget);
|
||||
|
||||
private:
|
||||
|
||||
// internal methods
|
||||
static void EnsureAtoms (void);
|
||||
static void ParseCommand (const char *aCommand, char **aResponse);
|
||||
static void FindLastInList (nsCString &aString, nsCString &retString, PRUint32 *aIndexRet);
|
||||
static char *BuildResponse (const char *aError, const char *aMessage);
|
||||
|
||||
// these are for the actions
|
||||
static NS_METHOD OpenURLDialog (void);
|
||||
static NS_METHOD OpenURL (const char *aURL, PRBool aNewWindow, PRBool raiseWindow);
|
||||
static NS_METHOD OpenFileDialog (void);
|
||||
static NS_METHOD OpenFile (const char *aURL, PRBool raiseWindow);
|
||||
static NS_METHOD SaveAsDialog (void);
|
||||
static NS_METHOD SaveAs (const char *aFileName, const char *aType);
|
||||
static NS_METHOD MailTo (const PRUnichar *aToList);
|
||||
static NS_METHOD AddBookmark (const char *aURL, const char *aTitle);
|
||||
|
||||
// utility functions for getting windows
|
||||
static NS_METHOD GetLastBrowserWindow (nsIDOMWindow **_retval);
|
||||
static NS_METHOD OpenXULWindow (const char *aChromeURL, nsIDOMWindow *aParent,
|
||||
const char *aWindowFeatures,
|
||||
const char *aName, const PRUnichar *aURL);
|
||||
|
||||
static Atom sMozVersionAtom;
|
||||
static Atom sMozLockAtom;
|
||||
static Atom sMozCommandAtom;
|
||||
|
@ -70,4 +53,20 @@ public:
|
|||
|
||||
};
|
||||
|
||||
// {84f94aac-1dd2-11b2-a05f-9b338fea662c}
|
||||
|
||||
#define NS_GTKXREMOTEWIDGETHELPER_CID \
|
||||
{ 0x84f94aac, 0x1dd2, 0x11b2, \
|
||||
{ 0xa0, 0x5f, 0x9b, 0x33, 0x8f, 0xea, 0x66, 0x2c } }
|
||||
|
||||
class nsGtkXRemoteWidgetHelper : public nsIXRemoteWidgetHelper {
|
||||
public:
|
||||
nsGtkXRemoteWidgetHelper();
|
||||
virtual ~nsGtkXRemoteWidgetHelper();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD EnableXRemoteCommands(nsIWidget *aWidget);
|
||||
};
|
||||
|
||||
#endif /* __nsGtkMozRemoteHelper_h__ */
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "nsDragService.h"
|
||||
#include "nsScrollbar.h"
|
||||
#include "nsSound.h"
|
||||
#include "nsGtkMozRemoteHelper.h"
|
||||
#ifdef IBMBIDI
|
||||
#include "nsBidiKeyboard.h"
|
||||
#endif
|
||||
|
@ -63,6 +64,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsGtkXRemoteWidgetHelper)
|
||||
#ifdef IBMBIDI
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
|
||||
#endif
|
||||
|
@ -198,7 +200,11 @@ static nsModuleComponentInfo components[] =
|
|||
NS_DRAGSERVICE_CID,
|
||||
// "@mozilla.org/widget/dragservice/gtk;1",
|
||||
"@mozilla.org/widget/dragservice;1",
|
||||
nsDragServiceConstructor }
|
||||
nsDragServiceConstructor },
|
||||
{ NS_IXREMOTEWIDGETHELPER_CLASSNAME,
|
||||
NS_GTKXREMOTEWIDGETHELPER_CID,
|
||||
NS_IXREMOTEWIDGETHELPER_CONTRACTID,
|
||||
nsGtkXRemoteWidgetHelperConstructor }
|
||||
#ifdef IBMBIDI
|
||||
, { "Gtk Bidi Keyboard",
|
||||
NS_BIDIKEYBOARD_CID,
|
||||
|
|
|
@ -114,9 +114,9 @@ void handle_toplevel_configure (
|
|||
nsWindow * aWindow);
|
||||
|
||||
gboolean handle_toplevel_property_change (
|
||||
GtkWidget *widget,
|
||||
GtkWidget *aGtkWidget,
|
||||
GdkEventProperty *event,
|
||||
gpointer aData);
|
||||
nsWindow *aWindow);
|
||||
|
||||
// are we grabbing?
|
||||
PRBool nsWindow::sIsGrabbing = PR_FALSE;
|
||||
|
@ -1938,8 +1938,6 @@ NS_METHOD nsWindow::CreateNative(GtkObject *parentWidget)
|
|||
gdk_window_set_events(mShell->window,
|
||||
mask);
|
||||
|
||||
// set up the version information
|
||||
nsGtkMozRemoteHelper::SetupVersion(mShell->window);
|
||||
}
|
||||
|
||||
if (mMozArea) {
|
||||
|
@ -2948,11 +2946,13 @@ void handle_toplevel_configure (
|
|||
|
||||
|
||||
gboolean handle_toplevel_property_change (
|
||||
GtkWidget *widget,
|
||||
GtkWidget *aGtkWidget,
|
||||
GdkEventProperty *event,
|
||||
gpointer aData)
|
||||
nsWindow *aWindow)
|
||||
{
|
||||
return nsGtkMozRemoteHelper::HandlePropertyChange(widget, event);
|
||||
nsIWidget *widget = NS_STATIC_CAST(nsIWidget *, aWindow);
|
||||
return nsGtkMozRemoteHelper::HandlePropertyChange(aGtkWidget, event,
|
||||
widget);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -29,7 +29,7 @@ include $(DEPTH)/config/autoconf.mk
|
|||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
MODULE = apprunner
|
||||
REQUIRES = xpcom string webbrwsr widget dom necko pref appshell wallet layout chrome rdf profile xpinstall uriloader editor view windowwatcher embed_base embedcomponents mpfilelocprovider browser mozcomps docshell
|
||||
REQUIRES = xpcom string webbrwsr widget dom necko pref appshell wallet layout chrome rdf profile xpinstall uriloader editor view windowwatcher embed_base embedcomponents mpfilelocprovider browser mozcomps docshell xremoteservice
|
||||
# for jprof
|
||||
REQUIRES += jprof
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@
|
|||
#ifdef MOZ_ENABLE_XREMOTE
|
||||
#include "nsXRemoteClientCID.h"
|
||||
#include "nsIXRemoteClient.h"
|
||||
#include "nsIXRemoteService.h"
|
||||
#endif
|
||||
#define TURBO_PREF "browser.turbo.enabled"
|
||||
|
||||
|
@ -1323,12 +1324,28 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp )
|
|||
|
||||
// From this point on, should be true
|
||||
appShell->SetQuitOnLastWindowClosing(PR_TRUE);
|
||||
|
||||
#ifdef MOZ_ENABLE_XREMOTE
|
||||
// if we have X remote support and we have our one window up and
|
||||
// running start listening for requests on the proxy window.
|
||||
nsCOMPtr<nsIXRemoteService> remoteService;
|
||||
remoteService = do_GetService(NS_IXREMOTESERVICE_CONTRACTID);
|
||||
if (remoteService)
|
||||
remoteService->Startup();
|
||||
#endif /* MOZ_ENABLE_XREMOTE */
|
||||
|
||||
// Start main event loop
|
||||
NS_TIMELINE_ENTER("appShell->Run");
|
||||
rv = appShell->Run();
|
||||
NS_TIMELINE_LEAVE("appShell->Run");
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to run appshell");
|
||||
|
||||
#ifdef MOZ_ENABLE_XREMOTE
|
||||
// shut down the x remote proxy window
|
||||
if (remoteService)
|
||||
remoteService->Shutdown();
|
||||
#endif /* MOZ_ENABLE_XREMOTE */
|
||||
|
||||
/*
|
||||
* Shut down the Shell instance... This is done even if the Run(...)
|
||||
* method returned an error.
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
|
||||
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
|
||||
const XREMOTESERVICE_CONTRACTID = "@mozilla.org/browser/xremoteservice;1";
|
||||
|
||||
var gURLBar = null;
|
||||
var gProxyButton = null;
|
||||
|
@ -342,6 +343,14 @@ function Startup()
|
|||
|
||||
// Perform default browser checking.
|
||||
checkForDefaultBrowser();
|
||||
|
||||
// hook up remote support
|
||||
if (XREMOTESERVICE_CONTRACTID in Components.classes) {
|
||||
var remoteService;
|
||||
remoteService = Components.classes[XREMOTESERVICE_CONTRACTID]
|
||||
.getService(Components.interfaces.nsIXRemoteService);
|
||||
remoteService.addBrowserInstance(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,6 +372,14 @@ function BrowserFlushBookmarksAndHistory() {
|
|||
|
||||
function Shutdown()
|
||||
{
|
||||
// remove remote support
|
||||
if (XREMOTESERVICE_CONTRACTID in Components.classes) {
|
||||
var remoteService;
|
||||
remoteService = Components.classes[XREMOTESERVICE_CONTRACTID]
|
||||
.getService(Components.interfaces.nsIXRemoteService);
|
||||
remoteService.removeBrowserInstance(window);
|
||||
}
|
||||
|
||||
var browser = getBrowser();
|
||||
|
||||
browser.boxObject.removeProperty("listenerkungfu");
|
||||
|
|
|
@ -41,7 +41,9 @@ function onLoad()
|
|||
dialog.openEditWindow = document.getElementById("editWindow");
|
||||
dialog.bundle = document.getElementById("openLocationBundle");
|
||||
|
||||
browser = window.arguments[0];
|
||||
if ("arguments" in window && window.arguments.length >= 1)
|
||||
browser = window.arguments[0];
|
||||
|
||||
if (!browser) {
|
||||
// No browser supplied - we are calling from Composer
|
||||
dialog.openAppList.selectedItem = dialog.openEditWindow;
|
||||
|
@ -163,4 +165,5 @@ function useUBHistoryItem(aMenuItem)
|
|||
{
|
||||
var urlbar = document.getElementById("dialog.input");
|
||||
urlbar.value = aMenuItem.getAttribute("label");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,5 +28,9 @@ include $(DEPTH)/config/autoconf.mk
|
|||
|
||||
DIRS = public bookmarks directory filepicker find history search sidebar related regviewer xfer prefwindow shistory remote timebomb console autocomplete urlbarhistory build
|
||||
|
||||
ifdef MOZ_ENABLE_XREMOTE
|
||||
DIRS += xremote
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ XRemoteService::ParseCommand(nsIWidget *aWidget,
|
|||
*/
|
||||
|
||||
if (action.Equals("openurl") || action.Equals("openfile")) {
|
||||
if (argument.Length() == 0)
|
||||
if (argument.IsEmpty())
|
||||
rv = OpenURLDialog(domWindow);
|
||||
else
|
||||
rv = OpenURL(argument, domWindow, PR_TRUE);
|
||||
|
@ -199,7 +199,7 @@ XRemoteService::ParseCommand(nsIWidget *aWidget,
|
|||
*/
|
||||
|
||||
else if (action.Equals("saveas")) {
|
||||
if (argument.Length() == 0) {
|
||||
if (argument.IsEmpty()) {
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
else {
|
||||
|
@ -252,7 +252,7 @@ XRemoteService::ParseCommand(nsIWidget *aWidget,
|
|||
*/
|
||||
|
||||
else if (action.Equals("addbookmark")) {
|
||||
if (argument.Length() == 0) {
|
||||
if (argument.IsEmpty()) {
|
||||
rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -220,6 +220,8 @@ bin/components/nsDictionary.js
|
|||
bin/components/nsProxyAutoConfig.js
|
||||
bin/components/nsXmlRpcClient.js
|
||||
bin/components/libxremote_client.so
|
||||
bin/components/libxremoteservice.so
|
||||
bin/components/xremoteservice.xpt
|
||||
bin/components/windowwatcher.xpt
|
||||
bin/components/xmlextras.xpt
|
||||
bin/components/libxmlextras.so
|
||||
|
|
Загрузка…
Ссылка в новой задаче