Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
nsGTKRemoteService Class Reference

#include <nsGTKRemoteService.h>

Inheritance diagram for nsGTKRemoteService:
Inheritance graph
[legend]
Collaboration diagram for nsGTKRemoteService:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIREMOTESERVICE
NS_DECL_NSIOBSERVER 
nsGTKRemoteService ()
void startup (in string appName, in string profileName)
 Start the remote service.
void registerWindow (in nsIDOMWindow aWindow)
 Register a XUL window with the xremote service.
void shutdown ()
 Stop the remote service from accepting additional requests.
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Private Member Functions

 ~nsGTKRemoteService ()
void HandleCommandsFor (GtkWidget *aWidget, nsIWeakReference *aWindow)

Static Private Member Functions

static void EnsureAtoms ()
static PLDHashOperator StartupHandler (const void *aKey, nsIWeakReference *aData, void *aClosure)
static const char * HandleCommand (char *aCommand, nsIDOMWindow *aWindow)
static gboolean HandlePropertyChange (GtkWidget *widget, GdkEventProperty *event, nsIWeakReference *aThis)

Private Attributes

GtkWidget * mServerWindow
nsCString mAppName
nsCString mProfileName
nsInterfaceHashtable
< nsVoidPtrHashKey,
nsIWeakReference
mWindows

Static Private Attributes

static Atom sMozVersionAtom
static Atom sMozLockAtom
static Atom sMozCommandAtom
static Atom sMozResponseAtom
static Atom sMozUserAtom
static Atom sMozProfileAtom
static Atom sMozProgramAtom
static Atom sMozCommandLineAtom

Detailed Description

Definition at line 60 of file nsGTKRemoteService.h.


Constructor & Destructor Documentation

NS_DECL_ISUPPORTS NS_DECL_NSIREMOTESERVICE NS_DECL_NSIOBSERVER nsGTKRemoteService::nsGTKRemoteService ( ) [inline]

Definition at line 69 of file nsGTKRemoteService.h.

Definition at line 73 of file nsGTKRemoteService.h.

{ }

Member Function Documentation

void nsGTKRemoteService::EnsureAtoms ( void  ) [static, private]

Definition at line 243 of file nsGTKRemoteService.cpp.

const char * nsGTKRemoteService::HandleCommand ( char *  aCommand,
nsIDOMWindow aWindow 
) [static, private]

Definition at line 263 of file nsGTKRemoteService.cpp.

