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):
|
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
2010-03-10 23:35:29 -08:00
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
|
|
|
#include <glib.h>
|
2010-07-29 15:38:32 -07:00
|
|
|
#elif XP_MACOSX
|
|
|
|
#include "PluginUtilsOSX.h"
|
2010-08-13 09:45:50 -07:00
|
|
|
#include "PluginInterposeOSX.h"
|
2010-03-10 23:35:29 -08:00
|
|
|
#endif
|
2010-06-01 20:58:00 -07:00
|
|
|
#ifdef MOZ_WIDGET_QT
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
#include <QtCore/QEventLoop>
|
|
|
|
#endif
|
2010-03-10 23:35:29 -08:00
|
|
|
|
2010-02-11 12:32:18 -08:00
|
|
|
#include "base/process_util.h"
|
|
|
|
|
2010-04-26 22:43:03 -07:00
|
|
|
#include "mozilla/unused.h"
|
2010-02-11 12:32:18 -08:00
|
|
|
#include "mozilla/ipc/SyncChannel.h"
|
2009-09-08 23:31:35 -07:00
|
|
|
#include "mozilla/plugins/PluginModuleParent.h"
|
2009-09-09 07:04:09 -07:00
|
|
|
#include "mozilla/plugins/BrowserStreamParent.h"
|
2010-03-23 07:30:51 -07:00
|
|
|
#include "PluginIdentifierParent.h"
|
2009-07-02 09:54:22 -07:00
|
|
|
|
2010-08-10 14:14:10 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2010-02-11 12:32:18 -08:00
|
|
|
#include "nsContentUtils.h"
|
2010-01-13 17:20:00 -08:00
|
|
|
#include "nsCRT.h"
|
2010-03-24 14:22:03 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsExceptionHandler.h"
|
|
|
|
#endif
|
2009-09-14 13:01:31 -07:00
|
|
|
#include "nsNPAPIPlugin.h"
|
|
|
|
|
2010-02-11 12:32:18 -08:00
|
|
|
using base::KillProcess;
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2010-02-11 12:32:18 -08:00
|
|
|
using mozilla::PluginLibrary;
|
|
|
|
using mozilla::ipc::SyncChannel;
|
2009-09-14 13:01:31 -07:00
|
|
|
|
|
|
|
using namespace mozilla::plugins;
|
|
|
|
|
2010-02-11 12:32:18 -08:00
|
|
|
static const char kTimeoutPref[] = "dom.ipc.plugins.timeoutSecs";
|
2010-08-10 14:14:10 -07:00
|
|
|
static const char kLaunchTimeoutPref[] = "dom.ipc.plugins.processLaunchTimeoutSecs";
|
2010-02-11 12:32:18 -08:00
|
|
|
|
|
|
|
template<>
|
|
|
|
struct RunnableMethodTraits<mozilla::plugins::PluginModuleParent>
|
|
|
|
{
|
|
|
|
typedef mozilla::plugins::PluginModuleParent Class;
|
|
|
|
static void RetainCallee(Class* obj) { }
|
|
|
|
static void ReleaseCallee(Class* obj) { }
|
|
|
|
};
|
|
|
|
|
2009-11-09 14:56:55 -08:00
|
|
|
// static
|
2009-10-27 12:51:12 -07:00
|
|
|
PluginLibrary*
|
|
|
|
PluginModuleParent::LoadModule(const char* aFilePath)
|
2009-06-30 11:51:05 -07:00
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_FUNCTION;
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2010-08-10 14:14:10 -07:00
|
|
|
PRInt32 prefSecs = nsContentUtils::GetIntPref(kLaunchTimeoutPref, 0);
|
|
|
|
|
2009-06-30 11:51:05 -07:00
|
|
|
// Block on the child process being launched and initialized.
|
2010-08-10 14:14:10 -07:00
|
|
|
nsAutoPtr<PluginModuleParent> parent(new PluginModuleParent(aFilePath));
|
|
|
|
bool launched = parent->mSubprocess->Launch(prefSecs * 1000);
|
|
|
|
if (!launched) {
|
|
|
|
// Need to set this so the destructor doesn't complain.
|
|
|
|
parent->mShutdown = true;
|
|
|
|
return nsnull;
|
|
|
|
}
|
2009-11-09 14:56:55 -08:00
|
|
|
parent->Open(parent->mSubprocess->GetChannel(),
|
|
|
|
parent->mSubprocess->GetChildProcessHandle());
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2010-02-11 12:32:18 -08:00
|
|
|
TimeoutChanged(kTimeoutPref, parent);
|
2010-08-10 14:14:10 -07:00
|
|
|
return parent.forget();
|
2009-06-30 11:51:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-09 14:56:55 -08:00
|
|
|
PluginModuleParent::PluginModuleParent(const char* aFilePath)
|
2009-12-03 12:31:52 -08:00
|
|
|
: mSubprocess(new PluginProcessParent(aFilePath))
|
2010-03-30 17:24:47 -07:00
|
|
|
, mPluginThread(0)
|
2009-12-03 12:31:52 -08:00
|
|
|
, mShutdown(false)
|
|
|
|
, mNPNIface(NULL)
|
2009-12-16 12:08:45 -08:00
|
|
|
, mPlugin(NULL)
|
2010-01-13 17:20:00 -08:00
|
|
|
, mProcessStartTime(time(NULL))
|
2010-03-24 14:22:03 -07:00
|
|
|
, mTaskFactory(this)
|
2009-06-30 11:51:05 -07:00
|
|
|
{
|
2009-11-09 14:56:55 -08:00
|
|
|
NS_ASSERTION(mSubprocess, "Out of memory!");
|
|
|
|
|
2010-03-23 07:30:51 -07:00
|
|
|
if (!mIdentifiers.Init()) {
|
2009-12-03 12:31:52 -08:00
|
|
|
NS_ERROR("Out of memory");
|
|
|
|
}
|
2010-02-11 12:32:18 -08:00
|
|
|
|
|
|
|
nsContentUtils::RegisterPrefCallback(kTimeoutPref, TimeoutChanged, this);
|
2009-06-30 11:51:05 -07:00
|
|
|
}
|
|
|
|
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginModuleParent::~PluginModuleParent()
|
2009-06-30 11:51:05 -07:00
|
|
|
{
|
2010-03-07 12:16:02 -08:00
|
|
|
NS_ASSERTION(OkToCleanup(), "unsafe destruction");
|
|
|
|
|
2010-11-01 06:47:23 -07:00
|
|
|
#ifdef OS_MACOSX
|
|
|
|
if (mCATimer) {
|
|
|
|
mCATimer->Cancel();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-12-03 12:31:52 -08:00
|
|
|
if (!mShutdown) {
|
|
|
|
NS_WARNING("Plugin host deleted the module without shutting down.");
|
|
|
|
NPError err;
|
|
|
|
NP_Shutdown(&err);
|
|
|
|
}
|
|
|
|
NS_ASSERTION(mShutdown, "NP_Shutdown didn't");
|
|
|
|
|
2009-11-09 14:56:55 -08:00
|
|
|
if (mSubprocess) {
|
|
|
|
mSubprocess->Delete();
|
|
|
|
mSubprocess = nsnull;
|
|
|
|
}
|
2010-02-11 12:32:18 -08:00
|
|
|
|
|
|
|
nsContentUtils::UnregisterPrefCallback(kTimeoutPref, TimeoutChanged, this);
|
2009-06-30 11:51:05 -07:00
|
|
|
}
|
|
|
|
|
2010-03-24 14:22:03 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2010-01-13 17:20:00 -08:00
|
|
|
void
|
2010-03-24 14:22:03 -07:00
|
|
|
PluginModuleParent::WritePluginExtraDataForMinidump(const nsAString& id)
|
2010-01-13 17:20:00 -08:00
|
|
|
{
|
2010-03-24 14:22:03 -07:00
|
|
|
typedef nsDependentCString CS;
|
2010-01-13 17:20:00 -08:00
|
|
|
|
2010-03-24 14:22:03 -07:00
|
|
|
CrashReporter::AnnotationTable notes;
|
|
|
|
if (!notes.Init(32))
|
2010-01-13 17:20:00 -08:00
|
|
|
return;
|
|
|
|
|
2010-03-24 14:22:03 -07:00
|
|
|
notes.Put(CS("ProcessType"), CS("plugin"));
|
2010-01-13 17:20:00 -08:00
|
|
|
|
|
|
|
char startTime[32];
|
|
|
|
sprintf(startTime, "%lld", static_cast<PRInt64>(mProcessStartTime));
|
2010-03-24 14:22:03 -07:00
|
|
|
notes.Put(CS("StartupTime"), CS(startTime));
|
2010-01-13 17:20:00 -08:00
|
|
|
|
|
|
|
// Get the plugin filename, try to get just the file leafname
|
|
|
|
const std::string& pluginFile = mSubprocess->GetPluginFilePath();
|
|
|
|
size_t filePos = pluginFile.rfind(FILE_PATH_SEPARATOR);
|
|
|
|
if (filePos == std::string::npos)
|
|
|
|
filePos = 0;
|
|
|
|
else
|
|
|
|
filePos++;
|
2010-03-24 14:22:03 -07:00
|
|
|
notes.Put(CS("PluginFilename"), CS(pluginFile.substr(filePos).c_str()));
|
|
|
|
|
2010-01-13 17:20:00 -08:00
|
|
|
//TODO: add plugin name and version: bug 539841
|
|
|
|
// (as PluginName, PluginVersion)
|
2010-03-24 14:22:03 -07:00
|
|
|
notes.Put(CS("PluginName"), CS(""));
|
|
|
|
notes.Put(CS("PluginVersion"), CS(""));
|
2010-02-24 14:25:16 -08:00
|
|
|
|
2010-03-24 14:22:03 -07:00
|
|
|
if (!mCrashNotes.IsEmpty())
|
|
|
|
notes.Put(CS("Notes"), CS(mCrashNotes.get()));
|
2010-02-24 14:25:16 -08:00
|
|
|
|
2010-03-24 14:22:03 -07:00
|
|
|
if (!mHangID.IsEmpty())
|
|
|
|
notes.Put(CS("HangID"), NS_ConvertUTF16toUTF8(mHangID));
|
|
|
|
|
|
|
|
if (!CrashReporter::AppendExtraData(id, notes))
|
|
|
|
NS_WARNING("problem appending plugin data to .extra");
|
2010-01-13 17:20:00 -08:00
|
|
|
}
|
|
|
|
|
2010-03-24 14:22:03 -07:00
|
|
|
void
|
|
|
|
PluginModuleParent::WriteExtraDataForHang()
|
|
|
|
{
|
|
|
|
// this writes HangID
|
|
|
|
WritePluginExtraDataForMinidump(mPluginDumpID);
|
|
|
|
|
|
|
|
CrashReporter::AnnotationTable notes;
|
|
|
|
if (!notes.Init(4))
|
|
|
|
return;
|
|
|
|
|
|
|
|
notes.Put(nsDependentCString("HangID"), NS_ConvertUTF16toUTF8(mHangID));
|
|
|
|
if (!CrashReporter::AppendExtraData(mBrowserDumpID, notes))
|
|
|
|
NS_WARNING("problem appending browser data to .extra");
|
|
|
|
}
|
|
|
|
#endif // MOZ_CRASHREPORTER
|
2010-02-24 14:25:16 -08:00
|
|
|
|
|
|
|
bool
|
|
|
|
PluginModuleParent::RecvAppendNotesToCrashReport(const nsCString& aNotes)
|
|
|
|
{
|
|
|
|
mCrashNotes.Append(aNotes);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-11 12:32:18 -08:00
|
|
|
int
|
|
|
|
PluginModuleParent::TimeoutChanged(const char* aPref, void* aModule)
|
|
|
|
{
|
2010-03-24 12:30:45 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thead!");
|
2010-02-11 12:32:18 -08:00
|
|
|
NS_ABORT_IF_FALSE(!strcmp(aPref, kTimeoutPref),
|
|
|
|
"unexpected pref callback");
|
|
|
|
|
|
|
|
PRInt32 timeoutSecs = nsContentUtils::GetIntPref(kTimeoutPref, 0);
|
|
|
|
int32 timeoutMs = (timeoutSecs > 0) ? (1000 * timeoutSecs) :
|
|
|
|
SyncChannel::kNoTimeout;
|
|
|
|
|
|
|
|
static_cast<PluginModuleParent*>(aModule)->SetReplyTimeoutMs(timeoutMs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginModuleParent::CleanupFromTimeout()
|
|
|
|
{
|
|
|
|
if (!mShutdown)
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginModuleParent::ShouldContinueFromReplyTimeout()
|
|
|
|
{
|
2010-03-24 14:22:03 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
nsCOMPtr<nsILocalFile> pluginDump;
|
|
|
|
nsCOMPtr<nsILocalFile> browserDump;
|
2010-08-27 06:32:45 -07:00
|
|
|
CrashReporter::ProcessHandle child;
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
child = mSubprocess->GetChildTask();
|
|
|
|
#else
|
|
|
|
child = OtherProcess();
|
|
|
|
#endif
|
|
|
|
if (CrashReporter::CreatePairedMinidumps(child,
|
2010-03-30 17:24:47 -07:00
|
|
|
mPluginThread,
|
2010-03-24 14:22:03 -07:00
|
|
|
&mHangID,
|
|
|
|
getter_AddRefs(pluginDump),
|
|
|
|
getter_AddRefs(browserDump)) &&
|
|
|
|
CrashReporter::GetIDFromMinidump(pluginDump, mPluginDumpID) &&
|
|
|
|
CrashReporter::GetIDFromMinidump(browserDump, mBrowserDumpID)) {
|
|
|
|
|
|
|
|
PLUGIN_LOG_DEBUG(
|
|
|
|
("generated paired browser/plugin minidumps: %s/%s (ID=%s)",
|
|
|
|
NS_ConvertUTF16toUTF8(mBrowserDumpID).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(mPluginDumpID).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(mHangID).get()));
|
2010-02-11 12:32:18 -08:00
|
|
|
}
|
2010-03-24 14:22:03 -07:00
|
|
|
else {
|
|
|
|
NS_WARNING("failed to capture paired minidumps from hang");
|
|
|
|
}
|
|
|
|
#endif
|
2010-02-11 12:32:18 -08:00
|
|
|
|
2010-03-24 14:22:03 -07:00
|
|
|
// this must run before the error notification from the channel,
|
|
|
|
// or not at all
|
|
|
|
MessageLoop::current()->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
mTaskFactory.NewRunnableMethod(
|
|
|
|
&PluginModuleParent::CleanupFromTimeout));
|
|
|
|
|
|
|
|
if (!KillProcess(OtherProcess(), 1, false))
|
|
|
|
NS_WARNING("failed to kill subprocess!");
|
|
|
|
|
|
|
|
return false;
|
2010-02-11 12:32:18 -08:00
|
|
|
}
|
|
|
|
|
2009-12-03 12:31:52 -08:00
|
|
|
void
|
|
|
|
PluginModuleParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
switch (why) {
|
2010-01-13 17:20:00 -08:00
|
|
|
case AbnormalShutdown: {
|
2010-03-24 14:22:03 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
nsCOMPtr<nsILocalFile> pluginDump;
|
|
|
|
if (TakeMinidump(getter_AddRefs(pluginDump)) &&
|
|
|
|
CrashReporter::GetIDFromMinidump(pluginDump, mPluginDumpID)) {
|
|
|
|
PLUGIN_LOG_DEBUG(("got child minidump: %s",
|
|
|
|
NS_ConvertUTF16toUTF8(mPluginDumpID).get()));
|
|
|
|
WritePluginExtraDataForMinidump(mPluginDumpID);
|
|
|
|
}
|
|
|
|
else if (!mPluginDumpID.IsEmpty() && !mBrowserDumpID.IsEmpty()) {
|
|
|
|
WriteExtraDataForHang();
|
2010-01-13 17:20:00 -08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_WARNING("[PluginModuleParent::ActorDestroy] abnormal shutdown without minidump!");
|
|
|
|
}
|
2010-03-24 14:22:03 -07:00
|
|
|
#endif
|
2010-01-13 17:20:00 -08:00
|
|
|
|
2009-12-16 12:08:45 -08:00
|
|
|
mShutdown = true;
|
|
|
|
// Defer the PluginCrashed method so that we don't re-enter
|
|
|
|
// and potentially modify the actor child list while enumerating it.
|
2010-03-24 14:22:03 -07:00
|
|
|
if (mPlugin)
|
|
|
|
MessageLoop::current()->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
mTaskFactory.NewRunnableMethod(
|
|
|
|
&PluginModuleParent::NotifyPluginCrashed));
|
2009-12-16 12:08:45 -08:00
|
|
|
break;
|
2010-01-13 17:20:00 -08:00
|
|
|
}
|
2009-12-03 12:31:52 -08:00
|
|
|
case NormalShutdown:
|
|
|
|
mShutdown = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unexpected shutdown reason for toplevel actor.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-07 12:16:02 -08:00
|
|
|
void
|
|
|
|
PluginModuleParent::NotifyPluginCrashed()
|
|
|
|
{
|
2010-03-18 15:52:35 -07:00
|
|
|
if (!OkToCleanup()) {
|
|
|
|
// there's still plugin code on the C++ stack. try again
|
|
|
|
MessageLoop::current()->PostDelayedTask(
|
2010-03-24 14:22:03 -07:00
|
|
|
FROM_HERE,
|
|
|
|
mTaskFactory.NewRunnableMethod(
|
|
|
|
&PluginModuleParent::NotifyPluginCrashed), 10);
|
2010-03-18 15:52:35 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-07 12:16:02 -08:00
|
|
|
if (mPlugin)
|
2010-03-24 14:22:04 -07:00
|
|
|
mPlugin->PluginCrashed(mPluginDumpID, mBrowserDumpID);
|
2010-03-07 12:16:02 -08:00
|
|
|
}
|
|
|
|
|
2010-03-23 07:30:51 -07:00
|
|
|
PPluginIdentifierParent*
|
|
|
|
PluginModuleParent::AllocPPluginIdentifier(const nsCString& aString,
|
|
|
|
const int32_t& aInt)
|
|
|
|
{
|
|
|
|
NPIdentifier npident = aString.IsVoid() ?
|
|
|
|
mozilla::plugins::parent::_getintidentifier(aInt) :
|
|
|
|
mozilla::plugins::parent::_getstringidentifier(aString.get());
|
|
|
|
|
|
|
|
if (!npident) {
|
|
|
|
NS_WARNING("Failed to get identifier!");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginIdentifierParent* ident = new PluginIdentifierParent(npident);
|
|
|
|
mIdentifiers.Put(npident, ident);
|
|
|
|
return ident;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginModuleParent::DeallocPPluginIdentifier(PPluginIdentifierParent* aActor)
|
|
|
|
{
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-09 15:59:06 -07:00
|
|
|
PPluginInstanceParent*
|
2009-09-22 10:31:11 -07:00
|
|
|
PluginModuleParent::AllocPPluginInstance(const nsCString& aMimeType,
|
|
|
|
const uint16_t& aMode,
|
2010-11-08 18:49:00 -08:00
|
|
|
const InfallibleTArray<nsCString>& aNames,
|
|
|
|
const InfallibleTArray<nsCString>& aValues,
|
2009-09-22 10:31:11 -07:00
|
|
|
NPError* rv)
|
2009-07-02 09:54:22 -07:00
|
|
|
{
|
2009-08-18 13:20:03 -07:00
|
|
|
NS_ERROR("Not reachable!");
|
|
|
|
return NULL;
|
2009-07-02 09:54:22 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2009-12-03 00:16:14 -08:00
|
|
|
PluginModuleParent::DeallocPPluginInstance(PPluginInstanceParent* aActor)
|
2009-07-02 09:54:22 -07:00
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_METHOD;
|
2009-09-08 23:31:35 -07:00
|
|
|
delete aActor;
|
2009-09-17 16:09:20 -07:00
|
|
|
return true;
|
2009-07-02 09:54:22 -07:00
|
|
|
}
|
|
|
|
|
2009-06-30 11:51:05 -07:00
|
|
|
void
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginModuleParent::SetPluginFuncs(NPPluginFuncs* aFuncs)
|
2009-06-30 11:51:05 -07:00
|
|
|
{
|
2009-07-02 09:54:22 -07:00
|
|
|
aFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
|
|
|
|
aFuncs->javaClass = nsnull;
|
|
|
|
|
2009-10-27 12:51:12 -07:00
|
|
|
aFuncs->newp = nsnull; // Gecko should always call this through a PluginLibrary object
|
2009-09-14 11:56:23 -07:00
|
|
|
aFuncs->destroy = NPP_Destroy;
|
|
|
|
aFuncs->setwindow = NPP_SetWindow;
|
|
|
|
aFuncs->newstream = NPP_NewStream;
|
|
|
|
aFuncs->destroystream = NPP_DestroyStream;
|
|
|
|
aFuncs->asfile = NPP_StreamAsFile;
|
|
|
|
aFuncs->writeready = NPP_WriteReady;
|
|
|
|
aFuncs->write = NPP_Write;
|
|
|
|
aFuncs->print = NPP_Print;
|
|
|
|
aFuncs->event = NPP_HandleEvent;
|
|
|
|
aFuncs->urlnotify = NPP_URLNotify;
|
|
|
|
aFuncs->getvalue = NPP_GetValue;
|
|
|
|
aFuncs->setvalue = NPP_SetValue;
|
2009-06-30 11:51:05 -07:00
|
|
|
}
|
|
|
|
|
2009-07-01 14:19:32 -07:00
|
|
|
NPError
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginModuleParent::NPP_Destroy(NPP instance,
|
2010-01-15 12:35:57 -08:00
|
|
|
NPSavedData** /*saved*/)
|
2009-07-01 14:19:32 -07:00
|
|
|
{
|
|
|
|
// FIXME/cjones:
|
|
|
|
// (1) send a "destroy" message to the child
|
|
|
|
// (2) the child shuts down its instance
|
|
|
|
// (3) remove both parent and child IDs from map
|
|
|
|
// (4) free parent
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_FUNCTION;
|
2009-07-01 14:19:32 -07:00
|
|
|
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceParent* parentInstance =
|
|
|
|
static_cast<PluginInstanceParent*>(instance->pdata);
|
2009-07-01 14:19:32 -07:00
|
|
|
|
2009-11-20 00:23:07 -08:00
|
|
|
if (!parentInstance)
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
|
2010-01-15 12:35:57 -08:00
|
|
|
NPError retval = parentInstance->Destroy();
|
|
|
|
instance->pdata = nsnull;
|
2009-10-07 16:50:48 -07:00
|
|
|
|
2010-04-26 22:43:03 -07:00
|
|
|
unused << PluginInstanceParent::Call__delete__(parentInstance);
|
2010-01-15 12:35:57 -08:00
|
|
|
return retval;
|
2009-11-20 00:23:07 -08:00
|
|
|
}
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-09-14 11:56:23 -07:00
|
|
|
NPError
|
|
|
|
PluginModuleParent::NPP_NewStream(NPP instance, NPMIMEType type,
|
|
|
|
NPStream* stream, NPBool seekable,
|
|
|
|
uint16_t* stype)
|
|
|
|
{
|
2009-12-03 12:31:01 -08:00
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
|
|
|
|
return i->NPP_NewStream(type, stream, seekable,
|
|
|
|
stype);
|
2009-09-14 11:56:23 -07:00
|
|
|
}
|
|
|
|
|
2009-09-14 13:01:31 -07:00
|
|
|
NPError
|
|
|
|
PluginModuleParent::NPP_SetWindow(NPP instance, NPWindow* window)
|
|
|
|
{
|
2009-12-03 12:31:01 -08:00
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
|
|
|
|
return i->NPP_SetWindow(window);
|
2009-09-14 13:01:31 -07:00
|
|
|
}
|
|
|
|
|
2009-09-14 11:56:23 -07:00
|
|
|
NPError
|
|
|
|
PluginModuleParent::NPP_DestroyStream(NPP instance,
|
|
|
|
NPStream* stream,
|
|
|
|
NPReason reason)
|
|
|
|
{
|
2009-12-03 12:31:01 -08:00
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
|
|
|
|
return i->NPP_DestroyStream(stream, reason);
|
2009-09-14 11:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
PluginModuleParent::NPP_WriteReady(NPP instance,
|
|
|
|
NPStream* stream)
|
|
|
|
{
|
2009-12-03 12:31:01 -08:00
|
|
|
BrowserStreamParent* s = StreamCast(instance, stream);
|
|
|
|
if (!s)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return s->WriteReady();
|
2009-09-14 11:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
PluginModuleParent::NPP_Write(NPP instance,
|
|
|
|
NPStream* stream,
|
|
|
|
int32_t offset,
|
|
|
|
int32_t len,
|
|
|
|
void* buffer)
|
|
|
|
{
|
2009-12-03 12:31:01 -08:00
|
|
|
BrowserStreamParent* s = StreamCast(instance, stream);
|
|
|
|
if (!s)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return s->Write(offset, len, buffer);
|
2009-09-14 11:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginModuleParent::NPP_StreamAsFile(NPP instance,
|
|
|
|
NPStream* stream,
|
|
|
|
const char* fname)
|
|
|
|
{
|
2009-12-03 12:31:01 -08:00
|
|
|
BrowserStreamParent* s = StreamCast(instance, stream);
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s->StreamAsFile(fname);
|
2009-09-14 11:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginModuleParent::NPP_Print(NPP instance, NPPrint* platformPrint)
|
|
|
|
{
|
2009-12-03 12:31:01 -08:00
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (i)
|
|
|
|
i->NPP_Print(platformPrint);
|
2009-09-14 11:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int16_t
|
|
|
|
PluginModuleParent::NPP_HandleEvent(NPP instance, void* event)
|
|
|
|
{
|
2009-12-03 12:31:01 -08:00
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return i->NPP_HandleEvent(event);
|
2009-09-14 11:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginModuleParent::NPP_URLNotify(NPP instance, const char* url,
|
|
|
|
NPReason reason, void* notifyData)
|
|
|
|
{
|
2009-12-03 12:31:01 -08:00
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return;
|
|
|
|
|
|
|
|
i->NPP_URLNotify(url, reason, notifyData);
|
2009-09-14 11:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NPError
|
|
|
|
PluginModuleParent::NPP_GetValue(NPP instance,
|
|
|
|
NPPVariable variable, void *ret_value)
|
|
|
|
{
|
2009-12-03 12:31:01 -08:00
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
|
|
|
|
return i->NPP_GetValue(variable, ret_value);
|
2009-09-14 11:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NPError
|
|
|
|
PluginModuleParent::NPP_SetValue(NPP instance, NPNVariable variable,
|
|
|
|
void *value)
|
|
|
|
{
|
2009-12-03 12:31:01 -08:00
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
|
|
|
|
return i->NPP_SetValue(variable, value);
|
2009-09-14 11:56:23 -07:00
|
|
|
}
|
|
|
|
|
2010-11-08 18:48:59 -08:00
|
|
|
bool
|
|
|
|
PluginModuleParent::RecvBackUpXResources(const FileDescriptor& aXSocketFd)
|
|
|
|
{
|
|
|
|
#ifndef MOZ_X11
|
|
|
|
NS_RUNTIMEABORT("This message only makes sense on X11 platforms");
|
|
|
|
#else
|
|
|
|
NS_ABORT_IF_FALSE(0 > mPluginXSocketFdDup.mFd,
|
|
|
|
"Already backed up X resources??");
|
|
|
|
mPluginXSocketFdDup.mFd = aXSocketFd.fd;
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-08 00:54:16 -07:00
|
|
|
bool
|
|
|
|
PluginModuleParent::AnswerNPN_UserAgent(nsCString* userAgent)
|
|
|
|
{
|
2009-12-01 13:27:13 -08:00
|
|
|
*userAgent = NullableString(mNPNIface->uagent(nsnull));
|
2009-10-08 00:54:16 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-23 07:30:51 -07:00
|
|
|
PPluginIdentifierParent*
|
|
|
|
PluginModuleParent::GetIdentifierForNPIdentifier(NPIdentifier aIdentifier)
|
2009-08-10 16:28:22 -07:00
|
|
|
{
|
2010-03-23 07:30:51 -07:00
|
|
|
PluginIdentifierParent* ident;
|
|
|
|
if (!mIdentifiers.Get(aIdentifier, &ident)) {
|
|
|
|
nsCString string;
|
|
|
|
int32_t intval = -1;
|
|
|
|
if (mozilla::plugins::parent::_identifierisstring(aIdentifier)) {
|
|
|
|
NPUTF8* chars =
|
|
|
|
mozilla::plugins::parent::_utf8fromidentifier(aIdentifier);
|
|
|
|
if (!chars) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
string.Adopt(chars);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
intval = mozilla::plugins::parent::_intfromidentifier(aIdentifier);
|
|
|
|
string.SetIsVoid(PR_TRUE);
|
|
|
|
}
|
|
|
|
ident = new PluginIdentifierParent(aIdentifier);
|
2010-04-20 06:15:31 -07:00
|
|
|
if (!SendPPluginIdentifierConstructor(ident, string, intval))
|
2010-03-23 07:30:51 -07:00
|
|
|
return nsnull;
|
2010-04-20 06:15:31 -07:00
|
|
|
|
2010-03-23 07:30:51 -07:00
|
|
|
mIdentifiers.Put(aIdentifier, ident);
|
2009-09-14 13:01:31 -07:00
|
|
|
}
|
2010-03-23 07:30:51 -07:00
|
|
|
return ident;
|
2009-08-10 16:28:22 -07:00
|
|
|
}
|
2009-08-18 13:20:03 -07:00
|
|
|
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceParent*
|
|
|
|
PluginModuleParent::InstCast(NPP instance)
|
2009-08-18 13:20:03 -07:00
|
|
|
{
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceParent* ip =
|
|
|
|
static_cast<PluginInstanceParent*>(instance->pdata);
|
2009-12-03 12:31:01 -08:00
|
|
|
|
|
|
|
// If the plugin crashed and the PluginInstanceParent was deleted,
|
|
|
|
// instance->pdata will be NULL.
|
|
|
|
if (!ip)
|
|
|
|
return NULL;
|
|
|
|
|
2009-09-08 23:31:35 -07:00
|
|
|
if (instance != ip->mNPP) {
|
2009-08-18 13:20:03 -07:00
|
|
|
NS_RUNTIMEABORT("Corrupted plugin data.");
|
2009-09-08 23:31:35 -07:00
|
|
|
}
|
2009-08-18 13:20:03 -07:00
|
|
|
return ip;
|
|
|
|
}
|
|
|
|
|
2009-09-09 07:04:09 -07:00
|
|
|
BrowserStreamParent*
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginModuleParent::StreamCast(NPP instance,
|
|
|
|
NPStream* s)
|
2009-08-18 13:20:03 -07:00
|
|
|
{
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginInstanceParent* ip = InstCast(instance);
|
2009-12-03 12:31:01 -08:00
|
|
|
if (!ip)
|
|
|
|
return NULL;
|
|
|
|
|
2009-09-09 07:04:09 -07:00
|
|
|
BrowserStreamParent* sp =
|
2009-09-21 07:51:35 -07:00
|
|
|
static_cast<BrowserStreamParent*>(static_cast<AStream*>(s->pdata));
|
2009-09-08 23:31:35 -07:00
|
|
|
if (sp->mNPP != ip || s != sp->mStream) {
|
2009-08-18 13:20:03 -07:00
|
|
|
NS_RUNTIMEABORT("Corrupted plugin stream data.");
|
2009-09-08 23:31:35 -07:00
|
|
|
}
|
2009-08-18 13:20:03 -07:00
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
|
2009-10-27 12:51:12 -07:00
|
|
|
bool
|
|
|
|
PluginModuleParent::HasRequiredFunctions()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-10 11:28:52 -07:00
|
|
|
nsresult
|
|
|
|
PluginModuleParent::AsyncSetWindow(NPP instance, NPWindow* window)
|
|
|
|
{
|
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return i->AsyncSetWindow(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PluginModuleParent::GetSurface(NPP instance, gfxASurface** aSurface)
|
|
|
|
{
|
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return i->GetSurface(aSurface);
|
|
|
|
}
|
|
|
|
|
2009-10-27 12:51:12 -07:00
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
|
|
|
nsresult
|
|
|
|
PluginModuleParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs, NPError* error)
|
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_METHOD;
|
2009-10-27 12:51:12 -07:00
|
|
|
|
|
|
|
mNPNIface = bFuncs;
|
|
|
|
|
2009-12-03 12:31:52 -08:00
|
|
|
if (mShutdown) {
|
|
|
|
*error = NPERR_GENERIC_ERROR;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-03-30 17:24:47 -07:00
|
|
|
if (!CallNP_Initialize(&mPluginThread, error)) {
|
2009-11-20 07:34:20 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-10-27 12:51:12 -07:00
|
|
|
}
|
|
|
|
else if (*error != NPERR_NO_ERROR) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetPluginFuncs(pFuncs);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
nsresult
|
|
|
|
PluginModuleParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error)
|
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_METHOD;
|
2009-10-27 12:51:12 -07:00
|
|
|
|
|
|
|
mNPNIface = bFuncs;
|
|
|
|
|
2009-12-03 12:31:52 -08:00
|
|
|
if (mShutdown) {
|
|
|
|
*error = NPERR_GENERIC_ERROR;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-03-30 17:24:47 -07:00
|
|
|
if (!CallNP_Initialize(&mPluginThread, error))
|
2009-11-20 07:34:20 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-10-27 12:51:12 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PluginModuleParent::NP_Shutdown(NPError* error)
|
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_METHOD;
|
2009-10-27 12:51:12 -07:00
|
|
|
|
2009-12-03 12:31:52 -08:00
|
|
|
if (mShutdown) {
|
|
|
|
*error = NPERR_GENERIC_ERROR;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2009-11-03 13:37:07 -08:00
|
|
|
bool ok = CallNP_Shutdown(error);
|
2009-12-03 00:16:28 -08:00
|
|
|
|
|
|
|
// if NP_Shutdown() is nested within another RPC call, this will
|
|
|
|
// break things. but lord help us if we're doing that anyway; the
|
|
|
|
// plugin dso will have been unloaded on the other side by the
|
|
|
|
// CallNP_Shutdown() message
|
2009-11-03 13:37:07 -08:00
|
|
|
Close();
|
|
|
|
|
|
|
|
return ok ? NS_OK : NS_ERROR_FAILURE;
|
2009-10-27 12:51:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-01-29 12:18:50 -08:00
|
|
|
PluginModuleParent::NP_GetMIMEDescription(const char** mimeDesc)
|
2009-10-27 12:51:12 -07:00
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_METHOD;
|
2009-10-27 12:51:12 -07:00
|
|
|
|
2010-01-29 12:18:50 -08:00
|
|
|
*mimeDesc = "application/x-foobar";
|
2009-10-27 12:51:12 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PluginModuleParent::NP_GetValue(void *future, NPPVariable aVariable,
|
|
|
|
void *aValue, NPError* error)
|
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PR_LOG(gPluginLog, PR_LOG_WARNING, ("%s Not implemented, requested variable %i", __FUNCTION__,
|
|
|
|
(int) aVariable));
|
2009-10-27 12:51:12 -07:00
|
|
|
|
|
|
|
//TODO: implement this correctly
|
|
|
|
*error = NPERR_GENERIC_ERROR;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-23 13:12:00 -08:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_OS2)
|
2009-10-27 12:51:12 -07:00
|
|
|
nsresult
|
|
|
|
PluginModuleParent::NP_GetEntryPoints(NPPluginFuncs* pFuncs, NPError* error)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(pFuncs, "Null pointer!");
|
|
|
|
|
|
|
|
SetPluginFuncs(pFuncs);
|
|
|
|
*error = NPERR_NO_ERROR;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PluginModuleParent::NPP_New(NPMIMEType pluginType, NPP instance,
|
|
|
|
uint16_t mode, int16_t argc, char* argn[],
|
|
|
|
char* argv[], NPSavedData* saved,
|
|
|
|
NPError* error)
|
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_METHOD;
|
2009-10-27 12:51:12 -07:00
|
|
|
|
2009-12-03 12:31:52 -08:00
|
|
|
if (mShutdown) {
|
|
|
|
*error = NPERR_GENERIC_ERROR;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2009-10-27 12:51:12 -07:00
|
|
|
// create the instance on the other side
|
2010-11-08 18:49:00 -08:00
|
|
|
InfallibleTArray<nsCString> names;
|
|
|
|
InfallibleTArray<nsCString> values;
|
2009-10-27 12:51:12 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
names.AppendElement(NullableString(argn[i]));
|
|
|
|
values.AppendElement(NullableString(argv[i]));
|
|
|
|
}
|
|
|
|
|
2009-11-19 14:47:09 -08:00
|
|
|
PluginInstanceParent* parentInstance =
|
2010-04-20 07:52:19 -07:00
|
|
|
new PluginInstanceParent(this, instance,
|
|
|
|
nsDependentCString(pluginType), mNPNIface);
|
2009-10-27 12:51:12 -07:00
|
|
|
|
2010-01-15 12:35:57 -08:00
|
|
|
if (!parentInstance->Init()) {
|
|
|
|
delete parentInstance;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2009-11-19 14:47:09 -08:00
|
|
|
instance->pdata = parentInstance;
|
2009-10-27 12:51:12 -07:00
|
|
|
|
|
|
|
if (!CallPPluginInstanceConstructor(parentInstance,
|
|
|
|
nsDependentCString(pluginType), mode,
|
2009-11-19 14:47:09 -08:00
|
|
|
names, values, error)) {
|
|
|
|
// |parentInstance| is automatically deleted.
|
|
|
|
instance->pdata = nsnull;
|
2009-11-20 00:23:07 -08:00
|
|
|
// if IPC is down, we'll get an immediate "failed" return, but
|
|
|
|
// without *error being set. So make sure that the error
|
|
|
|
// condition is signaled to nsNPAPIPluginInstance
|
|
|
|
if (NPERR_NO_ERROR == *error)
|
|
|
|
*error = NPERR_GENERIC_ERROR;
|
2009-10-27 12:51:12 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-11-19 14:47:09 -08:00
|
|
|
}
|
2009-10-27 12:51:12 -07:00
|
|
|
|
2009-11-19 14:47:09 -08:00
|
|
|
if (*error != NPERR_NO_ERROR) {
|
2010-01-15 12:35:57 -08:00
|
|
|
NPP_Destroy(instance, 0);
|
2010-05-12 11:12:49 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-11-19 14:47:09 -08:00
|
|
|
}
|
2009-10-27 12:51:12 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-01 13:27:13 -08:00
|
|
|
bool
|
|
|
|
PluginModuleParent::AnswerNPN_GetValue_WithBoolReturn(const NPNVariable& aVariable,
|
|
|
|
NPError* aError,
|
|
|
|
bool* aBoolVal)
|
|
|
|
{
|
|
|
|
NPBool boolVal = false;
|
|
|
|
*aError = mozilla::plugins::parent::_getvalue(nsnull, aVariable, &boolVal);
|
|
|
|
*aBoolVal = boolVal ? true : false;
|
|
|
|
return true;
|
|
|
|
}
|
2010-02-16 10:44:25 -08:00
|
|
|
|
2010-06-01 20:58:00 -07:00
|
|
|
#if defined(MOZ_WIDGET_QT)
|
|
|
|
static const int kMaxtimeToProcessEvents = 30;
|
|
|
|
bool
|
|
|
|
PluginModuleParent::AnswerProcessSomeEvents()
|
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("Spinning mini nested loop ..."));
|
|
|
|
QCoreApplication::processEvents(QEventLoop::AllEvents, kMaxtimeToProcessEvents);
|
|
|
|
|
|
|
|
PLUGIN_LOG_DEBUG(("... quitting mini nested loop"));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-29 15:38:32 -07:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
bool
|
|
|
|
PluginModuleParent::AnswerProcessSomeEvents()
|
|
|
|
{
|
|
|
|
mozilla::plugins::PluginUtilsOSX::InvokeNativeEventLoop();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-01 20:58:00 -07:00
|
|
|
#elif !defined(MOZ_WIDGET_GTK2)
|
2010-02-16 10:44:25 -08:00
|
|
|
bool
|
|
|
|
PluginModuleParent::AnswerProcessSomeEvents()
|
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("unreached");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
static const int kMaxChancesToProcessEvents = 20;
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginModuleParent::AnswerProcessSomeEvents()
|
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("Spinning mini nested loop ..."));
|
|
|
|
|
2010-03-10 23:35:29 -08:00
|
|
|
int i = 0;
|
|
|
|
for (; i < kMaxChancesToProcessEvents; ++i)
|
|
|
|
if (!g_main_context_iteration(NULL, FALSE))
|
|
|
|
break;
|
|
|
|
|
|
|
|
PLUGIN_LOG_DEBUG(("... quitting mini nested loop; processed %i tasks", i));
|
2010-02-16 10:44:25 -08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2010-04-20 07:52:19 -07:00
|
|
|
|
2010-04-30 11:42:51 -07:00
|
|
|
bool
|
|
|
|
PluginModuleParent::RecvProcessNativeEventsInRPCCall()
|
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("%s", FULLFUNCTION));
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
ProcessNativeEventsInRPCCall();
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_NOTREACHED(
|
2010-08-13 09:45:50 -07:00
|
|
|
"PluginInstanceParent::RecvProcessNativeEventsInRPCCall not implemented!");
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginModuleParent::RecvPluginShowWindow(const uint32_t& aWindowId, const bool& aModal,
|
|
|
|
const int32_t& aX, const int32_t& aY,
|
|
|
|
const size_t& aWidth, const size_t& aHeight)
|
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("%s", FULLFUNCTION));
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
CGRect windowBound = ::CGRectMake(aX, aY, aWidth, aHeight);
|
|
|
|
mac_plugin_interposing::parent::OnPluginShowWindow(aWindowId, windowBound, aModal);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_NOTREACHED(
|
|
|
|
"PluginInstanceParent::RecvPluginShowWindow not implemented!");
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginModuleParent::RecvPluginHideWindow(const uint32_t& aWindowId)
|
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("%s", FULLFUNCTION));
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
mac_plugin_interposing::parent::OnPluginHideWindow(aWindowId, OtherSidePID());
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_NOTREACHED(
|
|
|
|
"PluginInstanceParent::RecvPluginHideWindow not implemented!");
|
2010-04-30 11:42:51 -07:00
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-04-20 07:52:19 -07:00
|
|
|
#ifdef OS_MACOSX
|
|
|
|
#define DEFAULT_REFRESH_MS 20 // CoreAnimation: 50 FPS
|
2010-11-01 06:47:23 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
CAUpdate(nsITimer *aTimer, void *aClosure) {
|
|
|
|
nsTObserverArray<PluginInstanceParent*> *ips =
|
|
|
|
static_cast<nsTObserverArray<PluginInstanceParent*> *>(aClosure);
|
|
|
|
nsTObserverArray<PluginInstanceParent*>::ForwardIterator iter(*ips);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
iter.GetNext()->Invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-20 07:52:19 -07:00
|
|
|
void
|
|
|
|
PluginModuleParent::AddToRefreshTimer(PluginInstanceParent *aInstance) {
|
|
|
|
if (mCATimerTargets.Contains(aInstance)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCATimerTargets.AppendElement(aInstance);
|
|
|
|
if (mCATimerTargets.Length() == 1) {
|
2010-11-01 06:47:23 -07:00
|
|
|
if (!mCATimer) {
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsITimer> xpcomTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Could not create Core Animation timer for plugin.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mCATimer = xpcomTimer;
|
|
|
|
}
|
|
|
|
mCATimer->InitWithFuncCallback(CAUpdate, &mCATimerTargets, DEFAULT_REFRESH_MS,
|
|
|
|
nsITimer::TYPE_REPEATING_SLACK);
|
2010-04-20 07:52:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginModuleParent::RemoveFromRefreshTimer(PluginInstanceParent *aInstance) {
|
|
|
|
PRBool visibleRemoved = mCATimerTargets.RemoveElement(aInstance);
|
|
|
|
if (visibleRemoved && mCATimerTargets.IsEmpty()) {
|
2010-11-01 06:47:23 -07:00
|
|
|
mCATimer->Cancel();
|
2010-04-20 07:52:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|