зеркало из https://github.com/mozilla/gecko-dev.git
First Checked In.
This commit is contained in:
Родитель
cf5893514c
Коммит
4e638fbf71
|
@ -0,0 +1,316 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
TopLevelFrame.cpp
|
||||
|
||||
An MRJFrame sub-class that manages the behavior of a top-level window
|
||||
running inside the Communicator.
|
||||
|
||||
by Patrick C. Beard.
|
||||
*/
|
||||
|
||||
#include <Controls.h>
|
||||
#include <Events.h>
|
||||
|
||||
#include "MRJPlugin.h"
|
||||
#include "MRJSession.h"
|
||||
|
||||
#include "nsIPluginInstancePeer.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "EmbeddedFrame.h"
|
||||
#include "JSEvaluator.h"
|
||||
#include "LocalPort.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
static void UnsetPort(GrafPtr port);
|
||||
static short getModifiers();
|
||||
|
||||
EmbeddedFrame::EmbeddedFrame(MRJPluginInstance* pluginInstance, JMFrameRef frameRef, JMFrameKind kind,
|
||||
const Rect* initialBounds, Boolean resizeable)
|
||||
: MRJFrame(frameRef),
|
||||
mPluginInstance(pluginInstance), mEvaluator(NULL), mWindow(NULL), mBounds(*initialBounds)
|
||||
{
|
||||
Boolean hasGoAway = true;
|
||||
SInt16 windowProc = documentProc;
|
||||
SInt16 resizeHeight = resizeable ? 15 : 0;
|
||||
|
||||
switch (kind) {
|
||||
case eBorderlessModelessWindowFrame:
|
||||
hasGoAway = false;
|
||||
windowProc = plainDBox;
|
||||
// mBounds.bottom += resizeHeight;
|
||||
resizeable = false;
|
||||
break;
|
||||
case eModelessWindowFrame:
|
||||
case eModelessDialogFrame:
|
||||
hasGoAway = true;
|
||||
windowProc = resizeable ? zoomDocProc : documentProc;
|
||||
// mBounds.bottom += resizeHeight;
|
||||
break;
|
||||
case eModalWindowFrame:
|
||||
hasGoAway = true;
|
||||
// We have to allow resizeable modal windows.
|
||||
windowProc = resizeable ? documentProc : movableDBoxProc;
|
||||
break;
|
||||
}
|
||||
|
||||
#if 0
|
||||
mWindow = ::NewCWindow(NULL, &mBounds, "\p", false, windowProc, WindowPtr(-1), hasGoAway, long(this));
|
||||
if (mWindow != NULL) {
|
||||
if (getModifiers() & controlKey) {
|
||||
// hack: Try creating a root control, to see if that messes up MRJ controls.
|
||||
ControlHandle rootControl = NULL;
|
||||
OSErr result = ::GetRootControl(mWindow, &rootControl);
|
||||
if (result != noErr || rootControl == NULL) {
|
||||
result = ::CreateRootControl(mWindow, &rootControl);
|
||||
if (result == noErr && rootControl != NULL) {
|
||||
FSSpec dumpFile = { -1, 2, "\pJava Console Controls" };
|
||||
result = DumpControlHierarchy(mWindow, &dumpFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
#if 0
|
||||
|
||||
class NewStreamMessage : public NativeMessage {
|
||||
nsIPluginInstancePeer* mPeer;
|
||||
const char* mType;
|
||||
public:
|
||||
NewStreamMessage(nsIPluginInstancePeer* peer, const char* type) : mPeer(peer), mType(type) {}
|
||||
|
||||
virtual void execute() {
|
||||
nsIOutputStream* output = NULL;
|
||||
if (mPeer->NewStream(mType, "_blank", &output) == NS_OK) {
|
||||
// write some data to the stream.
|
||||
output->Close();
|
||||
NS_RELEASE(output);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// open a stream of type "application/x-java-frame", which should cause a full-screen plugin to get created for a Java frame's
|
||||
// behalf. communicate with the other instance via this stream.
|
||||
nsIPluginInstancePeer* peer = NULL;
|
||||
if (pluginInstance->GetPeer(&peer) == NS_OK) {
|
||||
NewStreamMessage msg(peer, "application/x-java-frame");
|
||||
pluginInstance->getSession()->sendMessage(&msg);
|
||||
NS_RELEASE(peer);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Use JavaScript to create a window with an <EMBED TYPE="application/x-java-frame"> tag.
|
||||
const char* kEmbeddedFrameScript = "javascript:var w = window.open('', '', 'resizable=yes,status=no,width=400,height=400'); "
|
||||
"var d = w.document; d.write('<HTML><HEAD></HEAD><BODY><EMBED TYPE=\"application/x-java-frame\""
|
||||
"BORDER=5 WIDTH=400 HEIGHT=400 FRAME=XXXXXXXX></EMBED></BODY></HTML>'); d.close();";
|
||||
char* script = strdup(kEmbeddedFrameScript);
|
||||
char* address = strchr(script, 'X');
|
||||
sprintf(address, "%08X", this);
|
||||
address[8] = '>';
|
||||
|
||||
JSEvaluator* evaluator = new JSEvaluator(pluginInstance);
|
||||
evaluator->AddRef();
|
||||
|
||||
// create the window. It will be created after returning from eval.
|
||||
const char* result = evaluator->eval(script);
|
||||
|
||||
delete[] script;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
if (mWindow != NULL) {
|
||||
Point zeroPt = { 5, 5 };
|
||||
::JMSetFrameVisibility(mFrameRef, mWindow, zeroPt, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
EmbeddedFrame::~EmbeddedFrame()
|
||||
{
|
||||
// make sure the window is hidden (and unregistered with the browser).
|
||||
showHide(false);
|
||||
|
||||
// make sure this port isn't ever current again.
|
||||
::UnsetPort(mWindow);
|
||||
|
||||
// if (mWindow != NULL)
|
||||
// ::DisposeWindow(mWindow);
|
||||
}
|
||||
|
||||
void EmbeddedFrame::setSize(const Rect* newSize)
|
||||
{
|
||||
mBounds = *newSize;
|
||||
|
||||
if (mWindow != NULL) {
|
||||
SInt16 width = newSize->right - newSize->left;
|
||||
SInt16 height = newSize->bottom - newSize->top;
|
||||
::SizeWindow(mWindow, width, height, true);
|
||||
::MoveWindow(mWindow, newSize->left, newSize->top, false);
|
||||
}
|
||||
}
|
||||
|
||||
void EmbeddedFrame::invalRect(const Rect* invalidRect)
|
||||
{
|
||||
if (mWindow != NULL) {
|
||||
::InvalRect(invalidRect);
|
||||
}
|
||||
}
|
||||
|
||||
void EmbeddedFrame::showHide(Boolean visible)
|
||||
{
|
||||
if (mWindow != NULL && visible != IsWindowVisible(mWindow)) {
|
||||
if (visible) {
|
||||
// Have to notify the browser that this window exists, so that it will receive events.
|
||||
::ShowWindow(mWindow);
|
||||
::SelectWindow(mWindow);
|
||||
} else {
|
||||
::HideWindow(mWindow);
|
||||
}
|
||||
|
||||
// ::ShowHide(mWindow, visible);
|
||||
}
|
||||
}
|
||||
|
||||
void EmbeddedFrame::setTitle(const StringPtr title)
|
||||
{
|
||||
if (mWindow != NULL) {
|
||||
::SetWTitle(mWindow, title);
|
||||
}
|
||||
}
|
||||
|
||||
void EmbeddedFrame::checkUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
void EmbeddedFrame::reorder(ReorderRequest request)
|
||||
{
|
||||
switch (request) {
|
||||
case eBringToFront: /* bring the window to front */
|
||||
break;
|
||||
case eSendToBack: /* send the window to back */
|
||||
break;
|
||||
case eSendBehindFront: /* send the window behind the front window */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void EmbeddedFrame::setResizeable(Boolean resizeable)
|
||||
{
|
||||
// this might have to recreate the window, no?
|
||||
}
|
||||
|
||||
static void computeBounds(WindowRef window, Rect* bounds)
|
||||
{
|
||||
LocalPort port(window);
|
||||
port.Enter();
|
||||
|
||||
Point position = { 0, 0 };
|
||||
::LocalToGlobal(&position);
|
||||
|
||||
*bounds = window->portRect;
|
||||
|
||||
port.Exit();
|
||||
|
||||
::OffsetRect(bounds, position.h, position.v);
|
||||
}
|
||||
|
||||
void EmbeddedFrame::activate(Boolean active)
|
||||
{
|
||||
focusEvent(active);
|
||||
MRJFrame::activate(active);
|
||||
}
|
||||
|
||||
void EmbeddedFrame::click(const EventRecord* event)
|
||||
{
|
||||
Point where = event->where;
|
||||
SInt16 modifiers = event->modifiers;
|
||||
WindowRef hitWindow;
|
||||
short partCode = ::FindWindow(where, &hitWindow);
|
||||
switch (partCode) {
|
||||
case inContent:
|
||||
::SelectWindow(mWindow);
|
||||
MRJFrame::click(event);
|
||||
break;
|
||||
case inDrag:
|
||||
Rect bounds = (**GetGrayRgn()).rgnBBox;
|
||||
DragWindow(mWindow, where, &bounds);
|
||||
computeBounds(mWindow, &mBounds);
|
||||
break;
|
||||
case inGrow:
|
||||
Rect limits = { 30, 30, 5000, 5000 };
|
||||
long result = GrowWindow(mWindow, where, &limits);
|
||||
if (result != 0) {
|
||||
short width = (result & 0xFFFF);
|
||||
short height = (result >> 16) & 0xFFFF;
|
||||
Rect newBounds;
|
||||
topLeft(newBounds) = topLeft(mBounds);
|
||||
newBounds.right = newBounds.left + width;
|
||||
newBounds.bottom = newBounds.top + height;
|
||||
::JMSetFrameSize(mFrameRef, &newBounds);
|
||||
}
|
||||
break;
|
||||
case inGoAway:
|
||||
if (::TrackGoAway(mWindow, where))
|
||||
::JMFrameGoAway(mFrameRef);
|
||||
break;
|
||||
case inZoomIn:
|
||||
case inZoomOut:
|
||||
if (::TrackBox(mWindow, where, partCode)) {
|
||||
ZoomWindow(mWindow, partCode, true);
|
||||
computeBounds(mWindow, &mBounds);
|
||||
::JMSetFrameSize(mFrameRef, &mBounds);
|
||||
}
|
||||
break;
|
||||
case inCollapseBox:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void EmbeddedFrame::setWindow(WindowRef window)
|
||||
{
|
||||
mWindow = window;
|
||||
}
|
||||
|
||||
WindowRef EmbeddedFrame::getWindow()
|
||||
{
|
||||
return mWindow;
|
||||
}
|
||||
|
||||
GrafPtr EmbeddedFrame::getPort()
|
||||
{
|
||||
return mWindow;
|
||||
}
|
||||
|
||||
static void UnsetPort(GrafPtr port)
|
||||
{
|
||||
GrafPtr curPort;
|
||||
::GetPort(&curPort);
|
||||
if (curPort == port) {
|
||||
::GetWMgrPort(&port);
|
||||
::SetPort(port);
|
||||
}
|
||||
}
|
||||
|
||||
static short getModifiers()
|
||||
{
|
||||
EventRecord event;
|
||||
::OSEventAvail(0, &event);
|
||||
return event.modifiers;
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
EmbeddedFrame.h
|
||||
|
||||
An MRJFrame sub-class that manages the behavior of a top-level window
|
||||
running inside the Communicator.
|
||||
|
||||
by Patrick C. Beard.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "MRJFrame.h"
|
||||
|
||||
#ifndef __MACWINDOWS__
|
||||
#include <MacWindows.h>
|
||||
#endif
|
||||
|
||||
class MRJPluginInstance;
|
||||
class JSEvaluator;
|
||||
|
||||
class EmbeddedFrame : public MRJFrame {
|
||||
public:
|
||||
EmbeddedFrame(MRJPluginInstance* pluginInstance, JMFrameRef frameRef, JMFrameKind kind, const Rect* initialBounds, Boolean resizeable);
|
||||
virtual ~EmbeddedFrame();
|
||||
|
||||
virtual void setSize(const Rect* newSize);
|
||||
virtual void invalRect(const Rect* invalidRect);
|
||||
virtual void showHide(Boolean visible);
|
||||
virtual void setTitle(const StringPtr title);
|
||||
virtual void checkUpdate();
|
||||
virtual void reorder(ReorderRequest request);
|
||||
virtual void setResizeable(Boolean resizeable);
|
||||
|
||||
virtual void activate(Boolean active);
|
||||
virtual void click(const EventRecord* event);
|
||||
|
||||
void setWindow(WindowRef window);
|
||||
WindowRef getWindow();
|
||||
|
||||
protected:
|
||||
virtual GrafPtr getPort();
|
||||
|
||||
private:
|
||||
MRJPluginInstance* mPluginInstance;
|
||||
JSEvaluator* mEvaluator;
|
||||
WindowRef mWindow;
|
||||
Rect mBounds;
|
||||
};
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
EmbeddedFramePluginInstance.cpp
|
||||
*/
|
||||
|
||||
#include "EmbeddedFramePluginInstance.h"
|
||||
#include "EmbeddedFrame.h"
|
||||
#include "MRJPlugin.h"
|
||||
|
||||
#include "nsIPluginInstancePeer.h"
|
||||
#include "nsIPluginTagInfo.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
EmbeddedFramePluginInstance::EmbeddedFramePluginInstance()
|
||||
: mPeer(NULL), mParentInstance(NULL), mFrame(NULL)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
EmbeddedFramePluginInstance::~EmbeddedFramePluginInstance()
|
||||
{
|
||||
if (mFrame != NULL)
|
||||
delete mFrame;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(EmbeddedFramePluginInstance, nsIPluginInstance::GetIID())
|
||||
|
||||
NS_METHOD EmbeddedFramePluginInstance::Initialize(nsIPluginInstancePeer* peer)
|
||||
{
|
||||
mPeer = peer;
|
||||
NS_ADDREF(mPeer);
|
||||
|
||||
nsIPluginTagInfo* tagInfo = NULL;
|
||||
if (mPeer->QueryInterface(nsIPluginTagInfo::GetIID(), &tagInfo) == NS_OK) {
|
||||
const char* frameValue = NULL;
|
||||
if (tagInfo->GetAttribute("FRAME", &frameValue) == NS_OK) {
|
||||
sscanf(frameValue, "%X", &mFrame);
|
||||
}
|
||||
NS_RELEASE(tagInfo);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD EmbeddedFramePluginInstance::GetPeer(nsIPluginInstancePeer* *resultingPeer)
|
||||
{
|
||||
if (mPeer != NULL) {
|
||||
*resultingPeer = mPeer;
|
||||
mPeer->AddRef();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD EmbeddedFramePluginInstance::Destroy()
|
||||
{
|
||||
NS_IF_RELEASE(mPeer);
|
||||
NS_IF_RELEASE(mParentInstance);
|
||||
if (mFrame != NULL) {
|
||||
delete mFrame;
|
||||
mFrame = NULL;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD EmbeddedFramePluginInstance::SetWindow(nsPluginWindow* pluginWindow)
|
||||
{
|
||||
if (pluginWindow != NULL)
|
||||
mFrame->setWindow(WindowRef(pluginWindow->window->port));
|
||||
else
|
||||
mFrame->setWindow(NULL);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD EmbeddedFramePluginInstance::HandleEvent(nsPluginEvent* pluginEvent, PRBool* eventHandled)
|
||||
{
|
||||
if (mFrame != NULL)
|
||||
*eventHandled = mFrame->handleEvent(pluginEvent->event);
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
EmbeddedFramePluginInstance.h
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "nsIPluginInstance.h"
|
||||
|
||||
class EmbeddedFrame;
|
||||
class MRJPluginInstance;
|
||||
|
||||
class EmbeddedFramePluginInstance : public nsIPluginInstance {
|
||||
public:
|
||||
EmbeddedFramePluginInstance();
|
||||
virtual ~EmbeddedFramePluginInstance();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/**
|
||||
* Initializes a newly created plugin instance, passing to it the plugin
|
||||
* instance peer which it should use for all communication back to the browser.
|
||||
*
|
||||
* @param peer - the corresponding plugin instance peer
|
||||
* @result - NS_OK if this operation was successful
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Initialize(nsIPluginInstancePeer* peer);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param resultingPeer - the resulting plugin instance peer
|
||||
* @result - NS_OK if this operation was successful
|
||||
*/
|
||||
NS_IMETHOD
|
||||
GetPeer(nsIPluginInstancePeer* *resultingPeer);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @result - NS_OK if this operation was successful
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Start(void)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @result - NS_OK if this operation was successful
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Stop(void)
|
||||
{
|
||||
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.
|
||||
*
|
||||
* @result - NS_OK if this operation was successful
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Destroy(void);
|
||||
|
||||
/**
|
||||
* Called when the window containing the plugin instance changes.
|
||||
*
|
||||
* (Corresponds to NPP_SetWindow.)
|
||||
*
|
||||
* @param window - the plugin window structure
|
||||
* @result - NS_OK if this operation was successful
|
||||
*/
|
||||
NS_IMETHOD
|
||||
SetWindow(nsPluginWindow* window);
|
||||
|
||||
/**
|
||||
* Called to tell the plugin that the initial src/data stream is
|
||||
* ready. Expects the plugin to return a nsIPluginStreamListener.
|
||||
*
|
||||
* (Corresponds to NPP_NewStream.)
|
||||
*
|
||||
* @param listener - listener the browser will use to give the plugin the data
|
||||
* @result - NS_OK if this operation was successful
|
||||
*/
|
||||
NS_IMETHOD
|
||||
NewStream(nsIPluginStreamListener** listener)
|
||||
{
|
||||
*listener = NULL;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to instruct the plugin instance to print itself to a printer.
|
||||
*
|
||||
* (Corresponds to NPP_Print.)
|
||||
*
|
||||
* @param platformPrint - platform-specific printing information
|
||||
* @result - NS_OK if this operation was successful
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Print(nsPluginPrint* platformPrint)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a variable associated with the plugin instance.
|
||||
*
|
||||
* @param variable - the plugin instance variable to get
|
||||
* @param value - the address of where to store the resulting value
|
||||
* @result - NS_OK if this operation was successful
|
||||
*/
|
||||
NS_IMETHOD
|
||||
GetValue(nsPluginInstanceVariable variable, void *value)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.)
|
||||
*
|
||||
* @param event - the event to be handled
|
||||
* @param handled - set to PR_TRUE if event was handled
|
||||
* @result - NS_OK if this operation was successful
|
||||
*/
|
||||
NS_IMETHOD
|
||||
HandleEvent(nsPluginEvent* event, PRBool* handled);
|
||||
|
||||
private:
|
||||
nsIPluginInstancePeer* mPeer;
|
||||
MRJPluginInstance* mParentInstance;
|
||||
EmbeddedFrame* mFrame;
|
||||
};
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
JSEvaluator.cpp
|
||||
*/
|
||||
|
||||
#include "JSEvaluator.h"
|
||||
#include "MRJPlugin.h"
|
||||
#include "MRJSession.h"
|
||||
#include "MRJMonitor.h"
|
||||
#include "nsIPluginManager.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
extern nsIPluginManager* thePluginManager;
|
||||
|
||||
JSEvaluator::JSEvaluator(MRJPluginInstance* pluginInstance)
|
||||
: mPluginInstance(pluginInstance)
|
||||
{
|
||||
NS_ADDREF(pluginInstance);
|
||||
mSession = pluginInstance->getSession();
|
||||
mJSMonitor = new MRJMonitor(mSession);
|
||||
}
|
||||
|
||||
JSEvaluator::~JSEvaluator()
|
||||
{
|
||||
NS_IF_RELEASE(mPluginInstance);
|
||||
if (mJSMonitor != NULL)
|
||||
delete mJSMonitor;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(JSEvaluator, nsIPluginStreamListener::GetIID())
|
||||
|
||||
const char* JSEvaluator::eval(const char* script)
|
||||
{
|
||||
JNIEnv* env = mSession->getCurrentEnv();
|
||||
nsIPluginStreamListener* listener = this;
|
||||
|
||||
mJSMonitor->enter();
|
||||
|
||||
while (mScript != NULL) {
|
||||
// some other thread is evaluating a script.
|
||||
mJSMonitor->wait();
|
||||
}
|
||||
|
||||
// construct a "javascript:" URL from the passed-in script.
|
||||
const char* kJavaScriptPrefix = "javascript:";
|
||||
mScript = new char[strlen(kJavaScriptPrefix) + strlen(script) + 1];
|
||||
if (mScript != NULL) {
|
||||
strcpy(mScript, kJavaScriptPrefix);
|
||||
strcat(mScript, script);
|
||||
|
||||
// start an async evaluation of this script.
|
||||
nsresult result = thePluginManager->GetURL((nsIPluginInstance*)mPluginInstance, mScript, NULL, (nsIPluginStreamListener*)this);
|
||||
|
||||
// default result is NULL, in case JavaScript returns undefined value.
|
||||
if (mResult != NULL) {
|
||||
delete[] mResult;
|
||||
mResult = NULL;
|
||||
}
|
||||
|
||||
// need to block until the result is ready.
|
||||
mJSMonitor->wait();
|
||||
|
||||
// can now delete the script.
|
||||
delete[] mScript;
|
||||
mScript = NULL;
|
||||
}
|
||||
|
||||
mJSMonitor->notifyAll();
|
||||
|
||||
mJSMonitor->exit();
|
||||
|
||||
return mResult;
|
||||
}
|
||||
|
||||
NS_METHOD JSEvaluator::OnDataAvailable(nsIPluginStreamInfo* pluginInfo, nsIInputStream* input, PRUint32 length)
|
||||
{
|
||||
// hopefully all our data is available.
|
||||
mResult = new char[length + 1];
|
||||
if (mResult != NULL) {
|
||||
if (input->Read(mResult, length, &length) == NS_OK) {
|
||||
// We've delayed processing the applet tag, because we
|
||||
// don't know the location of the curren document yet.
|
||||
mResult[length] = '\0';
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD JSEvaluator::OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status)
|
||||
{
|
||||
// the stream has been closed, notify any waiting Java threads.
|
||||
mJSMonitor->notifyAll();
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
JSEvaluator.h
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "nsIPluginStreamListener.h"
|
||||
|
||||
#ifndef JNI_H
|
||||
#include <jni.h>
|
||||
#endif
|
||||
|
||||
class MRJMonitor;
|
||||
class MRJSession;
|
||||
class MRJPluginInstance;
|
||||
|
||||
class JSEvaluator : public nsIPluginStreamListener {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
JSEvaluator(MRJPluginInstance* pluginInstance);
|
||||
virtual ~JSEvaluator();
|
||||
|
||||
const char* eval(const char* script);
|
||||
|
||||
const char* getResult()
|
||||
{
|
||||
return mResult;
|
||||
}
|
||||
|
||||
// nsIPluginStreamListener implementation.
|
||||
|
||||
/**
|
||||
* 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
|
||||
OnStartBinding(nsIPluginStreamInfo* pluginInfo)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
OnDataAvailable(nsIPluginStreamInfo* pluginInfo, nsIInputStream* input, PRUint32 length);
|
||||
|
||||
NS_IMETHOD
|
||||
OnFileAvailable(nsIPluginStreamInfo* pluginInfo, const char* fileName)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status);
|
||||
|
||||
/**
|
||||
* What is this method supposed to do?
|
||||
*/
|
||||
NS_IMETHOD
|
||||
GetStreamType(nsPluginStreamType *result)
|
||||
{
|
||||
*result = nsPluginStreamType_Normal;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
MRJPluginInstance* mPluginInstance;
|
||||
MRJSession* mSession;
|
||||
MRJMonitor* mJSMonitor;
|
||||
char* mScript;
|
||||
char* mResult;
|
||||
};
|
Загрузка…
Ссылка в новой задаче