{
  nsresult rv;

  nsCOMPtr<nsISuiteRemoteService> remote
    (do_GetService("@mozilla.org/browser/xremoteservice;2"));
  if (!remote)
    return "509 internal error";

  rv = remote->ParseCommand(aCommand, aWindow);
  if (NS_SUCCEEDED(rv))
    return "200 executed command";

  if (NS_ERROR_INVALID_ARG == rv)
    return "500 command not parseable";

  if (NS_ERROR_NOT_IMPLEMENTED == rv)
    return "501 unrecognized command";

  return "509 internal error";
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsGTKRemoteService::HandleCommandsFor ( GtkWidget *  aWidget,
nsIWeakReference aWindow 
) [private]

Definition at line 401 of file nsGTKRemoteService.cpp.

{
#ifdef MOZ_WIDGET_GTK2
  g_signal_connect(G_OBJECT(widget), "property_notify_event",
                   G_CALLBACK(HandlePropertyChange), aWindow);
#else // GTK+
  gtk_signal_connect(GTK_OBJECT(widget), "property_notify_event",
                     GTK_SIGNAL_FUNC(HandlePropertyChange), aWindow);
#endif

  gtk_widget_add_events(widget, GDK_PROPERTY_CHANGE_MASK);

  Window window = GDK_WINDOW_XWINDOW(widget->window);

  // set our version
  XChangeProperty(GDK_DISPLAY(), window, sMozVersionAtom, XA_STRING,
                  8, PropModeReplace, kRemoteVersion, sizeof(kRemoteVersion) - 1);

  // get our username
  unsigned char *logname;
  logname = (unsigned char*) PR_GetEnv("LOGNAME");
  if (logname) {
    // set the property on the window if it's available
    XChangeProperty(GDK_DISPLAY(), window, sMozUserAtom, XA_STRING,
                    8, PropModeReplace, logname, strlen((char*) logname));
  }

  XChangeProperty(GDK_DISPLAY(), window, sMozProgramAtom, XA_STRING,
                  8, PropModeReplace, (unsigned char*) mAppName.get(), mAppName.Length());

  if (!mProfileName.IsEmpty()) {
    XChangeProperty(GDK_DISPLAY(), window, sMozProfileAtom, XA_STRING,
                    8, PropModeReplace, (unsigned char*) mProfileName.get(), mProfileName.Length());
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean nsGTKRemoteService::HandlePropertyChange ( GtkWidget *  widget,
GdkEventProperty *  event,
nsIWeakReference aThis 
) [static, private]

Definition at line 445 of file nsGTKRemoteService.cpp.

{
  nsCOMPtr<nsIDOMWindow> window (do_QueryReferent(aThis));

  if (pevent->state == GDK_PROPERTY_NEW_VALUE &&
      CMP_GATOM_XATOM(pevent->atom, sMozCommandAtom)) {

    // We got a new command atom.
    int result;
    Atom actual_type;
    int actual_format;
    unsigned long nitems, bytes_after;
    char *data = 0;

    result = XGetWindowProperty (GDK_DISPLAY(),
                                 GDK_WINDOW_XWINDOW(pevent->window),
                                 sMozCommandAtom,
                                 0,                        /* long_offset */
                                 (65536 / sizeof (long)),  /* long_length */
                                 True,                     /* atomic delete after */
                                 XA_STRING,                /* req_type */
                                 &actual_type,             /* actual_type return */
                                 &actual_format,           /* actual_format_return */
                                 &nitems,                  /* nitems_return */
                                 &bytes_after,             /* bytes_after_return */
                                 (unsigned char **)&data); /* prop_return
                                                              (we only care
                                                              about the first ) */

#ifdef DEBUG_bsmedberg
    printf("Handling command: %s\n", data);
#endif

    // Failed to get property off the window?
    if (result != Success)
      return FALSE;

    // Failed to get the data off the window or it was the wrong type?
    if (!data || !TO_LITTLE_ENDIAN32(*NS_REINTERPRET_CAST(PRInt32*, data)))
      return FALSE;

    // cool, we got the property data.
    const char *response = HandleCommand(data, window);

    // put the property onto the window as the response
    XChangeProperty (GDK_DISPLAY(), GDK_WINDOW_XWINDOW(pevent->window),
                     sMozResponseAtom, XA_STRING,
                     8, PropModeReplace, (const unsigned char *)response, strlen (response));
    XFree(data);
    return TRUE;
  }

#ifdef MOZ_XUL_APP
  if (pevent->state == GDK_PROPERTY_NEW_VALUE &&
      CMP_GATOM_XATOM(pevent->atom, sMozCommandLineAtom)) {

    // We got a new commandline atom.
    int result;
    Atom actual_type;
    int actual_format;
    unsigned long nitems, bytes_after;
    char *data = 0;

    result = XGetWindowProperty (GDK_DISPLAY(),
                                 GDK_WINDOW_XWINDOW(pevent->window),
                                 sMozCommandLineAtom,
                                 0,                        /* long_offset */
                                 (65536 / sizeof (long)),  /* long_length */
                                 True,                     /* atomic delete after */
                                 XA_STRING,                /* req_type */
                                 &actual_type,             /* actual_type return */
                                 &actual_format,           /* actual_format_return */
                                 &nitems,                  /* nitems_return */
                                 &bytes_after,             /* bytes_after_return */
                                 (unsigned char **)&data); /* prop_return
                                                              (we only care
                                                              about the first ) */

    // Failed to get property off the window?
    if (result != Success)
      return FALSE;

    // Failed to get the data off the window or it was the wrong type?
    if (!data || !TO_LITTLE_ENDIAN32(*NS_REINTERPRET_CAST(PRInt32*, data)))
      return FALSE;

    // cool, we got the property data.
    const char *response = HandleCommandLine(data, window);

    // put the property onto the window as the response
    XChangeProperty (GDK_DISPLAY(), GDK_WINDOW_XWINDOW(pevent->window),
                     sMozResponseAtom, XA_STRING,
                     8, PropModeReplace, (const unsigned char *)response, strlen (response));
    XFree(data);
    return TRUE;
  }
#endif //MOZ_XUL_APP

  if (pevent->state == GDK_PROPERTY_NEW_VALUE && 
      CMP_GATOM_XATOM(pevent->atom, sMozResponseAtom)) {
    // client accepted the response.  party on wayne.
    return TRUE;
  }

  if (pevent->state == GDK_PROPERTY_NEW_VALUE && 
      CMP_GATOM_XATOM(pevent->atom, sMozLockAtom)) {
    // someone locked the window
    return TRUE;
  }

  return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.

Register a XUL window with the xremote service.

The window will be configured to accept incoming remote requests. If this method is called before startup(), the registration will happen once startup() is called.

Stop the remote service from accepting additional requests.

void nsIRemoteService::startup ( in string  appName,
in string  profileName 
) [inherited]

Start the remote service.

This should not be done until app startup appears to have been successful.

Parameters:
appName(Required) Sets a window property identifying the application.
profileName(May be null) Sets a window property identifying the profile name.
PLDHashOperator nsGTKRemoteService::StartupHandler ( const void aKey,
nsIWeakReference aData,
void aClosure 
) [static, private]

Definition at line 147 of file nsGTKRemoteService.cpp.

{
  GtkWidget* widget = (GtkWidget*) aKey;
  nsGTKRemoteService* aThis = (nsGTKRemoteService*) aClosure;

  aThis->HandleCommandsFor(widget, aData);
  return PL_DHASH_NEXT;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 94 of file nsGTKRemoteService.h.

Definition at line 95 of file nsGTKRemoteService.h.

GtkWidget* nsGTKRemoteService::mServerWindow [private]

Definition at line 93 of file nsGTKRemoteService.h.

Definition at line 96 of file nsGTKRemoteService.h.

Atom nsGTKRemoteService::sMozCommandAtom [static, private]

Definition at line 100 of file nsGTKRemoteService.h.

Definition at line 105 of file nsGTKRemoteService.h.

Atom nsGTKRemoteService::sMozLockAtom [static, private]

Definition at line 99 of file nsGTKRemoteService.h.

Atom nsGTKRemoteService::sMozProfileAtom [static, private]

Definition at line 103 of file nsGTKRemoteService.h.

Atom nsGTKRemoteService::sMozProgramAtom [static, private]

Definition at line 104 of file nsGTKRemoteService.h.

Atom nsGTKRemoteService::sMozResponseAtom [static, private]

Definition at line 101 of file nsGTKRemoteService.h.

Atom nsGTKRemoteService::sMozUserAtom [static, private]

Definition at line 102 of file nsGTKRemoteService.h.

Atom nsGTKRemoteService::sMozVersionAtom [static, private]

Definition at line 98 of file nsGTKRemoteService.h.


The documentation for this class was generated from the following files: