Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions
XRemoteService Class Reference

#include <XRemoteService.h>

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

List of all members.

Public Member Functions

 XRemoteService ()
virtual ~XRemoteService ()
 NS_DEFINE_STATIC_CID_ACCESSOR (NS_XREMOTESERVICE_CID)
void parseCommand (in string aCommand, in nsIDOMWindow aContext)
 Parse the command given.

Private Member Functions

void FindLastInList (nsCString &aString, nsCString &retString, PRUint32 *aIndexRet)
void FindRestInList (nsCString &aString, nsCString &retString, PRUint32 *aIndexRet)
nsresult OpenChromeWindow (nsIDOMWindow *aParent, const char *aUrl, const char *aFeatures, nsISupports *aArguments, nsIDOMWindow **_retval)
nsresult GetBrowserLocation (char **_retval)
nsresult GetMailLocation (char **_retval)
nsresult GetComposeLocation (const char **_retval)
nsresult GetCalendarLocation (char **_retval)
PRBool MayOpenURL (const nsCString &aURL)
nsresult OpenURL (nsCString &aArgument, nsIDOMWindow *aParent, PRBool aOpenBrowser)
nsresult XfeDoCommand (nsCString &aArgument, nsIDOMWindow *aParent)
nsresult FindWindow (const PRUnichar *aType, nsIDOMWindowInternal **_retval)

Detailed Description

Definition at line 51 of file XRemoteService.h.


Constructor & Destructor Documentation

Definition at line 75 of file XRemoteService.cpp.

{
}

Definition at line 79 of file XRemoteService.cpp.

{
}

Member Function Documentation

void XRemoteService::FindLastInList ( nsCString aString,
nsCString retString,
PRUint32 aIndexRet 
) [private]

Definition at line 284 of file XRemoteService.cpp.

{
  // 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;

}

Here is the caller graph for this function:

void XRemoteService::FindRestInList ( nsCString aString,
nsCString retString,
PRUint32 aIndexRet 
) [private]

Definition at line 252 of file XRemoteService.cpp.

{
  // init our return
  *aIndexRet = 0;
  nsCString tempString;
  PRInt32   strIndex;
  // find out if there's a comma from the start of the string
  strIndex = aString.FindChar(',');

  // give up now if you can
  if (strIndex == kNotFound)
    return;

  // cut the string down to the first ,
  tempString = Substring(aString, strIndex+1, aString.Length());

  // 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;

}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult XRemoteService::FindWindow ( const PRUnichar aType,
nsIDOMWindowInternal **  _retval 
) [private]

Definition at line 772 of file XRemoteService.cpp.

