Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Protected Member Functions
AEGetURLSuiteHandler Class Reference

#include <nsAEGetURLSuiteHandler.h>

List of all members.

Public Types

enum  { kSuiteSignature = 'GURL', kGetURLEvent = 'GURL', kInsideWindowParameter = 'HWIN', kReferrerParameter = 'refe' }

Public Member Functions

 AEGetURLSuiteHandler ()
 ~AEGetURLSuiteHandler ()
void HandleGetURLSuiteEvent (const AppleEvent *appleEvent, AppleEvent *reply)

Protected Member Functions

void HandleGetURLEvent (const AppleEvent *appleEvent, AppleEvent *reply)

Detailed Description

Definition at line 48 of file nsAEGetURLSuiteHandler.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
kSuiteSignature 
kGetURLEvent 
kInsideWindowParameter 
kReferrerParameter 

Definition at line 51 of file nsAEGetURLSuiteHandler.h.

            {
              kSuiteSignature                    = 'GURL',
              kGetURLEvent                = 'GURL',
              
              kInsideWindowParameter      = 'HWIN',
              kReferrerParameter          = 'refe'             
       };

Constructor & Destructor Documentation

Definition at line 63 of file nsAEGetURLSuiteHandler.cpp.

{
}

Definition at line 71 of file nsAEGetURLSuiteHandler.cpp.

{
}

Member Function Documentation

void AEGetURLSuiteHandler::HandleGetURLEvent ( const AppleEvent *  appleEvent,
AppleEvent *  reply 
) [protected]

Definition at line 127 of file nsAEGetURLSuiteHandler.cpp.

{
       StAEDesc             directParameter;
       WindowPtr            targetWindow = NULL;
       OSErr                       err;
       
       // extract the direct parameter (an object specifier)
       err = ::AEGetKeyDesc(appleEvent, keyDirectObject, typeWildCard, &directParameter);
       ThrowIfOSErr(err);

       // we need to look for other parameters, to do with destination etc.
       long          dataSize = directParameter.GetDataSize();
       char*  urlString = (char *)nsMemory::Alloc(dataSize + 1);
       ThrowIfNil(urlString);      
       directParameter.GetCString(urlString, dataSize + 1);

       // bail if it is a chrome URL for security reasons (bug 305374)
        // Don't use nsIURI because xpcom may not be running
        CFURLRef url = ::CFURLCreateWithBytes(nsnull, (UInt8*)urlString,
                                              dataSize,
                                              kCFStringEncodingUTF8,
                                              nsnull);
        if (!url)
          return;

        CFStringRef scheme = ::CFURLCopyScheme(url);
        ::CFRelease(url);
        if (!scheme)
          return;

        CFComparisonResult isChrome = ::CFStringCompare(scheme, CFSTR("chrome"),
                                                        kCFCompareCaseInsensitive);
        ::CFRelease(scheme);

        if (isChrome == kCFCompareEqualTo)
          return;

       // get the destination window, if applicable
       StAEDesc             openInWindowDesc;
       err = ::AEGetKeyDesc(appleEvent, kInsideWindowParameter, typeObjectSpecifier, &openInWindowDesc);
       if (err != errAEDescNotFound)
       {
              // resolve the object specifier into a token record
              StAEDesc             tokenDesc;
              err = ::AEResolve(&openInWindowDesc, kAEIDoMinimum, &tokenDesc);
              ThrowIfOSErr(err);
              
              ConstAETokenDesc     tokenContainer(&tokenDesc);
              targetWindow = tokenContainer.GetWindowPtr();           
       }

  // if the AE didn't specify a target, try to dispatch to the frontmost
  // window. there user prefs for determining the actual target window
  // will be respected.
  if ( targetWindow )
    LoadURLInWindow(targetWindow, urlString);
  else {
    nsCOMPtr<nsIXULWindow> xulwindow;
    nsCOMPtr<nsIWindowMediator> mediator (
                                do_GetService(NS_WINDOWMEDIATOR_CONTRACTID) );
    if ( mediator ) {
      nsCOMPtr<nsISimpleEnumerator> windowEnum;
      mediator->GetZOrderXULWindowEnumerator(
                  NS_LITERAL_STRING("navigator:browser").get(),
                  PR_TRUE, getter_AddRefs(windowEnum));
      if ( windowEnum ) {
        nsCOMPtr<nsISupports> windowSupports;
        windowEnum->GetNext(getter_AddRefs(windowSupports));
        xulwindow = do_QueryInterface(windowSupports);
      }
    }
    if ( xulwindow )
      LoadURLInXULWindow(xulwindow, urlString);
    else
      LoadURLInWindow(nsnull, urlString);
  }

       nsMemory::Free(urlString);  
}

Here is the call graph for this function:

void AEGetURLSuiteHandler::HandleGetURLSuiteEvent ( const AppleEvent *  appleEvent,
AppleEvent *  reply 
)

Definition at line 80 of file nsAEGetURLSuiteHandler.cpp.

{
       OSErr         err = noErr;
       
       AEEventID            eventID;
       OSType        typeCode;
       Size                 actualSize    = 0L;
       
       // Get the event ID
       err = AEGetAttributePtr(appleEvent,       keyEventIDAttr, 
                                                               typeType, 
                                                               &typeCode, 
                                                               (Ptr)&eventID, 
                                                               sizeof(eventID), 
                                                               &actualSize);
       ThrowIfOSErr(err);
       
       try
       {
              switch (eventID)
              {
                     case kGetURLEvent:
                            HandleGetURLEvent(appleEvent, reply);
                            break;
                            
                     default:
                            ThrowOSErr(errAEEventNotHandled);
                            break;
              }
       }
       catch (OSErr catchErr)
       {
              PutReplyErrorNumber(reply, catchErr);
              throw;
       }
       catch ( ... )
       {
              PutReplyErrorNumber(reply, paramErr);
              throw;
       }
}

Here is the call graph for this function:


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