1998-07-11 01:40:24 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-07-11 01:40:24 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-07-11 01:40:24 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-07-11 01:40:24 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-01-11 20:49:15 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
1998-07-11 01:40:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* npsimple.cpp
|
|
|
|
******************************************************************************
|
2000-07-22 01:34:13 +00:00
|
|
|
* Simple Sample Plugin
|
1998-07-11 01:40:24 +00:00
|
|
|
* Copyright (c) 1996 Netscape Communications. All rights reserved.
|
|
|
|
******************************************************************************
|
|
|
|
* OVERVIEW
|
|
|
|
* --------
|
|
|
|
* Section 1 - Includes
|
|
|
|
* Section 2 - Instance Structs
|
|
|
|
* Section 3 - API Plugin Implementations
|
2000-07-22 01:34:13 +00:00
|
|
|
* Section 4 - Utility Method Implementations
|
1998-07-11 01:40:24 +00:00
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* SECTION 1 - Includes
|
|
|
|
******************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "nsplugin.h"
|
1999-01-28 01:18:23 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-07-21 00:00:13 +00:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsIFactory.h"
|
2000-07-22 01:34:13 +00:00
|
|
|
#include "nsIGenericFactory.h"
|
|
|
|
#include "nsMemory.h"
|
2000-04-12 08:35:15 +00:00
|
|
|
#include "nsString.h"
|
1999-07-21 00:00:13 +00:00
|
|
|
#include "simpleCID.h"
|
2000-04-16 18:51:02 +00:00
|
|
|
|
|
|
|
#include "nsISimplePluginInstance.h"
|
2000-08-23 00:20:24 +00:00
|
|
|
#include "nsIScriptablePlugin.h"
|
2000-04-16 18:51:02 +00:00
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* Windows Includes
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
#ifdef _WINDOWS /* Windows Includes */
|
|
|
|
#include <windows.h>
|
|
|
|
#endif /* _WINDOWS */
|
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* UNIX includes
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
#ifdef XP_UNIX
|
2000-04-12 08:35:15 +00:00
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#include <gdk/gdkprivate.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdksuperwin.h>
|
|
|
|
#include <gtkmozbox.h>
|
1998-07-11 01:40:24 +00:00
|
|
|
#endif /* XP_UNIX */
|
|
|
|
|
2000-06-05 20:35:32 +00:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
|
|
|
|
gboolean draw (GtkWidget *widget, GdkEventExpose *event, gpointer data);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1999-07-21 00:00:13 +00:00
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* SECTION 2 - Instance Structs
|
|
|
|
*******************************************************************************
|
|
|
|
* Instance state information about the plugin.
|
|
|
|
*
|
|
|
|
* PLUGIN DEVELOPERS:
|
|
|
|
* Use this struct to hold per-instance information that you'll
|
|
|
|
* need in the various functions in this file.
|
|
|
|
******************************************************************************
|
|
|
|
* First comes the PlatformInstance struct, which contains platform specific
|
|
|
|
* information for each instance.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* Windows PlatformInstance
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
2000-06-02 22:32:53 +00:00
|
|
|
#if defined(XP_PC) && !defined(XP_OS2) // XXXX OS2TODO
|
1998-07-11 01:40:24 +00:00
|
|
|
typedef struct _PlatformInstance
|
|
|
|
{
|
|
|
|
HWND fhWnd;
|
|
|
|
WNDPROC fDefaultWindowProc;
|
|
|
|
} PlatformInstance;
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* UNIX PlatformInstance
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
2000-05-17 04:38:13 +00:00
|
|
|
#elif defined(XP_UNIX)
|
1998-07-11 01:40:24 +00:00
|
|
|
typedef struct _PlatformInstance
|
|
|
|
{
|
1999-12-07 23:50:00 +00:00
|
|
|
Window window;
|
|
|
|
GtkWidget *moz_box;
|
|
|
|
GdkSuperWin *superwin;
|
2000-06-05 20:35:32 +00:00
|
|
|
GtkWidget *label;
|
1999-12-07 23:50:00 +00:00
|
|
|
Display * display;
|
|
|
|
uint32 x, y;
|
|
|
|
uint32 width, height;
|
1998-07-11 01:40:24 +00:00
|
|
|
} PlatformInstance;
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* Macintosh PlatformInstance
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
2000-05-17 04:38:13 +00:00
|
|
|
#elif defined(XP_MAC)
|
|
|
|
typedef struct _PlatformInstance
|
|
|
|
{
|
|
|
|
int placeholder;
|
|
|
|
} PlatformInstance;
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* Stub PlatformInstance
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#else
|
1998-07-11 01:40:24 +00:00
|
|
|
typedef struct _PlatformInstance
|
|
|
|
{
|
|
|
|
int placeholder;
|
|
|
|
} PlatformInstance;
|
2000-05-17 04:38:13 +00:00
|
|
|
#endif /* end Section 2 */
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
|
1999-07-21 00:00:13 +00:00
|
|
|
// Define constants for easy use
|
|
|
|
static NS_DEFINE_CID(kSimplePluginCID, NS_SIMPLEPLUGIN_CID);
|
2000-07-22 01:34:13 +00:00
|
|
|
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
|
1999-07-21 00:00:13 +00:00
|
|
|
|
|
|
|
#define PLUGIN_MIME_TYPE "application/x-simple"
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
static const char kPluginName[] = "Simple Sample Plug-in";
|
|
|
|
static const char kPluginDescription[] = "Demonstrates a simple plug-in.";
|
1999-07-21 00:00:13 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
static const char* kMimeTypes[] = {
|
|
|
|
PLUGIN_MIME_TYPE
|
|
|
|
};
|
1999-07-21 00:00:13 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
static const char* kMimeDescriptions[] = {
|
|
|
|
"Simple Sample Plug-in"
|
|
|
|
};
|
1998-07-11 01:40:24 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
static const char* kFileExtensions[] = {
|
|
|
|
"smp"
|
|
|
|
};
|
1998-07-11 01:40:24 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
static const PRInt32 kNumMimeTypes = sizeof(kMimeTypes) / sizeof(*kMimeTypes);
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Simple Plugin Classes
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2000-07-22 01:34:13 +00:00
|
|
|
// SimplePluginInstance represents an instance of the simple plugin class.
|
1998-07-11 01:40:24 +00:00
|
|
|
|
2000-04-16 18:51:02 +00:00
|
|
|
class SimplePluginInstance :
|
|
|
|
public nsIPluginInstance,
|
2000-08-23 00:20:24 +00:00
|
|
|
public nsIScriptablePlugin,
|
2000-04-16 18:51:02 +00:00
|
|
|
public nsISimplePluginInstance {
|
2000-08-23 00:20:24 +00:00
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
public:
|
2000-07-22 01:34:13 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// for implementing a generic module
|
|
|
|
static NS_METHOD
|
|
|
|
Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
|
|
|
|
|
|
|
static NS_METHOD
|
|
|
|
RegisterSelf(nsIComponentManager* aCompMgr,
|
|
|
|
nsIFile* aPath,
|
|
|
|
const char* aRegistryLocation,
|
|
|
|
const char* aComponentType);
|
|
|
|
|
|
|
|
static NS_METHOD
|
|
|
|
UnregisterSelf(nsIComponentManager* aCompMgr,
|
|
|
|
nsIFile* aPath,
|
|
|
|
const char* aRegistryLocation);
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
|
2000-04-16 18:51:02 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2000-08-23 00:20:24 +00:00
|
|
|
NS_DECL_NSISCRIPTABLEPLUGIN
|
2000-04-16 18:51:02 +00:00
|
|
|
NS_DECL_NSISIMPLEPLUGININSTANCE
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// from nsIEventHandler:
|
|
|
|
|
|
|
|
// (Corresponds to NPP_HandleEvent.)
|
|
|
|
// 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.
|
|
|
|
NS_IMETHOD
|
|
|
|
HandleEvent(nsPluginEvent* event, PRBool* handled);
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// from nsIPluginInstance:
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_IMETHOD
|
1998-07-11 01:40:24 +00:00
|
|
|
Initialize(nsIPluginInstancePeer* peer);
|
|
|
|
|
|
|
|
// Required backpointer to the peer.
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_IMETHOD
|
|
|
|
GetPeer(nsIPluginInstancePeer* *result);
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
// See comment for nsIPlugin::CreateInstance, above.
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_IMETHOD
|
1998-07-11 01:40:24 +00:00
|
|
|
Start(void);
|
|
|
|
|
|
|
|
// The old NPP_Destroy call has been factored into two plugin instance
|
|
|
|
// methods:
|
|
|
|
//
|
|
|
|
// Stop -- called when the plugin instance is to be stopped (e.g. by
|
|
|
|
// displaying another plugin manager window, causing the page containing
|
|
|
|
// the plugin to become removed from the display).
|
|
|
|
//
|
|
|
|
// Destroy -- called once, before the plugin instance peer is to be
|
|
|
|
// destroyed. This method is used to destroy the plugin instance.
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_IMETHOD
|
1998-07-11 01:40:24 +00:00
|
|
|
Stop(void);
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_IMETHOD
|
1998-07-11 01:40:24 +00:00
|
|
|
Destroy(void);
|
|
|
|
|
|
|
|
// (Corresponds to NPP_SetWindow.)
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_IMETHOD
|
1998-07-11 01:40:24 +00:00
|
|
|
SetWindow(nsPluginWindow* window);
|
|
|
|
|
1999-01-28 01:18:23 +00:00
|
|
|
NS_IMETHOD
|
|
|
|
NewStream(nsIPluginStreamListener** listener);
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
// (Corresponds to NPP_Print.)
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_IMETHOD
|
1998-07-11 01:40:24 +00:00
|
|
|
Print(nsPluginPrint* platformPrint);
|
|
|
|
|
1998-09-15 03:45:38 +00:00
|
|
|
NS_IMETHOD
|
|
|
|
GetValue(nsPluginInstanceVariable variable, void *value);
|
|
|
|
|
2000-04-16 18:51:02 +00:00
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SimplePluginInstance specific methods:
|
|
|
|
|
|
|
|
SimplePluginInstance(void);
|
|
|
|
virtual ~SimplePluginInstance(void);
|
|
|
|
|
|
|
|
void PlatformNew(void);
|
1998-07-31 20:19:50 +00:00
|
|
|
nsresult PlatformDestroy(void);
|
|
|
|
nsresult PlatformSetWindow(nsPluginWindow* window);
|
1998-07-11 01:40:24 +00:00
|
|
|
PRInt16 PlatformHandleEvent(nsPluginEvent* event);
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
void SetMode(nsPluginMode mode) { fMode = mode; }
|
1998-07-11 01:40:24 +00:00
|
|
|
|
2000-06-05 20:35:32 +00:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
NS_IMETHOD Repaint(void);
|
|
|
|
#endif
|
|
|
|
|
2000-06-02 22:32:53 +00:00
|
|
|
#if defined(XP_PC) && !defined(XP_OS2)
|
1998-07-11 01:40:24 +00:00
|
|
|
static LRESULT CALLBACK
|
|
|
|
PluginWindowProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
|
|
|
#endif
|
|
|
|
|
2000-04-16 18:51:02 +00:00
|
|
|
char* fText;
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
protected:
|
|
|
|
nsIPluginInstancePeer* fPeer;
|
|
|
|
nsPluginWindow* fWindow;
|
1998-07-31 20:19:50 +00:00
|
|
|
nsPluginMode fMode;
|
1998-07-11 01:40:24 +00:00
|
|
|
PlatformInstance fPlatform;
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SimplePluginStream represents the stream used by SimplePluginInstances
|
|
|
|
// to receive data from the browser.
|
|
|
|
|
1998-10-01 02:59:16 +00:00
|
|
|
class SimplePluginStreamListener : public nsIPluginStreamListener {
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// from nsIPluginStreamListener:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify the observer that the URL has started to load. This method is
|
|
|
|
* called only once, at the beginning of a URL load.<BR><BR>
|
|
|
|
*
|
|
|
|
* @return The return value is currently ignored. In the future it may be
|
|
|
|
* used to cancel the URL load..
|
|
|
|
*/
|
|
|
|
NS_IMETHOD
|
1999-07-21 00:00:13 +00:00
|
|
|
OnStartBinding(nsIPluginStreamInfo* pluginInfo);
|
1998-10-01 02:59:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify the client that data is available in the input stream. This
|
|
|
|
* method is called whenver data is written into the input stream by the
|
|
|
|
* networking library...<BR><BR>
|
|
|
|
*
|
|
|
|
* @param aIStream The input stream containing the data. This stream can
|
|
|
|
* be either a blocking or non-blocking stream.
|
|
|
|
* @param length The amount of data that was just pushed into the stream.
|
|
|
|
* @return The return value is currently ignored.
|
|
|
|
*/
|
|
|
|
NS_IMETHOD
|
1999-07-21 00:00:13 +00:00
|
|
|
OnDataAvailable(nsIPluginStreamInfo* pluginInfo,
|
|
|
|
nsIInputStream* input,
|
|
|
|
PRUint32 length);
|
1998-10-01 02:59:16 +00:00
|
|
|
|
|
|
|
NS_IMETHOD
|
1999-07-21 00:00:13 +00:00
|
|
|
OnFileAvailable(nsIPluginStreamInfo* pluginInfo, const char* fileName);
|
1998-10-01 02:59:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify the observer that the URL has finished loading. This method is
|
|
|
|
* called once when the networking library has finished processing the
|
|
|
|
* URL transaction initiatied via the nsINetService::Open(...) call.<BR><BR>
|
|
|
|
*
|
|
|
|
* This method is called regardless of whether the URL loaded successfully.<BR><BR>
|
|
|
|
*
|
|
|
|
* @param status Status code for the URL load.
|
|
|
|
* @param msg A text string describing the error.
|
|
|
|
* @return The return value is currently ignored.
|
|
|
|
*/
|
|
|
|
NS_IMETHOD
|
1999-07-21 00:00:13 +00:00
|
|
|
OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status);
|
1999-01-28 01:18:23 +00:00
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
OnNotify(const char* url, nsresult status);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
GetStreamType(nsPluginStreamType *result);
|
1998-10-01 02:59:16 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SimplePluginStreamListener specific methods:
|
|
|
|
|
1998-10-01 19:07:36 +00:00
|
|
|
SimplePluginStreamListener(SimplePluginInstance* inst, const char* url);
|
1998-10-01 02:59:16 +00:00
|
|
|
virtual ~SimplePluginStreamListener(void);
|
|
|
|
|
|
|
|
protected:
|
1998-10-01 19:07:36 +00:00
|
|
|
const char* fMessageName;
|
1998-10-01 02:59:16 +00:00
|
|
|
};
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* SECTION 3 - API Plugin Implementations
|
|
|
|
******************************************************************************/
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
// XXXwaterson document!
|
|
|
|
static nsModuleComponentInfo gComponentInfo[] = {
|
|
|
|
{ "Simple Plugin",
|
|
|
|
NS_SIMPLEPLUGIN_CID,
|
2000-09-13 23:57:52 +00:00
|
|
|
NS_INLINE_PLUGIN_CONTRACTID_PREFIX PLUGIN_MIME_TYPE,
|
2000-07-22 01:34:13 +00:00
|
|
|
SimplePluginInstance::Create,
|
|
|
|
SimplePluginInstance::RegisterSelf,
|
|
|
|
SimplePluginInstance::UnregisterSelf },
|
|
|
|
};
|
1998-10-01 02:59:16 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
NS_IMPL_NSGETMODULE("SimplePlugin", gComponentInfo);
|
1998-10-01 02:59:16 +00:00
|
|
|
|
2000-08-23 00:20:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIScriptablePlugin methods
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
NS_METHOD
|
|
|
|
SimplePluginInstance::GetScriptablePeer(void **aScriptablePeer)
|
|
|
|
{
|
|
|
|
// We implement the interface we want to be scriptable by
|
|
|
|
// (nsISimplePluginInstance) so we just return this.
|
2000-08-23 00:24:07 +00:00
|
|
|
|
|
|
|
// NOTE if this function returns something other than
|
|
|
|
// nsIPluginInstance, then that object will also need to implement
|
|
|
|
// nsISecurityCheckedComponent to be scriptable. The security
|
|
|
|
// system knows to special-case nsIPluginInstance when checking
|
|
|
|
// security, but in general, XPCOM components must implement
|
|
|
|
// nsISecurityCheckedComponent to be scriptable from content
|
|
|
|
// javascript.
|
|
|
|
|
2000-08-23 00:20:24 +00:00
|
|
|
*aScriptablePeer = NS_STATIC_CAST(nsISimplePluginInstance *, this);
|
|
|
|
NS_ADDREF(NS_STATIC_CAST(nsISimplePluginInstance *, *aScriptablePeer));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
SimplePluginInstance::GetScriptableInterface(nsIID **aScriptableInterface)
|
|
|
|
{
|
|
|
|
*aScriptableInterface = (nsIID *)nsMemory::Alloc(sizeof(nsIID));
|
|
|
|
NS_ENSURE_TRUE(*aScriptableInterface, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
**aScriptableInterface = NS_GET_IID(nsISimplePluginInstance);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2000-07-22 01:34:13 +00:00
|
|
|
// SimplePluginInstance Methods
|
1998-07-11 01:40:24 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_METHOD
|
2000-07-22 01:34:13 +00:00
|
|
|
SimplePluginInstance::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
1999-07-21 00:00:13 +00:00
|
|
|
{
|
2000-07-22 01:34:13 +00:00
|
|
|
NS_PRECONDITION(aOuter == nsnull, "no aggregation");
|
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
1999-07-21 00:00:13 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
SimplePluginInstance* plugin = new SimplePluginInstance();
|
|
|
|
if (! plugin)
|
1998-07-11 01:40:24 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
nsresult rv;
|
|
|
|
NS_ADDREF(plugin);
|
|
|
|
rv = plugin->QueryInterface(aIID, aResult);
|
|
|
|
NS_RELEASE(plugin);
|
|
|
|
return rv;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_METHOD
|
2000-07-22 01:34:13 +00:00
|
|
|
SimplePluginInstance::RegisterSelf(nsIComponentManager* aCompMgr,
|
|
|
|
nsIFile* aPath,
|
|
|
|
const char* aRegistryLocation,
|
|
|
|
const char* aComponentType)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsIPluginManager* pm;
|
|
|
|
rv = nsServiceManager::GetService(kPluginManagerCID, NS_GET_IID(nsIPluginManager),
|
|
|
|
NS_REINTERPRET_CAST(nsISupports**, &pm));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = pm->RegisterPlugin(kSimplePluginCID,
|
|
|
|
kPluginName,
|
|
|
|
kPluginDescription,
|
|
|
|
kMimeTypes,
|
|
|
|
kMimeDescriptions,
|
|
|
|
kFileExtensions,
|
|
|
|
kNumMimeTypes);
|
|
|
|
|
|
|
|
NS_RELEASE(pm);
|
|
|
|
}
|
1999-08-02 23:19:29 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
return rv;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_METHOD
|
2000-07-22 01:34:13 +00:00
|
|
|
SimplePluginInstance::UnregisterSelf(nsIComponentManager* aCompMgr,
|
|
|
|
nsIFile* aPath,
|
|
|
|
const char* aRegistryLocation)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsIPluginManager* pm;
|
|
|
|
rv = nsServiceManager::GetService(kPluginManagerCID, NS_GET_IID(nsIPluginManager),
|
|
|
|
NS_REINTERPRET_CAST(nsISupports**, &pm));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = pm->UnregisterPlugin(kSimplePluginCID);
|
|
|
|
NS_RELEASE(pm);
|
2000-04-12 08:35:15 +00:00
|
|
|
}
|
2000-07-22 01:34:13 +00:00
|
|
|
|
|
|
|
return rv;
|
1999-07-21 00:00:13 +00:00
|
|
|
}
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
SimplePluginInstance::SimplePluginInstance(void)
|
2000-07-22 01:34:13 +00:00
|
|
|
: fText(NULL), fPeer(NULL), fWindow(NULL), fMode(nsPluginMode_Embedded)
|
1998-07-11 01:40:24 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
2000-04-16 18:51:02 +00:00
|
|
|
|
|
|
|
static const char text[] = "Hello World!";
|
2000-06-03 09:46:12 +00:00
|
|
|
fText = (char*) nsMemory::Clone(text, sizeof(text));
|
2000-06-05 20:35:32 +00:00
|
|
|
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
fPlatform.moz_box = nsnull;
|
|
|
|
fPlatform.superwin = nsnull;
|
|
|
|
fPlatform.label = nsnull;
|
|
|
|
#endif
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SimplePluginInstance::~SimplePluginInstance(void)
|
|
|
|
{
|
2000-04-16 18:51:02 +00:00
|
|
|
if(fText)
|
2000-06-03 09:46:12 +00:00
|
|
|
nsMemory::Free(fText);
|
1998-07-11 01:40:24 +00:00
|
|
|
PlatformDestroy(); // Perform platform specific cleanup
|
|
|
|
}
|
|
|
|
|
|
|
|
// These macros produce simple version of QueryInterface and AddRef.
|
|
|
|
// See the nsISupports.h header file for details.
|
|
|
|
|
2000-08-23 00:20:24 +00:00
|
|
|
NS_IMPL_ISUPPORTS3(SimplePluginInstance, nsIPluginInstance, nsISimplePluginInstance, nsIScriptablePlugin)
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* NewInstance:
|
|
|
|
* Creates a new instance of a plug-in and returns an error value.
|
|
|
|
*
|
|
|
|
* NewInstance creates a new instance of your plug-in with MIME type specified
|
|
|
|
* by pluginType. The parameter mode is NP_EMBED if the instance was created
|
|
|
|
* by an EMBED tag, or NP_FULL if the instance was created by a separate file.
|
|
|
|
* You can allocate any instance-specific private data in instance->pdata at this
|
|
|
|
* time. The NPP pointer is valid until the instance is destroyed.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_METHOD
|
1998-07-11 01:40:24 +00:00
|
|
|
SimplePluginInstance::Initialize(nsIPluginInstancePeer* peer)
|
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::Initialize\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_ASSERTION(peer != NULL, "null peer");
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
fPeer = peer;
|
1999-08-02 23:19:29 +00:00
|
|
|
nsIPluginTagInfo* taginfo;
|
|
|
|
const char* const* names = nsnull;
|
|
|
|
const char* const* values = nsnull;
|
|
|
|
PRUint16 count = 0;
|
|
|
|
nsresult result;
|
|
|
|
|
1998-10-01 02:59:16 +00:00
|
|
|
peer->AddRef();
|
1999-08-02 23:19:29 +00:00
|
|
|
result = peer->GetMode(&fMode);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
2000-01-11 20:49:15 +00:00
|
|
|
result = peer->QueryInterface(NS_GET_IID(nsIPluginTagInfo), (void **)&taginfo);
|
1999-08-02 23:19:29 +00:00
|
|
|
|
|
|
|
if (!NS_FAILED(result))
|
|
|
|
{
|
|
|
|
taginfo->GetAttributes(count, names, values);
|
|
|
|
NS_IF_RELEASE(taginfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("Attribute count = %d\n", count);
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
printf("plugin param=%s, value=%s\n", names[i], values[i]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
PlatformNew(); /* Call Platform-specific initializations */
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_METHOD
|
|
|
|
SimplePluginInstance::GetPeer(nsIPluginInstancePeer* *result)
|
1998-07-11 01:40:24 +00:00
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::GetPeer\n");
|
|
|
|
#endif
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
fPeer->AddRef();
|
|
|
|
*result = fPeer;
|
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_METHOD
|
1998-07-11 01:40:24 +00:00
|
|
|
SimplePluginInstance::Start(void)
|
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::Start\n");
|
|
|
|
#endif
|
1998-10-01 08:08:09 +00:00
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_METHOD
|
1998-07-11 01:40:24 +00:00
|
|
|
SimplePluginInstance::Stop(void)
|
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::Stop\n");
|
|
|
|
#endif
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_METHOD
|
1998-07-11 01:40:24 +00:00
|
|
|
SimplePluginInstance::Destroy(void)
|
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::Destroy\n");
|
|
|
|
#endif
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* NPP_SetWindow:
|
|
|
|
* Sets the window in which a plug-in draws, and returns an error value.
|
|
|
|
*
|
|
|
|
* NPP_SetWindow informs the plug-in instance specified by instance of the
|
|
|
|
* the window denoted by window in which the instance draws. This nsPluginWindow
|
|
|
|
* pointer is valid for the life of the instance, or until NPP_SetWindow is called
|
|
|
|
* again with a different value. Subsequent calls to NPP_SetWindow for a given
|
|
|
|
* instance typically indicate that the window has been resized. If either window
|
|
|
|
* or window->window are NULL, the plug-in must not perform any additional
|
|
|
|
* graphics operations on the window and should free any resources associated
|
|
|
|
* with the window.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_METHOD
|
1998-07-11 01:40:24 +00:00
|
|
|
SimplePluginInstance::SetWindow(nsPluginWindow* window)
|
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::SetWindow\n");
|
|
|
|
#endif
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
nsresult result;
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PLUGIN DEVELOPERS:
|
|
|
|
* Before setting window to point to the
|
|
|
|
* new window, you may wish to compare the new window
|
|
|
|
* info to the previous window (if any) to note window
|
|
|
|
* size changes, etc.
|
|
|
|
*/
|
|
|
|
result = PlatformSetWindow(window);
|
|
|
|
fWindow = window;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-01-28 01:18:23 +00:00
|
|
|
NS_METHOD
|
|
|
|
SimplePluginInstance::NewStream(nsIPluginStreamListener** listener)
|
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::NewStream\n");
|
|
|
|
#endif
|
1999-01-28 01:18:23 +00:00
|
|
|
|
1999-08-02 23:19:29 +00:00
|
|
|
if(listener != NULL)
|
2000-04-12 08:35:15 +00:00
|
|
|
{
|
|
|
|
SimplePluginStreamListener* sl =
|
|
|
|
new SimplePluginStreamListener(this, "http://www.mozilla.org");
|
|
|
|
if(!sl)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
sl->AddRef();
|
|
|
|
*listener = sl;
|
|
|
|
}
|
1999-08-02 23:19:29 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-01-28 01:18:23 +00:00
|
|
|
}
|
|
|
|
|
2000-04-16 18:51:02 +00:00
|
|
|
|
|
|
|
/* attribute string text; */
|
|
|
|
NS_IMETHODIMP SimplePluginInstance::GetText(char * *aText)
|
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::GetText\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!fText)
|
|
|
|
{
|
|
|
|
*aText = NULL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-06-03 09:46:12 +00:00
|
|
|
char* ptr = *aText = (char*) nsMemory::Clone(fText, strlen(fText)+1);
|
2000-04-16 18:51:02 +00:00
|
|
|
return ptr ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP SimplePluginInstance::SetText(const char * aText)
|
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::SetText\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(fText)
|
|
|
|
{
|
2000-06-03 09:46:12 +00:00
|
|
|
nsMemory::Free(fText);
|
2000-04-16 18:51:02 +00:00
|
|
|
fText = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(aText)
|
|
|
|
{
|
2000-06-03 09:46:12 +00:00
|
|
|
fText = (char*) nsMemory::Clone(aText, strlen(aText)+1);
|
2000-04-16 18:51:02 +00:00
|
|
|
if(!fText)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2000-06-02 22:32:53 +00:00
|
|
|
#if defined(XP_PC) && !defined(XP_OS2)
|
2000-04-16 18:51:02 +00:00
|
|
|
if(fPlatform.fhWnd) {
|
|
|
|
InvalidateRect( fPlatform.fhWnd, NULL, TRUE );
|
|
|
|
UpdateWindow( fPlatform.fhWnd );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-06-05 20:35:32 +00:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
// force a redraw
|
|
|
|
Repaint();
|
|
|
|
#endif
|
|
|
|
|
2000-04-16 18:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* NPP_Print:
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_METHOD
|
1998-07-11 01:40:24 +00:00
|
|
|
SimplePluginInstance::Print(nsPluginPrint* printInfo)
|
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::Print\n");
|
|
|
|
#endif
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
if (printInfo == NULL)
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
1998-07-11 01:40:24 +00:00
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
if (printInfo->mode == nsPluginMode_Full) {
|
1998-07-11 01:40:24 +00:00
|
|
|
/*
|
|
|
|
* PLUGIN DEVELOPERS:
|
|
|
|
* If your plugin would like to take over
|
|
|
|
* printing completely when it is in full-screen mode,
|
|
|
|
* set printInfo->pluginPrinted to TRUE and print your
|
|
|
|
* plugin as you see fit. If your plugin wants Netscape
|
|
|
|
* to handle printing in this case, set
|
|
|
|
* printInfo->pluginPrinted to FALSE (the default) and
|
|
|
|
* do nothing. If you do want to handle printing
|
|
|
|
* yourself, printOne is true if the print button
|
|
|
|
* (as opposed to the print menu) was clicked.
|
|
|
|
* On the Macintosh, platformPrint is a THPrint; on
|
|
|
|
* Windows, platformPrint is a structure
|
|
|
|
* (defined in npapi.h) containing the printer name, port,
|
|
|
|
* etc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Do the default*/
|
|
|
|
printInfo->print.fullPrint.pluginPrinted = PR_FALSE;
|
|
|
|
}
|
|
|
|
else { /* If not fullscreen, we must be embedded */
|
|
|
|
/*
|
|
|
|
* PLUGIN DEVELOPERS:
|
|
|
|
* If your plugin is embedded, or is full-screen
|
|
|
|
* but you returned false in pluginPrinted above, NPP_Print
|
1998-07-31 20:19:50 +00:00
|
|
|
* will be called with mode == nsPluginMode_Embedded. The nsPluginWindow
|
1998-07-11 01:40:24 +00:00
|
|
|
* in the printInfo gives the location and dimensions of
|
|
|
|
* the embedded plugin on the printed page. On the
|
|
|
|
* Macintosh, platformPrint is the printer port; on
|
|
|
|
* Windows, platformPrint is the handle to the printing
|
|
|
|
* device context.
|
|
|
|
*/
|
|
|
|
}
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* NPP_HandleEvent:
|
|
|
|
* Mac-only, but stub must be present for Windows
|
|
|
|
* Delivers a platform-specific event to the instance.
|
|
|
|
*
|
|
|
|
* On the Macintosh, event is a pointer to a standard Macintosh EventRecord.
|
|
|
|
* All standard event types are passed to the instance as appropriate. In general,
|
|
|
|
* return TRUE if you handle the event and FALSE if you ignore the event.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
NS_METHOD
|
|
|
|
SimplePluginInstance::HandleEvent(nsPluginEvent* event, PRBool* handled)
|
1998-07-11 01:40:24 +00:00
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::HandleEvent\n");
|
|
|
|
#endif
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
*handled = (PRBool)PlatformHandleEvent(event);
|
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 03:45:38 +00:00
|
|
|
NS_METHOD
|
|
|
|
SimplePluginInstance::GetValue(nsPluginInstanceVariable variable, void *value)
|
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::GetValue\n");
|
|
|
|
#endif
|
|
|
|
|
1998-10-01 02:59:16 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SimplePluginStreamListener Methods
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-10-01 19:07:36 +00:00
|
|
|
SimplePluginStreamListener::SimplePluginStreamListener(SimplePluginInstance* inst,
|
|
|
|
const char* msgName)
|
1999-01-28 01:18:23 +00:00
|
|
|
: fMessageName(msgName)
|
1998-10-01 02:59:16 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
1998-10-01 19:07:36 +00:00
|
|
|
char msg[256];
|
|
|
|
sprintf(msg, "### Creating SimplePluginStreamListener for %s\n", fMessageName);
|
1998-10-01 02:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SimplePluginStreamListener::~SimplePluginStreamListener(void)
|
|
|
|
{
|
1998-10-01 19:07:36 +00:00
|
|
|
char msg[256];
|
|
|
|
sprintf(msg, "### Destroying SimplePluginStreamListener for %s\n", fMessageName);
|
1998-10-01 02:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This macro produces a simple version of QueryInterface, AddRef and Release.
|
|
|
|
// See the nsISupports.h header file for details.
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(SimplePluginStreamListener, nsIPluginStreamListener);
|
1998-10-01 02:59:16 +00:00
|
|
|
|
|
|
|
NS_METHOD
|
1999-07-21 00:00:13 +00:00
|
|
|
SimplePluginStreamListener::OnStartBinding(nsIPluginStreamInfo* pluginInfo)
|
1998-10-01 02:59:16 +00:00
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginStreamListener::OnStartBinding\n");
|
|
|
|
#endif
|
|
|
|
|
1998-10-01 19:07:36 +00:00
|
|
|
char msg[256];
|
|
|
|
sprintf(msg, "### Opening plugin stream for %s\n", fMessageName);
|
1998-10-01 02:59:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
1999-07-21 00:00:13 +00:00
|
|
|
SimplePluginStreamListener::OnDataAvailable(nsIPluginStreamInfo* pluginInfo,
|
|
|
|
nsIInputStream* input,
|
|
|
|
PRUint32 length)
|
1998-10-01 02:59:16 +00:00
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginStreamListener::OnDataAvailable\n");
|
|
|
|
#endif
|
|
|
|
|
1998-10-01 02:59:16 +00:00
|
|
|
char* buffer = new char[length];
|
|
|
|
if (buffer) {
|
1999-01-28 01:18:23 +00:00
|
|
|
PRUint32 amountRead = 0;
|
1999-07-21 00:00:13 +00:00
|
|
|
nsresult rslt = input->Read(buffer, length, &amountRead);
|
1998-10-01 19:07:36 +00:00
|
|
|
if (rslt == NS_OK) {
|
|
|
|
char msg[256];
|
1999-07-21 00:00:13 +00:00
|
|
|
sprintf(msg, "### Received %d bytes for %s\n", length, fMessageName);
|
1998-10-01 19:07:36 +00:00
|
|
|
}
|
1998-10-01 02:59:16 +00:00
|
|
|
delete buffer;
|
|
|
|
}
|
1998-09-15 03:45:38 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-01 02:59:16 +00:00
|
|
|
NS_METHOD
|
1999-07-21 00:00:13 +00:00
|
|
|
SimplePluginStreamListener::OnFileAvailable(nsIPluginStreamInfo* pluginInfo,
|
|
|
|
const char* fileName)
|
1998-10-01 02:59:16 +00:00
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginStreamListener::OnFileAvailable\n");
|
|
|
|
#endif
|
|
|
|
|
1998-10-01 19:07:36 +00:00
|
|
|
char msg[256];
|
|
|
|
sprintf(msg, "### File available for %s: %s\n", fMessageName, fileName);
|
1998-10-01 02:59:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
1999-07-21 00:00:13 +00:00
|
|
|
SimplePluginStreamListener::OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status )
|
1998-10-01 02:59:16 +00:00
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginStreamListener::OnStopBinding\n");
|
|
|
|
#endif
|
|
|
|
|
1998-10-01 19:07:36 +00:00
|
|
|
char msg[256];
|
|
|
|
sprintf(msg, "### Closing plugin stream for %s\n", fMessageName);
|
1998-10-01 02:59:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-28 01:18:23 +00:00
|
|
|
NS_METHOD
|
|
|
|
SimplePluginStreamListener::OnNotify(const char* url, nsresult status)
|
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginStreamListener::OnNotify\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-01-28 01:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
SimplePluginStreamListener::GetStreamType(nsPluginStreamType *result)
|
|
|
|
{
|
1999-08-02 23:19:29 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginStreamListener::GetStreamType\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
*result = nsPluginStreamType_Normal;
|
|
|
|
return NS_OK;
|
1999-01-28 01:18:23 +00:00
|
|
|
}
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
/*******************************************************************************
|
2000-07-22 01:34:13 +00:00
|
|
|
* SECTION 4 - Utility Method Implementations
|
1999-07-21 00:00:13 +00:00
|
|
|
*******************************************************************************/
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* Platform-Specific Implemenations
|
|
|
|
*------------------------------------------------------------------------------
|
|
|
|
* UNIX Implementations
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
2000-05-17 04:38:13 +00:00
|
|
|
#if defined(XP_UNIX)
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PlatformNew
|
|
|
|
*
|
|
|
|
* Initialize any Platform-Specific instance data.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
|
|
|
void
|
|
|
|
SimplePluginInstance::PlatformNew(void)
|
|
|
|
{
|
|
|
|
fPlatform.window = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PlatformDestroy
|
|
|
|
*
|
|
|
|
* Destroy any Platform-Specific instance data.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
nsresult
|
1998-07-11 01:40:24 +00:00
|
|
|
SimplePluginInstance::PlatformDestroy(void)
|
|
|
|
{
|
1999-12-07 23:50:00 +00:00
|
|
|
gtk_widget_destroy(fPlatform.moz_box);
|
|
|
|
fPlatform.moz_box = 0;
|
1999-08-31 00:12:15 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PlatformSetWindow
|
|
|
|
*
|
|
|
|
* Perform platform-specific window operations
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
nsresult
|
1998-07-11 01:40:24 +00:00
|
|
|
SimplePluginInstance::PlatformSetWindow(nsPluginWindow* window)
|
|
|
|
{
|
1999-12-07 23:50:00 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("SimplePluginInstance::PlatformSetWindow\n");
|
|
|
|
#endif
|
2000-06-05 20:35:32 +00:00
|
|
|
|
1999-08-31 00:12:15 +00:00
|
|
|
if (window == NULL || window->window == NULL)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-10-13 01:10:21 +00:00
|
|
|
|
|
|
|
GdkWindow *win = gdk_window_lookup((XID)window->window);
|
|
|
|
|
|
|
|
if ( fPlatform.superwin && fPlatform.superwin->bin_window == win )
|
2000-06-05 20:35:32 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2000-10-13 01:10:21 +00:00
|
|
|
// should we destroy fPlatform.superwin ??
|
|
|
|
|
|
|
|
fPlatform.superwin = gdk_superwin_new(win, 0, 0, window->width, window->height);
|
2000-06-05 20:35:32 +00:00
|
|
|
|
|
|
|
// a little cleanup
|
|
|
|
if (fPlatform.label)
|
|
|
|
gtk_widget_destroy(fPlatform.label);
|
|
|
|
if (fPlatform.moz_box)
|
|
|
|
gtk_widget_destroy(fPlatform.moz_box);
|
|
|
|
|
|
|
|
// create a containing mozbox and a label to put in it
|
1999-12-07 23:50:00 +00:00
|
|
|
fPlatform.moz_box = gtk_mozbox_new(fPlatform.superwin->bin_window);
|
2000-06-05 20:35:32 +00:00
|
|
|
fPlatform.label = gtk_label_new(fText);
|
|
|
|
gtk_container_add(GTK_CONTAINER(fPlatform.moz_box), fPlatform.label);
|
1999-12-07 23:50:00 +00:00
|
|
|
|
2000-06-05 20:35:32 +00:00
|
|
|
// grow the label to fit the entire mozbox
|
|
|
|
gtk_widget_set_usize(fPlatform.label, window->width, window->height);
|
1999-08-31 00:12:15 +00:00
|
|
|
|
2000-06-05 20:35:32 +00:00
|
|
|
// connect to expose events
|
|
|
|
gtk_signal_connect (GTK_OBJECT(fPlatform.label), "expose_event",
|
|
|
|
GTK_SIGNAL_FUNC(draw), this);
|
1999-08-31 00:12:15 +00:00
|
|
|
|
2000-06-05 20:35:32 +00:00
|
|
|
gtk_widget_show(fPlatform.label);
|
1999-12-07 23:50:00 +00:00
|
|
|
gtk_widget_show(fPlatform.moz_box);
|
1999-08-31 00:12:15 +00:00
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PlatformHandleEvent
|
|
|
|
*
|
|
|
|
* Handle platform-specific events.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
|
|
|
int16
|
|
|
|
SimplePluginInstance::PlatformHandleEvent(nsPluginEvent* event)
|
|
|
|
{
|
|
|
|
/* UNIX Plugins do not use HandleEvent */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-05 20:35:32 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SimplePluginInstance::Repaint(void)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("SimplePluginInstance::Repaint()\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( !fPlatform.moz_box || !fPlatform.label )
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Set the label text
|
|
|
|
gtk_label_set_text(GTK_LABEL(fPlatform.label), fText);
|
|
|
|
|
|
|
|
// show the new label
|
|
|
|
gtk_widget_show(fPlatform.label);
|
|
|
|
gtk_widget_show(fPlatform.moz_box);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean draw (GtkWidget *widget, GdkEventExpose *event, gpointer data)
|
|
|
|
{
|
|
|
|
SimplePluginInstance * pthis = (SimplePluginInstance *)data;
|
|
|
|
|
|
|
|
pthis->Repaint();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1998-07-11 01:40:24 +00:00
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* Windows Implementations
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
2000-06-02 22:32:53 +00:00
|
|
|
#elif defined(XP_PC) && !defined(XP_OS2)
|
1998-07-11 01:40:24 +00:00
|
|
|
const char* gInstanceLookupString = "instance->pdata";
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PlatformNew
|
|
|
|
*
|
|
|
|
* Initialize any Platform-Specific instance data.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
|
|
|
void
|
|
|
|
SimplePluginInstance::PlatformNew(void)
|
|
|
|
{
|
|
|
|
fPlatform.fhWnd = NULL;
|
|
|
|
fPlatform.fDefaultWindowProc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PlatformDestroy
|
|
|
|
*
|
|
|
|
* Destroy any Platform-Specific instance data.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
nsresult
|
1998-07-11 01:40:24 +00:00
|
|
|
SimplePluginInstance::PlatformDestroy(void)
|
|
|
|
{
|
|
|
|
if( fWindow != NULL ) { /* If we have a window, clean
|
|
|
|
* it up. */
|
|
|
|
SetWindowLong( fPlatform.fhWnd, GWL_WNDPROC, (LONG)fPlatform.fDefaultWindowProc);
|
|
|
|
fPlatform.fDefaultWindowProc = NULL;
|
|
|
|
fPlatform.fhWnd = NULL;
|
|
|
|
}
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PlatformSetWindow
|
|
|
|
*
|
|
|
|
* Perform platform-specific window operations
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
nsresult
|
1998-07-11 01:40:24 +00:00
|
|
|
SimplePluginInstance::PlatformSetWindow(nsPluginWindow* window)
|
|
|
|
{
|
|
|
|
if( fWindow != NULL ) /* If we already have a window, clean
|
|
|
|
* it up before trying to subclass
|
|
|
|
* the new window. */
|
|
|
|
{
|
|
|
|
if( (window == NULL) || ( window->window == NULL ) ) {
|
|
|
|
/* There is now no window to use. get rid of the old
|
|
|
|
* one and exit. */
|
|
|
|
SetWindowLong( fPlatform.fhWnd, GWL_WNDPROC, (LONG)fPlatform.fDefaultWindowProc);
|
|
|
|
fPlatform.fDefaultWindowProc = NULL;
|
|
|
|
fPlatform.fhWnd = NULL;
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if ( fPlatform.fhWnd == (HWND) window->window ) {
|
|
|
|
/* The new window is the same as the old one. Exit now. */
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Clean up the old window, so that we can subclass the new
|
|
|
|
* one later. */
|
|
|
|
SetWindowLong( fPlatform.fhWnd, GWL_WNDPROC, (LONG)fPlatform.fDefaultWindowProc);
|
|
|
|
fPlatform.fDefaultWindowProc = NULL;
|
|
|
|
fPlatform.fhWnd = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( (window == NULL) || ( window->window == NULL ) ) {
|
|
|
|
/* We can just get out of here if there is no current
|
|
|
|
* window and there is no new window to use. */
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* At this point, we will subclass
|
|
|
|
* window->window so that we can begin drawing and
|
|
|
|
* receiving window messages. */
|
|
|
|
fPlatform.fDefaultWindowProc =
|
|
|
|
(WNDPROC)SetWindowLong( (HWND)window->window,
|
|
|
|
GWL_WNDPROC, (LONG)SimplePluginInstance::PluginWindowProc);
|
|
|
|
fPlatform.fhWnd = (HWND) window->window;
|
|
|
|
SetProp(fPlatform.fhWnd, gInstanceLookupString, (HANDLE)this);
|
|
|
|
|
|
|
|
InvalidateRect( fPlatform.fhWnd, NULL, TRUE );
|
|
|
|
UpdateWindow( fPlatform.fhWnd );
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PlatformHandleEvent
|
|
|
|
*
|
|
|
|
* Handle platform-specific events.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
|
|
|
PRInt16
|
|
|
|
SimplePluginInstance::PlatformHandleEvent(nsPluginEvent* event)
|
|
|
|
{
|
|
|
|
/* Windows Plugins use the Windows event call-back mechanism
|
|
|
|
for events. (See PluginWindowProc) */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PluginWindowProc
|
|
|
|
*
|
|
|
|
* Handle the Windows window-event loop.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
|
|
|
LRESULT CALLBACK
|
|
|
|
SimplePluginInstance::PluginWindowProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
SimplePluginInstance* inst = (SimplePluginInstance*) GetProp(hWnd, gInstanceLookupString);
|
|
|
|
|
|
|
|
switch( Msg ) {
|
|
|
|
case WM_PAINT: {
|
|
|
|
PAINTSTRUCT paintStruct;
|
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
hdc = BeginPaint( hWnd, &paintStruct );
|
2000-04-12 08:35:15 +00:00
|
|
|
|
|
|
|
if(paintStruct.fErase)
|
|
|
|
FillRect(hdc, &paintStruct.rcPaint,
|
|
|
|
(HBRUSH) GetStockObject(WHITE_BRUSH));
|
|
|
|
|
2000-04-16 18:51:02 +00:00
|
|
|
if(inst->fText)
|
|
|
|
TextOut(hdc, 0, 0, inst->fText, strlen(inst->fText));
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
EndPaint( hWnd, &paintStruct );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
inst->fPlatform.fDefaultWindowProc(hWnd, Msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* Macintosh Implementations
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
2000-05-17 04:38:13 +00:00
|
|
|
#elif defined(XP_MAC)
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
PRBool StartDraw(nsPluginWindow* window);
|
|
|
|
void EndDraw(nsPluginWindow* window);
|
|
|
|
void DoDraw(SimplePluginInstance* This);
|
|
|
|
|
|
|
|
CGrafPort gSavePort;
|
|
|
|
CGrafPtr gOldPort;
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PlatformNew
|
|
|
|
*
|
|
|
|
* Initialize any Platform-Specific instance data.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
|
|
|
void
|
|
|
|
SimplePluginInstance::PlatformNew(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PlatformDestroy
|
|
|
|
*
|
|
|
|
* Destroy any Platform-Specific instance data.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
nsresult
|
1998-07-11 01:40:24 +00:00
|
|
|
SimplePluginInstance::PlatformDestroy(void)
|
|
|
|
{
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PlatformSetWindow
|
|
|
|
*
|
|
|
|
* Perform platform-specific window operations
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
1998-07-31 20:19:50 +00:00
|
|
|
nsresult
|
1998-07-11 01:40:24 +00:00
|
|
|
SimplePluginInstance::PlatformSetWindow(nsPluginWindow* window)
|
|
|
|
{
|
|
|
|
fWindow = window;
|
|
|
|
if( StartDraw( window ) ) {
|
|
|
|
DoDraw(This);
|
|
|
|
EndDraw( window );
|
|
|
|
}
|
1998-07-31 20:19:50 +00:00
|
|
|
return NS_OK;
|
1998-07-11 01:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* PlatformHandleEvent
|
|
|
|
*
|
|
|
|
* Handle platform-specific events.
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
|
|
|
int16
|
|
|
|
SimplePluginInstance::PlatformHandleEvent(nsPluginEvent* event)
|
|
|
|
{
|
|
|
|
int16 eventHandled = FALSE;
|
|
|
|
|
|
|
|
EventRecord* ev = (EventRecord*) event;
|
|
|
|
if (This != NULL && event != NULL)
|
|
|
|
{
|
|
|
|
switch (ev->what)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Draw ourselves on update events
|
|
|
|
*/
|
|
|
|
case updateEvt:
|
|
|
|
if( StartDraw( fWindow ) ) {
|
|
|
|
DoDraw(This);
|
|
|
|
EndDraw( fWindow );
|
|
|
|
}
|
|
|
|
eventHandled = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return eventHandled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* StartDraw
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
SimplePluginInstance::StartDraw(nsPluginWindow* window)
|
|
|
|
{
|
|
|
|
NP_Port* port;
|
|
|
|
Rect clipRect;
|
|
|
|
RGBColor col;
|
|
|
|
|
|
|
|
if (window == NULL)
|
|
|
|
return FALSE;
|
|
|
|
port = (NP_Port*) window->window;
|
|
|
|
if (window->clipRect.left < window->clipRect.right)
|
|
|
|
{
|
|
|
|
/* Preserve the old port */
|
|
|
|
GetPort((GrafPtr*)&gOldPort);
|
|
|
|
SetPort((GrafPtr)port->port);
|
|
|
|
/* Preserve the old drawing environment */
|
|
|
|
gSavePort.portRect = port->port->portRect;
|
|
|
|
gSavePort.txFont = port->port->txFont;
|
|
|
|
gSavePort.txFace = port->port->txFace;
|
|
|
|
gSavePort.txMode = port->port->txMode;
|
|
|
|
gSavePort.rgbFgColor = port->port->rgbFgColor;
|
|
|
|
gSavePort.rgbBkColor = port->port->rgbBkColor;
|
|
|
|
GetClip(gSavePort.clipRgn);
|
|
|
|
/* Setup our drawing environment */
|
|
|
|
clipRect.top = window->clipRect.top + port->porty;
|
|
|
|
clipRect.left = window->clipRect.left + port->portx;
|
|
|
|
clipRect.bottom = window->clipRect.bottom + port->porty;
|
|
|
|
clipRect.right = window->clipRect.right + port->portx;
|
|
|
|
SetOrigin(port->portx,port->porty);
|
|
|
|
ClipRect(&clipRect);
|
|
|
|
clipRect.top = clipRect.left = 0;
|
|
|
|
TextSize(12);
|
|
|
|
TextFont(geneva);
|
|
|
|
TextMode(srcCopy);
|
|
|
|
col.red = col.green = col.blue = 0;
|
|
|
|
RGBForeColor(&col);
|
|
|
|
col.red = col.green = col.blue = 65000;
|
|
|
|
RGBBackColor(&col);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* EndDraw
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
|
|
|
void
|
|
|
|
SimplePluginInstance::EndDraw(nsPluginWindow* window)
|
|
|
|
{
|
|
|
|
CGrafPtr myPort;
|
|
|
|
NP_Port* port = (NP_Port*) window->window;
|
|
|
|
SetOrigin(gSavePort.portRect.left, gSavePort.portRect.top);
|
|
|
|
SetClip(gSavePort.clipRgn);
|
|
|
|
GetPort((GrafPtr*)&myPort);
|
|
|
|
myPort->txFont = gSavePort.txFont;
|
|
|
|
myPort->txFace = gSavePort.txFace;
|
|
|
|
myPort->txMode = gSavePort.txMode;
|
|
|
|
RGBForeColor(&gSavePort.rgbFgColor);
|
|
|
|
RGBBackColor(&gSavePort.rgbBkColor);
|
|
|
|
SetPort((GrafPtr)gOldPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
* DoDraw
|
|
|
|
+++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
|
|
|
|
void
|
|
|
|
SimplePluginInstance::DoDraw(void)
|
|
|
|
{
|
|
|
|
Rect drawRect;
|
|
|
|
drawRect.top = 0;
|
|
|
|
drawRect.left = 0;
|
|
|
|
drawRect.bottom = drawRect.top + fWindow->height;
|
|
|
|
drawRect.right = drawRect.left + fWindow->width;
|
|
|
|
EraseRect( &drawRect );
|
|
|
|
MoveTo( 2, 12 );
|
|
|
|
DrawString("\pHello, World!");
|
|
|
|
}
|
|
|
|
|
2000-05-17 04:38:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* Stub Implementations
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
void
|
|
|
|
SimplePluginInstance::PlatformNew(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SimplePluginInstance::PlatformDestroy(void)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SimplePluginInstance::PlatformSetWindow(nsPluginWindow* window)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
int16
|
|
|
|
SimplePluginInstance::PlatformHandleEvent(nsPluginEvent* event)
|
|
|
|
{
|
|
|
|
int16 eventHandled = FALSE;
|
|
|
|
return eventHandled;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* end Section 5 */
|
1998-07-11 01:40:24 +00:00
|
|
|
|
|
|
|
/******************************************************************************/
|