Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
ns4xPluginInstance Class Reference

#include <ns4xPluginInstance.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS NS_METHOD Initialize (nsIPluginInstancePeer *peer)
 Actually initialize the plugin instance.
NS_IMETHOD GetPeer (nsIPluginInstancePeer **resultingPeer)
NS_IMETHOD Start (void)
NS_IMETHOD Stop (void)
NS_IMETHOD Destroy (void)
NS_IMETHOD SetWindow (nsPluginWindow *window)
NS_IMETHOD NewStream (nsIPluginStreamListener **listener)
NS_IMETHOD Print (nsPluginPrint *platformPrint)
NS_IMETHOD GetValue (nsPluginInstanceVariable variable, void *value)
NS_IMETHOD HandleEvent (nsPluginEvent *event, PRBool *handled)
NS_IMETHOD GetScriptablePeer (void **aScriptablePeer)
NS_IMETHOD GetScriptableInterface (nsIID **aScriptableInterface)
virtual JSObjectGetJSObject (JSContext *cx)
virtual nsresult GetFormValue (nsAString &aValue)
virtual void PushPopupsEnabledState (PRBool aEnabled)
virtual void PopPopupsEnabledState ()
virtual PRUint16 GetPluginAPIVersion ()
nsresult GetNPP (NPP *aNPP)
 Return the 4.x-style interface object.
nsresult GetCallbacks (const NPPluginFuncs **aCallbacks)
 Return the callbacks for the plugin instance.
nsresult SetWindowless (PRBool aWindowless)
nsresult SetTransparent (PRBool aTransparent)
nsresult NewNotifyStream (nsIPluginStreamListener **listener, void *notifyData, PRBool aCallNotify, const char *aURL)
 ns4xPluginInstance (NPPluginFuncs *callbacks, PRLibrary *aLibrary)
 Construct a new 4.x plugin instance with the specified peer and callbacks.
virtual ~ns4xPluginInstance (void)
PRBool IsStarted (void)
nsresult SetCached (PRBool aCache)
nsIPluginInstancePeerPeer ()
already_AddRefed< nsIDOMWindowGetDOMWindow ()
void initialize (in nsIPluginInstancePeer aPeer)
 Initializes a newly created plugin instance, passing to it the plugin instance peer which it should use for all communication back to the browser.
void start ()
 Called to instruct the plugin instance to start.
void stop ()
 Called to instruct the plugin instance to stop, thereby suspending its state.
void destroy ()
 Called to instruct the plugin instance to destroy itself.
void setWindow (in nsPluginWindowPtr aWindow)
 Called when the window containing the plugin instance changes.
void newStream (out nsIPluginStreamListener aListener)
 Called to tell the plugin that the initial src/data stream is ready.
void print (in nsPluginPrintPtr aPlatformPrint)
 Called to instruct the plugin instance to print itself to a printer.
void getValue (in nsPluginInstanceVariable aVariable, in voidPtr aValue)
 Returns the value of a variable associated with the plugin instance.
void handleEvent (in nsPluginEventPtr aEvent, out boolean aHandled)
 Handles an event.

Public Attributes

PRLibraryfLibrary
nsInstanceStreammStreams
nsVoidArray mPopupStates
readonly attribute
nsIPluginInstancePeer 
peer
 Returns a reference back to the plugin instance peer.
readonly attribute nsQIResult scriptablePeer
 The object to be wrapped and exposed to JavaScript.
readonly attribute nsIIDPtr scriptableInterface
 The interface that XPConnect should use when exposing the peer object to JavaScript.

Protected Member Functions

nsresult InitializePlugin (nsIPluginInstancePeer *peer)
nsresult GetValueInternal (NPPVariable variable, void *value)
 Calls NPP_GetValue.

Protected Attributes

nsCOMPtr< nsIPluginInstancePeermPeer
 The plugin instance peer for this instance.
NPPluginFuncsfCallbacks
 A pointer to the plugin's callback functions.
NPP_t fNPP
 The 4.x-style structure used to communicate between the plugin instance and the browser.
PRPackedBool mWindowless
PRPackedBool mTransparent
PRPackedBool mStarted
PRPackedBool mCached

Detailed Description

Definition at line 86 of file ns4xPluginInstance.h.


Constructor & Destructor Documentation

Construct a new 4.x plugin instance with the specified peer and callbacks.

Definition at line 834 of file ns4xPluginInstance.cpp.

{
  PLUGIN_LOG(PLUGIN_LOG_BASIC, ("ns4xPluginInstance dtor: this=%p\n",this));

#if defined(MOZ_WIDGET_GTK) || defined (MOZ_WIDGET_GTK2)
  if (mXtBin)
    gtk_widget_destroy(mXtBin);
#elif defined(MOZ_WIDGET_XLIB)
  if (mXlibXtBin) {
    delete mXlibXtBin;
  }
#endif

  // clean the stream list if any
  for(nsInstanceStream *is = mStreams; is != nsnull;) {
    nsInstanceStream * next = is->mNext;
    delete is;
    is = next;
  }
}

Member Function Documentation

