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 :
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2013-08-01 18:21:32 -07:00
|
|
|
#ifdef MOZ_WIDGET_QT
|
2014-11-19 22:02:51 -08:00
|
|
|
#include "PluginHelperQt.h"
|
2013-08-01 18:21:32 -07:00
|
|
|
#endif
|
|
|
|
|
2013-07-24 00:41:03 -07:00
|
|
|
#include "mozilla/plugins/PluginModuleParent.h"
|
2010-03-10 23:35:29 -08:00
|
|
|
|
2010-02-11 12:32:18 -08:00
|
|
|
#include "base/process_util.h"
|
2013-07-24 00:41:03 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-10-29 08:05:36 -07:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2013-07-24 00:41:03 -07:00
|
|
|
#include "mozilla/dom/PCrashReporterParent.h"
|
2013-09-27 18:42:08 -07:00
|
|
|
#include "mozilla/ipc/MessageChannel.h"
|
2009-09-09 07:04:09 -07:00
|
|
|
#include "mozilla/plugins/BrowserStreamParent.h"
|
2014-10-29 08:05:36 -07:00
|
|
|
#include "mozilla/plugins/PluginBridge.h"
|
2013-08-14 00:00:47 -07:00
|
|
|
#include "mozilla/plugins/PluginInstanceParent.h"
|
2013-07-24 00:41:03 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "mozilla/unused.h"
|
2010-08-10 14:14:10 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2010-01-13 17:20:00 -08:00
|
|
|
#include "nsCRT.h"
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2013-07-24 00:41:03 -07:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsNPAPIPlugin.h"
|
2012-07-25 05:38:43 -07:00
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
#include "prsystem.h"
|
2013-09-10 13:56:05 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2009-09-14 13:01:31 -07:00
|
|
|
|
2011-06-24 07:20:03 -07:00
|
|
|
#ifdef XP_WIN
|
2013-01-04 14:59:05 -08:00
|
|
|
#include "PluginHangUIParent.h"
|
2011-06-24 07:20:03 -07:00
|
|
|
#include "mozilla/widget/AudioSession.h"
|
|
|
|
#endif
|
2013-07-24 00:41:03 -07:00
|
|
|
|
2013-04-27 07:20:23 -07:00
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
2014-11-18 09:50:25 -08:00
|
|
|
#include "nsIProfiler.h"
|
2013-03-21 02:17:23 -07:00
|
|
|
#include "nsIProfileSaveEvent.h"
|
2013-04-27 07:20:23 -07:00
|
|
|
#endif
|
2013-07-24 00:41:03 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
#include <glib.h>
|
|
|
|
#elif XP_MACOSX
|
|
|
|
#include "PluginInterposeOSX.h"
|
|
|
|
#include "PluginUtilsOSX.h"
|
|
|
|
#endif
|
|
|
|
|
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;
|
2013-09-27 18:42:08 -07:00
|
|
|
using mozilla::ipc::MessageChannel;
|
2011-06-08 12:56:31 -07:00
|
|
|
using mozilla::dom::PCrashReporterParent;
|
|
|
|
using mozilla::dom::CrashReporterParent;
|
2009-09-14 13:01:31 -07:00
|
|
|
|
2011-05-24 23:32:00 -07:00
|
|
|
using namespace mozilla;
|
2009-09-14 13:01:31 -07:00
|
|
|
using namespace mozilla::plugins;
|
2011-06-14 12:49:48 -07:00
|
|
|
using namespace mozilla::plugins::parent;
|
2009-09-14 13:01:31 -07:00
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "mozilla/dom/CrashReporterParent.h"
|
|
|
|
|
|
|
|
using namespace CrashReporter;
|
|
|
|
#endif
|
|
|
|
|
2011-08-16 03:25:34 -07:00
|
|
|
static const char kChildTimeoutPref[] = "dom.ipc.plugins.timeoutSecs";
|
|
|
|
static const char kParentTimeoutPref[] = "dom.ipc.plugins.parentTimeoutSecs";
|
2010-08-10 14:14:10 -07:00
|
|
|
static const char kLaunchTimeoutPref[] = "dom.ipc.plugins.processLaunchTimeoutSecs";
|
2013-01-04 14:59:05 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
static const char kHangUITimeoutPref[] = "dom.ipc.plugins.hangUITimeoutSecs";
|
|
|
|
static const char kHangUIMinDisplayPref[] = "dom.ipc.plugins.hangUIMinDisplaySecs";
|
|
|
|
#define CHILD_TIMEOUT_PREF kHangUITimeoutPref
|
|
|
|
#else
|
|
|
|
#define CHILD_TIMEOUT_PREF kChildTimeoutPref
|
|
|
|
#endif
|
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) { }
|
|
|
|
};
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
bool
|
|
|
|
mozilla::plugins::SetupBridge(uint32_t aPluginId, dom::ContentParent* aContentParent)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsPluginHost> host = nsPluginHost::GetInst();
|
|
|
|
nsRefPtr<nsNPAPIPlugin> plugin;
|
|
|
|
nsresult rv = host->GetPluginForContentProcess(aPluginId, getter_AddRefs(plugin));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PluginModuleParent* chromeParent = static_cast<PluginModuleParent*>(plugin->GetLibrary());
|
|
|
|
return PPluginModule::Bridge(aContentParent, chromeParent);
|
|
|
|
}
|
|
|
|
|
2014-11-21 14:00:55 -08:00
|
|
|
// A linked list used to fetch newly created PluginModuleContentParent instances
|
|
|
|
// for LoadModule. Each pending LoadModule call owns an element in this list.
|
|
|
|
// The element's mModule field is filled in when the new
|
|
|
|
// PluginModuleContentParent arrives from chrome.
|
|
|
|
struct MOZ_STACK_CLASS SavedPluginModule
|
|
|
|
{
|
|
|
|
SavedPluginModule() : mModule(nullptr), mNext(sSavedModuleStack)
|
|
|
|
{
|
|
|
|
sSavedModuleStack = this;
|
|
|
|
}
|
|
|
|
~SavedPluginModule()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(sSavedModuleStack == this);
|
|
|
|
sSavedModuleStack = mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginModuleContentParent* GetModule() { return mModule; }
|
|
|
|
|
|
|
|
// LoadModule can be on the stack multiple times since the intr message it
|
|
|
|
// sends will dispatch arbitrary incoming messages from the chrome process,
|
|
|
|
// which can include new HTTP data. This makes it somewhat tricky to match
|
|
|
|
// up the object created in PluginModuleContentParent::Create with the
|
|
|
|
// LoadModule call that asked for it.
|
|
|
|
//
|
|
|
|
// Each invocation of LoadModule pushes a new SavedPluginModule object on
|
|
|
|
// the sSavedModuleStack stack, with the most recent invocation at the
|
|
|
|
// front. LoadModule messages are always processed by the chrome process in
|
|
|
|
// order, and PluginModuleContentParent allocation messages will also be
|
|
|
|
// received in order. Therefore, we need to match up the first received
|
|
|
|
// PluginModuleContentParent creation message with the first sent LoadModule
|
|
|
|
// call. This call will be the last one in the list that doesn't already
|
|
|
|
// have a module attached to it.
|
|
|
|
static void SaveModule(PluginModuleContentParent* module)
|
|
|
|
{
|
|
|
|
SavedPluginModule* saved = sSavedModuleStack;
|
|
|
|
SavedPluginModule* prev = nullptr;
|
|
|
|
while (saved && !saved->mModule) {
|
|
|
|
prev = saved;
|
|
|
|
saved = saved->mNext;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(prev);
|
|
|
|
MOZ_ASSERT(!prev->mModule);
|
|
|
|
prev->mModule = module;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
PluginModuleContentParent* mModule;
|
|
|
|
SavedPluginModule* mNext;
|
|
|
|
|
|
|
|
static SavedPluginModule* sSavedModuleStack;
|
|
|
|
};
|
|
|
|
|
|
|
|
SavedPluginModule* SavedPluginModule::sSavedModuleStack;
|
2014-10-29 08:05:36 -07:00
|
|
|
|
|
|
|
/* static */ PluginLibrary*
|
|
|
|
PluginModuleContentParent::LoadModule(uint32_t aPluginId)
|
|
|
|
{
|
2014-11-21 14:00:55 -08:00
|
|
|
SavedPluginModule saved;
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Content);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We send a LoadPlugin message to the chrome process using an intr
|
2014-11-21 14:00:55 -08:00
|
|
|
* message. Before it sends its response, it sends a message to create a
|
|
|
|
* PluginModuleContentParent instance. That message is handled by
|
|
|
|
* PluginModuleContentParent::Create. See SavedPluginModule for details
|
|
|
|
* about how we match up the result of PluginModuleContentParent::Create
|
|
|
|
* with the LoadModule call that requested it.
|
2014-10-29 08:05:36 -07:00
|
|
|
*/
|
|
|
|
dom::ContentChild* cp = dom::ContentChild::GetSingleton();
|
|
|
|
if (!cp->CallLoadPlugin(aPluginId)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-11-21 14:00:55 -08:00
|
|
|
PluginModuleContentParent* parent = saved.GetModule();
|
2014-10-29 08:05:36 -07:00
|
|
|
MOZ_ASSERT(parent);
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ PluginModuleContentParent*
|
|
|
|
PluginModuleContentParent::Create(mozilla::ipc::Transport* aTransport,
|
|
|
|
base::ProcessId aOtherProcess)
|
|
|
|
{
|
|
|
|
nsAutoPtr<PluginModuleContentParent> parent(new PluginModuleContentParent());
|
|
|
|
ProcessHandle handle;
|
|
|
|
if (!base::OpenProcessHandle(aOtherProcess, &handle)) {
|
|
|
|
// Bug 1090578 - need to kill |aOtherProcess|, it's boned.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-11-21 14:00:55 -08:00
|
|
|
SavedPluginModule::SaveModule(parent);
|
2014-10-29 08:05:36 -07:00
|
|
|
|
|
|
|
DebugOnly<bool> ok = parent->Open(aTransport, handle, XRE_GetIOMessageLoop(),
|
|
|
|
mozilla::ipc::ParentSide);
|
|
|
|
MOZ_ASSERT(ok);
|
|
|
|
|
|
|
|
// Request Windows message deferral behavior on our channel. This
|
|
|
|
// applies to the top level and all sub plugin protocols since they
|
|
|
|
// all share the same channel.
|
|
|
|
parent->GetIPCChannel()->SetChannelFlags(MessageChannel::REQUIRE_DEFERRED_MESSAGE_PROTECTION);
|
|
|
|
|
|
|
|
return parent.forget();
|
|
|
|
}
|
|
|
|
|
2009-11-09 14:56:55 -08:00
|
|
|
// static
|
2009-10-27 12:51:12 -07:00
|
|
|
PluginLibrary*
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::LoadModule(const char* aFilePath, uint32_t aPluginId)
|
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
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t prefSecs = Preferences::GetInt(kLaunchTimeoutPref, 0);
|
2010-08-10 14:14:10 -07:00
|
|
|
|
2009-06-30 11:51:05 -07:00
|
|
|
// Block on the child process being launched and initialized.
|
2014-10-29 08:05:36 -07:00
|
|
|
nsAutoPtr<PluginModuleChromeParent> parent(new PluginModuleChromeParent(aFilePath, aPluginId));
|
2010-08-10 14:14:10 -07:00
|
|
|
bool launched = parent->mSubprocess->Launch(prefSecs * 1000);
|
|
|
|
if (!launched) {
|
2014-02-28 15:39:17 -08:00
|
|
|
// We never reached open
|
2010-08-10 14:14:10 -07:00
|
|
|
parent->mShutdown = true;
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-08-10 14:14:10 -07:00
|
|
|
}
|
2009-11-09 14:56:55 -08:00
|
|
|
parent->Open(parent->mSubprocess->GetChannel(),
|
|
|
|
parent->mSubprocess->GetChildProcessHandle());
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2014-08-15 10:12:37 -07:00
|
|
|
// Request Windows message deferral behavior on our channel. This
|
|
|
|
// applies to the top level and all sub plugin protocols since they
|
|
|
|
// all share the same channel.
|
|
|
|
parent->GetIPCChannel()->SetChannelFlags(MessageChannel::REQUIRE_DEFERRED_MESSAGE_PROTECTION);
|
|
|
|
|
2013-01-04 14:59:05 -08:00
|
|
|
TimeoutChanged(CHILD_TIMEOUT_PREF, parent);
|
2011-06-08 12:56:31 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2011-10-19 12:32:17 -07:00
|
|
|
// If this fails, we're having IPC troubles, and we're doomed anyways.
|
|
|
|
if (!CrashReporterParent::CreateCrashReporter(parent.get())) {
|
2014-02-28 15:39:17 -08:00
|
|
|
parent->Close();
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-10-19 12:32:17 -07:00
|
|
|
}
|
2013-12-03 14:19:58 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
mozilla::MutexAutoLock lock(parent->mCrashReporterMutex);
|
|
|
|
parent->mCrashReporter = parent->CrashReporter();
|
|
|
|
#endif
|
2011-06-08 12:56:31 -07:00
|
|
|
#endif
|
|
|
|
|
2010-08-10 14:14:10 -07:00
|
|
|
return parent.forget();
|
2009-06-30 11:51:05 -07:00
|
|
|
}
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleParent::PluginModuleParent(bool aIsChrome)
|
|
|
|
: mIsChrome(aIsChrome)
|
2009-12-03 12:31:52 -08:00
|
|
|
, mShutdown(false)
|
2011-02-08 14:16:07 -08:00
|
|
|
, mClearSiteDataSupported(false)
|
|
|
|
, mGetSitesWithDataSupported(false)
|
2013-10-23 13:34:46 -07:00
|
|
|
, mNPNIface(nullptr)
|
|
|
|
, mPlugin(nullptr)
|
2013-07-24 00:41:03 -07:00
|
|
|
, mTaskFactory(MOZ_THIS_IN_INITIALIZER_LIST())
|
2014-10-29 08:05:36 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginModuleParent::~PluginModuleParent()
|
|
|
|
{
|
|
|
|
if (!OkToCleanup()) {
|
|
|
|
NS_RUNTIMEABORT("unsafe destruction");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mShutdown) {
|
|
|
|
NS_WARNING("Plugin host deleted the module without shutting down.");
|
|
|
|
NPError err;
|
|
|
|
NP_Shutdown(&err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginModuleContentParent::PluginModuleContentParent()
|
|
|
|
: PluginModuleParent(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginModuleChromeParent::PluginModuleChromeParent(const char* aFilePath, uint32_t aPluginId)
|
|
|
|
: PluginModuleParent(true)
|
|
|
|
, mSubprocess(new PluginProcessParent(aFilePath))
|
|
|
|
, mPluginId(aPluginId)
|
|
|
|
, mChromeTaskFactory(MOZ_THIS_IN_INITIALIZER_LIST())
|
2014-10-21 10:48:08 -07:00
|
|
|
, mHangAnnotationFlags(0)
|
2012-07-25 05:38:43 -07:00
|
|
|
#ifdef XP_WIN
|
2012-08-09 03:36:30 -07:00
|
|
|
, mPluginCpuUsageOnHang()
|
2013-01-04 14:59:05 -08:00
|
|
|
, mHangUIParent(nullptr)
|
|
|
|
, mHangUIEnabled(true)
|
|
|
|
, mIsTimerReset(true)
|
2013-12-03 14:19:58 -08:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
, mCrashReporterMutex("PluginModuleParent::mCrashReporterMutex")
|
|
|
|
, mCrashReporter(nullptr)
|
|
|
|
#endif
|
2012-07-25 05:38:43 -07:00
|
|
|
#endif
|
2012-07-03 04:49:23 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
, mFlashProcess1(0)
|
|
|
|
, mFlashProcess2(0)
|
|
|
|
#endif
|
2009-06-30 11:51:05 -07:00
|
|
|
{
|
2009-11-09 14:56:55 -08:00
|
|
|
NS_ASSERTION(mSubprocess, "Out of memory!");
|
|
|
|
|
2011-08-16 03:25:34 -07:00
|
|
|
Preferences::RegisterCallback(TimeoutChanged, kChildTimeoutPref, this);
|
|
|
|
Preferences::RegisterCallback(TimeoutChanged, kParentTimeoutPref, this);
|
2013-01-04 14:59:05 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
Preferences::RegisterCallback(TimeoutChanged, kHangUITimeoutPref, this);
|
|
|
|
Preferences::RegisterCallback(TimeoutChanged, kHangUIMinDisplayPref, this);
|
|
|
|
#endif
|
2013-03-21 02:17:23 -07:00
|
|
|
|
2014-11-18 21:46:01 -08:00
|
|
|
RegisterSettingsCallbacks();
|
|
|
|
|
2013-04-27 07:20:23 -07:00
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
2013-03-21 02:17:23 -07:00
|
|
|
InitPluginProfiling();
|
2013-04-27 07:20:23 -07:00
|
|
|
#endif
|
2014-10-21 10:48:08 -07:00
|
|
|
|
|
|
|
mozilla::HangMonitor::RegisterAnnotator(*this);
|
2009-06-30 11:51:05 -07:00
|
|
|
}
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::~PluginModuleChromeParent()
|
2009-06-30 11:51:05 -07:00
|
|
|
{
|
2014-02-28 15:39:17 -08:00
|
|
|
if (!OkToCleanup()) {
|
|
|
|
NS_RUNTIMEABORT("unsafe destruction");
|
|
|
|
}
|
2010-03-07 12:16:02 -08:00
|
|
|
|
2013-04-27 07:20:23 -07:00
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
2013-03-21 02:17:23 -07:00
|
|
|
ShutdownPluginProfiling();
|
2013-04-27 07:20:23 -07:00
|
|
|
#endif
|
2013-03-21 02:17:23 -07:00
|
|
|
|
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);
|
|
|
|
}
|
2014-02-28 15:39:17 -08:00
|
|
|
|
2009-12-03 12:31:52 -08:00
|
|
|
NS_ASSERTION(mShutdown, "NP_Shutdown didn't");
|
|
|
|
|
2009-11-09 14:56:55 -08:00
|
|
|
if (mSubprocess) {
|
|
|
|
mSubprocess->Delete();
|
2012-07-30 07:20:58 -07:00
|
|
|
mSubprocess = nullptr;
|
2009-11-09 14:56:55 -08:00
|
|
|
}
|
2010-02-11 12:32:18 -08:00
|
|
|
|
2012-07-03 04:49:23 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
if (mFlashProcess1)
|
2012-07-10 19:20:05 -07:00
|
|
|
UnregisterInjectorCallback(mFlashProcess1);
|
2012-07-03 04:49:23 -07:00
|
|
|
if (mFlashProcess2)
|
2012-07-10 19:20:05 -07:00
|
|
|
UnregisterInjectorCallback(mFlashProcess2);
|
2012-07-03 04:49:23 -07:00
|
|
|
#endif
|
|
|
|
|
2014-11-21 14:00:24 -08:00
|
|
|
UnregisterSettingsCallbacks();
|
|
|
|
|
2011-08-16 03:25:34 -07:00
|
|
|
Preferences::UnregisterCallback(TimeoutChanged, kChildTimeoutPref, this);
|
|
|
|
Preferences::UnregisterCallback(TimeoutChanged, kParentTimeoutPref, this);
|
2013-01-04 14:59:05 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
Preferences::UnregisterCallback(TimeoutChanged, kHangUITimeoutPref, this);
|
|
|
|
Preferences::UnregisterCallback(TimeoutChanged, kHangUIMinDisplayPref, this);
|
|
|
|
|
|
|
|
if (mHangUIParent) {
|
|
|
|
delete mHangUIParent;
|
|
|
|
mHangUIParent = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2014-10-21 10:48:08 -07:00
|
|
|
|
|
|
|
mozilla::HangMonitor::UnregisterAnnotator(*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
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::WriteExtraDataForMinidump(AnnotationTable& notes)
|
2010-01-13 17:20:00 -08:00
|
|
|
{
|
2013-12-03 14:19:58 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// mCrashReporterMutex is already held by the caller
|
|
|
|
mCrashReporterMutex.AssertCurrentThreadOwns();
|
|
|
|
#endif
|
2010-03-24 14:22:03 -07:00
|
|
|
typedef nsDependentCString CS;
|
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++;
|
2012-12-13 09:06:52 -08:00
|
|
|
notes.Put(NS_LITERAL_CSTRING("PluginFilename"), CS(pluginFile.substr(filePos).c_str()));
|
|
|
|
|
2014-10-21 10:48:08 -07:00
|
|
|
notes.Put(NS_LITERAL_CSTRING("PluginName"), mPluginName);
|
|
|
|
notes.Put(NS_LITERAL_CSTRING("PluginVersion"), mPluginVersion);
|
2010-02-24 14:25:16 -08:00
|
|
|
|
2012-07-03 04:49:23 -07:00
|
|
|
CrashReporterParent* crashReporter = CrashReporter();
|
|
|
|
if (crashReporter) {
|
2012-07-25 05:38:43 -07:00
|
|
|
#ifdef XP_WIN
|
2012-09-08 10:20:59 -07:00
|
|
|
if (mPluginCpuUsageOnHang.Length() > 0) {
|
2012-12-13 09:06:52 -08:00
|
|
|
notes.Put(NS_LITERAL_CSTRING("NumberOfProcessors"),
|
2012-09-08 10:20:59 -07:00
|
|
|
nsPrintfCString("%d", PR_GetNumberOfProcessors()));
|
2012-08-09 03:36:30 -07:00
|
|
|
|
2012-09-08 10:20:59 -07:00
|
|
|
nsCString cpuUsageStr;
|
|
|
|
cpuUsageStr.AppendFloat(std::ceil(mPluginCpuUsageOnHang[0] * 100) / 100);
|
2012-12-13 09:06:52 -08:00
|
|
|
notes.Put(NS_LITERAL_CSTRING("PluginCpuUsage"), cpuUsageStr);
|
2012-08-09 02:04:27 -07:00
|
|
|
|
2012-08-09 03:36:30 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
2012-09-08 10:20:59 -07:00
|
|
|
for (uint32_t i=1; i<mPluginCpuUsageOnHang.Length(); ++i) {
|
2012-08-09 03:36:30 -07:00
|
|
|
nsCString tempStr;
|
|
|
|
tempStr.AppendFloat(std::ceil(mPluginCpuUsageOnHang[i] * 100) / 100);
|
|
|
|
notes.Put(nsPrintfCString("CpuUsageFlashProcess%d", i), tempStr);
|
2012-07-25 05:38:43 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2012-09-08 10:20:59 -07:00
|
|
|
#endif
|
2012-07-03 04:49:23 -07:00
|
|
|
}
|
2010-03-24 14:22:03 -07:00
|
|
|
}
|
|
|
|
#endif // MOZ_CRASHREPORTER
|
2010-02-24 14:25:16 -08:00
|
|
|
|
2013-01-04 14:59:05 -08:00
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::SetChildTimeout(const int32_t aChildTimeout)
|
2013-01-04 14:59:05 -08:00
|
|
|
{
|
|
|
|
int32_t timeoutMs = (aChildTimeout > 0) ? (1000 * aChildTimeout) :
|
2013-09-27 18:42:08 -07:00
|
|
|
MessageChannel::kNoTimeout;
|
2013-01-04 14:59:05 -08:00
|
|
|
SetReplyTimeoutMs(timeoutMs);
|
|
|
|
}
|
|
|
|
|
2013-12-10 15:10:01 -08:00
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::TimeoutChanged(const char* aPref, void* aModule)
|
2010-02-11 12:32:18 -08:00
|
|
|
{
|
2013-01-04 14:59:05 -08:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
#ifndef XP_WIN
|
2011-08-16 03:25:34 -07:00
|
|
|
if (!strcmp(aPref, kChildTimeoutPref)) {
|
|
|
|
// The timeout value used by the parent for children
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t timeoutSecs = Preferences::GetInt(kChildTimeoutPref, 0);
|
2014-10-29 08:05:36 -07:00
|
|
|
static_cast<PluginModuleChromeParent*>(aModule)->SetChildTimeout(timeoutSecs);
|
2013-01-04 14:59:05 -08:00
|
|
|
#else
|
|
|
|
if (!strcmp(aPref, kChildTimeoutPref) ||
|
|
|
|
!strcmp(aPref, kHangUIMinDisplayPref) ||
|
|
|
|
!strcmp(aPref, kHangUITimeoutPref)) {
|
2014-10-29 08:05:36 -07:00
|
|
|
static_cast<PluginModuleChromeParent*>(aModule)->EvaluateHangUIState(true);
|
2013-01-04 14:59:05 -08:00
|
|
|
#endif // XP_WIN
|
2011-08-16 03:25:34 -07:00
|
|
|
} else if (!strcmp(aPref, kParentTimeoutPref)) {
|
|
|
|
// The timeout value used by the child for its parent
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t timeoutSecs = Preferences::GetInt(kParentTimeoutPref, 0);
|
2014-10-29 08:05:36 -07:00
|
|
|
unused << static_cast<PluginModuleChromeParent*>(aModule)->SendSetParentHangTimeout(timeoutSecs);
|
2011-08-16 03:25:34 -07:00
|
|
|
}
|
2010-02-11 12:32:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::CleanupFromTimeout(const bool aFromHangUI)
|
2010-02-11 12:32:18 -08:00
|
|
|
{
|
2012-10-15 03:29:47 -07:00
|
|
|
if (mShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!OkToCleanup()) {
|
|
|
|
// there's still plugin code on the C++ stack, try again
|
|
|
|
MessageLoop::current()->PostDelayedTask(
|
|
|
|
FROM_HERE,
|
2014-10-29 08:05:36 -07:00
|
|
|
mChromeTaskFactory.NewRunnableMethod(
|
|
|
|
&PluginModuleChromeParent::CleanupFromTimeout, aFromHangUI), 10);
|
2012-10-15 03:29:47 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-24 18:10:02 -08:00
|
|
|
/* If the plugin container was terminated by the Plugin Hang UI,
|
|
|
|
then either the I/O thread detects a channel error, or the
|
|
|
|
main thread must set the error (whomever gets there first).
|
|
|
|
OTOH, if we terminate and return false from
|
|
|
|
ShouldContinueFromReplyTimeout, then the channel state has
|
|
|
|
already been set to ChannelTimeout and we should call the
|
|
|
|
regular Close function. */
|
|
|
|
if (aFromHangUI) {
|
|
|
|
GetIPCChannel()->CloseWithError();
|
|
|
|
} else {
|
|
|
|
Close();
|
|
|
|
}
|
2010-02-11 12:32:18 -08:00
|
|
|
}
|
|
|
|
|
2012-07-25 05:38:43 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
namespace {
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-07-25 05:38:43 -07:00
|
|
|
FileTimeToUTC(const FILETIME& ftime)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER li;
|
|
|
|
li.LowPart = ftime.dwLowDateTime;
|
|
|
|
li.HighPart = ftime.dwHighDateTime;
|
|
|
|
return li.QuadPart;
|
|
|
|
}
|
|
|
|
|
2012-08-09 03:36:30 -07:00
|
|
|
struct CpuUsageSamples
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t sampleTimes[2];
|
|
|
|
uint64_t cpuTimes[2];
|
2012-08-09 03:36:30 -07:00
|
|
|
};
|
|
|
|
|
2012-07-25 05:38:43 -07:00
|
|
|
bool
|
2012-08-09 03:36:30 -07:00
|
|
|
GetProcessCpuUsage(const InfallibleTArray<base::ProcessHandle>& processHandles, InfallibleTArray<float>& cpuUsage)
|
2012-07-25 05:38:43 -07:00
|
|
|
{
|
2012-08-09 03:36:30 -07:00
|
|
|
InfallibleTArray<CpuUsageSamples> samples(processHandles.Length());
|
2012-07-25 05:38:43 -07:00
|
|
|
FILETIME creationTime, exitTime, kernelTime, userTime, currentTime;
|
|
|
|
BOOL res;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < processHandles.Length(); ++i) {
|
2012-08-09 03:36:30 -07:00
|
|
|
::GetSystemTimeAsFileTime(¤tTime);
|
|
|
|
res = ::GetProcessTimes(processHandles[i], &creationTime, &exitTime, &kernelTime, &userTime);
|
|
|
|
if (!res) {
|
|
|
|
NS_WARNING("failed to get process times");
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-08 15:30:26 -07:00
|
|
|
|
2012-08-09 03:36:30 -07:00
|
|
|
CpuUsageSamples s;
|
|
|
|
s.sampleTimes[0] = FileTimeToUTC(currentTime);
|
|
|
|
s.cpuTimes[0] = FileTimeToUTC(kernelTime) + FileTimeToUTC(userTime);
|
|
|
|
samples.AppendElement(s);
|
|
|
|
}
|
2012-08-08 15:30:26 -07:00
|
|
|
|
2012-07-25 05:38:43 -07:00
|
|
|
// we already hung for a while, a little bit longer won't matter
|
|
|
|
::Sleep(50);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
const int32_t numberOfProcessors = PR_GetNumberOfProcessors();
|
2012-08-09 03:36:30 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < processHandles.Length(); ++i) {
|
2012-08-09 03:36:30 -07:00
|
|
|
::GetSystemTimeAsFileTime(¤tTime);
|
|
|
|
res = ::GetProcessTimes(processHandles[i], &creationTime, &exitTime, &kernelTime, &userTime);
|
|
|
|
if (!res) {
|
|
|
|
NS_WARNING("failed to get process times");
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-25 05:38:43 -07:00
|
|
|
|
2012-08-09 03:36:30 -07:00
|
|
|
samples[i].sampleTimes[1] = FileTimeToUTC(currentTime);
|
|
|
|
samples[i].cpuTimes[1] = FileTimeToUTC(kernelTime) + FileTimeToUTC(userTime);
|
2012-07-25 05:38:43 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint64_t deltaSampleTime = samples[i].sampleTimes[1] - samples[i].sampleTimes[0];
|
|
|
|
const uint64_t deltaCpuTime = samples[i].cpuTimes[1] - samples[i].cpuTimes[0];
|
2012-08-09 03:36:30 -07:00
|
|
|
const float usage = 100.f * (float(deltaCpuTime) / deltaSampleTime) / numberOfProcessors;
|
|
|
|
cpuUsage.AppendElement(usage);
|
|
|
|
}
|
2012-07-25 05:38:43 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
2013-01-04 14:59:05 -08:00
|
|
|
|
2014-10-21 10:48:08 -07:00
|
|
|
#endif // #ifdef XP_WIN
|
|
|
|
|
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::EnteredCxxStack()
|
2014-10-21 10:48:08 -07:00
|
|
|
{
|
|
|
|
mHangAnnotationFlags |= kInPluginCall;
|
|
|
|
}
|
|
|
|
|
2013-01-04 14:59:05 -08:00
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::ExitedCxxStack()
|
2013-01-04 14:59:05 -08:00
|
|
|
{
|
2014-10-21 10:48:08 -07:00
|
|
|
mHangAnnotationFlags = 0;
|
|
|
|
#ifdef XP_WIN
|
2013-01-04 14:59:05 -08:00
|
|
|
FinishHangUI();
|
2014-10-21 10:48:08 -07:00
|
|
|
#endif
|
2013-01-04 14:59:05 -08:00
|
|
|
}
|
|
|
|
|
2014-10-21 10:48:08 -07:00
|
|
|
/**
|
|
|
|
* This function is always called by the HangMonitor thread.
|
|
|
|
*/
|
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::AnnotateHang(mozilla::HangMonitor::HangAnnotations& aAnnotations)
|
2014-10-21 10:48:08 -07:00
|
|
|
{
|
|
|
|
uint32_t flags = mHangAnnotationFlags;
|
|
|
|
if (flags) {
|
|
|
|
/* We don't actually annotate anything specifically for kInPluginCall;
|
|
|
|
we use it to determine whether to annotate other things. It will
|
|
|
|
be pretty obvious from the ChromeHang stack that we're in a plugin
|
|
|
|
call when the hang occurred. */
|
|
|
|
if (flags & kHangUIShown) {
|
|
|
|
aAnnotations.AddAnnotation(NS_LITERAL_STRING("HangUIShown"),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
if (flags & kHangUIContinued) {
|
|
|
|
aAnnotations.AddAnnotation(NS_LITERAL_STRING("HangUIContinued"),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
if (flags & kHangUIDontShow) {
|
|
|
|
aAnnotations.AddAnnotation(NS_LITERAL_STRING("HangUIDontShow"),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
aAnnotations.AddAnnotation(NS_LITERAL_STRING("pluginName"), mPluginName);
|
|
|
|
aAnnotations.AddAnnotation(NS_LITERAL_STRING("pluginVersion"),
|
|
|
|
mPluginVersion);
|
|
|
|
}
|
|
|
|
}
|
2012-07-25 05:38:43 -07:00
|
|
|
|
2012-09-26 13:49:20 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
static bool
|
|
|
|
CreateFlashMinidump(DWORD processId, ThreadId childThread,
|
|
|
|
nsIFile* parentMinidump, const nsACString& name)
|
|
|
|
{
|
|
|
|
if (processId == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
base::ProcessHandle handle;
|
|
|
|
if (!base::OpenPrivilegedProcessHandle(processId, &handle)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool res = CreateAdditionalChildMinidump(handle, 0, parentMinidump, name);
|
|
|
|
base::CloseProcessHandle(handle);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-11 12:32:18 -08:00
|
|
|
bool
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::ShouldContinueFromReplyTimeout()
|
2010-02-11 12:32:18 -08:00
|
|
|
{
|
2013-01-04 14:59:05 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
if (LaunchHangUI()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// If LaunchHangUI returned false then we should proceed with the
|
|
|
|
// original plugin hang behaviour and kill the plugin container.
|
|
|
|
FinishHangUI();
|
|
|
|
#endif // XP_WIN
|
|
|
|
TerminateChildProcess(MessageLoop::current());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::TerminateChildProcess(MessageLoop* aMsgLoop)
|
2013-01-04 14:59:05 -08:00
|
|
|
{
|
2010-03-24 14:22:03 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2013-12-03 14:19:58 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
mozilla::MutexAutoLock lock(mCrashReporterMutex);
|
|
|
|
CrashReporterParent* crashReporter = mCrashReporter;
|
|
|
|
if (!crashReporter) {
|
|
|
|
// If mCrashReporter is null then the hang has ended, the plugin module
|
|
|
|
// is shutting down. There's nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#else
|
2012-07-10 19:20:05 -07:00
|
|
|
CrashReporterParent* crashReporter = CrashReporter();
|
2013-12-03 14:19:58 -08:00
|
|
|
#endif
|
2012-09-08 10:20:59 -07:00
|
|
|
crashReporter->AnnotateCrashReport(NS_LITERAL_CSTRING("PluginHang"),
|
|
|
|
NS_LITERAL_CSTRING("1"));
|
2013-01-04 14:59:05 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
if (mHangUIParent) {
|
|
|
|
unsigned int hangUIDuration = mHangUIParent->LastShowDurationMs();
|
|
|
|
if (hangUIDuration) {
|
|
|
|
nsPrintfCString strHangUIDuration("%u", hangUIDuration);
|
|
|
|
crashReporter->AnnotateCrashReport(
|
|
|
|
NS_LITERAL_CSTRING("PluginHangUIDuration"),
|
|
|
|
strHangUIDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // XP_WIN
|
2012-07-10 19:20:05 -07:00
|
|
|
if (crashReporter->GeneratePairedMinidump(this)) {
|
|
|
|
mPluginDumpID = crashReporter->ChildDumpID();
|
|
|
|
PLUGIN_LOG_DEBUG(
|
2012-09-08 10:20:59 -07:00
|
|
|
("generated paired browser/plugin minidumps: %s)",
|
|
|
|
NS_ConvertUTF16toUTF8(mPluginDumpID).get()));
|
|
|
|
|
2012-09-11 08:21:26 -07:00
|
|
|
nsAutoCString additionalDumps("browser");
|
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
nsCOMPtr<nsIFile> pluginDumpFile;
|
|
|
|
|
|
|
|
if (GetMinidumpForID(mPluginDumpID, getter_AddRefs(pluginDumpFile)) &&
|
|
|
|
pluginDumpFile) {
|
|
|
|
nsCOMPtr<nsIFile> childDumpFile;
|
|
|
|
|
2012-09-26 13:49:20 -07:00
|
|
|
if (CreateFlashMinidump(mFlashProcess1, 0, pluginDumpFile,
|
|
|
|
NS_LITERAL_CSTRING("flash1"))) {
|
2014-05-21 20:48:51 -07:00
|
|
|
additionalDumps.AppendLiteral(",flash1");
|
2012-09-11 08:21:26 -07:00
|
|
|
}
|
2012-09-26 13:49:20 -07:00
|
|
|
if (CreateFlashMinidump(mFlashProcess2, 0, pluginDumpFile,
|
|
|
|
NS_LITERAL_CSTRING("flash2"))) {
|
2014-05-21 20:48:51 -07:00
|
|
|
additionalDumps.AppendLiteral(",flash2");
|
2012-09-11 08:21:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-09-08 10:20:59 -07:00
|
|
|
crashReporter->AnnotateCrashReport(
|
|
|
|
NS_LITERAL_CSTRING("additional_minidumps"),
|
2012-09-11 08:21:26 -07:00
|
|
|
additionalDumps);
|
2012-07-10 19:20:05 -07:00
|
|
|
} else {
|
|
|
|
NS_WARNING("failed to capture paired minidumps from hang");
|
2010-03-24 14:22:03 -07:00
|
|
|
}
|
|
|
|
#endif
|
2010-02-11 12:32:18 -08:00
|
|
|
|
2012-07-25 05:38:43 -07:00
|
|
|
#ifdef XP_WIN
|
2012-08-09 03:36:30 -07:00
|
|
|
// collect cpu usage for plugin processes
|
|
|
|
|
|
|
|
InfallibleTArray<base::ProcessHandle> processHandles;
|
|
|
|
|
|
|
|
processHandles.AppendElement(OtherProcess());
|
2013-02-27 17:25:38 -08:00
|
|
|
|
2012-08-09 03:36:30 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
2013-02-27 17:25:38 -08:00
|
|
|
{
|
|
|
|
base::ProcessHandle handle;
|
|
|
|
if (mFlashProcess1 && base::OpenProcessHandle(mFlashProcess1, &handle)) {
|
|
|
|
processHandles.AppendElement(handle);
|
|
|
|
}
|
|
|
|
if (mFlashProcess2 && base::OpenProcessHandle(mFlashProcess2, &handle)) {
|
|
|
|
processHandles.AppendElement(handle);
|
|
|
|
}
|
2012-08-09 03:36:30 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!GetProcessCpuUsage(processHandles, mPluginCpuUsageOnHang)) {
|
|
|
|
mPluginCpuUsageOnHang.Clear();
|
2012-07-25 05:38:43 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-24 14:22:03 -07:00
|
|
|
// this must run before the error notification from the channel,
|
|
|
|
// or not at all
|
2013-01-24 18:10:02 -08:00
|
|
|
bool isFromHangUI = aMsgLoop != MessageLoop::current();
|
2013-09-23 10:34:00 -07:00
|
|
|
aMsgLoop->PostTask(
|
|
|
|
FROM_HERE,
|
2014-10-29 08:05:36 -07:00
|
|
|
mChromeTaskFactory.NewRunnableMethod(
|
|
|
|
&PluginModuleChromeParent::CleanupFromTimeout, isFromHangUI));
|
2010-03-24 14:22:03 -07:00
|
|
|
|
|
|
|
if (!KillProcess(OtherProcess(), 1, false))
|
|
|
|
NS_WARNING("failed to kill subprocess!");
|
2013-01-04 14:59:05 -08:00
|
|
|
}
|
2010-03-24 14:22:03 -07:00
|
|
|
|
2014-10-21 10:48:08 -07:00
|
|
|
bool
|
|
|
|
PluginModuleParent::GetPluginDetails(nsACString& aPluginName,
|
|
|
|
nsACString& aPluginVersion)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsPluginHost> host = nsPluginHost::GetInst();
|
|
|
|
if (!host) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsPluginTag* pluginTag = host->TagForPlugin(mPlugin);
|
|
|
|
if (!pluginTag) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aPluginName = pluginTag->mName;
|
|
|
|
aPluginVersion = pluginTag->mVersion;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-04 14:59:05 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::EvaluateHangUIState(const bool aReset)
|
2013-01-04 14:59:05 -08:00
|
|
|
{
|
|
|
|
int32_t minDispSecs = Preferences::GetInt(kHangUIMinDisplayPref, 10);
|
|
|
|
int32_t autoStopSecs = Preferences::GetInt(kChildTimeoutPref, 0);
|
|
|
|
int32_t timeoutSecs = 0;
|
|
|
|
if (autoStopSecs > 0 && autoStopSecs < minDispSecs) {
|
|
|
|
/* If we're going to automatically terminate the plugin within a
|
|
|
|
time frame shorter than minDispSecs, there's no point in
|
|
|
|
showing the hang UI; it would just flash briefly on the screen. */
|
|
|
|
mHangUIEnabled = false;
|
|
|
|
} else {
|
|
|
|
timeoutSecs = Preferences::GetInt(kHangUITimeoutPref, 0);
|
|
|
|
mHangUIEnabled = timeoutSecs > 0;
|
|
|
|
}
|
|
|
|
if (mHangUIEnabled) {
|
|
|
|
if (aReset) {
|
|
|
|
mIsTimerReset = true;
|
|
|
|
SetChildTimeout(timeoutSecs);
|
|
|
|
return;
|
|
|
|
} else if (mIsTimerReset) {
|
|
|
|
/* The Hang UI is being shown, so now we're setting the
|
|
|
|
timeout to kChildTimeoutPref while we wait for a user
|
|
|
|
response. ShouldContinueFromReplyTimeout will fire
|
|
|
|
after (reply timeout / 2) seconds, which is not what
|
|
|
|
we want. Doubling the timeout value here so that we get
|
|
|
|
the right result. */
|
|
|
|
autoStopSecs *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mIsTimerReset = false;
|
|
|
|
SetChildTimeout(autoStopSecs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::LaunchHangUI()
|
2013-01-04 14:59:05 -08:00
|
|
|
{
|
|
|
|
if (!mHangUIEnabled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (mHangUIParent) {
|
|
|
|
if (mHangUIParent->IsShowing()) {
|
|
|
|
// We've already shown the UI but the timeout has expired again.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (mHangUIParent->DontShowAgain()) {
|
2014-10-21 10:48:08 -07:00
|
|
|
mHangAnnotationFlags |= kHangUIDontShow;
|
|
|
|
bool wasLastHangStopped = mHangUIParent->WasLastHangStopped();
|
|
|
|
if (!wasLastHangStopped) {
|
|
|
|
mHangAnnotationFlags |= kHangUIContinued;
|
|
|
|
}
|
|
|
|
return !wasLastHangStopped;
|
2013-01-04 14:59:05 -08:00
|
|
|
}
|
|
|
|
delete mHangUIParent;
|
|
|
|
mHangUIParent = nullptr;
|
|
|
|
}
|
2013-02-12 12:05:39 -08:00
|
|
|
mHangUIParent = new PluginHangUIParent(this,
|
2013-04-11 14:08:55 -07:00
|
|
|
Preferences::GetInt(kHangUITimeoutPref, 0),
|
|
|
|
Preferences::GetInt(kChildTimeoutPref, 0));
|
2014-10-21 10:48:08 -07:00
|
|
|
bool retval = mHangUIParent->Init(NS_ConvertUTF8toUTF16(mPluginName));
|
2013-01-04 14:59:05 -08:00
|
|
|
if (retval) {
|
2014-10-21 10:48:08 -07:00
|
|
|
mHangAnnotationFlags |= kHangUIShown;
|
2013-01-04 14:59:05 -08:00
|
|
|
/* Once the UI is shown we switch the timeout over to use
|
|
|
|
kChildTimeoutPref, allowing us to terminate a hung plugin
|
|
|
|
after kChildTimeoutPref seconds if the user doesn't respond to
|
|
|
|
the hang UI. */
|
|
|
|
EvaluateHangUIState(false);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::FinishHangUI()
|
2013-01-04 14:59:05 -08:00
|
|
|
{
|
|
|
|
if (mHangUIEnabled && mHangUIParent) {
|
|
|
|
bool needsCancel = mHangUIParent->IsShowing();
|
|
|
|
// If we're still showing, send a Cancel notification
|
|
|
|
if (needsCancel) {
|
|
|
|
mHangUIParent->Cancel();
|
|
|
|
}
|
|
|
|
/* If we cancelled the UI or if the user issued a response,
|
|
|
|
we need to reset the child process timeout. */
|
|
|
|
if (needsCancel ||
|
2014-11-27 01:58:58 -08:00
|
|
|
(!mIsTimerReset && mHangUIParent->WasShown())) {
|
2013-01-04 14:59:05 -08:00
|
|
|
/* We changed the timeout to kChildTimeoutPref when the plugin hang
|
|
|
|
UI was displayed. Now that we're finishing the UI, we need to
|
|
|
|
switch it back to kHangUITimeoutPref. */
|
|
|
|
EvaluateHangUIState(true);
|
|
|
|
}
|
|
|
|
}
|
2010-02-11 12:32:18 -08:00
|
|
|
}
|
2014-10-21 10:48:08 -07:00
|
|
|
|
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::OnHangUIContinue()
|
2014-10-21 10:48:08 -07:00
|
|
|
{
|
|
|
|
mHangAnnotationFlags |= kHangUIContinued;
|
|
|
|
}
|
2013-01-04 14:59:05 -08:00
|
|
|
#endif // XP_WIN
|
2010-02-11 12:32:18 -08:00
|
|
|
|
2011-06-08 12:56:31 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
CrashReporterParent*
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::CrashReporter()
|
2011-06-08 12:56:31 -07:00
|
|
|
{
|
|
|
|
return static_cast<CrashReporterParent*>(ManagedPCrashReporterParent()[0]);
|
|
|
|
}
|
|
|
|
|
2012-08-07 00:06:29 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
2012-07-10 19:20:05 -07:00
|
|
|
static void
|
|
|
|
RemoveMinidump(nsIFile* minidump)
|
|
|
|
{
|
|
|
|
if (!minidump)
|
|
|
|
return;
|
|
|
|
|
|
|
|
minidump->Remove(false);
|
|
|
|
nsCOMPtr<nsIFile> extraFile;
|
|
|
|
if (GetExtraFileForMinidump(minidump,
|
|
|
|
getter_AddRefs(extraFile))) {
|
|
|
|
extraFile->Remove(true);
|
|
|
|
}
|
|
|
|
}
|
2012-08-07 00:06:29 -07:00
|
|
|
#endif // MOZ_CRASHREPORTER_INJECTOR
|
2012-07-10 19:20:05 -07:00
|
|
|
|
2009-12-03 12:31:52 -08:00
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::ProcessFirstMinidump()
|
2009-12-03 12:31:52 -08:00
|
|
|
{
|
2013-12-03 14:19:58 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
mozilla::MutexAutoLock lock(mCrashReporterMutex);
|
|
|
|
#endif
|
2012-07-10 19:20:05 -07:00
|
|
|
CrashReporterParent* crashReporter = CrashReporter();
|
|
|
|
if (!crashReporter)
|
|
|
|
return;
|
2011-06-08 12:56:31 -07:00
|
|
|
|
2013-09-02 01:41:57 -07:00
|
|
|
AnnotationTable notes(4);
|
2012-07-10 19:20:05 -07:00
|
|
|
WriteExtraDataForMinidump(notes);
|
2012-09-08 10:20:59 -07:00
|
|
|
|
|
|
|
if (!mPluginDumpID.IsEmpty()) {
|
|
|
|
crashReporter->GenerateChildData(¬es);
|
2012-07-10 19:20:05 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-27 23:57:33 -07:00
|
|
|
uint32_t sequence = UINT32_MAX;
|
2012-07-10 19:20:05 -07:00
|
|
|
nsCOMPtr<nsIFile> dumpFile;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString flashProcessType;
|
2012-07-10 19:20:05 -07:00
|
|
|
TakeMinidump(getter_AddRefs(dumpFile), &sequence);
|
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
nsCOMPtr<nsIFile> childDumpFile;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t childSequence;
|
2012-07-10 19:20:05 -07:00
|
|
|
|
|
|
|
if (mFlashProcess1 &&
|
|
|
|
TakeMinidumpForChild(mFlashProcess1,
|
|
|
|
getter_AddRefs(childDumpFile),
|
|
|
|
&childSequence)) {
|
|
|
|
if (childSequence < sequence) {
|
|
|
|
RemoveMinidump(dumpFile);
|
|
|
|
dumpFile = childDumpFile;
|
|
|
|
sequence = childSequence;
|
|
|
|
flashProcessType.AssignLiteral("Broker");
|
2012-07-03 04:49:23 -07:00
|
|
|
}
|
2012-07-10 19:20:05 -07:00
|
|
|
else {
|
|
|
|
RemoveMinidump(childDumpFile);
|
2012-07-03 04:49:23 -07:00
|
|
|
}
|
2012-07-10 19:20:05 -07:00
|
|
|
}
|
|
|
|
if (mFlashProcess2 &&
|
|
|
|
TakeMinidumpForChild(mFlashProcess2,
|
|
|
|
getter_AddRefs(childDumpFile),
|
|
|
|
&childSequence)) {
|
|
|
|
if (childSequence < sequence) {
|
|
|
|
RemoveMinidump(dumpFile);
|
|
|
|
dumpFile = childDumpFile;
|
|
|
|
sequence = childSequence;
|
|
|
|
flashProcessType.AssignLiteral("Sandbox");
|
2010-03-24 14:22:03 -07:00
|
|
|
}
|
2010-01-13 17:20:00 -08:00
|
|
|
else {
|
2012-07-10 19:20:05 -07:00
|
|
|
RemoveMinidump(childDumpFile);
|
2010-01-13 17:20:00 -08:00
|
|
|
}
|
2012-07-10 19:20:05 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!dumpFile) {
|
|
|
|
NS_WARNING("[PluginModuleParent::ActorDestroy] abnormal shutdown without minidump!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLUGIN_LOG_DEBUG(("got child minidump: %s",
|
|
|
|
NS_ConvertUTF16toUTF8(mPluginDumpID).get()));
|
|
|
|
|
|
|
|
GetIDFromMinidump(dumpFile, mPluginDumpID);
|
|
|
|
if (!flashProcessType.IsEmpty()) {
|
|
|
|
notes.Put(NS_LITERAL_CSTRING("FlashProcessDump"), flashProcessType);
|
|
|
|
}
|
|
|
|
crashReporter->GenerateCrashReportForMinidump(dumpFile, ¬es);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginModuleParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
switch (why) {
|
|
|
|
case AbnormalShutdown: {
|
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:
|
2014-02-28 15:39:17 -08:00
|
|
|
NS_RUNTIMEABORT("Unexpected shutdown reason for toplevel actor.");
|
2009-12-03 12:31:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
void
|
|
|
|
PluginModuleChromeParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
if (why == AbnormalShutdown) {
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
ProcessFirstMinidump();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-11-18 21:46:01 -08:00
|
|
|
// We can't broadcast settings changes anymore.
|
|
|
|
UnregisterSettingsCallbacks();
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleParent::ActorDestroy(why);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-09-09 15:59:06 -07:00
|
|
|
PPluginInstanceParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
PluginModuleParent::AllocPPluginInstanceParent(const nsCString& aMimeType,
|
|
|
|
const uint16_t& aMode,
|
|
|
|
const InfallibleTArray<nsCString>& aNames,
|
|
|
|
const InfallibleTArray<nsCString>& aValues,
|
|
|
|
NPError* rv)
|
2009-07-02 09:54:22 -07:00
|
|
|
{
|
2009-08-18 13:20:03 -07:00
|
|
|
NS_ERROR("Not reachable!");
|
2013-10-23 13:34:46 -07:00
|
|
|
return nullptr;
|
2009-07-02 09:54:22 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
PluginModuleParent::DeallocPPluginInstanceParent(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;
|
2012-07-30 07:20:58 -07:00
|
|
|
aFuncs->javaClass = nullptr;
|
2009-07-02 09:54:22 -07:00
|
|
|
|
2011-02-08 14:16:07 -08:00
|
|
|
// Gecko should always call these functions through a PluginLibrary object.
|
2013-10-23 13:34:46 -07:00
|
|
|
aFuncs->newp = nullptr;
|
|
|
|
aFuncs->clearsitedata = nullptr;
|
|
|
|
aFuncs->getsiteswithdata = nullptr;
|
2011-02-08 14:16:07 -08:00
|
|
|
|
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;
|
2013-10-23 13:34:46 -07:00
|
|
|
aFuncs->gotfocus = nullptr;
|
|
|
|
aFuncs->lostfocus = nullptr;
|
|
|
|
aFuncs->urlredirectnotify = nullptr;
|
2011-01-05 11:44:21 -08:00
|
|
|
|
2011-02-08 14:16:07 -08:00
|
|
|
// Provide 'NPP_URLRedirectNotify', 'NPP_ClearSiteData', and
|
|
|
|
// 'NPP_GetSitesWithData' functionality if it is supported by the plugin.
|
2011-01-05 11:44:21 -08:00
|
|
|
bool urlRedirectSupported = false;
|
2011-02-08 14:16:07 -08:00
|
|
|
unused << CallOptionalFunctionsSupported(&urlRedirectSupported,
|
|
|
|
&mClearSiteDataSupported,
|
|
|
|
&mGetSitesWithDataSupported);
|
2011-01-05 11:44:21 -08:00
|
|
|
if (urlRedirectSupported) {
|
|
|
|
aFuncs->urlredirectnotify = NPP_URLRedirectNotify;
|
|
|
|
}
|
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();
|
2012-07-30 07:20:58 -07:00
|
|
|
instance->pdata = nullptr;
|
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)
|
|
|
|
{
|
2014-05-23 14:12:29 -07:00
|
|
|
PROFILER_LABEL("PluginModuleParent", "NPP_NewStream",
|
|
|
|
js::ProfileEntry::Category::OTHER);
|
|
|
|
|
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
|
2012-04-12 03:21:24 -07:00
|
|
|
NS_ABORT_IF_FALSE(0 > mPluginXSocketFdDup.get(),
|
2010-11-08 18:48:59 -08:00
|
|
|
"Already backed up X resources??");
|
2012-04-12 03:21:24 -07:00
|
|
|
mPluginXSocketFdDup.forget();
|
2013-01-24 17:10:39 -08:00
|
|
|
if (aXSocketFd.IsValid()) {
|
|
|
|
mPluginXSocketFdDup.reset(aXSocketFd.PlatformHandle());
|
|
|
|
}
|
2010-11-08 18:48:59 -08:00
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-05 11:44:21 -08:00
|
|
|
void
|
|
|
|
PluginModuleParent::NPP_URLRedirectNotify(NPP instance, const char* url,
|
|
|
|
int32_t status, void* notifyData)
|
|
|
|
{
|
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return;
|
|
|
|
|
|
|
|
i->NPP_URLRedirectNotify(url, status, notifyData);
|
|
|
|
}
|
|
|
|
|
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,
|
2013-10-23 13:34:46 -07:00
|
|
|
// instance->pdata will be nullptr.
|
2009-12-03 12:31:01 -08:00
|
|
|
if (!ip)
|
2013-10-23 13:34:46 -07:00
|
|
|
return nullptr;
|
2009-12-03 12:31:01 -08:00
|
|
|
|
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)
|
2013-10-23 13:34:46 -07:00
|
|
|
return nullptr;
|
2009-12-03 12:31:01 -08:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-02-12 08:07:10 -08:00
|
|
|
nsresult
|
2012-02-08 07:34:27 -08:00
|
|
|
PluginModuleParent::GetImageContainer(NPP instance,
|
|
|
|
mozilla::layers::ImageContainer** aContainer)
|
2011-02-12 08:07:10 -08:00
|
|
|
{
|
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
2012-02-08 07:34:27 -08:00
|
|
|
return !i ? NS_ERROR_FAILURE : i->GetImageContainer(aContainer);
|
2011-02-12 08:07:10 -08:00
|
|
|
}
|
|
|
|
|
2011-02-22 21:38:09 -08:00
|
|
|
nsresult
|
|
|
|
PluginModuleParent::GetImageSize(NPP instance,
|
|
|
|
nsIntSize* aSize)
|
|
|
|
{
|
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
return !i ? NS_ERROR_FAILURE : i->GetImageSize(aSize);
|
|
|
|
}
|
|
|
|
|
2011-02-16 14:43:31 -08:00
|
|
|
nsresult
|
|
|
|
PluginModuleParent::SetBackgroundUnknown(NPP instance)
|
|
|
|
{
|
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return i->SetBackgroundUnknown();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PluginModuleParent::BeginUpdateBackground(NPP instance,
|
|
|
|
const nsIntRect& aRect,
|
|
|
|
gfxContext** aCtx)
|
|
|
|
{
|
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return i->BeginUpdateBackground(aRect, aCtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PluginModuleParent::EndUpdateBackground(NPP instance,
|
|
|
|
gfxContext* aCtx,
|
|
|
|
const nsIntRect& aRect)
|
|
|
|
{
|
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return i->EndUpdateBackground(aCtx, aRect);
|
|
|
|
}
|
|
|
|
|
2014-11-18 21:46:01 -08:00
|
|
|
class OfflineObserver MOZ_FINAL : public nsIObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
explicit OfflineObserver(PluginModuleChromeParent* pmp)
|
|
|
|
: mPmp(pmp)
|
|
|
|
{}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~OfflineObserver() {}
|
|
|
|
PluginModuleChromeParent* mPmp;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(OfflineObserver, nsIObserver)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineObserver::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
|
|
|
const char16_t *aData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!strcmp(aTopic, "ipc:network:set-offline"));
|
|
|
|
mPmp->CachedSettingChanged();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* kSettingsPrefs[] =
|
|
|
|
{"javascript.enabled",
|
|
|
|
"dom.ipc.plugins.nativeCursorSupport"};
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginModuleChromeParent::RegisterSettingsCallbacks()
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < ArrayLength(kSettingsPrefs); i++) {
|
|
|
|
Preferences::RegisterCallback(CachedSettingChanged, kSettingsPrefs[i], this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
mOfflineObserver = new OfflineObserver(this);
|
|
|
|
observerService->AddObserver(mOfflineObserver, "ipc:network:set-offline", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginModuleChromeParent::UnregisterSettingsCallbacks()
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < ArrayLength(kSettingsPrefs); i++) {
|
|
|
|
Preferences::UnregisterCallback(CachedSettingChanged, kSettingsPrefs[i], this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
observerService->RemoveObserver(mOfflineObserver, "ipc:network:set-offline");
|
|
|
|
mOfflineObserver = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginModuleParent::GetSetting(NPNVariable aVariable)
|
|
|
|
{
|
|
|
|
NPBool boolVal = false;
|
|
|
|
mozilla::plugins::parent::_getvalue(nullptr, aVariable, &boolVal);
|
|
|
|
return boolVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginModuleParent::GetSettings(PluginSettings* aSettings)
|
|
|
|
{
|
|
|
|
aSettings->javascriptEnabled() = GetSetting(NPNVjavascriptEnabledBool);
|
|
|
|
aSettings->asdEnabled() = GetSetting(NPNVasdEnabledBool);
|
|
|
|
aSettings->isOffline() = GetSetting(NPNVisOfflineBool);
|
|
|
|
aSettings->supportsXembed() = GetSetting(NPNVSupportsXEmbedBool);
|
|
|
|
aSettings->supportsWindowless() = GetSetting(NPNVSupportsWindowless);
|
|
|
|
aSettings->userAgent() = NullableString(mNPNIface->uagent(nullptr));
|
|
|
|
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
aSettings->nativeCursorsSupported() =
|
|
|
|
Preferences::GetBool("dom.ipc.plugins.nativeCursorSupport", false);
|
|
|
|
#else
|
|
|
|
// Need to initialize this to satisfy IPDL.
|
|
|
|
aSettings->nativeCursorsSupported() = false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginModuleChromeParent::CachedSettingChanged()
|
|
|
|
{
|
|
|
|
PluginSettings settings;
|
|
|
|
GetSettings(&settings);
|
|
|
|
unused << SendSettingChanged(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
PluginModuleChromeParent::CachedSettingChanged(const char* aPref, void* aModule)
|
|
|
|
{
|
|
|
|
PluginModuleChromeParent *module = static_cast<PluginModuleChromeParent*>(aModule);
|
|
|
|
module->CachedSettingChanged();
|
|
|
|
}
|
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX) && !defined(MOZ_WIDGET_GONK)
|
2009-10-27 12:51:12 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
*error = NPERR_NO_ERROR;
|
|
|
|
if (IsChrome()) {
|
2014-11-18 21:46:01 -08:00
|
|
|
PluginSettings settings;
|
|
|
|
GetSettings(&settings);
|
|
|
|
if (!CallNP_Initialize(settings, error)) {
|
2014-10-29 08:05:36 -07:00
|
|
|
Close();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
else if (*error != NPERR_NO_ERROR) {
|
|
|
|
Close();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-10-27 12:51:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SetPluginFuncs(pFuncs);
|
2011-01-05 11:44:21 -08:00
|
|
|
|
2009-10-27 12:51:12 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
*error = NPERR_NO_ERROR;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PluginModuleChromeParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error)
|
|
|
|
{
|
|
|
|
nsresult rv = PluginModuleParent::NP_Initialize(bFuncs, error);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2014-11-18 21:46:01 -08:00
|
|
|
PluginSettings settings;
|
|
|
|
GetSettings(&settings);
|
|
|
|
if (!CallNP_Initialize(settings, error)) {
|
2014-02-28 15:39:17 -08:00
|
|
|
Close();
|
2009-11-20 07:34:20 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2013-07-19 07:02:47 -07:00
|
|
|
}
|
|
|
|
if (*error != NPERR_NO_ERROR) {
|
2014-02-28 15:39:17 -08:00
|
|
|
Close();
|
2013-07-19 07:02:47 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-10-27 12:51:12 -07:00
|
|
|
|
2012-02-22 16:33:19 -08:00
|
|
|
#if defined XP_WIN
|
2011-06-24 07:20:03 -07:00
|
|
|
// Send the info needed to join the chrome process's audio session to the
|
|
|
|
// plugin process
|
|
|
|
nsID id;
|
|
|
|
nsString sessionName;
|
|
|
|
nsString iconPath;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mozilla::widget::GetAudioSessionData(id, sessionName,
|
|
|
|
iconPath)))
|
2012-05-16 01:48:45 -07:00
|
|
|
unused << SendSetAudioSessionData(id, sessionName, iconPath);
|
2011-06-24 07:20:03 -07:00
|
|
|
#endif
|
|
|
|
|
2012-07-03 04:49:23 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
InitializeInjector();
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
bool ok = true;
|
|
|
|
if (IsChrome()) {
|
|
|
|
ok = CallNP_Shutdown(error);
|
|
|
|
}
|
2009-12-03 00:16:28 -08:00
|
|
|
|
2013-09-30 17:27:45 -07:00
|
|
|
// if NP_Shutdown() is nested within another interrupt call, this will
|
2009-12-03 00:16:28 -08:00
|
|
|
// 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)
|
|
|
|
{
|
2012-10-29 16:32:10 -07:00
|
|
|
PR_LOG(GetPluginLog(), PR_LOG_WARNING, ("%s Not implemented, requested variable %i", __FUNCTION__,
|
2009-12-18 14:22:51 -08:00
|
|
|
(int) aVariable));
|
2009-10-27 12:51:12 -07:00
|
|
|
|
|
|
|
//TODO: implement this correctly
|
|
|
|
*error = NPERR_GENERIC_ERROR;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-10 14:57:01 -08:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX)
|
2009-10-27 12:51:12 -07:00
|
|
|
nsresult
|
|
|
|
PluginModuleParent::NP_GetEntryPoints(NPPluginFuncs* pFuncs, NPError* error)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(pFuncs, "Null pointer!");
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
// We need to have the plugin process update its function table here by
|
|
|
|
// actually calling NP_GetEntryPoints. The parent's function table will
|
|
|
|
// reflect nullptr entries in the child's table once SetPluginFuncs is
|
|
|
|
// called.
|
|
|
|
|
|
|
|
if (IsChrome()) {
|
|
|
|
if (!CallNP_GetEntryPoints(error)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
else if (*error != NPERR_NO_ERROR) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-01-05 11:44:21 -08:00
|
|
|
}
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
*error = NPERR_NO_ERROR;
|
2009-10-27 12:51:12 -07:00
|
|
|
SetPluginFuncs(pFuncs);
|
2011-01-05 11:44:21 -08:00
|
|
|
|
2009-10-27 12:51:12 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-21 10:48:08 -07:00
|
|
|
if (mPluginName.IsEmpty()) {
|
|
|
|
GetPluginDetails(mPluginName, mPluginVersion);
|
|
|
|
}
|
|
|
|
|
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.
|
2012-07-30 07:20:58 -07:00
|
|
|
instance->pdata = nullptr;
|
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
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
UpdatePluginTimeout();
|
|
|
|
|
2009-10-27 12:51:12 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
void
|
|
|
|
PluginModuleChromeParent::UpdatePluginTimeout()
|
|
|
|
{
|
|
|
|
TimeoutChanged(kParentTimeoutPref, this);
|
|
|
|
}
|
|
|
|
|
2011-02-08 14:16:07 -08:00
|
|
|
nsresult
|
|
|
|
PluginModuleParent::NPP_ClearSiteData(const char* site, uint64_t flags,
|
|
|
|
uint64_t maxAge)
|
|
|
|
{
|
|
|
|
if (!mClearSiteDataSupported)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
NPError result;
|
|
|
|
if (!CallNPP_ClearSiteData(NullableString(site), flags, maxAge, &result))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case NPERR_NO_ERROR:
|
|
|
|
return NS_OK;
|
|
|
|
case NPERR_TIME_RANGE_NOT_SUPPORTED:
|
|
|
|
return NS_ERROR_PLUGIN_TIME_RANGE_NOT_SUPPORTED;
|
|
|
|
case NPERR_MALFORMED_SITE:
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PluginModuleParent::NPP_GetSitesWithData(InfallibleTArray<nsCString>& result)
|
|
|
|
{
|
|
|
|
if (!mGetSitesWithDataSupported)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
if (!CallNPP_GetSitesWithData(&result))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-30 09:46:26 -07:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
PluginModuleParent::IsRemoteDrawingCoreAnimation(NPP instance, bool *aDrawing)
|
2011-06-30 09:46:26 -07:00
|
|
|
{
|
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return i->IsRemoteDrawingCoreAnimation(aDrawing);
|
|
|
|
}
|
2012-10-16 12:41:21 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
PluginModuleParent::ContentsScaleFactorChanged(NPP instance, double aContentsScaleFactor)
|
|
|
|
{
|
|
|
|
PluginInstanceParent* i = InstCast(instance);
|
|
|
|
if (!i)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return i->ContentsScaleFactorChanged(aContentsScaleFactor);
|
|
|
|
}
|
|
|
|
#endif // #if defined(XP_MACOSX)
|
2011-06-30 09:46:26 -07:00
|
|
|
|
2010-06-01 20:58:00 -07:00
|
|
|
#if defined(MOZ_WIDGET_QT)
|
|
|
|
bool
|
|
|
|
PluginModuleParent::AnswerProcessSomeEvents()
|
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("Spinning mini nested loop ..."));
|
2014-11-19 22:02:51 -08:00
|
|
|
PluginHelperQt::AnswerProcessSomeEvents();
|
2010-06-01 20:58:00 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-06-27 17:15:32 -07:00
|
|
|
#elif !defined(MOZ_WIDGET_GTK)
|
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)
|
2013-10-23 13:34:46 -07:00
|
|
|
if (!g_main_context_iteration(nullptr, FALSE))
|
2010-03-10 23:35:29 -08:00
|
|
|
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
|
2013-09-30 17:27:45 -07:00
|
|
|
PluginModuleParent::RecvProcessNativeEventsInInterruptCall()
|
2010-04-30 11:42:51 -07:00
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("%s", FULLFUNCTION));
|
|
|
|
#if defined(OS_WIN)
|
2013-09-30 17:27:45 -07:00
|
|
|
ProcessNativeEventsInInterruptCall();
|
2010-04-30 11:42:51 -07:00
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_NOTREACHED(
|
2013-09-30 17:27:45 -07:00
|
|
|
"PluginModuleParent::RecvProcessNativeEventsInInterruptCall not implemented!");
|
2010-08-13 09:45:50 -07:00
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-05-18 04:57:08 -07:00
|
|
|
void
|
2013-09-30 17:27:45 -07:00
|
|
|
PluginModuleParent::ProcessRemoteNativeEventsInInterruptCall()
|
2011-05-18 04:57:08 -07:00
|
|
|
{
|
|
|
|
#if defined(OS_WIN)
|
2013-09-30 17:27:45 -07:00
|
|
|
unused << SendProcessNativeEventsInInterruptCall();
|
2011-05-18 04:57:08 -07:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
NS_NOTREACHED(
|
2013-09-30 17:27:45 -07:00
|
|
|
"PluginModuleParent::ProcessRemoteNativeEventsInInterruptCall not implemented!");
|
2011-05-18 04:57:08 -07:00
|
|
|
}
|
|
|
|
|
2010-08-13 09:45:50 -07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2011-06-08 12:56:31 -07:00
|
|
|
PCrashReporterParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
PluginModuleParent::AllocPCrashReporterParent(mozilla::dom::NativeThreadId* id,
|
|
|
|
uint32_t* processType)
|
2014-10-29 08:05:36 -07:00
|
|
|
{
|
|
|
|
MOZ_CRASH("unreachable");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginModuleParent::DeallocPCrashReporterParent(PCrashReporterParent* actor)
|
|
|
|
{
|
|
|
|
MOZ_CRASH("unreachable");
|
|
|
|
}
|
|
|
|
|
|
|
|
PCrashReporterParent*
|
|
|
|
PluginModuleChromeParent::AllocPCrashReporterParent(mozilla::dom::NativeThreadId* id,
|
|
|
|
uint32_t* processType)
|
2011-06-08 12:56:31 -07:00
|
|
|
{
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
return new CrashReporterParent();
|
|
|
|
#else
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-06-08 12:56:31 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::DeallocPCrashReporterParent(PCrashReporterParent* actor)
|
2011-06-08 12:56:31 -07:00
|
|
|
{
|
2013-12-04 05:20:41 -08:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2013-12-03 14:19:58 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
mozilla::MutexAutoLock lock(mCrashReporterMutex);
|
|
|
|
if (actor == static_cast<PCrashReporterParent*>(mCrashReporter)) {
|
|
|
|
mCrashReporter = nullptr;
|
|
|
|
}
|
2013-12-04 05:20:41 -08:00
|
|
|
#endif
|
2013-12-03 14:19:58 -08:00
|
|
|
#endif
|
2011-06-08 12:56:31 -07:00
|
|
|
delete actor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-23 23:58:28 -07:00
|
|
|
bool
|
|
|
|
PluginModuleParent::RecvSetCursor(const NSCursorInfo& aCursorInfo)
|
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("%s", FULLFUNCTION));
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
mac_plugin_interposing::parent::OnSetCursor(aCursorInfo);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_NOTREACHED(
|
|
|
|
"PluginInstanceParent::RecvSetCursor not implemented!");
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginModuleParent::RecvShowCursor(const bool& aShow)
|
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("%s", FULLFUNCTION));
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
mac_plugin_interposing::parent::OnShowCursor(aShow);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_NOTREACHED(
|
|
|
|
"PluginInstanceParent::RecvShowCursor not implemented!");
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginModuleParent::RecvPushCursor(const NSCursorInfo& aCursorInfo)
|
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("%s", FULLFUNCTION));
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
mac_plugin_interposing::parent::OnPushCursor(aCursorInfo);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_NOTREACHED(
|
|
|
|
"PluginInstanceParent::RecvPushCursor not implemented!");
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginModuleParent::RecvPopCursor()
|
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("%s", FULLFUNCTION));
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
mac_plugin_interposing::parent::OnPopCursor();
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_NOTREACHED(
|
|
|
|
"PluginInstanceParent::RecvPopCursor not implemented!");
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-07-26 09:55:58 -07:00
|
|
|
bool
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleParent::RecvNPN_SetException(const nsCString& aMessage)
|
2011-07-26 09:55:58 -07:00
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("%s", FULLFUNCTION));
|
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
// This function ignores its first argument.
|
|
|
|
mozilla::plugins::parent::_setexception(nullptr, NullableStringGet(aMessage));
|
2011-07-26 09:55:58 -07:00
|
|
|
return true;
|
|
|
|
}
|
2012-05-30 07:23:03 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
PluginModuleParent::RecvNPN_ReloadPlugins(const bool& aReloadPages)
|
|
|
|
{
|
|
|
|
PLUGIN_LOG_DEBUG(("%s", FULLFUNCTION));
|
|
|
|
|
|
|
|
mozilla::plugins::parent::_reloadplugins(aReloadPages);
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-03 04:49:23 -07:00
|
|
|
|
2014-10-29 08:05:36 -07:00
|
|
|
bool
|
|
|
|
PluginModuleChromeParent::RecvNotifyContentModuleDestroyed()
|
|
|
|
{
|
|
|
|
nsRefPtr<nsPluginHost> host = nsPluginHost::GetInst();
|
|
|
|
if (host) {
|
|
|
|
host->NotifyContentModuleDestroyed(mPluginId);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-03 04:49:23 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
|
|
|
|
// We only add the crash reporter to subprocess which have the filename
|
|
|
|
// FlashPlayerPlugin*
|
|
|
|
#define FLASH_PROCESS_PREFIX "FLASHPLAYERPLUGIN"
|
|
|
|
|
|
|
|
static DWORD
|
|
|
|
GetFlashChildOfPID(DWORD pid, HANDLE snapshot)
|
|
|
|
{
|
|
|
|
PROCESSENTRY32 entry = {
|
|
|
|
sizeof(entry)
|
|
|
|
};
|
|
|
|
for (BOOL ok = Process32First(snapshot, &entry);
|
|
|
|
ok;
|
|
|
|
ok = Process32Next(snapshot, &entry)) {
|
|
|
|
if (entry.th32ParentProcessID == pid) {
|
|
|
|
nsString name(entry.szExeFile);
|
|
|
|
ToUpperCase(name);
|
|
|
|
if (StringBeginsWith(name, NS_LITERAL_STRING(FLASH_PROCESS_PREFIX))) {
|
|
|
|
return entry.th32ProcessID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We only look for child processes of the Flash plugin, NPSWF*
|
|
|
|
#define FLASH_PLUGIN_PREFIX "NPSWF"
|
|
|
|
|
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::InitializeInjector()
|
2012-07-03 04:49:23 -07:00
|
|
|
{
|
|
|
|
if (!Preferences::GetBool("dom.ipc.plugins.flash.subprocess.crashreporter.enabled", false))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCString path(Process()->GetPluginFilePath().c_str());
|
|
|
|
ToUpperCase(path);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t lastSlash = path.RFindCharInSet("\\/");
|
2012-07-03 04:49:23 -07:00
|
|
|
if (kNotFound == lastSlash)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!StringBeginsWith(Substring(path, lastSlash + 1),
|
|
|
|
NS_LITERAL_CSTRING(FLASH_PLUGIN_PREFIX)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
|
|
if (INVALID_HANDLE_VALUE == snapshot)
|
|
|
|
return;
|
|
|
|
|
|
|
|
DWORD pluginProcessPID = GetProcessId(Process()->GetChildProcessHandle());
|
|
|
|
mFlashProcess1 = GetFlashChildOfPID(pluginProcessPID, snapshot);
|
|
|
|
if (mFlashProcess1) {
|
|
|
|
InjectCrashReporterIntoProcess(mFlashProcess1, this);
|
|
|
|
|
|
|
|
mFlashProcess2 = GetFlashChildOfPID(mFlashProcess1, snapshot);
|
|
|
|
if (mFlashProcess2) {
|
|
|
|
InjectCrashReporterIntoProcess(mFlashProcess2, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::OnCrash(DWORD processID)
|
2012-07-03 04:49:23 -07:00
|
|
|
{
|
2012-10-04 09:58:42 -07:00
|
|
|
if (!mShutdown) {
|
|
|
|
GetIPCChannel()->CloseWithError();
|
|
|
|
KillProcess(OtherProcess(), 1, false);
|
|
|
|
}
|
2012-07-03 04:49:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MOZ_CRASHREPORTER_INJECTOR
|
2013-03-21 02:17:23 -07:00
|
|
|
|
2013-04-27 07:20:23 -07:00
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
2013-03-21 02:17:23 -07:00
|
|
|
class PluginProfilerObserver MOZ_FINAL : public nsIObserver,
|
|
|
|
public nsSupportsWeakReference
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
explicit PluginProfilerObserver(PluginModuleParent* pmp)
|
|
|
|
: mPmp(pmp)
|
|
|
|
{}
|
|
|
|
|
|
|
|
private:
|
2014-06-23 12:56:07 -07:00
|
|
|
~PluginProfilerObserver() {}
|
2013-03-21 02:17:23 -07:00
|
|
|
PluginModuleParent* mPmp;
|
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(PluginProfilerObserver, nsIObserver, nsISupportsWeakReference)
|
2013-03-21 02:17:23 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PluginProfilerObserver::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *aData)
|
2013-03-21 02:17:23 -07:00
|
|
|
{
|
2014-11-18 09:50:25 -08:00
|
|
|
if (!strcmp(aTopic, "profiler-started")) {
|
|
|
|
nsCOMPtr<nsIProfilerStartParams> params(do_QueryInterface(aSubject));
|
|
|
|
uint32_t entries;
|
|
|
|
double interval;
|
|
|
|
params->GetEntries(&entries);
|
|
|
|
params->GetInterval(&interval);
|
|
|
|
const nsTArray<nsCString>& features = params->GetFeatures();
|
|
|
|
const nsTArray<nsCString>& threadFilterNames = params->GetThreadFilterNames();
|
|
|
|
unused << mPmp->SendStartProfiler(entries, interval, features, threadFilterNames);
|
|
|
|
} else if (!strcmp(aTopic, "profiler-stopped")) {
|
|
|
|
unused << mPmp->SendStopProfiler();
|
|
|
|
} else if (!strcmp(aTopic, "profiler-subprocess")) {
|
|
|
|
nsCOMPtr<nsIProfileSaveEvent> pse = do_QueryInterface(aSubject);
|
|
|
|
if (pse) {
|
|
|
|
nsCString result;
|
|
|
|
bool success = mPmp->CallGetProfile(&result);
|
|
|
|
if (success && !result.IsEmpty()) {
|
|
|
|
pse->AddSubProfile(result.get());
|
|
|
|
}
|
|
|
|
}
|
2013-03-21 02:17:23 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::InitPluginProfiling()
|
2013-03-21 02:17:23 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
mProfilerObserver = new PluginProfilerObserver(this);
|
2014-11-18 09:50:25 -08:00
|
|
|
observerService->AddObserver(mProfilerObserver, "profiler-started", false);
|
|
|
|
observerService->AddObserver(mProfilerObserver, "profiler-stopped", false);
|
2013-03-21 02:17:23 -07:00
|
|
|
observerService->AddObserver(mProfilerObserver, "profiler-subprocess", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-29 08:05:36 -07:00
|
|
|
PluginModuleChromeParent::ShutdownPluginProfiling()
|
2013-03-21 02:17:23 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
2014-11-18 09:50:25 -08:00
|
|
|
observerService->RemoveObserver(mProfilerObserver, "profiler-started");
|
|
|
|
observerService->RemoveObserver(mProfilerObserver, "profiler-stopped");
|
2013-03-21 02:17:23 -07:00
|
|
|
observerService->RemoveObserver(mProfilerObserver, "profiler-subprocess");
|
|
|
|
}
|
|
|
|
}
|
2013-04-27 07:20:23 -07:00
|
|
|
#endif
|