2009-06-30 11:51:05 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: sw=4 ts=4 et :
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Plugin App.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Chris Jones <jones.chris.g@gmail.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2009-12-01 13:05:26 -08:00
|
|
|
* Jim Mathies <jmathies@mozilla.com>
|
2009-06-30 11:51:05 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2009-09-08 23:31:35 -07:00
|
|
|
#include "PluginInstanceChild.h"
|
2009-09-17 15:15:12 -07:00
|
|
|
#include "PluginModuleChild.h"
|
2009-09-09 07:04:09 -07:00
|
|
|
#include "BrowserStreamChild.h"
|
2009-09-21 07:51:35 -07:00
|
|
|
#include "PluginStreamChild.h"
|
2009-09-08 14:22:50 -07:00
|
|
|
#include "StreamNotifyChild.h"
|
2009-07-02 09:54:22 -07:00
|
|
|
|
2009-11-06 14:33:12 -08:00
|
|
|
#include "mozilla/ipc/SyncChannel.h"
|
|
|
|
|
2009-09-17 15:15:12 -07:00
|
|
|
using namespace mozilla::plugins;
|
|
|
|
|
2009-09-30 14:36:14 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
2009-07-01 14:19:32 -07:00
|
|
|
|
2009-06-30 11:51:05 -07:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#include "gtk2xtbin.h"
|
2009-07-01 14:19:32 -07:00
|
|
|
|
|
|
|
#elif defined(OS_WIN)
|
2009-12-01 15:33:51 -08:00
|
|
|
using mozilla::gfx::SharedDIB;
|
2009-07-01 14:19:32 -07:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
2009-12-14 16:27:25 -08:00
|
|
|
#define NS_OOPP_DOUBLEPASS_MSGID TEXT("MozDoublePassMsg")
|
2009-07-02 09:54:22 -07:00
|
|
|
#endif
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-10-11 16:54:49 -07:00
|
|
|
PluginInstanceChild::PluginInstanceChild(const NPPluginFuncs* aPluginIface) :
|
2010-01-15 12:35:57 -08:00
|
|
|
mPluginIface(aPluginIface)
|
2009-10-11 16:54:49 -07:00
|
|
|
#if defined(OS_WIN)
|
2010-01-15 12:35:57 -08:00
|
|
|
, mPluginWindowHWND(0)
|
|
|
|
, mPluginWndProc(0)
|
|
|
|
, mPluginParentHWND(0)
|
|
|
|
#endif // OS_WIN
|
|
|
|
{
|
|
|
|
memset(&mWindow, 0, sizeof(mWindow));
|
|
|
|
mData.ndata = (void*) this;
|
2009-10-11 16:54:49 -07:00
|
|
|
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
|
2010-01-15 12:35:57 -08:00
|
|
|
mWindow.ws_info = &mWsInfo;
|
|
|
|
memset(&mWsInfo, 0, sizeof(mWsInfo));
|
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
|
|
|
mWsInfo.display = GDK_DISPLAY();
|
|
|
|
#endif // MOZ_WIDGET_GTK2
|
|
|
|
#endif // MOZ_X11 && XP_UNIX && !XP_MACOSX
|
2009-12-14 16:27:25 -08:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
memset(&mAlphaExtract, 0, sizeof(mAlphaExtract));
|
|
|
|
mAlphaExtract.doublePassEvent = ::RegisterWindowMessage(NS_OOPP_DOUBLEPASS_MSGID);
|
2010-01-15 12:35:57 -08:00
|
|
|
#endif // OS_WIN
|
|
|
|
}
|
2009-10-11 16:54:49 -07:00
|
|
|
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceChild::~PluginInstanceChild()
|
2009-07-01 14:19:32 -07:00
|
|
|
{
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
DestroyPluginWindow();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-06-30 11:51:05 -07:00
|
|
|
NPError
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceChild::NPN_GetValue(NPNVariable aVar,
|
|
|
|
void* aValue)
|
2009-06-30 11:51:05 -07:00
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG(("%s (aVar=%i)", FULLFUNCTION, (int) aVar));
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
2009-06-30 11:51:05 -07:00
|
|
|
|
|
|
|
switch(aVar) {
|
2009-07-02 09:54:22 -07:00
|
|
|
|
|
|
|
case NPNVSupportsWindowless:
|
2009-10-27 12:58:33 -07:00
|
|
|
#if defined(OS_LINUX) || defined(OS_WIN)
|
2009-09-24 19:03:59 -07:00
|
|
|
*((NPBool*)aValue) = true;
|
|
|
|
#else
|
2009-07-01 14:19:32 -07:00
|
|
|
*((NPBool*)aValue) = false;
|
2009-09-24 19:03:59 -07:00
|
|
|
#endif
|
2009-07-02 09:54:22 -07:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
|
|
|
|
#if defined(OS_LINUX)
|
2009-06-30 11:51:05 -07:00
|
|
|
case NPNVSupportsXEmbedBool:
|
2009-07-01 14:19:32 -07:00
|
|
|
*((NPBool*)aValue) = true;
|
2009-06-30 11:51:05 -07:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
|
|
|
|
case NPNVToolkit:
|
|
|
|
*((NPNToolkitType*)aValue) = NPNVGtk2;
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
#elif defined(OS_WIN)
|
|
|
|
case NPNVToolkit:
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
#endif
|
2009-09-15 13:33:24 -07:00
|
|
|
case NPNVjavascriptEnabledBool: {
|
|
|
|
bool v = false;
|
|
|
|
NPError result;
|
2009-09-19 12:24:24 -07:00
|
|
|
if (!CallNPN_GetValue_NPNVjavascriptEnabledBool(&v, &result)) {
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
2009-09-15 13:33:24 -07:00
|
|
|
*static_cast<NPBool*>(aValue) = v;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NPNVisOfflineBool: {
|
|
|
|
bool v = false;
|
|
|
|
NPError result;
|
2009-09-19 12:24:24 -07:00
|
|
|
if (!CallNPN_GetValue_NPNVisOfflineBool(&v, &result)) {
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
2009-09-15 13:33:24 -07:00
|
|
|
*static_cast<NPBool*>(aValue) = v;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NPNVprivateModeBool: {
|
|
|
|
bool v = false;
|
|
|
|
NPError result;
|
2009-09-19 12:24:24 -07:00
|
|
|
if (!CallNPN_GetValue_NPNVprivateModeBool(&v, &result)) {
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
2009-09-15 13:33:24 -07:00
|
|
|
*static_cast<NPBool*>(aValue) = v;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
case NPNVWindowNPObject: {
|
|
|
|
PPluginScriptableObjectChild* actor;
|
|
|
|
NPError result;
|
|
|
|
if (!CallNPN_GetValue_NPNVWindowNPObject(&actor, &result)) {
|
|
|
|
NS_WARNING("Failed to send message!");
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != NPERR_NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-11-11 17:12:01 -08:00
|
|
|
NS_ASSERTION(actor, "Null actor!");
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
NPObject* object =
|
2010-01-15 12:35:57 -08:00
|
|
|
static_cast<PluginScriptableObjectChild*>(actor)->GetObject(true);
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ASSERTION(object, "Null object?!");
|
|
|
|
|
|
|
|
PluginModuleChild::sBrowserFuncs.retainobject(object);
|
|
|
|
*((NPObject**)aValue) = object;
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NPNVPluginElementNPObject: {
|
|
|
|
PPluginScriptableObjectChild* actor;
|
|
|
|
NPError result;
|
|
|
|
if (!CallNPN_GetValue_NPNVPluginElementNPObject(&actor, &result)) {
|
|
|
|
NS_WARNING("Failed to send message!");
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != NPERR_NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-11-11 17:12:01 -08:00
|
|
|
NS_ASSERTION(actor, "Null actor!");
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
NPObject* object =
|
2010-01-15 12:35:57 -08:00
|
|
|
static_cast<PluginScriptableObjectChild*>(actor)->GetObject(true);
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ASSERTION(object, "Null object?!");
|
|
|
|
|
|
|
|
PluginModuleChild::sBrowserFuncs.retainobject(object);
|
|
|
|
*((NPObject**)aValue) = object;
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-01-13 17:47:38 -08:00
|
|
|
case NPNVnetscapeWindow: {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (mWindow.type == NPWindowTypeDrawable) {
|
|
|
|
HWND hwnd = NULL;
|
|
|
|
NPError result;
|
2010-01-14 07:18:34 -08:00
|
|
|
if (!CallNPN_GetValue_NPNVnetscapeWindow(&hwnd, &result)) {
|
2010-01-13 17:47:38 -08:00
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
*static_cast<HWND*>(aValue) = hwnd;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*static_cast<HWND*>(aValue) = mPluginWindowHWND;
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2010-01-14 07:18:34 -08:00
|
|
|
#elif defined(MOZ_X11)
|
|
|
|
NPError result;
|
|
|
|
CallNPN_GetValue_NPNVnetscapeWindow(static_cast<XID*>(aValue), &result);
|
|
|
|
return result;
|
2010-01-13 17:47:38 -08:00
|
|
|
#else
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-06-30 11:51:05 -07:00
|
|
|
default:
|
2009-12-18 14:22:51 -08:00
|
|
|
PR_LOG(gPluginLog, PR_LOG_WARNING,
|
|
|
|
("In PluginInstanceChild::NPN_GetValue: Unhandled NPNVariable %i (%s)",
|
|
|
|
(int) aVar, NPNVariableToString(aVar)));
|
2009-09-24 19:03:59 -07:00
|
|
|
return NPERR_GENERIC_ERROR;
|
2009-06-30 11:51:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-09-24 19:03:59 -07:00
|
|
|
|
|
|
|
NPError
|
|
|
|
PluginInstanceChild::NPN_SetValue(NPPVariable aVar, void* aValue)
|
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PR_LOG(gPluginLog, PR_LOG_DEBUG, ("%s (aVar=%i, aValue=%p)",
|
|
|
|
FULLFUNCTION, (int) aVar, aValue));
|
|
|
|
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
2009-09-24 19:03:59 -07:00
|
|
|
|
|
|
|
switch (aVar) {
|
|
|
|
case NPPVpluginWindowBool: {
|
|
|
|
NPError rv;
|
|
|
|
bool windowed = (NPBool) (intptr_t) aValue;
|
|
|
|
|
|
|
|
if (!CallNPN_SetValue_NPPVpluginWindow(windowed, &rv))
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NPPVpluginTransparentBool: {
|
|
|
|
NPError rv;
|
|
|
|
bool transparent = (NPBool) (intptr_t) aValue;
|
|
|
|
|
|
|
|
if (!CallNPN_SetValue_NPPVpluginTransparent(transparent, &rv))
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2009-12-18 14:22:51 -08:00
|
|
|
PR_LOG(gPluginLog, PR_LOG_WARNING,
|
|
|
|
("In PluginInstanceChild::NPN_SetValue: Unhandled NPPVariable %i (%s)",
|
|
|
|
(int) aVar, NPPVariableToString(aVar)));
|
2009-09-24 19:03:59 -07:00
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginWindow(
|
|
|
|
bool* windowed, NPError* rv)
|
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
|
|
|
|
2009-09-24 19:03:59 -07:00
|
|
|
NPBool isWindowed;
|
|
|
|
*rv = mPluginIface->getvalue(GetNPP(), NPPVpluginWindowBool,
|
|
|
|
reinterpret_cast<void*>(&isWindowed));
|
|
|
|
*windowed = isWindowed;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginTransparent(
|
|
|
|
bool* transparent, NPError* rv)
|
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
|
|
|
|
2009-09-24 19:03:59 -07:00
|
|
|
NPBool isTransparent;
|
|
|
|
*rv = mPluginIface->getvalue(GetNPP(), NPPVpluginTransparentBool,
|
|
|
|
reinterpret_cast<void*>(&isTransparent));
|
|
|
|
*transparent = isTransparent;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginNeedsXEmbed(
|
|
|
|
bool* needs, NPError* rv)
|
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
|
|
|
|
2009-09-24 19:03:59 -07:00
|
|
|
#ifdef OS_LINUX
|
|
|
|
|
2009-12-16 22:32:44 -08:00
|
|
|
// on x86/32-bit, flash stores to this using |movl 0x1,&needsXEmbed|.
|
|
|
|
// thus we can't NPBool for needsXEmbed, or the three bytes above
|
|
|
|
// it on the stack would get clobbered. so protect with unsigned
|
|
|
|
// long.
|
|
|
|
unsigned long needsXEmbed = 0;
|
2009-09-24 19:03:59 -07:00
|
|
|
*rv = mPluginIface->getvalue(GetNPP(), NPPVpluginNeedsXEmbed,
|
|
|
|
reinterpret_cast<void*>(&needsXEmbed));
|
|
|
|
*needs = needsXEmbed;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
NS_RUNTIMEABORT("shouldn't be called on non-linux platforms");
|
2009-09-24 19:14:41 -07:00
|
|
|
return false; // not reached
|
2009-09-24 19:03:59 -07:00
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2009-09-17 15:15:12 -07:00
|
|
|
PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginScriptableNPObject(
|
2009-11-12 14:16:54 -08:00
|
|
|
PPluginScriptableObjectChild** aValue,
|
|
|
|
NPError* aResult)
|
2009-07-02 09:54:22 -07:00
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
2009-09-17 15:15:12 -07:00
|
|
|
|
|
|
|
NPObject* object;
|
2009-11-12 14:16:54 -08:00
|
|
|
NPError result = mPluginIface->getvalue(GetNPP(),
|
|
|
|
NPPVpluginScriptableNPObject,
|
|
|
|
&object);
|
|
|
|
if (result == NPERR_NO_ERROR && object) {
|
|
|
|
PluginScriptableObjectChild* actor = GetActorForNPObject(object);
|
|
|
|
|
|
|
|
// If we get an actor then it has retained. Otherwise we don't need it
|
|
|
|
// any longer.
|
|
|
|
PluginModuleChild::sBrowserFuncs.releaseobject(object);
|
|
|
|
if (actor) {
|
|
|
|
*aValue = actor;
|
|
|
|
*aResult = NPERR_NO_ERROR;
|
|
|
|
return true;
|
|
|
|
}
|
2009-10-07 16:50:48 -07:00
|
|
|
|
2009-11-12 14:16:54 -08:00
|
|
|
NS_ERROR("Failed to get actor!");
|
|
|
|
result = NPERR_GENERIC_ERROR;
|
2009-09-17 15:15:12 -07:00
|
|
|
}
|
|
|
|
|
2009-11-12 14:16:54 -08:00
|
|
|
*aValue = nsnull;
|
|
|
|
*aResult = result;
|
2009-09-17 16:09:20 -07:00
|
|
|
return true;
|
2009-07-02 09:54:22 -07:00
|
|
|
}
|
|
|
|
|
2010-01-19 19:23:35 -08:00
|
|
|
bool
|
|
|
|
PluginInstanceChild::AnswerNPP_SetValue_NPNVprivateModeBool(const bool& value,
|
|
|
|
NPError* result)
|
|
|
|
{
|
|
|
|
// Use `long` instead of NPBool because Flash and other plugins read
|
|
|
|
// this as a word-size value instead of the 1-byte NPBool that it is.
|
|
|
|
long v = value;
|
|
|
|
*result = mPluginIface->setvalue(GetNPP(), NPNVprivateModeBool, &v);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:19:11 -07:00
|
|
|
bool
|
2009-10-27 12:58:33 -07:00
|
|
|
PluginInstanceChild::AnswerNPP_HandleEvent(const NPRemoteEvent& event,
|
2009-09-18 18:19:11 -07:00
|
|
|
int16_t* handled)
|
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_FUNCTION;
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
2009-09-24 19:03:59 -07:00
|
|
|
|
2009-10-27 14:07:49 -07:00
|
|
|
#if defined(OS_LINUX) && defined(DEBUG)
|
|
|
|
if (GraphicsExpose == event.event.type)
|
2009-09-24 19:03:59 -07:00
|
|
|
printf(" received drawable 0x%lx\n",
|
2009-10-27 14:07:49 -07:00
|
|
|
event.event.xgraphicsexpose.drawable);
|
2009-09-24 19:03:59 -07:00
|
|
|
#endif
|
|
|
|
|
2009-12-01 13:05:26 -08:00
|
|
|
// Make a copy since we may modify values.
|
2009-10-27 12:58:33 -07:00
|
|
|
NPEvent evcopy = event.event;
|
2009-12-01 13:05:26 -08:00
|
|
|
|
|
|
|
#ifdef OS_WIN
|
2009-12-14 16:27:25 -08:00
|
|
|
// Painting for win32. SharedSurfacePaint handles everything.
|
|
|
|
if (mWindow.type == NPWindowTypeDrawable) {
|
|
|
|
if (evcopy.event == WM_PAINT) {
|
|
|
|
*handled = SharedSurfacePaint(evcopy);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (evcopy.event == mAlphaExtract.doublePassEvent) {
|
|
|
|
// We'll render to mSharedSurfaceDib first, then render to a cached bitmap
|
|
|
|
// we store locally. The two passes are for alpha extraction, so the second
|
|
|
|
// pass must be to a flat white surface in order for things to work.
|
|
|
|
mAlphaExtract.doublePass = RENDER_BACK_ONE;
|
|
|
|
*handled = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-12-01 13:05:26 -08:00
|
|
|
#endif
|
|
|
|
|
2009-09-18 18:19:11 -07:00
|
|
|
*handled = mPluginIface->event(&mData, reinterpret_cast<void*>(&evcopy));
|
2009-10-11 16:54:49 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
2009-10-27 13:59:40 -07:00
|
|
|
if (GraphicsExpose == event.event.type) {
|
2009-10-11 16:54:49 -07:00
|
|
|
// Make sure the X server completes the drawing before the parent
|
|
|
|
// draws on top and destroys the Drawable.
|
|
|
|
//
|
|
|
|
// XSync() waits for the X server to complete. Really this child
|
|
|
|
// process does not need to wait; the parent is the process that needs
|
|
|
|
// to wait. A possibly-slightly-better alternative would be to send
|
|
|
|
// an X event to the parent that the parent would wait for.
|
|
|
|
XSync(mWsInfo.display, False);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-18 18:19:11 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-30 14:36:14 -07:00
|
|
|
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
|
|
|
|
static bool
|
|
|
|
XVisualIDToInfo(Display* aDisplay, VisualID aVisualID,
|
|
|
|
Visual** aVisual, unsigned int* aDepth)
|
|
|
|
{
|
|
|
|
if (aVisualID == None) {
|
|
|
|
*aVisual = NULL;
|
|
|
|
*aDepth = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Screen* screen = DefaultScreenOfDisplay(aDisplay);
|
|
|
|
|
|
|
|
for (int d = 0; d < screen->ndepths; d++) {
|
|
|
|
Depth *d_info = &screen->depths[d];
|
|
|
|
for (int v = 0; v < d_info->nvisuals; v++) {
|
|
|
|
Visual* visual = &d_info->visuals[v];
|
|
|
|
if (visual->visualid == aVisualID) {
|
|
|
|
*aVisual = visual;
|
|
|
|
*aDepth = d_info->depth;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ERROR("VisualID not on Screen.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2009-09-30 14:36:14 -07:00
|
|
|
PluginInstanceChild::AnswerNPP_SetWindow(const NPRemoteWindow& aWindow,
|
2009-09-08 23:31:35 -07:00
|
|
|
NPError* rv)
|
2009-06-30 11:51:05 -07:00
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG(("%s (aWindow=<window: 0x%lx, x: %d, y: %d, width: %d, height: %d>)",
|
|
|
|
FULLFUNCTION,
|
|
|
|
aWindow.window,
|
|
|
|
aWindow.x, aWindow.y,
|
|
|
|
aWindow.width, aWindow.height));
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-09-30 14:36:14 -07:00
|
|
|
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
|
|
|
|
// The minimum info is sent over IPC to allow this
|
|
|
|
// code to determine the rest.
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-09-30 14:36:14 -07:00
|
|
|
mWindow.window = reinterpret_cast<void*>(aWindow.window);
|
|
|
|
mWindow.x = aWindow.x;
|
|
|
|
mWindow.y = aWindow.y;
|
|
|
|
mWindow.width = aWindow.width;
|
|
|
|
mWindow.height = aWindow.height;
|
|
|
|
mWindow.clipRect = aWindow.clipRect;
|
|
|
|
mWindow.type = aWindow.type;
|
2009-07-02 09:54:22 -07:00
|
|
|
|
2009-09-30 14:36:14 -07:00
|
|
|
mWsInfo.colormap = aWindow.colormap;
|
|
|
|
if (!XVisualIDToInfo(mWsInfo.display, aWindow.visualID,
|
|
|
|
&mWsInfo.visual, &mWsInfo.depth))
|
|
|
|
return false;
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2010-01-19 13:45:56 -08:00
|
|
|
if (aWindow.type == NPWindowTypeWindow) {
|
|
|
|
if (GdkWindow* socket_window = gdk_window_lookup(aWindow.window)) {
|
|
|
|
// A GdkWindow for the socket already exists. Need to
|
|
|
|
// workaround https://bugzilla.gnome.org/show_bug.cgi?id=607061
|
|
|
|
// See wrap_gtk_plug_embedded in PluginModuleChild.cpp.
|
|
|
|
g_object_set_data(G_OBJECT(socket_window),
|
|
|
|
"moz-existed-before-set-window",
|
|
|
|
GUINT_TO_POINTER(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-01 14:19:32 -07:00
|
|
|
*rv = mPluginIface->setwindow(&mData, &mWindow);
|
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
#elif defined(OS_WIN)
|
2009-12-01 13:05:26 -08:00
|
|
|
switch (aWindow.type) {
|
|
|
|
case NPWindowTypeWindow:
|
|
|
|
{
|
|
|
|
if (!CreatePluginWindow())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ReparentPluginWindow((HWND)aWindow.window);
|
|
|
|
SizePluginWindow(aWindow.width, aWindow.height);
|
|
|
|
|
|
|
|
mWindow.window = (void*)mPluginWindowHWND;
|
|
|
|
mWindow.x = aWindow.x;
|
|
|
|
mWindow.y = aWindow.y;
|
|
|
|
mWindow.width = aWindow.width;
|
|
|
|
mWindow.height = aWindow.height;
|
|
|
|
mWindow.type = aWindow.type;
|
|
|
|
|
|
|
|
*rv = mPluginIface->setwindow(&mData, &mWindow);
|
|
|
|
if (*rv == NPERR_NO_ERROR) {
|
|
|
|
WNDPROC wndProc = reinterpret_cast<WNDPROC>(
|
|
|
|
GetWindowLongPtr(mPluginWindowHWND, GWLP_WNDPROC));
|
|
|
|
if (wndProc != PluginWindowProc) {
|
|
|
|
mPluginWndProc = reinterpret_cast<WNDPROC>(
|
|
|
|
SetWindowLongPtr(mPluginWindowHWND, GWLP_WNDPROC,
|
|
|
|
reinterpret_cast<LONG>(PluginWindowProc)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NPWindowTypeDrawable:
|
|
|
|
return SharedSurfaceSetWindow(aWindow, rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Bad plugin window type.");
|
|
|
|
return false;
|
|
|
|
break;
|
2009-07-01 14:19:32 -07:00
|
|
|
}
|
|
|
|
|
2009-11-10 18:25:10 -08:00
|
|
|
#elif defined(OS_MACOSX)
|
|
|
|
# warning This is only a stub implementation IMPLEMENT ME
|
|
|
|
|
2009-06-30 11:51:05 -07:00
|
|
|
#else
|
|
|
|
# error Implement me for your OS
|
|
|
|
#endif
|
2009-07-02 09:54:22 -07:00
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
return true;
|
2009-06-30 11:51:05 -07:00
|
|
|
}
|
|
|
|
|
2009-07-01 14:19:32 -07:00
|
|
|
bool
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceChild::Initialize()
|
2009-07-01 14:19:32 -07:00
|
|
|
{
|
2009-10-07 16:50:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-01 14:19:32 -07:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
|
|
|
|
static const TCHAR kWindowClassName[] = TEXT("GeckoPluginWindow");
|
2009-09-08 23:31:35 -07:00
|
|
|
static const TCHAR kPluginInstanceChildProperty[] = TEXT("PluginInstanceChildProperty");
|
2009-07-01 14:19:32 -07:00
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceChild::RegisterWindowClass()
|
2009-07-01 14:19:32 -07:00
|
|
|
{
|
|
|
|
static bool alreadyRegistered = false;
|
|
|
|
if (alreadyRegistered)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
alreadyRegistered = true;
|
|
|
|
|
|
|
|
WNDCLASSEX wcex;
|
|
|
|
wcex.cbSize = sizeof(WNDCLASSEX);
|
|
|
|
wcex.style = CS_DBLCLKS;
|
|
|
|
wcex.lpfnWndProc = DummyWindowProc;
|
|
|
|
wcex.cbClsExtra = 0;
|
|
|
|
wcex.cbWndExtra = 0;
|
|
|
|
wcex.hInstance = GetModuleHandle(NULL);
|
|
|
|
wcex.hIcon = 0;
|
|
|
|
wcex.hCursor = 0;
|
2009-07-02 13:48:33 -07:00
|
|
|
wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1);
|
2009-07-01 14:19:32 -07:00
|
|
|
wcex.lpszMenuName = 0;
|
|
|
|
wcex.lpszClassName = kWindowClassName;
|
|
|
|
wcex.hIconSm = 0;
|
|
|
|
|
|
|
|
return RegisterClassEx(&wcex) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceChild::CreatePluginWindow()
|
2009-07-01 14:19:32 -07:00
|
|
|
{
|
2009-12-01 13:05:26 -08:00
|
|
|
// already initialized
|
|
|
|
if (mPluginWindowHWND)
|
|
|
|
return true;
|
|
|
|
|
2009-07-01 14:19:32 -07:00
|
|
|
if (!RegisterWindowClass())
|
|
|
|
return false;
|
|
|
|
|
2009-12-01 13:05:26 -08:00
|
|
|
mPluginWindowHWND =
|
|
|
|
CreateWindowEx(WS_EX_LEFT | WS_EX_LTRREADING |
|
|
|
|
WS_EX_NOPARENTNOTIFY | // XXXbent Get rid of this!
|
|
|
|
WS_EX_RIGHTSCROLLBAR,
|
|
|
|
kWindowClassName, 0,
|
|
|
|
WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0,
|
|
|
|
0, 0, NULL, 0, GetModuleHandle(NULL), 0);
|
|
|
|
if (!mPluginWindowHWND)
|
|
|
|
return false;
|
|
|
|
if (!SetProp(mPluginWindowHWND, kPluginInstanceChildProperty, this))
|
|
|
|
return false;
|
2009-07-01 14:19:32 -07:00
|
|
|
|
2009-12-01 13:05:26 -08:00
|
|
|
// Apparently some plugins require an ASCII WndProc.
|
|
|
|
SetWindowLongPtrA(mPluginWindowHWND, GWLP_WNDPROC,
|
|
|
|
reinterpret_cast<LONG>(DefWindowProcA));
|
2009-07-01 14:19:32 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceChild::DestroyPluginWindow()
|
2009-07-01 14:19:32 -07:00
|
|
|
{
|
|
|
|
if (mPluginWindowHWND) {
|
|
|
|
// Unsubclass the window.
|
|
|
|
WNDPROC wndProc = reinterpret_cast<WNDPROC>(
|
|
|
|
GetWindowLongPtr(mPluginWindowHWND, GWLP_WNDPROC));
|
|
|
|
if (wndProc == PluginWindowProc) {
|
|
|
|
NS_ASSERTION(mPluginWndProc, "Should have old proc here!");
|
|
|
|
SetWindowLongPtr(mPluginWindowHWND, GWLP_WNDPROC,
|
|
|
|
reinterpret_cast<LONG>(mPluginWndProc));
|
|
|
|
mPluginWndProc = 0;
|
|
|
|
}
|
|
|
|
|
2009-09-08 23:31:35 -07:00
|
|
|
RemoveProp(mPluginWindowHWND, kPluginInstanceChildProperty);
|
2009-07-01 14:19:32 -07:00
|
|
|
DestroyWindow(mPluginWindowHWND);
|
|
|
|
mPluginWindowHWND = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceChild::ReparentPluginWindow(HWND hWndParent)
|
2009-07-01 14:19:32 -07:00
|
|
|
{
|
|
|
|
if (hWndParent != mPluginParentHWND && IsWindow(hWndParent)) {
|
2009-11-13 12:20:03 -08:00
|
|
|
// Fix the child window's style to be a child window.
|
2009-07-01 14:19:32 -07:00
|
|
|
LONG style = GetWindowLongPtr(mPluginWindowHWND, GWL_STYLE);
|
|
|
|
style |= WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
|
2009-11-13 12:20:03 -08:00
|
|
|
style &= ~WS_POPUP;
|
2009-07-01 14:19:32 -07:00
|
|
|
SetWindowLongPtr(mPluginWindowHWND, GWL_STYLE, style);
|
2009-11-13 12:20:03 -08:00
|
|
|
|
|
|
|
// Do the reparenting.
|
2009-07-01 14:19:32 -07:00
|
|
|
SetParent(mPluginWindowHWND, hWndParent);
|
2009-11-13 12:20:03 -08:00
|
|
|
|
|
|
|
// Make sure we're visible.
|
2009-07-01 14:19:32 -07:00
|
|
|
ShowWindow(mPluginWindowHWND, SW_SHOWNA);
|
|
|
|
}
|
|
|
|
mPluginParentHWND = hWndParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceChild::SizePluginWindow(int width,
|
|
|
|
int height)
|
2009-07-01 14:19:32 -07:00
|
|
|
{
|
|
|
|
if (mPluginWindowHWND) {
|
|
|
|
SetWindowPos(mPluginWindowHWND, NULL, 0, 0, width, height,
|
|
|
|
SWP_NOZORDER | SWP_NOREPOSITION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See chromium's webplugin_delegate_impl.cc for explanation of this function.
|
|
|
|
// static
|
|
|
|
LRESULT CALLBACK
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceChild::DummyWindowProc(HWND hWnd,
|
|
|
|
UINT message,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
2009-07-01 14:19:32 -07:00
|
|
|
{
|
|
|
|
return CallWindowProc(DefWindowProc, hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
LRESULT CALLBACK
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceChild::PluginWindowProc(HWND hWnd,
|
|
|
|
UINT message,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
2009-07-01 14:19:32 -07:00
|
|
|
{
|
2009-11-06 14:33:12 -08:00
|
|
|
NS_ASSERTION(!mozilla::ipc::SyncChannel::IsPumpingMessages(),
|
|
|
|
"Failed to prevent a nonqueued message from running!");
|
|
|
|
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceChild* self = reinterpret_cast<PluginInstanceChild*>(
|
|
|
|
GetProp(hWnd, kPluginInstanceChildProperty));
|
2009-07-01 14:19:32 -07:00
|
|
|
if (!self) {
|
|
|
|
NS_NOTREACHED("Badness!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(self->mPluginWindowHWND == hWnd, "Wrong window!");
|
|
|
|
|
|
|
|
LRESULT res = CallWindowProc(self->mPluginWndProc, hWnd, message, wParam,
|
|
|
|
lParam);
|
|
|
|
|
|
|
|
if (message == WM_CLOSE)
|
|
|
|
self->DestroyPluginWindow();
|
|
|
|
|
|
|
|
if (message == WM_NCDESTROY)
|
2009-09-08 23:31:35 -07:00
|
|
|
RemoveProp(hWnd, kPluginInstanceChildProperty);
|
2009-07-01 14:19:32 -07:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-12-01 13:05:26 -08:00
|
|
|
/* windowless drawing helpers */
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginInstanceChild::SharedSurfaceSetWindow(const NPRemoteWindow& aWindow,
|
|
|
|
NPError* rv)
|
|
|
|
{
|
|
|
|
// If the surfaceHandle is empty, parent is telling us we can reuse our cached
|
|
|
|
// memory surface and hdc. Otherwise, we need to reset, usually due to a
|
|
|
|
// expanding plugin port size.
|
|
|
|
if (!aWindow.surfaceHandle) {
|
|
|
|
if (!mSharedSurfaceDib.IsValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Attach to the new shared surface parent handed us.
|
|
|
|
if (NS_FAILED(mSharedSurfaceDib.Attach((SharedDIB::Handle)aWindow.surfaceHandle,
|
|
|
|
aWindow.width, aWindow.height, 32)))
|
|
|
|
return false;
|
2009-12-14 16:27:25 -08:00
|
|
|
// Free any alpha extraction resources if needed. This will be reset
|
|
|
|
// the next time it's used.
|
|
|
|
AlphaExtractCacheRelease();
|
2009-12-01 13:05:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// NPRemoteWindow's origin is the origin of our shared dib.
|
|
|
|
mWindow.x = 0;
|
|
|
|
mWindow.y = 0;
|
|
|
|
mWindow.width = aWindow.width;
|
|
|
|
mWindow.height = aWindow.height;
|
|
|
|
mWindow.type = aWindow.type;
|
|
|
|
|
|
|
|
mWindow.window = reinterpret_cast<void*>(mSharedSurfaceDib.GetHDC());
|
|
|
|
*rv = mPluginIface->setwindow(&mData, &mWindow);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginInstanceChild::SharedSurfaceRelease()
|
|
|
|
{
|
|
|
|
mSharedSurfaceDib.Close();
|
2009-12-14 16:27:25 -08:00
|
|
|
AlphaExtractCacheRelease();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* double pass cache buffer - (rarely) used in cases where alpha extraction
|
|
|
|
* occurs for windowless plugins. */
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginInstanceChild::AlphaExtractCacheSetup()
|
|
|
|
{
|
|
|
|
AlphaExtractCacheRelease();
|
|
|
|
|
|
|
|
mAlphaExtract.hdc = ::CreateCompatibleDC(NULL);
|
|
|
|
|
|
|
|
if (!mAlphaExtract.hdc)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
BITMAPINFOHEADER bmih;
|
|
|
|
memset((void*)&bmih, 0, sizeof(BITMAPINFOHEADER));
|
|
|
|
bmih.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
bmih.biWidth = mWindow.width;
|
|
|
|
bmih.biHeight = mWindow.height;
|
|
|
|
bmih.biPlanes = 1;
|
|
|
|
bmih.biBitCount = 32;
|
|
|
|
bmih.biCompression = BI_RGB;
|
|
|
|
|
|
|
|
void* ppvBits = nsnull;
|
|
|
|
mAlphaExtract.bmp = ::CreateDIBSection(mAlphaExtract.hdc,
|
|
|
|
(BITMAPINFO*)&bmih,
|
|
|
|
DIB_RGB_COLORS,
|
|
|
|
(void**)&ppvBits,
|
|
|
|
NULL,
|
|
|
|
(unsigned long)sizeof(BITMAPINFOHEADER));
|
|
|
|
if (!mAlphaExtract.bmp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DeleteObject(::SelectObject(mAlphaExtract.hdc, mAlphaExtract.bmp));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginInstanceChild::AlphaExtractCacheRelease()
|
|
|
|
{
|
|
|
|
if (mAlphaExtract.bmp)
|
|
|
|
::DeleteObject(mAlphaExtract.bmp);
|
|
|
|
|
|
|
|
if (mAlphaExtract.hdc)
|
|
|
|
::DeleteObject(mAlphaExtract.hdc);
|
|
|
|
|
|
|
|
mAlphaExtract.bmp = NULL;
|
|
|
|
mAlphaExtract.hdc = NULL;
|
2009-12-01 13:05:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-14 16:27:25 -08:00
|
|
|
PluginInstanceChild::UpdatePaintClipRect(RECT* aRect)
|
|
|
|
{
|
|
|
|
if (aRect) {
|
|
|
|
// Update the clip rect on our internal hdc
|
|
|
|
HRGN clip = ::CreateRectRgnIndirect(aRect);
|
|
|
|
::SelectClipRgn(mSharedSurfaceDib.GetHDC(), clip);
|
|
|
|
::DeleteObject(clip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t
|
|
|
|
PluginInstanceChild::SharedSurfacePaint(NPEvent& evcopy)
|
2009-12-01 13:05:26 -08:00
|
|
|
{
|
|
|
|
RECT* pRect = reinterpret_cast<RECT*>(evcopy.lParam);
|
2009-12-14 16:27:25 -08:00
|
|
|
|
|
|
|
switch(mAlphaExtract.doublePass) {
|
|
|
|
case RENDER_NATIVE:
|
|
|
|
// pass the internal hdc to the plugin
|
|
|
|
UpdatePaintClipRect(pRect);
|
|
|
|
evcopy.wParam = WPARAM(mSharedSurfaceDib.GetHDC());
|
|
|
|
return mPluginIface->event(&mData, reinterpret_cast<void*>(&evcopy));
|
|
|
|
break;
|
|
|
|
case RENDER_BACK_ONE:
|
|
|
|
// Handle a double pass render used in alpha extraction for transparent
|
|
|
|
// plugins. (See nsObjectFrame and gfxWindowsNativeDrawing for details.)
|
|
|
|
// We render twice, once to the shared dib, and once to a cache which
|
|
|
|
// we copy back on a second paint. These paints can't be spread across
|
|
|
|
// multiple rpc messages as delays cause animation frame changes.
|
|
|
|
if (!mAlphaExtract.bmp && !AlphaExtractCacheSetup()) {
|
|
|
|
mAlphaExtract.doublePass = RENDER_NATIVE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See gfxWindowsNativeDrawing, color order doesn't have to match.
|
|
|
|
::FillRect(mSharedSurfaceDib.GetHDC(), pRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
|
|
|
|
UpdatePaintClipRect(pRect);
|
|
|
|
evcopy.wParam = WPARAM(mSharedSurfaceDib.GetHDC());
|
|
|
|
if (!mPluginIface->event(&mData, reinterpret_cast<void*>(&evcopy))) {
|
|
|
|
mAlphaExtract.doublePass = RENDER_NATIVE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy to cache. We render to shared dib so we don't have to call
|
|
|
|
// setwindow between calls (flash issue).
|
|
|
|
::BitBlt(mAlphaExtract.hdc,
|
|
|
|
pRect->left,
|
|
|
|
pRect->top,
|
|
|
|
pRect->right - pRect->left,
|
|
|
|
pRect->bottom - pRect->top,
|
|
|
|
mSharedSurfaceDib.GetHDC(),
|
|
|
|
pRect->left,
|
|
|
|
pRect->top,
|
|
|
|
SRCCOPY);
|
|
|
|
|
|
|
|
::FillRect(mSharedSurfaceDib.GetHDC(), pRect, (HBRUSH)GetStockObject(BLACK_BRUSH));
|
|
|
|
if (!mPluginIface->event(&mData, reinterpret_cast<void*>(&evcopy))) {
|
|
|
|
mAlphaExtract.doublePass = RENDER_NATIVE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mAlphaExtract.doublePass = RENDER_BACK_TWO;
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
case RENDER_BACK_TWO:
|
|
|
|
// copy our cached surface back
|
|
|
|
::BitBlt(mSharedSurfaceDib.GetHDC(),
|
|
|
|
pRect->left,
|
|
|
|
pRect->top,
|
|
|
|
pRect->right - pRect->left,
|
|
|
|
pRect->bottom - pRect->top,
|
|
|
|
mAlphaExtract.hdc,
|
|
|
|
pRect->left,
|
|
|
|
pRect->top,
|
|
|
|
SRCCOPY);
|
|
|
|
mAlphaExtract.doublePass = RENDER_NATIVE;
|
|
|
|
return true;
|
|
|
|
break;
|
2009-12-01 13:05:26 -08:00
|
|
|
}
|
2009-12-14 16:27:25 -08:00
|
|
|
return false;
|
2009-12-01 13:05:26 -08:00
|
|
|
}
|
|
|
|
|
2009-07-01 14:19:32 -07:00
|
|
|
#endif // OS_WIN
|
|
|
|
|
2009-09-09 15:59:06 -07:00
|
|
|
PPluginScriptableObjectChild*
|
2009-09-22 10:31:11 -07:00
|
|
|
PluginInstanceChild::AllocPPluginScriptableObject()
|
2009-08-10 16:28:22 -07:00
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
2010-01-15 12:35:57 -08:00
|
|
|
return new PluginScriptableObjectChild(Proxy);
|
2009-08-10 16:28:22 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginInstanceChild::DeallocPPluginScriptableObject(
|
2009-12-03 00:16:14 -08:00
|
|
|
PPluginScriptableObjectChild* aObject)
|
2009-08-10 16:28:22 -07:00
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
|
|
|
|
2010-01-15 12:35:57 -08:00
|
|
|
PluginScriptableObjectChild* actor =
|
2009-09-17 15:15:12 -07:00
|
|
|
reinterpret_cast<PluginScriptableObjectChild*>(aObject);
|
|
|
|
|
2010-01-15 12:35:57 -08:00
|
|
|
NPObject* object = actor->GetObject(false);
|
|
|
|
if (object) {
|
|
|
|
PluginModuleChild::current()->UnregisterNPObject(object);
|
2009-10-07 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
2010-01-15 12:35:57 -08:00
|
|
|
delete actor;
|
|
|
|
return true;
|
2009-08-10 16:28:22 -07:00
|
|
|
}
|
2009-08-18 13:20:03 -07:00
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
bool
|
|
|
|
PluginInstanceChild::AnswerPPluginScriptableObjectConstructor(
|
|
|
|
PPluginScriptableObjectChild* aActor)
|
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
// This is only called in response to the parent process requesting the
|
|
|
|
// creation of an actor. This actor will represent an NPObject that is
|
|
|
|
// created by the browser and returned to the plugin.
|
|
|
|
PluginScriptableObjectChild* actor =
|
|
|
|
static_cast<PluginScriptableObjectChild*>(aActor);
|
2010-01-15 12:35:57 -08:00
|
|
|
NS_ASSERTION(!actor->GetObject(false), "Actor already has an object?!");
|
|
|
|
|
|
|
|
actor->InitializeProxy();
|
|
|
|
NS_ASSERTION(actor->GetObject(false), "Actor should have an object!");
|
2009-10-07 16:50:48 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-12 15:06:18 -08:00
|
|
|
bool
|
|
|
|
PluginInstanceChild::AnswerPBrowserStreamConstructor(
|
|
|
|
PBrowserStreamChild* aActor,
|
|
|
|
const nsCString& url,
|
|
|
|
const uint32_t& length,
|
|
|
|
const uint32_t& lastmodified,
|
|
|
|
PStreamNotifyChild* notifyData,
|
|
|
|
const nsCString& headers,
|
|
|
|
const nsCString& mimeType,
|
|
|
|
const bool& seekable,
|
|
|
|
NPError* rv,
|
|
|
|
uint16_t* stype)
|
|
|
|
{
|
|
|
|
AssertPluginThread();
|
|
|
|
*rv = static_cast<BrowserStreamChild*>(aActor)
|
|
|
|
->StreamConstructed(url, length, lastmodified,
|
|
|
|
notifyData, headers, mimeType, seekable,
|
|
|
|
stype);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-09 15:59:06 -07:00
|
|
|
PBrowserStreamChild*
|
2009-09-22 10:31:11 -07:00
|
|
|
PluginInstanceChild::AllocPBrowserStream(const nsCString& url,
|
|
|
|
const uint32_t& length,
|
|
|
|
const uint32_t& lastmodified,
|
2009-10-16 16:31:53 -07:00
|
|
|
PStreamNotifyChild* notifyData,
|
2009-09-22 10:31:11 -07:00
|
|
|
const nsCString& headers,
|
|
|
|
const nsCString& mimeType,
|
|
|
|
const bool& seekable,
|
|
|
|
NPError* rv,
|
|
|
|
uint16_t *stype)
|
2009-08-18 13:20:03 -07:00
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
2009-09-23 16:00:23 -07:00
|
|
|
return new BrowserStreamChild(this, url, length, lastmodified, notifyData,
|
|
|
|
headers, mimeType, seekable, rv, stype);
|
2009-08-18 13:20:03 -07:00
|
|
|
}
|
|
|
|
|
2009-09-21 07:51:35 -07:00
|
|
|
bool
|
2009-12-03 00:16:14 -08:00
|
|
|
PluginInstanceChild::DeallocPBrowserStream(PBrowserStreamChild* stream)
|
2009-08-18 13:20:03 -07:00
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
2009-08-18 13:20:03 -07:00
|
|
|
delete stream;
|
2009-09-17 16:09:20 -07:00
|
|
|
return true;
|
2009-08-18 13:20:03 -07:00
|
|
|
}
|
|
|
|
|
2009-09-21 07:51:35 -07:00
|
|
|
PPluginStreamChild*
|
2009-09-22 10:31:11 -07:00
|
|
|
PluginInstanceChild::AllocPPluginStream(const nsCString& mimeType,
|
|
|
|
const nsCString& target,
|
|
|
|
NPError* result)
|
2009-09-21 07:51:35 -07:00
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("not callable");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-12-03 00:16:14 -08:00
|
|
|
PluginInstanceChild::DeallocPPluginStream(PPluginStreamChild* stream)
|
2009-09-21 07:51:35 -07:00
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
2009-09-21 07:51:35 -07:00
|
|
|
delete stream;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-08 14:22:50 -07:00
|
|
|
PStreamNotifyChild*
|
2009-09-22 10:31:11 -07:00
|
|
|
PluginInstanceChild::AllocPStreamNotify(const nsCString& url,
|
|
|
|
const nsCString& target,
|
|
|
|
const bool& post,
|
|
|
|
const nsCString& buffer,
|
|
|
|
const bool& file,
|
|
|
|
NPError* result)
|
2009-09-08 14:22:50 -07:00
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
2009-09-08 14:22:50 -07:00
|
|
|
NS_RUNTIMEABORT("not reached");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2009-12-03 00:16:14 -08:00
|
|
|
StreamNotifyChild::Answer__delete__(const NPReason& reason)
|
2009-09-08 14:22:50 -07:00
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
2009-12-03 00:16:14 -08:00
|
|
|
return static_cast<PluginInstanceChild*>(Manager())
|
|
|
|
->NotifyStream(this, reason);
|
|
|
|
}
|
2009-10-08 12:11:13 -07:00
|
|
|
|
2009-12-03 00:16:14 -08:00
|
|
|
bool
|
|
|
|
PluginInstanceChild::NotifyStream(StreamNotifyChild* notifyData,
|
|
|
|
NPReason reason)
|
|
|
|
{
|
|
|
|
if (notifyData->mClosure)
|
|
|
|
mPluginIface->urlnotify(&mData, notifyData->mURL.get(), reason,
|
|
|
|
notifyData->mClosure);
|
2009-11-25 06:26:01 -08:00
|
|
|
return true;
|
|
|
|
}
|
2009-09-08 14:22:50 -07:00
|
|
|
|
2009-11-25 06:26:01 -08:00
|
|
|
bool
|
2009-12-03 00:16:14 -08:00
|
|
|
PluginInstanceChild::DeallocPStreamNotify(PStreamNotifyChild* notifyData)
|
2009-11-25 06:26:01 -08:00
|
|
|
{
|
2009-12-03 00:16:14 -08:00
|
|
|
AssertPluginThread();
|
2009-11-25 06:26:01 -08:00
|
|
|
delete notifyData;
|
2009-09-17 16:09:20 -07:00
|
|
|
return true;
|
2009-09-08 14:22:50 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 15:15:12 -07:00
|
|
|
PluginScriptableObjectChild*
|
2009-09-23 00:12:52 -07:00
|
|
|
PluginInstanceChild::GetActorForNPObject(NPObject* aObject)
|
2009-09-17 15:15:12 -07:00
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
2010-01-15 12:35:57 -08:00
|
|
|
NS_ASSERTION(aObject, "Null pointer!");
|
|
|
|
|
|
|
|
if (aObject->_class == PluginScriptableObjectChild::GetClass()) {
|
|
|
|
// One of ours! It's a browser-provided object.
|
|
|
|
ChildNPObject* object = static_cast<ChildNPObject*>(aObject);
|
|
|
|
NS_ASSERTION(object->parent, "Null actor!");
|
|
|
|
return object->parent;
|
|
|
|
}
|
2010-01-15 12:35:57 -08:00
|
|
|
|
2010-01-15 12:35:57 -08:00
|
|
|
PluginScriptableObjectChild* actor =
|
|
|
|
PluginModuleChild::current()->GetActorForNPObject(aObject);
|
|
|
|
if (actor) {
|
|
|
|
// Plugin-provided object that we've previously wrapped.
|
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
actor = new PluginScriptableObjectChild(LocalObject);
|
|
|
|
if (!CallPPluginScriptableObjectConstructor(actor)) {
|
|
|
|
NS_ERROR("Failed to send constructor message!");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
actor->InitializeLocal(aObject);
|
|
|
|
return actor;
|
2009-09-17 15:15:12 -07:00
|
|
|
}
|
2009-09-21 07:51:35 -07:00
|
|
|
|
|
|
|
NPError
|
|
|
|
PluginInstanceChild::NPN_NewStream(NPMIMEType aMIMEType, const char* aWindow,
|
|
|
|
NPStream** aStream)
|
|
|
|
{
|
2009-10-08 12:11:13 -07:00
|
|
|
AssertPluginThread();
|
|
|
|
|
2009-12-03 00:16:14 -08:00
|
|
|
PluginStreamChild* ps = new PluginStreamChild();
|
2009-09-21 07:51:35 -07:00
|
|
|
|
|
|
|
NPError result;
|
|
|
|
CallPPluginStreamConstructor(ps, nsDependentCString(aMIMEType),
|
2009-09-22 14:06:00 -07:00
|
|
|
NullableString(aWindow), &result);
|
2009-09-21 07:51:35 -07:00
|
|
|
if (NPERR_NO_ERROR != result) {
|
|
|
|
*aStream = NULL;
|
2009-12-03 00:16:14 -08:00
|
|
|
PPluginStreamChild::Call__delete__(ps, NPERR_GENERIC_ERROR, true);
|
2009-09-21 07:51:35 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aStream = &ps->mStream;
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2009-11-13 12:20:03 -08:00
|
|
|
|
2010-01-04 13:46:34 -08:00
|
|
|
void
|
|
|
|
PluginInstanceChild::InvalidateRect(NPRect* aInvalidRect)
|
2009-11-13 12:20:03 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aInvalidRect, "Null pointer!");
|
|
|
|
|
|
|
|
#ifdef OS_WIN
|
2009-12-01 13:05:26 -08:00
|
|
|
// Invalidate and draw locally for windowed plugins.
|
|
|
|
if (mWindow.type == NPWindowTypeWindow) {
|
|
|
|
NS_ASSERTION(IsWindow(mPluginWindowHWND), "Bad window?!");
|
|
|
|
RECT rect = { aInvalidRect->left, aInvalidRect->top,
|
|
|
|
aInvalidRect->right, aInvalidRect->bottom };
|
2010-01-04 14:41:34 -08:00
|
|
|
::InvalidateRect(mPluginWindowHWND, &rect, FALSE);
|
2010-01-04 13:46:34 -08:00
|
|
|
return;
|
2009-12-01 13:05:26 -08:00
|
|
|
}
|
2009-11-13 12:20:03 -08:00
|
|
|
#endif
|
2009-11-13 13:19:33 -08:00
|
|
|
|
2010-01-04 13:46:34 -08:00
|
|
|
SendNPN_InvalidateRect(*aInvalidRect);
|
2009-11-13 12:20:03 -08:00
|
|
|
}
|
2010-01-15 12:35:57 -08:00
|
|
|
|
2010-01-19 19:13:24 -08:00
|
|
|
uint32_t
|
|
|
|
PluginInstanceChild::ScheduleTimer(uint32_t interval, bool repeat,
|
|
|
|
TimerFunc func)
|
|
|
|
{
|
|
|
|
ChildTimer* t = new ChildTimer(this, interval, repeat, func);
|
|
|
|
if (0 == t->ID()) {
|
|
|
|
delete t;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimers.AppendElement(t);
|
|
|
|
return t->ID();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginInstanceChild::UnscheduleTimer(uint32_t id)
|
|
|
|
{
|
|
|
|
if (0 == id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PRUint32 i = mTimers.IndexOf(id, 0, ChildTimer::IDComparator());
|
|
|
|
if (nsTArray<ChildTimer*>::NoIndex == i)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mTimers.ElementAt(i)->Destroy();
|
|
|
|
mTimers.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
|
2010-01-15 12:35:57 -08:00
|
|
|
bool
|
|
|
|
PluginInstanceChild::AnswerNPP_Destroy(NPError* aResult)
|
|
|
|
{
|
2010-01-19 19:13:24 -08:00
|
|
|
for (PRUint32 i = 0; i < mPendingAsyncCalls.Length(); ++i)
|
|
|
|
mPendingAsyncCalls[i]->Cancel();
|
|
|
|
mPendingAsyncCalls.TruncateLength(0);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < mTimers.Length(); ++i)
|
|
|
|
mTimers[i]->Destroy();
|
|
|
|
mTimers.TruncateLength(0);
|
|
|
|
|
2010-01-15 12:35:57 -08:00
|
|
|
PluginModuleChild* module = PluginModuleChild::current();
|
|
|
|
bool retval = module->PluginInstanceDestroyed(this, aResult);
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
SharedSurfaceRelease();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|