{
  nsCOMPtr<nsIWindowMediator> mediator;
  mediator = do_GetService(NS_WINDOWMEDIATOR_CONTRACTID);

  if (!mediator)
    return NS_ERROR_FAILURE;

  return mediator->GetMostRecentWindow(aType, _retval);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult XRemoteService::GetBrowserLocation ( char **  _retval) [private]

Definition at line 333 of file XRemoteService.cpp.

{
  // get the browser chrome URL
  nsCOMPtr<nsIPref> prefs;
  prefs = do_GetService(NS_PREF_CONTRACTID);
  if (!prefs)
    return NS_ERROR_FAILURE;
  
  prefs->CopyCharPref("browser.chromeURL", _retval);

  // fallback
  if (!*_retval)
    *_retval = nsCRT::strdup("chrome://navigator/content/navigator.xul");

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult XRemoteService::GetCalendarLocation ( char **  _retval) [private]

Definition at line 384 of file XRemoteService.cpp.

{
  // get the calendar chrome URL
  nsCOMPtr<nsIPref> prefs;
  prefs = do_GetService(NS_PREF_CONTRACTID);
  if (!prefs)
    return NS_ERROR_FAILURE;

  prefs->CopyCharPref("calendar.chromeURL", _retval);

  // fallback
  if (!*_retval)
    *_retval = nsCRT::strdup("chrome://calendar/content/calendar.xul");

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult XRemoteService::GetComposeLocation ( const char **  _retval) [private]

Definition at line 375 of file XRemoteService.cpp.

{
  // get the Compose chrome URL
  *_retval = "chrome://messenger/content/messengercompose/messengercompose.xul";

  return NS_OK;
}

Here is the caller graph for this function:

nsresult XRemoteService::GetMailLocation ( char **  _retval) [private]

Definition at line 351 of file XRemoteService.cpp.

{
  // get the mail chrome URL
  nsCOMPtr<nsIPref> prefs;
  prefs = do_GetService(NS_PREF_CONTRACTID);
  if (!prefs)
    return NS_ERROR_FAILURE;
  
  PRInt32 retval = 0;
  nsresult rv;
  rv = prefs->GetIntPref("mail.pane_config", &retval);
  if (NS_FAILED(rv))
    return NS_ERROR_FAILURE;

  if (!retval)
    *_retval = nsCRT::strdup("chrome://messenger/content/messenger.xul");
  else
    *_retval = nsCRT::strdup("chrome://messenger/content/mail3PaneWindowVertLayout.xul");

  return NS_OK;
  
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 402 of file XRemoteService.cpp.

{
  // by default, we assume nothing can be loaded.
  PRBool allowURL= PR_FALSE;

  nsCOMPtr<nsIExternalProtocolService> extProtService =
      do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID);
  if (extProtService) {
    nsCAutoString scheme;

    // empty URLs will be treated as about:blank by OpenURL
    if (aURL.IsEmpty()) {
      scheme.AssignLiteral("about");
    }
    else {
      nsCOMPtr<nsIURIFixup> fixup = do_GetService(NS_URIFIXUP_CONTRACTID);
      if (fixup) {
        nsCOMPtr<nsIURI> uri;
        nsresult rv =
          fixup->CreateFixupURI(aURL, nsIURIFixup::FIXUP_FLAGS_MAKE_ALTERNATE_URI,
                                getter_AddRefs(uri));
        if (NS_SUCCEEDED(rv) && uri) {
          uri->GetScheme(scheme);
        }
      }
    }

    if (!scheme.IsEmpty()) {
      // if the given URL scheme corresponds to an exposed protocol, then we
      // can try to load it.  otherwise, we must not.
      PRBool isExposed;
      nsresult rv = extProtService->IsExposedProtocol(scheme.get(), &isExposed);
      if (NS_SUCCEEDED(rv) && isExposed)
        allowURL = PR_TRUE; // ok, we can load this URL.
    }
  }

  return allowURL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult XRemoteService::OpenChromeWindow ( nsIDOMWindow aParent,
const char *  aUrl,
const char *  aFeatures,
nsISupports *  aArguments,
nsIDOMWindow **  _retval 
) [private]

Definition at line 317 of file XRemoteService.cpp.

{
  nsCOMPtr<nsIWindowWatcher> watcher;
  watcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID);
    
  if (!watcher)
    return NS_ERROR_FAILURE;

  return watcher->OpenWindow(aParent, aUrl, "_blank",
                          aFeatures, aArguments, _retval);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult XRemoteService::OpenURL ( nsCString aArgument,
nsIDOMWindow aParent,
PRBool  aOpenBrowser 
) [private]

Definition at line 443 of file XRemoteService.cpp.

{
  // the eventual toplevel target of the load
  nsCOMPtr<nsIDOMWindowInternal> finalWindow = do_QueryInterface(aParent);

  // see if there's a new-window or new-tab argument on the end
  nsCString lastArgument;
  PRBool    newWindow = PR_FALSE, newTab = PR_FALSE;
  PRUint32  index = 0;
  FindLastInList(aArgument, lastArgument, &index);

  newTab = lastArgument.LowerCaseEqualsLiteral("new-tab");

  if (newTab || lastArgument.LowerCaseEqualsLiteral("new-window")) {
    aArgument.Truncate(index);
    // only open new windows if it's OK to do so
    if (!newTab && aOpenBrowser)
      newWindow = PR_TRUE;
    // recheck for a possible noraise argument since it might have
    // been before the new-window argument
    FindLastInList(aArgument, lastArgument, &index);
    if (lastArgument.LowerCaseEqualsLiteral("noraise"))
      aArgument.Truncate(index);
  }

  nsCOMPtr<nsIBrowserDOMWindow> bwin;

  // If it's OK to open a new browser window and a new window flag
  // wasn't passed in then try to find a current window.  If that's
  // not found then go ahead and open a new window.
  // If we're trying to open a new tab, we'll fall back to opening
  // a new window if there's no browser window open, so look for it
  // here.
  if (aOpenBrowser && (!newWindow || newTab)) {
    nsCOMPtr<nsIDOMWindowInternal> lastUsedWindow;
    FindWindow(NS_LITERAL_STRING("navigator:browser").get(),
              getter_AddRefs(lastUsedWindow));

    if (lastUsedWindow) {
      finalWindow = lastUsedWindow;
      nsCOMPtr<nsIWebNavigation> navNav(do_GetInterface(finalWindow));
      nsCOMPtr<nsIDocShellTreeItem> navItem(do_QueryInterface(navNav));
      if (navItem) {
        nsCOMPtr<nsIDocShellTreeItem> rootItem;
        navItem->GetRootTreeItem(getter_AddRefs(rootItem));
        nsCOMPtr<nsIDOMWindow> rootWin(do_GetInterface(rootItem));
        nsCOMPtr<nsIDOMChromeWindow> chromeWin(do_QueryInterface(rootWin));
        if (chromeWin)
          chromeWin->GetBrowserDOMWindow(getter_AddRefs(bwin));
      }
    }
    if (!finalWindow || !bwin)
      newWindow = PR_TRUE;
  }

  // check if we can handle this type of URL
  if (!MayOpenURL(aArgument))
    return NS_ERROR_ABORT;

  nsresult rv = NS_OK;

  // try to fixup the argument passed in
  nsString url;
  url.AssignWithConversion(aArgument.get());

  nsCOMPtr<nsIURI> uri;
  NS_NewURI(getter_AddRefs(uri), url);

  if (newWindow) {
    nsXPIDLCString urlString;
    GetBrowserLocation(getter_Copies(urlString));
    if (!urlString)
      return NS_ERROR_FAILURE;

    nsCOMPtr<nsISupportsString> arg;
    arg = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
    if (!arg)
      return NS_ERROR_FAILURE;
    
    // save the url into the string object
    arg->SetData(url);
    
    nsCOMPtr<nsIDOMWindow> window;
    rv = OpenChromeWindow(finalWindow, urlString, "chrome,all,dialog=no",
                       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 (!finalWindow) {
    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);

    // double-check our uri object
    if (!uri)
      return NS_ERROR_FAILURE;

    // open a channel
    nsCOMPtr<nsIChannel> channel;
    rv = NS_NewChannel(getter_AddRefs(channel), uri);
    if (NS_FAILED(rv))
      return NS_ERROR_FAILURE;

    // load it
    rv = loader->OpenURI(channel, PR_TRUE, listener);
  }

  else if (newTab && aOpenBrowser) {
    if (bwin && uri) {
      nsCOMPtr<nsIDOMWindow> container;
      rv = bwin->OpenURI(uri, 0,
                         nsIBrowserDOMWindow::OPEN_NEWTAB,
                         nsIBrowserDOMWindow::OPEN_EXTERNAL,
                         getter_AddRefs(container));
    }
    else {
      NS_ERROR("failed to open remote URL in new tab");
      return NS_ERROR_FAILURE;
    }
  }

  else if (bwin && uri) { // unspecified new browser URL; use prefs
    nsCOMPtr<nsIDOMWindow> container;
    rv = bwin->OpenURI(uri, 0,
                       nsIBrowserDOMWindow::OPEN_DEFAULTWINDOW,
                       nsIBrowserDOMWindow::OPEN_EXTERNAL,
                       getter_AddRefs(container));
    if (NS_SUCCEEDED(rv))
      return NS_OK;
  }

  else { // non-browser URLs
    // find the primary content shell for the window that we've been
    // asked to load into.
    nsCOMPtr<nsIScriptGlobalObject> scriptObject;
    scriptObject = do_QueryInterface(finalWindow);
    if (!scriptObject) {
      NS_WARNING("Failed to get script object for browser instance");
      return NS_ERROR_FAILURE;
    }

    nsCOMPtr<nsIDocShell> docShell = scriptObject->GetDocShell();
    if (!docShell) {
      NS_WARNING("Failed to get docshell object for browser instance");
      return NS_ERROR_FAILURE;
    }

    nsCOMPtr<nsIDocShellTreeItem> item(do_QueryInterface(docShell));
    if (!item) {
      NS_WARNING("failed to get doc shell tree item for browser instance");
      return NS_ERROR_FAILURE;
    }

    nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
    item->GetTreeOwner(getter_AddRefs(treeOwner));
    if (!treeOwner) {
      NS_WARNING("failed to get tree owner");
      return NS_ERROR_FAILURE;
    }

    nsCOMPtr<nsIDocShellTreeItem> primaryContent;
    treeOwner->GetPrimaryContentShell(getter_AddRefs(primaryContent));

    docShell = do_QueryInterface(primaryContent);
    if (!docShell) {
      NS_WARNING("failed to get docshell from primary content item");
      return NS_ERROR_FAILURE;
    }

    nsCOMPtr<nsIWebNavigation> webNav;
    webNav = do_GetInterface(docShell);
    if (!webNav) {
      NS_WARNING("failed to get web nav from inner docshell");
      return NS_ERROR_FAILURE;
    }

    rv = webNav->LoadURI(url.get(),
                         nsIWebNavigation::LOAD_FLAGS_NONE,
                         nsnull,
                         nsnull,
                         nsnull);

  }

  return rv;
}

Here is the call graph for this function:

void nsISuiteRemoteService::parseCommand ( in string  aCommand,
in nsIDOMWindow  aContext 
) [inherited]

Parse the command given.

Parameters:
aCommandThe command string, e.g. "openURL(http://www.foo.com/)"
aContextThe domwindow to target the command at. May be null, and may be ignored.
nsresult XRemoteService::XfeDoCommand ( nsCString aArgument,
nsIDOMWindow aParent 
) [private]

Definition at line 648 of file XRemoteService.cpp.

{
  nsresult rv = NS_OK;
  
  // see if there are any arguments on the end
  nsCString restArgument;
  PRUint32  index;
  FindRestInList(aArgument, restArgument, &index);

  if (!restArgument.IsEmpty())
    aArgument.Truncate(index);
  nsCOMPtr<nsISupportsString> arg;
  arg = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
  
  if (NS_FAILED(rv))
    return rv;
  
  // pass the second argument as parameter
  arg->SetData(NS_ConvertUTF8toUCS2(restArgument));

  // someone requested opening mail/news
  if (aArgument.LowerCaseEqualsLiteral("openinbox")) {

    // check to see if it's already running
    nsCOMPtr<nsIDOMWindowInternal> domWindow;

    rv = FindWindow(NS_LITERAL_STRING("mail:3pane").get(),
                    getter_AddRefs(domWindow));

    if (NS_FAILED(rv))
      return rv;

    // focus the window if it was found
    if (domWindow) {
      domWindow->Focus();
    }

    // otherwise open a new mail/news window
    else {
      // get the mail chrome location
      nsXPIDLCString mailLocation;
      GetMailLocation(getter_Copies(mailLocation));
      if (!mailLocation)
       return NS_ERROR_FAILURE;

      nsCOMPtr<nsIDOMWindow> newWindow;
      rv = OpenChromeWindow(0, mailLocation, "chrome,all,dialog=no",
                            arg, getter_AddRefs(newWindow));
    }
  }

  // open a new browser window
  else if (aArgument.LowerCaseEqualsLiteral("openbrowser")) {
    // Get the browser URL and the default start page URL.
    nsCOMPtr<nsICmdLineHandler> browserHandler =
        do_GetService("@mozilla.org/commandlinehandler/general-startup;1?type=browser");

    if (!browserHandler)
        return NS_ERROR_FAILURE;

    nsXPIDLCString browserLocation;
    browserHandler->GetChromeUrlForTask(getter_Copies(browserLocation));

    nsXPIDLString startPage;
    browserHandler->GetDefaultArgs(getter_Copies(startPage));

    arg->SetData(startPage);

    nsCOMPtr<nsIDOMWindow> newWindow;
    rv = OpenChromeWindow(0, browserLocation, "chrome,all,dialog=no",
                          arg, getter_AddRefs(newWindow));
  }

  // open a new compose window
  else if (aArgument.LowerCaseEqualsLiteral("composemessage")) {
    /*
     *  Here we change to OpenChromeWindow instead of OpenURL so as to
     *  pass argument values to the compose window, especially attachments
     */
    const char * composeLocation;
    rv = GetComposeLocation(&composeLocation);
    if (rv != NS_OK)
      return NS_ERROR_FAILURE;

    nsCOMPtr<nsIDOMWindow> newWindow;
    rv = OpenChromeWindow(0, composeLocation, "chrome,all,dialog=no",
                          arg, getter_AddRefs(newWindow));
  }

  // open a new calendar window
  else if (aArgument.LowerCaseEqualsLiteral("opencalendar")) {

    // check to see if it's already running
    nsCOMPtr<nsIDOMWindowInternal> aWindow;

    rv = FindWindow(NS_LITERAL_STRING("calendarMainWindow").get(),
                  getter_AddRefs(aWindow));

    if (NS_FAILED(rv))
      return rv;

    // focus the window if it was found
    if (aWindow) {
      aWindow->Focus();
    }

    // otherwise open a new calendar window
    else {
      nsXPIDLCString calendarChrome;
      rv = GetCalendarLocation(getter_Copies(calendarChrome));
      if (NS_FAILED(rv))
        return rv;

      nsCOMPtr<nsIDOMWindow> newWindow;
      rv = OpenChromeWindow(0, calendarChrome, "chrome,all,dialog=no",
                            arg, getter_AddRefs(newWindow));
    }
  }

  return rv;
}

Here is the call graph for this function:


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