Definition at line 1208 of file ns4xPluginInstance.cpp.

{
  PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("ns4xPluginInstance::Destroy this=%p\n",this));

  // destruction is handled in the Stop call
  return NS_OK;
}

Called to instruct the plugin instance to destroy itself.

This is called when it become no longer possible to return to the plugin instance, either because the browser window's history list of pages is being trimmed, or because the window containing this page in the history is being closed.

Returns:
- NS_OK if this operation was successful

Return the callbacks for the plugin instance.

Definition at line 1631 of file ns4xPluginInstance.cpp.

{
  if(aCallbacks != nsnull)
    *aCallbacks = fCallbacks;
  else
    return NS_ERROR_NULL_POINTER;

  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 981 of file ns4xPluginInstance.cpp.

{
  nsCOMPtr<nsPIPluginInstancePeer> pp (do_QueryInterface(mPeer));
  if (!pp) {
    return nsnull;
  }

  nsCOMPtr<nsIPluginInstanceOwner> owner;
  pp->GetOwner(getter_AddRefs(owner));

  if (!owner) {
    return nsnull;
  }

  nsCOMPtr<nsIDocument> doc;
  owner->GetDocument(getter_AddRefs(doc));

  if (!doc) {
    return nsnull;
  }

  nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject();

  if (!sgo) {
    return nsnull;
  }

  nsIDOMWindow *window;
  CallQueryInterface(sgo, &window);

  return window;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult ns4xPluginInstance::GetFormValue ( nsAString &  aValue) [virtual]

Definition at line 1697 of file ns4xPluginInstance.cpp.

{
  aValue.Truncate();

  char *value = nsnull;
  nsresult rv = GetValueInternal(NPPVformValue, &value);

  if (NS_SUCCEEDED(rv) && value) {
    CopyUTF8toUTF16(value, aValue);

    // NPPVformValue allocates with NPN_MemAlloc(), which uses
    // nsMemory.
    nsMemory::Free(value);
  }

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 1680 of file ns4xPluginInstance.cpp.

{
  JSObject *obj = nsnull;
  NPObject *npobj = nsnull;

  nsresult rv = GetValueInternal(NPPVpluginScriptableNPObject, &npobj);

  if (NS_SUCCEEDED(rv) && npobj) {
    obj = nsNPObjWrapper::GetNewOrUsed(&fNPP, cx, npobj);

    _releaseobject(npobj);
  }

  return obj;
}

Here is the call graph for this function:

Return the 4.x-style interface object.

Definition at line 1619 of file ns4xPluginInstance.cpp.

{
  if(aNPP != nsnull)
    *aNPP = &fNPP;
  else
    return NS_ERROR_NULL_POINTER;

  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 878 of file ns4xPluginInstance.cpp.

{
  *resultingPeer = mPeer;
  NS_IF_ADDREF(*resultingPeer);
  
  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 1761 of file ns4xPluginInstance.cpp.

{
  return fCallbacks->version;
}

Definition at line 1670 of file ns4xPluginInstance.cpp.

{
  if (!aScriptableInterface)
    return NS_ERROR_NULL_POINTER;

  *aScriptableInterface = nsnull;
  return GetValueInternal(NPPVpluginScriptableIID, (void*)aScriptableInterface);
}

Here is the call graph for this function:

Definition at line 1659 of file ns4xPluginInstance.cpp.

{
  if (!aScriptablePeer)
    return NS_ERROR_NULL_POINTER;

  *aScriptablePeer = nsnull;
  return GetValueInternal(NPPVpluginScriptableInstance, aScriptablePeer);
}

Here is the call graph for this function:

Definition at line 1588 of file ns4xPluginInstance.cpp.

{
  nsresult  res = NS_OK;

  switch (variable) {
    case nsPluginInstanceVariable_WindowlessBool:
      *(PRBool *)value = mWindowless;
      break;

    case nsPluginInstanceVariable_TransparentBool:
      *(PRBool *)value = mTransparent;
      break;

    case nsPluginInstanceVariable_DoCacheBool:
      *(PRBool *)value = mCached;
      break;

    case nsPluginInstanceVariable_CallSetWindowAfterDestroyBool:
      *(PRBool *)value = 0;  // not supported for 4.x plugins
      break;

    default:
      res = GetValueInternal((NPPVariable)variable, value);
  }

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIPluginInstance::getValue ( in nsPluginInstanceVariable  aVariable,
in voidPtr  aValue 
) [inherited]

Returns the value of a variable associated with the plugin instance.

Parameters:
aVariable- the plugin instance variable to get
aValue- the address of where to store the resulting value
Returns:
- NS_OK if this operation was successful
nsresult ns4xPluginInstance::GetValueInternal ( NPPVariable  variable,
void value 
) [protected]

Calls NPP_GetValue.

Definition at line 1549 of file ns4xPluginInstance.cpp.

{
  nsresult  res = NS_OK;
  if(fCallbacks->getvalue && mStarted) {

    NS_TRY_SAFE_CALL_RETURN(res, 
                            CallNPP_GetValueProc(fCallbacks->getvalue, 
                                                 &fNPP, 
                                                 variable, 
                                                 value), 
                                                 fLibrary, this);
    NPP_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
    ("NPP GetValue called: this=%p, npp=%p, var=%d, value=%d, return=%d\n", 
    this, &fNPP, variable, value, res));

#ifdef XP_OS2
    /* Query interface for legacy Flash plugin */
    if (res == NS_OK && variable == NPPVpluginScriptableInstance)
    {
      nsCOMPtr<nsILegacyPluginWrapperOS2> wrapper =
               do_GetService(NS_LEGACY_PLUGIN_WRAPPER_CONTRACTID, &res);
      if (res == NS_OK)
      {
        nsIID *iid = nsnull; 
        res = CallNPP_GetValueProc(fCallbacks->getvalue, &fNPP, 
                                   NPPVpluginScriptableIID, (void *)&iid);
        if (res == NS_OK)
          res = wrapper->MaybeWrap(*iid, *(nsISupports**)value,
                                   (nsISupports**)value);
      }
    }
#endif
  }

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1511 of file ns4xPluginInstance.cpp.

{
  if(!mStarted)
    return NS_OK;

  if (event == nsnull)
    return NS_ERROR_FAILURE;

  PRInt16 result = 0;
  
  if (fCallbacks->event) {
#if defined(XP_MAC) || defined(XP_MACOSX)
    result = CallNPP_HandleEventProc(fCallbacks->event,
                                     &fNPP,
                                     (void*) event->event);
#endif

#if defined(XP_WIN) || defined(XP_OS2)
      NPEvent npEvent;
      npEvent.event = event->event;
      npEvent.wParam = event->wParam;
      npEvent.lParam = event->lParam;

      NS_TRY_SAFE_CALL_RETURN(result, CallNPP_HandleEventProc(fCallbacks->event,
                                    &fNPP,
                                    (void*)&npEvent), fLibrary, this);
#endif

      NPP_PLUGIN_LOG(PLUGIN_LOG_NOISY,
      ("NPP HandleEvent called: this=%p, npp=%p, event=%d, return=%d\n", 
      this, &fNPP, event->event, result));

      *handled = result;
    }

  return NS_OK;
}
void nsIPluginInstance::handleEvent ( in nsPluginEventPtr  aEvent,
out boolean  aHandled 
) [inherited]

Handles an event.

An nsIEventHandler can also get registered with with nsIPluginManager2::RegisterWindow and will be called whenever an event comes in for that window.

Note that for Unix and Mac the nsPluginEvent structure is different from the old NPEvent structure -- it's no longer the native event record, but is instead a struct. This was done for future extensibility, and so that the Mac could receive the window argument too. For Windows and OS2, it's always been a struct, so there's no change for them.

(Corresponds to NPP_HandleEvent.)

Parameters:
aEvent- the event to be handled
aHandled- set to PR_TRUE if event was handled
Returns:
- NS_OK if this operation was successful

Initializes a newly created plugin instance, passing to it the plugin instance peer which it should use for all communication back to the browser.

Parameters:
aPeer- the corresponding plugin instance peer
Returns:
- NS_OK if this operation was successful

Actually initialize the plugin instance.

This calls the 4.x newp callback, and may return an error (which is why it is distinct from the constructor.) If an error is returned, the caller should not continue to use the ns4xPluginInstance object.

Definition at line 865 of file ns4xPluginInstance.cpp.

{
  PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("ns4xPluginInstance::Initialize this=%p\n",this));

#if defined (MOZ_WIDGET_GTK) || defined (MOZ_WIDGET_GTK2)
  mXtBin = nsnull;
#elif defined(MOZ_WIDGET_XLIB)
  mXlibXtBin = nsnull;
#endif
  return InitializePlugin(peer);
}

Here is the call graph for this function:

Definition at line 1015 of file ns4xPluginInstance.cpp.

{
  NS_ENSURE_ARG_POINTER(peer);
 
  nsCOMPtr<nsIPluginTagInfo2> taginfo = do_QueryInterface(peer);
  NS_ENSURE_TRUE(taginfo, NS_ERROR_NO_INTERFACE);
  
  PRUint16 count = 0;
  const char* const* names = nsnull;
  const char* const* values = nsnull;
  nsPluginTagType tagtype;
  nsresult rv = taginfo->GetTagType(&tagtype);
  if (NS_SUCCEEDED(rv)) {
    // Note: If we failed to get the tag type, we may be a full page plugin, so no arguments
    rv = taginfo->GetAttributes(count, names, values);
    NS_ENSURE_SUCCESS(rv, rv);
    
    // nsPluginTagType_Object or Applet may also have PARAM tags
    // Note: The arrays handed back by GetParameters() are
    // crafted specially to be directly behind the arrays from GetAtributes()
    // with a null entry as a separator. This is for 4.x backwards compatibility!
    // see bug 111008 for details
    if (tagtype != nsPluginTagType_Embed) {
      PRUint16 pcount = 0;
      const char* const* pnames = nsnull;
      const char* const* pvalues = nsnull;    
      if (NS_SUCCEEDED(taginfo->GetParameters(pcount, pnames, pvalues))) {
        NS_ASSERTION(nsnull == values[count], "attribute/parameter array not setup correctly for 4.x plugins");
        if (pcount)
          count += ++pcount; //if it's all setup correctly, then all we need is to change the count (attrs + PARAM/blank + params)
      }
    }
  }

#if defined(MOZ_WIDGET_PHOTON) && defined (OJI)
  /* our plugins require that "voyager.documentBase"/docbase is present in the array */
  /* and also the java_code, java_codebase are present */
  const char **qnames = nsnull, **qvalues = nsnull;
  if (tagtype == nsPluginTagType_Object || tagtype == nsPluginTagType_Applet ) {

    nsCOMPtr<nsIJVMPluginTagInfo> javataginfo = do_QueryInterface(peer, &rv);
    if ( NS_SUCCEEDED(rv)) {

      taginfo->GetParameters(count, names, values);
      const char * tmpvalue;
      PRUint32 tmpivalue;
      char widthb[10], heightb[10];
      int i, c = 0;
      qnames = (const char **)PR_Calloc(count + 7, sizeof(char *));
      qvalues = (const char **)PR_Calloc(count + 7, sizeof(char *));
      if (qnames != nsnull && qvalues != nsnull) {

        if ( javataginfo->GetArchive(&tmpvalue) == NS_OK ) {
          qnames[c] = "java_archive";
          qvalues[c++] = tmpvalue;
        }
        if ( javataginfo->GetCode(&tmpvalue) == NS_OK ) {
          qnames[c] = "java_code";
          qvalues[c++] = tmpvalue;
        }
        if ( javataginfo->GetCodeBase(&tmpvalue) == NS_OK ) {
          qnames[c] = "java_codebase";
          qvalues[c++] = tmpvalue;
        }
        if ( taginfo->GetDocumentBase(&tmpvalue) == NS_OK ) {
          qnames[c] = "voyager.documentBase";
          qvalues[c++] = tmpvalue;
        }
        if ( taginfo->GetWidth(&tmpivalue) == NS_OK ) {
          qnames[c] = "width";
          qvalues[c++] = ltoa(tmpivalue, widthb, 10);
        }
        if ( taginfo->GetHeight(&tmpivalue) == NS_OK ) {
          qnames[c] = "height";
          qvalues[c++] = ltoa(tmpivalue, heightb, 10);
        }

        for( i = c; i < count + c; i++) {
          qnames[i] = names[i-c];
          qvalues[i] = values[i-c];
        }

        qnames[i] = nsnull;
        qvalues[i] = nsnull;
        names = qnames;
        values = qvalues;
        count = i;
        }
    }
  }
#endif

  NS_ENSURE_TRUE(fCallbacks->newp, NS_ERROR_FAILURE);
  
  // XXX Note that the NPPluginType_* enums were crafted to be
  // backward compatible...
  
  nsPluginMode  mode;
  nsMIMEType    mimetype;
  NPError       error;

  peer->GetMode(&mode);
  peer->GetMIMEType(&mimetype);

  // Some older versions of Flash have a bug in them
  // that causes the stack to become currupt if we
  // pass swliveconect=1 in the NPP_NewProc arrays.
  // See bug 149336 (UNIX), bug 186287 (Mac)
  //
  // The code below disables the attribute unless
  // the environment variable:
  // MOZILLA_PLUGIN_DISABLE_FLASH_SWLIVECONNECT_HACK
  // is set.
  //
  // It is okay to disable this attribute because
  // back in 4.x, scripting required liveconnect to
  // start Java which was slow. Scripting no longer
  // requires starting Java and is quick plus controled
  // from the browser, so Flash now ignores this attribute.
  //
  // This code can not be put at the time of creating
  // the array because we may need to examine the
  // stream header to determine we want Flash.

  static const char flashMimeType[] = "application/x-shockwave-flash";
  static const char blockedParam[] = "swliveconnect";
  if (count && !PL_strcasecmp(mimetype, flashMimeType)) {
    static int cachedDisableHack = 0;
    if (!cachedDisableHack) {
       if (PR_GetEnv("MOZILLA_PLUGIN_DISABLE_FLASH_SWLIVECONNECT_HACK"))
         cachedDisableHack = -1;
       else
         cachedDisableHack = 1;
    }
    if (cachedDisableHack > 0) {
      for (PRUint16 i=0; i<count; i++) {
        if (!PL_strcasecmp(names[i], blockedParam)) {
          // BIG FAT WARNIG:
          // I'm ugly casting |const char*| to |char*| and altering it
          // because I know we do malloc it values in
          // http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/layout/html/base/src/nsObjectFrame.cpp&rev=1.349&root=/cvsroot#3020
          // and free it at line #2096, so it couldn't be a const ptr to string literal
          char *val = (char*) values[i];
          if (val && *val) {
            // we cannot just *val=0, it wont be free properly in such case
            val[0] = '0';
            val[1] = 0;
          }
          break;
        }
      }
    }
  }

  // Assign mPeer now and mark this instance as started before calling NPP_New 
  // because the plugin may call other NPAPI functions, like NPN_GetURLNotify,
  // that assume these are set before returning. If the plugin returns failure,
  // we'll clear them out below.
  mPeer = peer;
  mStarted = PR_TRUE;

  NS_TRY_SAFE_CALL_RETURN(error, CallNPP_NewProc(fCallbacks->newp,
                                          (char *)mimetype,
                                          &fNPP,
                                          (PRUint16)mode,
                                          count,
                                          (char**)names,
                                          (char**)values,
                                          NULL), fLibrary,this);

  NPP_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
  ("NPP New called: this=%p, npp=%p, mime=%s, mode=%d, argc=%d, return=%d\n",
  this, &fNPP, mimetype, mode, count, error));

#if defined(MOZ_WIDGET_PHOTON) && defined (OJI)
  /* free the names[], values[] arrays, since we overriden them */
  if( qnames ) PR_Free( (void*)qnames );
  if( qvalues ) PR_Free( (void*)qvalues );
#endif

  if(error != NPERR_NO_ERROR) {
    // since the plugin returned failure, these should not be set
    mPeer = nsnull;
    mStarted = PR_FALSE;

    return NS_ERROR_FAILURE;
  }
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 858 of file ns4xPluginInstance.cpp.

{
  return mStarted;
}

Here is the caller graph for this function:

nsresult ns4xPluginInstance::NewNotifyStream ( nsIPluginStreamListener **  listener,
void notifyData,
PRBool  aCallNotify,
const char *  aURL 
)

Definition at line 1438 of file ns4xPluginInstance.cpp.

{
  ns4xPluginStreamListener* stream = new ns4xPluginStreamListener(this, notifyData, aURL);
  NS_ENSURE_TRUE(stream, NS_ERROR_OUT_OF_MEMORY);

  // add it to the list
  nsInstanceStream * is = new nsInstanceStream();
  NS_ENSURE_TRUE(is, NS_ERROR_OUT_OF_MEMORY);

  is->mNext = mStreams;
  is->mPluginStreamListener = stream;
  mStreams = is;
  stream->SetCallNotify(aCallNotify);  // set flag in stream to call URLNotify

  NS_ADDREF(stream);  // Stabilize
    
  nsresult res = stream->QueryInterface(kIPluginStreamListenerIID, (void**)listener);

  // Destabilize and avoid leaks. Avoid calling delete <interface pointer>
  NS_RELEASE(stream);

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1430 of file ns4xPluginInstance.cpp.

{
  return NewNotifyStream(listener, nsnull, PR_FALSE, nsnull);
}

Here is the call graph for this function:

Called to tell the plugin that the initial src/data stream is ready.

Expects the plugin to return a nsIPluginStreamListener.

(Corresponds to NPP_NewStream.)

Parameters:
aListener- listener the browser will use to give the plugin the data
Returns:
- NS_OK if this operation was successful

Definition at line 180 of file ns4xPluginInstance.h.

    {
        return mPeer;
    }

Here is the caller graph for this function:

Definition at line 1736 of file ns4xPluginInstance.cpp.

{
  PRInt32 last = mPopupStates.Count() - 1;

  if (last < 0) {
    // Nothing to pop.

    return;
  }

  nsCOMPtr<nsIDOMWindow> window = GetDOMWindow();
  nsCOMPtr<nsPIDOMWindow> piwindow = do_QueryInterface(window);

  if (!piwindow)
    return;

  PopupControlState oldState =
    (PopupControlState)NS_PTR_TO_INT32(mPopupStates[last]);

  piwindow->PopPopupControlState(oldState);

  mPopupStates.RemoveElementAt(last);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1465 of file ns4xPluginInstance.cpp.

{
  NS_ENSURE_TRUE(platformPrint, NS_ERROR_NULL_POINTER);

  NPPrint* thePrint = (NPPrint *)platformPrint;

  // to be compatible with the older SDK versions and to match what
  // 4.x and other browsers do, overwrite |window.type| field with one
  // more copy of |platformPrint|. See bug 113264
  if(fCallbacks) {
    PRUint16 sdkmajorversion = (fCallbacks->version & 0xff00)>>8;
    PRUint16 sdkminorversion = fCallbacks->version & 0x00ff;
    if((sdkmajorversion == 0) && (sdkminorversion < 11)) { 
      // Let's copy platformPrint bytes over to where it was supposed to be 
      // in older versions -- four bytes towards the beginning of the struct
      // but we should be careful about possible misalignments
      if(sizeof(NPWindowType) >= sizeof(void *)) {
        void* source = thePrint->print.embedPrint.platformPrint; 
        void** destination = (void **)&(thePrint->print.embedPrint.window.type); 
        *destination = source;
      } 
      else 
        NS_ASSERTION(PR_FALSE, "Incompatible OS for assignment");
    }
  }

  NS_TRY_SAFE_CALL_VOID(CallNPP_PrintProc(fCallbacks->print,
                                          &fNPP,
                                          thePrint), fLibrary, this);

  NPP_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
  ("NPP PrintProc called: this=%p, pDC=%p, [x=%d,y=%d,w=%d,h=%d], clip[t=%d,b=%d,l=%d,r=%d]\n",
  this,
  platformPrint->print.embedPrint.platformPrint,
  platformPrint->print.embedPrint.window.x,
  platformPrint->print.embedPrint.window.y,
  platformPrint->print.embedPrint.window.width,
  platformPrint->print.embedPrint.window.height,
  platformPrint->print.embedPrint.window.clipRect.top,
  platformPrint->print.embedPrint.window.clipRect.bottom,
  platformPrint->print.embedPrint.window.clipRect.left,
  platformPrint->print.embedPrint.window.clipRect.right));

  return NS_OK;
}
void nsIPluginInstance::print ( in nsPluginPrintPtr  aPlatformPrint) [inherited]

Called to instruct the plugin instance to print itself to a printer.

(Corresponds to NPP_Print.)

Parameters:
aPlatformPrint- platform-specific printing information
Returns:
- NS_OK if this operation was successful

Definition at line 1716 of file ns4xPluginInstance.cpp.

{
  nsCOMPtr<nsIDOMWindow> window = GetDOMWindow();
  nsCOMPtr<nsPIDOMWindow> piwindow = do_QueryInterface(window);

  if (!piwindow)
    return;

  PopupControlState oldState =
    piwindow->PushPopupControlState(aEnabled ? openAllowed : openAbused,
                                    PR_TRUE);

  if (!mPopupStates.AppendElement(NS_INT32_TO_PTR(oldState))) {
    // Appending to our state stack failed, push what we just popped.

    piwindow->PopPopupControlState(oldState);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 177 of file ns4xPluginInstance.h.

{ mCached = aCache; return NS_OK; };

Here is the caller graph for this function:

Definition at line 1651 of file ns4xPluginInstance.cpp.

{
  mTransparent = aTransparent;
  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 1218 of file ns4xPluginInstance.cpp.

{
#if defined(MOZ_WIDGET_GTK) || defined (MOZ_WIDGET_GTK2) || defined(MOZ_WIDGET_XLIB)
  NPSetWindowCallbackStruct *ws;
#endif

  // XXX 4.x plugins don't want a SetWindow(NULL).
  if (!window || !mStarted)
    return NS_OK;
  
  NPError error;
  
#if defined (MOZ_WIDGET_GTK) || defined (MOZ_WIDGET_GTK2)
  PRBool isXembed = PR_FALSE;
  // bug 108337, flash plugin on linux doesn't like window->width <= 0
  if ((PRInt32) window->width <= 0 || (PRInt32) window->height <= 0)
    return NS_OK;

  // We need to test if this is an xembed window before doing checks
  // below, as they might be used on the first pass or on later passes
  // when we resize the plugin window.
  GdkWindow *win = gdk_window_lookup((XID)window->window);
  if (!win)
    return NS_ERROR_FAILURE;

  gpointer user_data = nsnull;
  gdk_window_get_user_data(win, &user_data);
  if (user_data && GTK_IS_WIDGET(user_data)) {
    GtkWidget* widget = GTK_WIDGET(user_data);

    if (GTK_IS_SOCKET(widget))
      isXembed = PR_TRUE;
  }

  // Allocate and fill out the ws_info data
  if (!window->ws_info) {
#ifdef NS_DEBUG
    printf("About to create new ws_info...\n");
#endif    

    // allocate a new NPSetWindowCallbackStruct structure at ws_info
    window->ws_info = (NPSetWindowCallbackStruct *)PR_MALLOC(sizeof(NPSetWindowCallbackStruct));

    if (!window->ws_info)
      return NS_ERROR_OUT_OF_MEMORY;

    ws = (NPSetWindowCallbackStruct *)window->ws_info;

    if (!isXembed)
    {  
#ifdef NS_DEBUG      
      printf("About to create new xtbin of %i X %i from %p...\n",
             window->width, window->height, win);
#endif

#if 0
      // if we destroyed the plugin when we left the page, we could remove this
      // code (i believe) the problem here is that the window gets destroyed when
      // its parent, etc does by changing a page the plugin instance is being
      // held on to, so when we return to the page, we have a mXtBin, but it is
      // in a not-so-good state.
      // --
      // this is lame.  we shouldn't be destroying this everytime, but I can't find
      // a good way to tell if we need to destroy/recreate the xtbin or not
      // what if the plugin wants to change the window and not just resize it??
      // (pav)

      if (mXtBin) {
        gtk_widget_destroy(mXtBin);
        mXtBin = NULL;
      }
#endif


      if (!mXtBin) {
        mXtBin = gtk_xtbin_new(win, 0);
        // Check to see if creating mXtBin failed for some reason.
        // if it did, we can't go any further.
        if (!mXtBin)
          return NS_ERROR_FAILURE;
      } 

      gtk_widget_set_usize(mXtBin, window->width, window->height);

#ifdef NS_DEBUG
      printf("About to show xtbin(%p)...\n", mXtBin); fflush(NULL);
#endif
      gtk_widget_show(mXtBin);
#ifdef NS_DEBUG
      printf("completed gtk_widget_show(%p)\n", mXtBin); fflush(NULL);
#endif
    }

    // fill in window info structure 
    ws->type = 0; // OK, that was a guess!!
#ifdef MOZ_X11
    ws->depth = gdk_window_get_visual(win)->depth;
    if (!isXembed)
      ws->display = GTK_XTBIN(mXtBin)->xtdisplay;
    else
      ws->display = GDK_WINDOW_XDISPLAY(win);
    ws->visual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(win));
    ws->colormap = GDK_COLORMAP_XCOLORMAP(gdk_window_get_colormap(win));

    XFlush(ws->display);
#endif
  } // !window->ws_info

  if (!mXtBin && !isXembed)
    return NS_ERROR_FAILURE;

  if (!isXembed) {
    // And now point the NPWindow structures window 
    // to the actual X window
    window->window = (nsPluginPort *)GTK_XTBIN(mXtBin)->xtwindow;
    
    gtk_xtbin_resize(mXtBin, window->width, window->height);
  }
  
#elif defined(MOZ_WIDGET_XLIB)


  // Allocate and fill out the ws_info data
  if (!window->ws_info) {
#ifdef NS_DEBUG
    printf("About to create new ws_info...\n");
#endif

    // allocate a new NPSetWindowCallbackStruct structure at ws_info
    window->ws_info = (NPSetWindowCallbackStruct *)PR_MALLOC(sizeof(NPSetWindowCallbackStruct));

    if (!window->ws_info)
      return NS_ERROR_OUT_OF_MEMORY;

    ws = (NPSetWindowCallbackStruct *)window->ws_info;

#if 1
     /* See comment above in GTK+ port ... */
     if (mXlibXtBin) {
       delete mXlibXtBin;
       mXlibXtBin = nsnull;
     }
#endif

      if (!mXlibXtBin) {
        mXlibXtBin = new xtbin();
        // Check to see if creating mXlibXtBin failed for some reason.
        // if it did, we can't go any further.
        if (!mXlibXtBin)
          return NS_ERROR_FAILURE;
      } 
      
    if (window->window) {
#ifdef NS_DEBUG
      printf("About to create new xtbin of %i X %i from %08x...\n",
             window->width, window->height, window->window);
#endif

      mXlibXtBin->xtbin_new((Window)window->window);
      mXlibXtBin->xtbin_resize(0, 0, window->width, window->height);
#ifdef NS_DEBUG
      printf("About to show xtbin(%p)...\n", mXlibXtBin); fflush(NULL);
#endif
      mXlibXtBin->xtbin_realize();
    }
    
    /* Set window attributes */
    XlibRgbHandle *xlibRgbHandle = xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE);
    Display *xdisplay = xxlib_rgb_get_display(xlibRgbHandle);

    /* Fill in window info structure */
    ws->type     = 0;
    ws->depth    = xxlib_rgb_get_depth(xlibRgbHandle);
    ws->display  = xdisplay;
    ws->visual   = xxlib_rgb_get_visual(xlibRgbHandle);
    ws->colormap = xxlib_rgb_get_cmap(xlibRgbHandle);
    XFlush(ws->display);
  } // !window->ws_info

  // And now point the NPWindow structures window 
  // to the actual X window
  window->window = (nsPluginPort *)mXlibXtBin->xtbin_xtwindow();
#endif // MOZ_WIDGET

  if (fCallbacks->setwindow) {
    // XXX Turns out that NPPluginWindow and NPWindow are structurally
    // identical (on purpose!), so there's no need to make a copy.

    PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("ns4xPluginInstance::SetWindow (about to call it) this=%p\n",this));

    NS_TRY_SAFE_CALL_RETURN(error, CallNPP_SetWindowProc(fCallbacks->setwindow,
                                  &fNPP,
                                  (NPWindow*) window), fLibrary, this);


    NPP_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
    ("NPP SetWindow called: this=%p, [x=%d,y=%d,w=%d,h=%d], clip[t=%d,b=%d,l=%d,r=%d], return=%d\n",
    this, window->x, window->y, window->width, window->height,
    window->clipRect.top, window->clipRect.bottom, window->clipRect.left, window->clipRect.right, error));
      
    // XXX In the old code, we'd just ignore any errors coming
    // back from the plugin's SetWindow(). Is this the correct
    // behavior?!?

  }
  return NS_OK;
}

Here is the call graph for this function:

Called when the window containing the plugin instance changes.

(Corresponds to NPP_SetWindow.)

Parameters:
aWindow- the plugin window structure
Returns:
- NS_OK if this operation was successful

Definition at line 1643 of file ns4xPluginInstance.cpp.

{
  mWindowless = aWindowless;
  return NS_OK;
}

Here is the caller graph for this function:

void nsIPluginInstance::start ( ) [inherited]

Called to instruct the plugin instance to start.

This will be called after the plugin is first created and initialized, and may be called after the plugin is stopped (via the Stop method) if the plugin instance is returned to in the browser window's history.

Returns:
- NS_OK if this operation was successful

Definition at line 887 of file ns4xPluginInstance.cpp.

{
  PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("ns4xPluginInstance::Start this=%p\n",this));

#ifdef MOZ_WIDGET_XLIB
  if (mXlibXtBin == nsnull)
    mXlibXtBin = new xtbin();

  if (mXlibXtBin == nsnull)
    return NS_ERROR_OUT_OF_MEMORY;

  if (!mXlibXtBin->xtbin_initialized())
    mXlibXtBin->xtbin_init();

#ifdef NS_DEBUG
  printf("Made new XtBin: %p, %d\n", mXlibXtBin, mXlibXtBin->xtbin_initialized());
#endif
#endif

  if(mStarted)
    return NS_OK;
  else
    return InitializePlugin(mPeer); 
}

Here is the call graph for this function:

Definition at line 914 of file ns4xPluginInstance.cpp.

{
  PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("ns4xPluginInstance::Stop this=%p\n",this));

  NPError error;

  // Make sure the plugin didn't leave popups enabled.
  if (mPopupStates.Count() > 0) {
    nsCOMPtr<nsIDOMWindow> window = GetDOMWindow();
    nsCOMPtr<nsPIDOMWindow> piwindow = do_QueryInterface(window);

    if (piwindow) {
      piwindow->PopPopupControlState(openAbused);
    }
  }

#if defined(MOZ_WIDGET_GTK) || defined (MOZ_WIDGET_GTK2)
  if (mXtBin) {
    gtk_widget_destroy(mXtBin);
    mXtBin = 0;
  }
#elif defined(MOZ_WIDGET_XLIB)
  if (mXlibXtBin) {
    mXlibXtBin->xtbin_destroy();
    mXlibXtBin = 0;
  }
#endif

  if(!mStarted)
    return NS_OK;

  if (fCallbacks->destroy == NULL)
    return NS_ERROR_FAILURE; // XXX right error?

  NPSavedData *sdata = 0;

  // clean up open streams
  for(nsInstanceStream *is = mStreams; is != nsnull;) {
    ns4xPluginStreamListener * listener = is->mPluginStreamListener;

    nsInstanceStream *next = is->mNext;
    delete is;
    is = next;
    mStreams = is;

    // Clean up our stream after removing it from the list because 
    // it may be released and destroyed at this point.
    if(listener)
      listener->CleanUpStream(NPRES_USER_BREAK);
  }

  NS_TRY_SAFE_CALL_RETURN(error, CallNPP_DestroyProc(fCallbacks->destroy, &fNPP, &sdata), fLibrary, this);

  NPP_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
  ("NPP Destroy called: this=%p, npp=%p, return=%d\n", this, &fNPP, error));

  mStarted = PR_FALSE;

  nsJSNPRuntime::OnPluginDestroy(&fNPP);

  if(error != NPERR_NO_ERROR)
    return NS_ERROR_FAILURE;
  else
    return NS_OK;
}

Here is the call graph for this function:

void nsIPluginInstance::stop ( ) [inherited]

Called to instruct the plugin instance to stop, thereby suspending its state.

This method will be called whenever the browser window goes on to display another page and the page containing the plugin goes into the window's history list.

Returns:
- NS_OK if this operation was successful

Member Data Documentation

A pointer to the plugin's callback functions.

This information is actually stored in the plugin class (nsPluginClass), and is common for all plugins of the class.

Definition at line 206 of file ns4xPluginInstance.h.

Definition at line 233 of file ns4xPluginInstance.h.

The 4.x-style structure used to communicate between the plugin instance and the browser.

Definition at line 222 of file ns4xPluginInstance.h.

Definition at line 230 of file ns4xPluginInstance.h.

The plugin instance peer for this instance.

Definition at line 199 of file ns4xPluginInstance.h.

Definition at line 236 of file ns4xPluginInstance.h.

Definition at line 229 of file ns4xPluginInstance.h.

Definition at line 234 of file ns4xPluginInstance.h.

Definition at line 228 of file ns4xPluginInstance.h.

Definition at line 227 of file ns4xPluginInstance.h.

Returns a reference back to the plugin instance peer.

This method is used whenever the browser needs to obtain the peer back from a plugin instance. The implementation of this method should be sure to increment the reference count on the peer by calling AddRef.

Parameters:
aPeer- the resulting plugin instance peer
Returns:
- NS_OK if this operation was successful

Definition at line 96 of file nsIPluginInstance.idl.

readonly attribute nsIIDPtr nsIScriptablePlugin::scriptableInterface [inherited]

The interface that XPConnect should use when exposing the peer object to JavaScript.

All scriptable methods on the interface will be available to JavaScript.

Definition at line 58 of file nsIScriptablePlugin.idl.

readonly attribute nsQIResult nsIScriptablePlugin::scriptablePeer [inherited]

The object to be wrapped and exposed to JavaScript.

It should be an XPCOM object, and it can be the same object as the plugin.

Definition at line 51 of file nsIScriptablePlugin.idl.


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