2004-04-11 09:33:17 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2009-10-22 03:01:16 +04:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2013-04-24 22:42:40 +04:00
|
|
|
/* This must occur *after* layers/PLayerTransaction.h to avoid typedefs
|
|
|
|
* conflicts. */
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2013-07-12 00:21:45 +04:00
|
|
|
#include "pratom.h"
|
2009-06-30 22:51:05 +04:00
|
|
|
#include "prenv.h"
|
2010-03-04 08:02:55 +03:00
|
|
|
|
2011-10-04 18:06:54 +04:00
|
|
|
#include "jsfriendapi.h"
|
2010-03-04 08:02:55 +03:00
|
|
|
|
2011-05-21 17:28:54 +04:00
|
|
|
#include "nsPluginHost.h"
|
2008-09-15 16:45:01 +04:00
|
|
|
#include "nsNPAPIPlugin.h"
|
|
|
|
#include "nsNPAPIPluginInstance.h"
|
|
|
|
#include "nsNPAPIPluginStreamListener.h"
|
2012-06-05 17:58:39 +04:00
|
|
|
#include "nsPluginStreamListenerPeer.h"
|
1999-07-08 00:18:27 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2007-07-12 03:25:45 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2018-05-10 08:04:12 +03:00
|
|
|
#include "mozilla/CycleCollectedJSContext.h" // for nsAutoMicroTask
|
2012-04-04 08:09:20 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-10-03 06:43:18 +04:00
|
|
|
#include "nsPluginInstanceOwner.h"
|
2001-10-16 07:35:52 +04:00
|
|
|
|
1999-07-08 00:18:27 +04:00
|
|
|
#include "nsPluginsDir.h"
|
2001-08-16 06:59:03 +04:00
|
|
|
#include "nsPluginLogging.h"
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-05-23 01:42:44 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2011-09-14 20:22:27 +04:00
|
|
|
#include "nsIContent.h"
|
2016-10-03 15:43:47 +03:00
|
|
|
#include "nsIIDNService.h"
|
2002-10-05 06:57:21 +04:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
2004-07-12 19:53:22 +04:00
|
|
|
#include "nsIScriptContext.h"
|
2006-06-13 07:07:47 +04:00
|
|
|
#include "nsDOMJSUtils.h"
|
2008-01-15 03:51:29 +03:00
|
|
|
#include "nsIPrincipal.h"
|
2010-08-15 13:10:15 +04:00
|
|
|
#include "nsWildCard.h"
|
2011-09-14 20:22:27 +04:00
|
|
|
#include "nsContentUtils.h"
|
2018-04-27 06:37:34 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-06-26 15:08:49 +04:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2018-04-27 06:37:34 +03:00
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
2014-12-12 21:24:24 +03:00
|
|
|
#include "nsIXULRuntime.h"
|
2004-07-12 19:53:22 +04:00
|
|
|
#include "nsIXPConnect.h"
|
2002-10-05 06:57:21 +04:00
|
|
|
|
2008-04-24 03:24:21 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include <prinrval.h>
|
|
|
|
|
2011-06-25 19:25:03 +04:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2008-09-11 19:10:26 +04:00
|
|
|
# include <Carbon/Carbon.h>
|
2010-04-22 03:57:22 +04:00
|
|
|
# include <ApplicationServices/ApplicationServices.h>
|
|
|
|
# include <OpenGL/OpenGL.h>
|
2012-01-10 04:11:04 +04:00
|
|
|
# include "nsCocoaFeatures.h"
|
2014-12-11 17:44:07 +03:00
|
|
|
# include "PluginUtilsOSX.h"
|
1999-07-08 00:18:27 +04:00
|
|
|
#endif
|
|
|
|
|
2008-09-11 19:10:26 +04:00
|
|
|
// needed for nppdf plugin
|
2012-06-28 04:15:32 +04:00
|
|
|
#if (MOZ_WIDGET_GTK)
|
2002-09-03 18:45:02 +04:00
|
|
|
# include <gdk/gdk.h>
|
|
|
|
# include <gdk/gdkx.h>
|
2012-06-28 04:15:32 +04:00
|
|
|
#endif
|
2002-09-03 18:45:02 +04:00
|
|
|
|
2014-03-09 22:35:52 +04:00
|
|
|
#include "nsJSUtils.h"
|
2004-07-12 19:53:22 +04:00
|
|
|
#include "nsJSNPRuntime.h"
|
2009-01-13 03:55:52 +03:00
|
|
|
#include "nsIHttpAuthManager.h"
|
|
|
|
#include "nsICookieService.h"
|
2012-04-24 08:49:25 +04:00
|
|
|
#include "nsILoadContext.h"
|
|
|
|
#include "nsIDocShell.h"
|
2002-09-03 18:45:02 +04:00
|
|
|
|
2010-11-19 23:58:59 +03:00
|
|
|
#include "nsNetUtil.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsNetCID.h"
|
2010-11-19 23:58:59 +03:00
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2009-10-27 22:51:12 +03:00
|
|
|
#include "mozilla/PluginLibrary.h"
|
|
|
|
using mozilla::PluginLibrary;
|
2009-07-25 02:21:07 +04:00
|
|
|
|
2009-09-09 10:31:35 +04:00
|
|
|
#include "mozilla/plugins/PluginModuleParent.h"
|
2014-10-29 18:05:36 +03:00
|
|
|
using mozilla::plugins::PluginModuleChromeParent;
|
|
|
|
using mozilla::plugins::PluginModuleContentParent;
|
2009-06-30 22:51:05 +04:00
|
|
|
|
2010-06-22 00:35:49 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
# include "mozilla/X11Util.h"
|
|
|
|
#endif
|
|
|
|
|
2011-02-19 15:16:51 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
# include <windows.h>
|
2013-10-18 22:14:31 +04:00
|
|
|
# include "mozilla/WindowsVersion.h"
|
2012-10-02 17:24:51 +04:00
|
|
|
# ifdef ACCESSIBILITY
|
|
|
|
# include "mozilla/a11y/Compatibility.h"
|
|
|
|
# endif
|
2011-02-19 15:16:51 +03:00
|
|
|
#endif
|
|
|
|
|
2015-07-29 00:09:48 +03:00
|
|
|
#include "nsIAudioChannelAgent.h"
|
2016-05-03 04:52:44 +03:00
|
|
|
#include "AudioChannelService.h"
|
2015-07-29 00:09:48 +03:00
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
using namespace mozilla;
|
2010-03-26 02:45:33 +03:00
|
|
|
using namespace mozilla::plugins::parent;
|
2019-01-02 16:05:23 +03:00
|
|
|
using mozilla::dom::Document;
|
2010-03-26 02:45:33 +03:00
|
|
|
|
|
|
|
// We should make this const...
|
|
|
|
static NPNetscapeFuncs sBrowserFuncs = {
|
|
|
|
sizeof(sBrowserFuncs),
|
|
|
|
(NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR,
|
|
|
|
_geturl,
|
|
|
|
_posturl,
|
|
|
|
_requestread,
|
2018-02-20 12:47:57 +03:00
|
|
|
nullptr, // _newstream, unimplemented
|
|
|
|
nullptr, // _write, unimplemented
|
|
|
|
nullptr, // _destroystream, unimplemented
|
2010-03-26 02:45:33 +03:00
|
|
|
_status,
|
|
|
|
_useragent,
|
|
|
|
_memalloc,
|
|
|
|
_memfree,
|
|
|
|
_memflush,
|
|
|
|
_reloadplugins,
|
2018-06-20 22:42:39 +03:00
|
|
|
_getJavaEnv,
|
|
|
|
_getJavaPeer,
|
2010-03-26 02:45:33 +03:00
|
|
|
_geturlnotify,
|
|
|
|
_posturlnotify,
|
|
|
|
_getvalue,
|
|
|
|
_setvalue,
|
|
|
|
_invalidaterect,
|
|
|
|
_invalidateregion,
|
|
|
|
_forceredraw,
|
|
|
|
_getstringidentifier,
|
|
|
|
_getstringidentifiers,
|
|
|
|
_getintidentifier,
|
|
|
|
_identifierisstring,
|
|
|
|
_utf8fromidentifier,
|
|
|
|
_intfromidentifier,
|
|
|
|
_createobject,
|
|
|
|
_retainobject,
|
|
|
|
_releaseobject,
|
|
|
|
_invoke,
|
|
|
|
_invokeDefault,
|
|
|
|
_evaluate,
|
|
|
|
_getproperty,
|
|
|
|
_setproperty,
|
|
|
|
_removeproperty,
|
|
|
|
_hasproperty,
|
|
|
|
_hasmethod,
|
|
|
|
_releasevariantvalue,
|
|
|
|
_setexception,
|
|
|
|
_pushpopupsenabledstate,
|
|
|
|
_poppopupsenabledstate,
|
|
|
|
_enumerate,
|
2017-08-03 15:12:51 +03:00
|
|
|
nullptr, // pluginthreadasynccall, not used
|
2010-03-26 02:45:33 +03:00
|
|
|
_construct,
|
|
|
|
_getvalueforurl,
|
|
|
|
_setvalueforurl,
|
2017-04-13 14:57:08 +03:00
|
|
|
nullptr, // NPN GetAuthenticationInfo, not supported
|
2010-03-26 02:45:33 +03:00
|
|
|
_scheduletimer,
|
|
|
|
_unscheduletimer,
|
|
|
|
_popupcontextmenu,
|
2010-11-09 18:26:44 +03:00
|
|
|
_convertpoint,
|
2013-10-24 00:34:30 +04:00
|
|
|
nullptr, // handleevent, unimplemented
|
|
|
|
nullptr, // unfocusinstance, unimplemented
|
2015-12-02 22:31:16 +03:00
|
|
|
_urlredirectresponse,
|
|
|
|
_initasyncsurface,
|
|
|
|
_finalizeasyncsurface,
|
|
|
|
_setcurrentasyncsurface};
|
2010-03-26 02:45:33 +03:00
|
|
|
|
2002-03-13 07:24:45 +03:00
|
|
|
// POST/GET stream type
|
|
|
|
enum eNPPStreamTypeInternal {
|
|
|
|
eNPPStreamTypeInternal_Get,
|
|
|
|
eNPPStreamTypeInternal_Post
|
|
|
|
};
|
|
|
|
|
2016-10-15 03:03:05 +03:00
|
|
|
void NS_NotifyBeginPluginCall(NSPluginCallReentry aReentryState) {
|
2013-02-27 15:50:27 +04:00
|
|
|
nsNPAPIPluginInstance::BeginPluginCall(aReentryState);
|
2012-12-07 03:58:14 +04:00
|
|
|
}
|
|
|
|
|
2016-10-15 03:03:05 +03:00
|
|
|
void NS_NotifyPluginCall(NSPluginCallReentry aReentryState) {
|
2013-02-27 15:50:27 +04:00
|
|
|
nsNPAPIPluginInstance::EndPluginCall(aReentryState);
|
2008-04-24 03:24:21 +04:00
|
|
|
}
|
|
|
|
|
2010-04-08 02:14:54 +04:00
|
|
|
nsNPAPIPlugin::nsNPAPIPlugin() {
|
2019-05-01 11:47:10 +03:00
|
|
|
memset((void*)&mPluginFuncs, 0, sizeof(mPluginFuncs));
|
2010-02-01 00:41:26 +03:00
|
|
|
mPluginFuncs.size = sizeof(mPluginFuncs);
|
2010-12-03 08:20:59 +03:00
|
|
|
mPluginFuncs.version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
|
2002-11-06 04:24:57 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mLibrary = nullptr;
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2009-07-13 06:44:48 +04:00
|
|
|
nsNPAPIPlugin::~nsNPAPIPlugin() {
|
2010-02-01 00:41:26 +03:00
|
|
|
delete mLibrary;
|
2012-07-30 18:20:58 +04:00
|
|
|
mLibrary = nullptr;
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void nsNPAPIPlugin::PluginCrashed(const nsAString& pluginDumpID,
|
|
|
|
const nsAString& browserDumpID) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPluginHost> host = nsPluginHost::GetInst();
|
2010-03-25 00:22:04 +03:00
|
|
|
host->PluginCrashed(this, pluginDumpID, browserDumpID);
|
2009-12-16 23:08:45 +03:00
|
|
|
}
|
2009-07-25 02:21:07 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
inline PluginLibrary* GetNewPluginLibrary(nsPluginTag* aPluginTag) {
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
AUTO_PROFILER_LABEL("GetNewPluginLibrary", OTHER);
|
2016-01-15 13:38:03 +03:00
|
|
|
|
2010-09-16 08:57:13 +04:00
|
|
|
if (!aPluginTag) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-09-16 08:57:13 +04:00
|
|
|
}
|
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
2015-09-01 02:04:25 +03:00
|
|
|
return PluginModuleContentParent::LoadModule(aPluginTag->mId, aPluginTag);
|
2014-10-29 18:05:36 +03:00
|
|
|
}
|
|
|
|
|
2017-11-02 13:03:24 +03:00
|
|
|
return PluginModuleChromeParent::LoadModule(aPluginTag->mFullPath.get(),
|
|
|
|
aPluginTag->mId, aPluginTag);
|
2009-07-25 02:21:07 +04:00
|
|
|
}
|
|
|
|
|
2010-04-08 02:14:54 +04:00
|
|
|
// Creates an nsNPAPIPlugin object. One nsNPAPIPlugin object exists per plugin
|
|
|
|
// (not instance).
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsNPAPIPlugin::CreatePlugin(nsPluginTag* aPluginTag,
|
|
|
|
nsNPAPIPlugin** aResult) {
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
AUTO_PROFILER_LABEL("nsNPAPIPlugin::CreatePlugin", OTHER);
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2010-09-16 08:57:13 +04:00
|
|
|
if (!aPluginTag) {
|
2010-08-18 04:05:48 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsNPAPIPlugin> plugin = new nsNPAPIPlugin();
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
PluginLibrary* pluginLib = GetNewPluginLibrary(aPluginTag);
|
2010-04-08 02:14:54 +04:00
|
|
|
if (!pluginLib) {
|
2002-03-26 06:04:37 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-07-19 00:25:40 +03:00
|
|
|
#if defined(XP_MACOSX)
|
2010-04-08 02:14:54 +04:00
|
|
|
if (!pluginLib->HasRequiredFunctions()) {
|
|
|
|
NS_WARNING(
|
|
|
|
"Not all necessary functions exposed by plugin, it will not load.");
|
2014-02-26 03:55:07 +04:00
|
|
|
delete pluginLib;
|
2001-08-16 06:59:03 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-04-08 02:14:54 +04:00
|
|
|
#endif
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2010-04-08 02:14:54 +04:00
|
|
|
plugin->mLibrary = pluginLib;
|
|
|
|
pluginLib->SetPlugin(plugin);
|
2002-04-03 03:36:06 +04:00
|
|
|
|
2010-04-08 02:14:54 +04:00
|
|
|
// Exchange NPAPI entry points.
|
2014-02-11 02:57:01 +04:00
|
|
|
#if defined(XP_WIN)
|
2010-04-08 02:14:54 +04:00
|
|
|
// NP_GetEntryPoints must be called before NP_Initialize on Windows.
|
2014-11-27 02:13:49 +03:00
|
|
|
NPError pluginCallError;
|
|
|
|
nsresult rv =
|
|
|
|
pluginLib->NP_GetEntryPoints(&plugin->mPluginFuncs, &pluginCallError);
|
2010-04-08 02:14:54 +04:00
|
|
|
if (rv != NS_OK || pluginCallError != NPERR_NO_ERROR) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2002-04-03 03:36:06 +04:00
|
|
|
}
|
2005-03-23 03:37:58 +03:00
|
|
|
|
2010-04-08 02:14:54 +04:00
|
|
|
// NP_Initialize must be called after NP_GetEntryPoints on Windows.
|
|
|
|
rv = pluginLib->NP_Initialize(&sBrowserFuncs, &pluginCallError);
|
|
|
|
if (rv != NS_OK || pluginCallError != NPERR_NO_ERROR) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2002-04-03 03:36:06 +04:00
|
|
|
}
|
2010-04-08 02:14:54 +04:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
// NP_Initialize must be called before NP_GetEntryPoints on Mac OS X.
|
|
|
|
// We need to match WebKit's behavior.
|
2014-11-27 02:13:49 +03:00
|
|
|
NPError pluginCallError;
|
|
|
|
nsresult rv = pluginLib->NP_Initialize(&sBrowserFuncs, &pluginCallError);
|
2010-04-08 02:14:54 +04:00
|
|
|
if (rv != NS_OK || pluginCallError != NPERR_NO_ERROR) {
|
2001-07-03 05:56:28 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2008-12-15 20:29:44 +03:00
|
|
|
|
2010-04-08 02:14:54 +04:00
|
|
|
rv = pluginLib->NP_GetEntryPoints(&plugin->mPluginFuncs, &pluginCallError);
|
|
|
|
if (rv != NS_OK || pluginCallError != NPERR_NO_ERROR) {
|
2001-08-16 06:59:03 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-04-08 02:14:54 +04:00
|
|
|
}
|
|
|
|
#else
|
2014-11-27 02:13:49 +03:00
|
|
|
NPError pluginCallError;
|
|
|
|
nsresult rv = pluginLib->NP_Initialize(&sBrowserFuncs, &plugin->mPluginFuncs,
|
|
|
|
&pluginCallError);
|
2010-04-08 02:14:54 +04:00
|
|
|
if (rv != NS_OK || pluginCallError != NPERR_NO_ERROR) {
|
2001-08-16 06:59:03 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-04-08 02:14:54 +04:00
|
|
|
}
|
2001-06-29 11:24:12 +04:00
|
|
|
#endif
|
|
|
|
|
2014-03-15 23:00:15 +04:00
|
|
|
plugin.forget(aResult);
|
2001-08-16 06:59:03 +04:00
|
|
|
return NS_OK;
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
PluginLibrary* nsNPAPIPlugin::GetLibrary() { return mLibrary; }
|
2010-07-20 06:11:26 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPPluginFuncs* nsNPAPIPlugin::PluginFuncs() { return &mPluginFuncs; }
|
2010-07-20 06:11:26 +04:00
|
|
|
|
2010-02-01 00:41:26 +03:00
|
|
|
nsresult nsNPAPIPlugin::Shutdown() {
|
2005-03-23 03:34:39 +03:00
|
|
|
NPP_PLUGIN_LOG(PLUGIN_LOG_BASIC,
|
|
|
|
("NPP Shutdown to be called: this=%p\n", this));
|
2001-08-16 06:59:03 +04:00
|
|
|
|
2009-10-27 22:51:12 +03:00
|
|
|
NPError shutdownError;
|
2010-02-01 00:41:26 +03:00
|
|
|
mLibrary->NP_Shutdown(&shutdownError);
|
2011-04-29 00:02:35 +04:00
|
|
|
|
1999-07-08 00:18:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsNPAPIPlugin::RetainStream(NPStream* pstream,
|
|
|
|
nsISupports** aRetainedPeer) {
|
2011-10-19 18:46:24 +04:00
|
|
|
if (!aRetainedPeer) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2013-10-24 00:34:30 +04:00
|
|
|
*aRetainedPeer = nullptr;
|
2011-10-19 18:46:24 +04:00
|
|
|
|
|
|
|
if (!pstream || !pstream->ndata) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIStreamWrapper* streamWrapper =
|
|
|
|
static_cast<nsNPAPIStreamWrapper*>(pstream->ndata);
|
|
|
|
nsNPAPIPluginStreamListener* listener = streamWrapper->GetStreamListener();
|
2012-05-18 03:54:26 +04:00
|
|
|
if (!listener) {
|
2012-07-30 13:24:36 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2012-05-18 03:54:26 +04:00
|
|
|
}
|
2011-10-19 18:46:24 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIStreamListener* streamListener = listener->GetStreamListenerPeer();
|
2012-06-05 17:58:39 +04:00
|
|
|
if (!streamListener) {
|
2012-07-30 13:24:36 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2012-06-05 17:58:39 +04:00
|
|
|
}
|
2011-10-19 18:46:24 +04:00
|
|
|
|
2012-06-05 17:58:39 +04:00
|
|
|
*aRetainedPeer = streamListener;
|
2011-10-19 18:46:24 +04:00
|
|
|
NS_ADDREF(*aRetainedPeer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-03-23 03:34:39 +03:00
|
|
|
// Create a new NPP GET or POST (given in the type argument) url
|
|
|
|
// stream that may have a notify callback
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError MakeNewNPAPIStreamInternal(NPP npp, const char* relativeURL,
|
|
|
|
const char* target,
|
2008-09-15 16:45:01 +04:00
|
|
|
eNPPStreamTypeInternal type,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool bDoNotify = false,
|
2019-05-01 11:47:10 +03:00
|
|
|
void* notifyData = nullptr, uint32_t len = 0,
|
|
|
|
const char* buf = nullptr) {
|
2005-03-23 03:34:39 +03:00
|
|
|
if (!npp) return NPERR_INVALID_INSTANCE_ERROR;
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
PluginDestructionGuard guard(npp);
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)npp->ndata;
|
2000-06-14 03:16:05 +04:00
|
|
|
if (!inst || !inst->IsRunning()) return NPERR_INVALID_INSTANCE_ERROR;
|
|
|
|
|
2011-05-21 17:28:54 +04:00
|
|
|
nsCOMPtr<nsIPluginHost> pluginHostCOM =
|
|
|
|
do_GetService(MOZ_PLUGIN_HOST_CONTRACTID);
|
2019-05-01 11:47:10 +03:00
|
|
|
nsPluginHost* pluginHost = static_cast<nsPluginHost*>(pluginHostCOM.get());
|
2011-05-21 17:28:54 +04:00
|
|
|
if (!pluginHost) {
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsNPAPIPluginStreamListener> listener;
|
2010-10-11 23:41:11 +04:00
|
|
|
// Set aCallNotify here to false. If pluginHost->GetURL or PostURL fail,
|
|
|
|
// the listener's destructor will do the notification while we are about to
|
|
|
|
// return a failure code.
|
2014-04-01 16:29:25 +04:00
|
|
|
// Call SetCallNotify(true) below after we are sure we cannot return a failure
|
2010-10-11 23:41:11 +04:00
|
|
|
// code.
|
2011-01-05 22:44:21 +03:00
|
|
|
if (!target) {
|
|
|
|
inst->NewStreamListener(relativeURL, notifyData, getter_AddRefs(listener));
|
|
|
|
if (listener) {
|
2012-05-18 03:54:26 +04:00
|
|
|
listener->SetCallNotify(false);
|
2011-01-05 22:44:21 +03:00
|
|
|
}
|
|
|
|
}
|
2002-03-13 07:24:45 +03:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case eNPPStreamTypeInternal_Get: {
|
2011-04-12 00:00:30 +04:00
|
|
|
if (NS_FAILED(pluginHost->GetURL(inst, relativeURL, target, listener,
|
2013-10-24 00:34:30 +04:00
|
|
|
nullptr, nullptr, false)))
|
2002-03-13 07:24:45 +03:00
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eNPPStreamTypeInternal_Post: {
|
2017-04-12 17:28:50 +03:00
|
|
|
if (NS_FAILED(pluginHost->PostURL(inst, relativeURL, len, buf, target,
|
2013-10-24 00:34:30 +04:00
|
|
|
listener, nullptr, nullptr, false, 0,
|
|
|
|
nullptr)))
|
2002-03-13 07:24:45 +03:00
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2009-08-14 18:09:00 +04:00
|
|
|
NS_ERROR("how'd I get here");
|
2002-03-13 07:24:45 +03:00
|
|
|
}
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2010-10-11 23:41:11 +04:00
|
|
|
if (listener) {
|
|
|
|
// SetCallNotify(bDoNotify) here, see comment above.
|
2012-05-18 03:54:26 +04:00
|
|
|
listener->SetCallNotify(bDoNotify);
|
2010-10-11 23:41:11 +04:00
|
|
|
}
|
|
|
|
|
2002-03-13 07:24:45 +03:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2000-06-14 03:16:05 +04:00
|
|
|
|
2017-08-30 10:53:10 +03:00
|
|
|
#if defined(MOZ_MEMORY) && defined(XP_WIN)
|
2019-05-01 11:47:10 +03:00
|
|
|
extern "C" size_t malloc_usable_size(const void* ptr);
|
2009-12-02 00:27:13 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
static char* gNPPException;
|
2009-12-02 00:27:13 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
static Document* GetDocumentFromNPP(NPP npp) {
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(npp, nullptr);
|
2009-12-02 00:27:13 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)npp->ndata;
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(inst, nullptr);
|
2009-12-02 00:27:13 +03:00
|
|
|
|
|
|
|
PluginDestructionGuard guard(inst);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPluginInstanceOwner> owner = inst->GetOwner();
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(owner, nullptr);
|
2009-12-02 00:27:13 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> doc;
|
2009-12-02 00:27:13 +03:00
|
|
|
owner->GetDocument(getter_AddRefs(doc));
|
|
|
|
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
static NPIdentifier doGetIdentifier(JSContext* cx, const NPUTF8* name) {
|
2009-12-02 00:27:13 +03:00
|
|
|
NS_ConvertUTF8toUTF16 utf16name(name);
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
JSString* str =
|
2015-06-30 17:58:31 +03:00
|
|
|
::JS_AtomizeAndPinUCStringN(cx, utf16name.get(), utf16name.Length());
|
2009-12-02 00:27:13 +03:00
|
|
|
|
2013-10-24 00:34:30 +04:00
|
|
|
if (!str) return nullptr;
|
2009-12-02 00:27:13 +03:00
|
|
|
|
2011-05-17 23:15:12 +04:00
|
|
|
return StringToNPIdentifier(cx, str);
|
2009-12-02 00:27:13 +03:00
|
|
|
}
|
|
|
|
|
2017-08-30 10:53:10 +03:00
|
|
|
#if defined(MOZ_MEMORY) && defined(XP_WIN)
|
2009-12-02 00:27:13 +03:00
|
|
|
BOOL InHeap(HANDLE hHeap, LPVOID lpMem) {
|
|
|
|
BOOL success = FALSE;
|
|
|
|
PROCESS_HEAP_ENTRY he;
|
2013-10-24 00:34:30 +04:00
|
|
|
he.lpData = nullptr;
|
2009-12-02 00:27:13 +03:00
|
|
|
while (HeapWalk(hHeap, &he) != 0) {
|
|
|
|
if (he.lpData == lpMem) {
|
|
|
|
success = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapUnlock(hHeap);
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} /* anonymous namespace */
|
|
|
|
|
|
|
|
NPPExceptionAutoHolder::NPPExceptionAutoHolder()
|
|
|
|
: mOldException(gNPPException) {
|
2012-07-30 18:20:58 +04:00
|
|
|
gNPPException = nullptr;
|
2009-12-02 00:27:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NPPExceptionAutoHolder::~NPPExceptionAutoHolder() {
|
|
|
|
NS_ASSERTION(!gNPPException, "NPP exception not properly cleared!");
|
|
|
|
|
|
|
|
gNPPException = mOldException;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NPP NPPStack::sCurrentNPP = nullptr;
|
2009-12-02 00:27:13 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* PeekException() { return gNPPException; }
|
2009-12-02 00:27:13 +03:00
|
|
|
|
|
|
|
void PopException() {
|
|
|
|
NS_ASSERTION(gNPPException, "Uh, no NPP exception to pop!");
|
|
|
|
|
|
|
|
if (gNPPException) {
|
|
|
|
free(gNPPException);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
gNPPException = nullptr;
|
2009-12-02 00:27:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-13 07:24:45 +03:00
|
|
|
//
|
|
|
|
// Static callbacks that get routed back through the new C++ API
|
|
|
|
//
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2009-12-02 00:27:13 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace plugins {
|
|
|
|
namespace parent {
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError _geturl(NPP npp, const char* relativeURL, const char* target) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_geturl called from the wrong thread\n"));
|
|
|
|
return NPERR_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
|
2005-03-23 03:34:39 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPN_GetURL: npp=%p, target=%s, url=%s\n",
|
2019-05-01 11:47:10 +03:00
|
|
|
(void*)npp, target, relativeURL));
|
2000-06-14 03:16:05 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
PluginDestructionGuard guard(npp);
|
|
|
|
|
2008-09-15 16:45:01 +04:00
|
|
|
return MakeNewNPAPIStreamInternal(npp, relativeURL, target,
|
|
|
|
eNPPStreamTypeInternal_Get);
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError _geturlnotify(NPP npp, const char* relativeURL, const char* target,
|
|
|
|
void* notifyData) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_geturlnotify called from the wrong thread\n"));
|
|
|
|
return NPERR_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
|
2005-03-23 03:37:58 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
|
2005-03-23 03:34:39 +03:00
|
|
|
("NPN_GetURLNotify: npp=%p, target=%s, notify=%p, url=%s\n",
|
2019-05-01 11:47:10 +03:00
|
|
|
(void*)npp, target, notifyData, relativeURL));
|
2001-08-16 06:59:03 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
PluginDestructionGuard guard(npp);
|
|
|
|
|
2008-09-15 16:45:01 +04:00
|
|
|
return MakeNewNPAPIStreamInternal(
|
2011-09-30 10:02:59 +04:00
|
|
|
npp, relativeURL, target, eNPPStreamTypeInternal_Get, true, notifyData);
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError _posturlnotify(NPP npp, const char* relativeURL, const char* target,
|
|
|
|
uint32_t len, const char* buf, NPBool file,
|
|
|
|
void* notifyData) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_posturlnotify called from the wrong thread\n"));
|
|
|
|
return NPERR_INVALID_PARAM;
|
|
|
|
}
|
2009-11-25 17:26:01 +03:00
|
|
|
if (!buf) return NPERR_INVALID_PARAM;
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
|
|
|
|
("NPN_PostURLNotify: npp=%p, target=%s, len=%d, file=%d, "
|
|
|
|
"notify=%p, url=%s, buf=%s\n",
|
|
|
|
(void*)npp, target, len, file, notifyData, relativeURL, buf));
|
2005-03-23 03:34:39 +03:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
PluginDestructionGuard guard(npp);
|
|
|
|
|
2008-09-15 16:45:01 +04:00
|
|
|
return MakeNewNPAPIStreamInternal(npp, relativeURL, target,
|
2011-09-30 10:02:59 +04:00
|
|
|
eNPPStreamTypeInternal_Post, true,
|
2017-04-12 17:28:50 +03:00
|
|
|
notifyData, len, buf);
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError _posturl(NPP npp, const char* relativeURL, const char* target,
|
|
|
|
uint32_t len, const char* buf, NPBool file) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_posturl called from the wrong thread\n"));
|
|
|
|
return NPERR_INVALID_PARAM;
|
|
|
|
}
|
2001-08-16 06:59:03 +04:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
|
2005-03-23 03:34:39 +03:00
|
|
|
("NPN_PostURL: npp=%p, target=%s, file=%d, len=%d, url=%s, "
|
|
|
|
"buf=%s\n",
|
2019-05-01 11:47:10 +03:00
|
|
|
(void*)npp, target, file, len, relativeURL, buf));
|
2001-08-16 06:59:03 +04:00
|
|
|
|
2009-12-02 00:27:13 +03:00
|
|
|
PluginDestructionGuard guard(npp);
|
|
|
|
|
|
|
|
return MakeNewNPAPIStreamInternal(npp, relativeURL, target,
|
2012-07-30 18:20:58 +04:00
|
|
|
eNPPStreamTypeInternal_Post, false, nullptr,
|
2017-04-12 17:28:50 +03:00
|
|
|
len, buf);
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void _status(NPP npp, const char* message) {
|
2015-06-14 08:50:03 +03:00
|
|
|
// NPN_Status is no longer supported.
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void _memfree(void* ptr) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_memfree called from the wrong thread\n"));
|
|
|
|
}
|
2001-08-16 06:59:03 +04:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY, ("NPN_MemFree: ptr=%p\n", ptr));
|
|
|
|
|
2015-03-27 03:01:12 +03:00
|
|
|
if (ptr) free(ptr);
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2008-09-11 19:10:26 +04:00
|
|
|
uint32_t _memflush(uint32_t size) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_memflush called from the wrong thread\n"));
|
|
|
|
}
|
2001-08-16 06:59:03 +04:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY, ("NPN_MemFlush: size=%d\n", size));
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2011-09-30 10:02:59 +04:00
|
|
|
nsMemory::HeapMinimize(true);
|
2001-08-16 06:59:03 +04:00
|
|
|
return 0;
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2000-11-14 00:40:27 +03:00
|
|
|
void _reloadplugins(NPBool reloadPages) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_reloadplugins called from the wrong thread\n"));
|
|
|
|
return;
|
|
|
|
}
|
2005-03-23 03:34:39 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
|
|
|
|
("NPN_ReloadPlugins: reloadPages=%d\n", reloadPages));
|
2000-06-14 03:16:05 +04:00
|
|
|
|
2009-06-26 01:06:54 +04:00
|
|
|
nsCOMPtr<nsIPluginHost> pluginHost(do_GetService(MOZ_PLUGIN_HOST_CONTRACTID));
|
|
|
|
if (!pluginHost) return;
|
2000-06-14 03:16:05 +04:00
|
|
|
|
2013-04-24 00:02:12 +04:00
|
|
|
pluginHost->ReloadPlugins();
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void _invalidaterect(NPP npp, NPRect* invalidRect) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_invalidaterect called from the wrong thread\n"));
|
|
|
|
return;
|
|
|
|
}
|
2001-08-16 06:59:03 +04:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
|
2005-03-23 03:34:39 +03:00
|
|
|
("NPN_InvalidateRect: npp=%p, top=%d, left=%d, bottom=%d, "
|
|
|
|
"right=%d\n",
|
2019-05-01 11:47:10 +03:00
|
|
|
(void*)npp, invalidRect->top, invalidRect->left,
|
2005-03-23 03:34:39 +03:00
|
|
|
invalidRect->bottom, invalidRect->right));
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2005-03-23 03:34:39 +03:00
|
|
|
if (!npp || !npp->ndata) {
|
2002-09-19 00:21:47 +04:00
|
|
|
NS_WARNING("_invalidaterect: npp or npp->ndata == 0");
|
2001-08-16 06:59:03 +04:00
|
|
|
return;
|
2002-09-19 00:21:47 +04:00
|
|
|
}
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)npp->ndata;
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
PluginDestructionGuard guard(inst);
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
inst->InvalidateRect((NPRect*)invalidRect);
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2000-11-14 00:40:27 +03:00
|
|
|
void _invalidateregion(NPP npp, NPRegion invalidRegion) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_invalidateregion called from the wrong thread\n"));
|
|
|
|
return;
|
|
|
|
}
|
2001-08-16 06:59:03 +04:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
|
2019-05-01 11:47:10 +03:00
|
|
|
("NPN_InvalidateRegion: npp=%p, region=%p\n", (void*)npp,
|
|
|
|
(void*)invalidRegion));
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2005-03-23 03:34:39 +03:00
|
|
|
if (!npp || !npp->ndata) {
|
2002-09-19 00:21:47 +04:00
|
|
|
NS_WARNING("_invalidateregion: npp or npp->ndata == 0");
|
2001-08-16 06:59:03 +04:00
|
|
|
return;
|
2002-09-19 00:21:47 +04:00
|
|
|
}
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)npp->ndata;
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
PluginDestructionGuard guard(inst);
|
|
|
|
|
2009-09-17 05:30:26 +04:00
|
|
|
inst->InvalidateRegion((NPRegion)invalidRegion);
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2000-11-14 00:40:27 +03:00
|
|
|
void _forceredraw(NPP npp) {}
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPObject* _getwindowobject(NPP npp) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_getwindowobject called from the wrong thread\n"));
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-03-30 19:23:21 +04:00
|
|
|
}
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2013-05-23 01:42:44 +04:00
|
|
|
// The window want to return here is the outer window, *not* the inner (since
|
2005-08-12 08:11:00 +04:00
|
|
|
// we don't know what the plugin will do with it).
|
2019-05-01 11:47:10 +03:00
|
|
|
Document* doc = GetDocumentFromNPP(npp);
|
2013-05-23 01:42:44 +04:00
|
|
|
NS_ENSURE_TRUE(doc, nullptr);
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> outer = doc->GetWindow();
|
2013-05-23 01:42:44 +04:00
|
|
|
NS_ENSURE_TRUE(outer, nullptr);
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
JS::Rooted<JSObject*> windowProxy(
|
2018-08-04 16:30:40 +03:00
|
|
|
dom::RootingCx(), nsGlobalWindowOuter::Cast(outer)->GetGlobalJSObject());
|
2019-05-01 11:47:10 +03:00
|
|
|
JS::Rooted<JSObject*> global(dom::RootingCx(),
|
|
|
|
JS::GetNonCCWObjectGlobal(windowProxy));
|
2018-08-04 16:30:40 +03:00
|
|
|
return nsJSObjWrapper::GetNewOrUsed(npp, windowProxy, global);
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPObject* _getpluginelement(NPP npp) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_getpluginelement called from the wrong thread\n"));
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-03-30 19:23:21 +04:00
|
|
|
}
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = static_cast<nsNPAPIPluginInstance*>(npp->ndata);
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!inst) return nullptr;
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2018-04-27 06:37:34 +03:00
|
|
|
RefPtr<dom::Element> element;
|
2009-09-10 22:11:30 +04:00
|
|
|
inst->GetDOMElement(getter_AddRefs(element));
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!element) return nullptr;
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
Document* doc = GetDocumentFromNPP(npp);
|
2014-06-26 15:08:49 +04:00
|
|
|
if (NS_WARN_IF(!doc)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom::AutoJSAPI jsapi;
|
|
|
|
if (NS_WARN_IF(!jsapi.Init(doc->GetInnerWindow()))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-05-01 11:47:10 +03:00
|
|
|
JSContext* cx = jsapi.cx();
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2018-09-06 17:01:58 +03:00
|
|
|
nsCOMPtr<nsIXPConnect> xpc(nsIXPConnect::XPConnect());
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(xpc, nullptr);
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2018-04-27 06:37:34 +03:00
|
|
|
JS::RootedValue val(cx);
|
|
|
|
if (!ToJSValue(cx, element, &val)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!val.isObject())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::RootedObject obj(cx, &val.toObject());
|
2018-08-04 16:30:40 +03:00
|
|
|
JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx));
|
|
|
|
return nsJSObjWrapper::GetNewOrUsed(npp, obj, global);
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPIdentifier _getstringidentifier(const NPUTF8* name) {
|
2008-03-30 18:55:42 +04:00
|
|
|
if (!name) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_getstringidentifier: passed null name"));
|
2013-10-24 00:34:30 +04:00
|
|
|
return nullptr;
|
2008-03-30 18:55:42 +04:00
|
|
|
}
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_getstringidentifier called from the wrong thread\n"));
|
|
|
|
}
|
2008-03-30 18:55:42 +04:00
|
|
|
|
2013-05-06 17:04:17 +04:00
|
|
|
AutoSafeJSContext cx;
|
2004-07-12 19:53:22 +04:00
|
|
|
return doGetIdentifier(cx, name);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void _getstringidentifiers(const NPUTF8** names, int32_t nameCount,
|
|
|
|
NPIdentifier* identifiers) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_getstringidentifiers called from the wrong thread\n"));
|
|
|
|
}
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2013-05-06 17:04:17 +04:00
|
|
|
AutoSafeJSContext cx;
|
2006-06-13 02:39:55 +04:00
|
|
|
|
2004-07-12 19:53:22 +04:00
|
|
|
for (int32_t i = 0; i < nameCount; ++i) {
|
2008-03-30 18:55:42 +04:00
|
|
|
if (names[i]) {
|
|
|
|
identifiers[i] = doGetIdentifier(cx, names[i]);
|
|
|
|
} else {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_getstringidentifiers: passed null name"));
|
2013-10-24 00:34:30 +04:00
|
|
|
identifiers[i] = nullptr;
|
2008-03-30 18:55:42 +04:00
|
|
|
}
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NPIdentifier _getintidentifier(int32_t intid) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_getstringidentifier called from the wrong thread\n"));
|
|
|
|
}
|
2010-07-15 10:19:36 +04:00
|
|
|
return IntToNPIdentifier(intid);
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPUTF8* _utf8fromidentifier(NPIdentifier id) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_utf8fromidentifier called from the wrong thread\n"));
|
|
|
|
}
|
2013-10-24 00:34:30 +04:00
|
|
|
if (!id) return nullptr;
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2010-07-15 10:19:36 +04:00
|
|
|
if (!NPIdentifierIsString(id)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
JSString* str = NPIdentifierToString(id);
|
2014-07-12 11:43:06 +04:00
|
|
|
nsAutoString autoStr;
|
|
|
|
AssignJSFlatString(autoStr, JS_ASSERT_STRING_IS_FLAT(str));
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2014-07-12 11:43:06 +04:00
|
|
|
return ToNewUTF8String(autoStr);
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2010-07-15 10:19:36 +04:00
|
|
|
int32_t _intfromidentifier(NPIdentifier id) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_intfromidentifier called from the wrong thread\n"));
|
|
|
|
}
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2010-07-15 10:19:36 +04:00
|
|
|
if (!NPIdentifierIsInt(id)) {
|
2012-09-28 10:57:33 +04:00
|
|
|
return INT32_MIN;
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2010-07-15 10:19:36 +04:00
|
|
|
return NPIdentifierToInt(id);
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2010-07-15 10:19:36 +04:00
|
|
|
bool _identifierisstring(NPIdentifier id) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_identifierisstring called from the wrong thread\n"));
|
|
|
|
}
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2010-07-15 10:19:36 +04:00
|
|
|
return NPIdentifierIsString(id);
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPObject* _createobject(NPP npp, NPClass* aClass) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_createobject called from the wrong thread\n"));
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-03-30 19:23:21 +04:00
|
|
|
}
|
2004-07-30 08:00:05 +04:00
|
|
|
if (!npp) {
|
|
|
|
NS_ERROR("Null npp passed to _createobject()!");
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2004-07-30 08:00:05 +04:00
|
|
|
}
|
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
PluginDestructionGuard guard(npp);
|
|
|
|
|
2004-07-12 19:53:22 +04:00
|
|
|
if (!aClass) {
|
|
|
|
NS_ERROR("Null class passed to _createobject()!");
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2004-07-30 08:00:05 +04:00
|
|
|
NPPAutoPusher nppPusher(npp);
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPObject* npobj;
|
2004-07-12 19:53:22 +04:00
|
|
|
|
|
|
|
if (aClass->allocate) {
|
2004-08-27 04:58:44 +04:00
|
|
|
npobj = aClass->allocate(npp, aClass);
|
2004-07-12 19:53:22 +04:00
|
|
|
} else {
|
2019-05-01 11:47:10 +03:00
|
|
|
npobj = (NPObject*)malloc(sizeof(NPObject));
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (npobj) {
|
|
|
|
npobj->_class = aClass;
|
|
|
|
npobj->referenceCount = 1;
|
2009-11-13 01:16:54 +03:00
|
|
|
NS_LOG_ADDREF(npobj, 1, "BrowserNPObject", sizeof(NPObject));
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY,
|
|
|
|
("Created NPObject %p, NPClass %p\n", npobj, aClass));
|
|
|
|
|
2004-07-12 19:53:22 +04:00
|
|
|
return npobj;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPObject* _retainobject(NPObject* npobj) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_retainobject called from the wrong thread\n"));
|
|
|
|
}
|
2004-07-12 19:53:22 +04:00
|
|
|
if (npobj) {
|
2011-02-06 08:27:31 +03:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2010-07-11 16:50:47 +04:00
|
|
|
int32_t refCnt =
|
|
|
|
#endif
|
2019-05-01 11:47:10 +03:00
|
|
|
PR_ATOMIC_INCREMENT((int32_t*)&npobj->referenceCount);
|
2009-11-13 01:16:54 +03:00
|
|
|
NS_LOG_ADDREF(npobj, refCnt, "BrowserNPObject", sizeof(NPObject));
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return npobj;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void _releaseobject(NPObject* npobj) {
|
2015-12-04 01:51:52 +03:00
|
|
|
// If nothing is passed, just return, even if we're on the wrong thread.
|
|
|
|
if (!npobj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
int32_t refCnt = PR_ATOMIC_DECREMENT((int32_t*)&npobj->referenceCount);
|
2009-11-13 01:16:54 +03:00
|
|
|
NS_LOG_RELEASE(npobj, refCnt, "BrowserNPObject");
|
2004-07-12 19:53:22 +04:00
|
|
|
|
|
|
|
if (refCnt == 0) {
|
2007-08-10 02:22:26 +04:00
|
|
|
nsNPObjWrapper::OnDestroy(npobj);
|
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY,
|
|
|
|
("Deleting NPObject %p, refcount hit 0\n", npobj));
|
|
|
|
|
2004-07-12 19:53:22 +04:00
|
|
|
if (npobj->_class && npobj->_class->deallocate) {
|
|
|
|
npobj->_class->deallocate(npobj);
|
|
|
|
} else {
|
2017-07-01 05:05:41 +03:00
|
|
|
free(npobj);
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool _invoke(NPP npp, NPObject* npobj, NPIdentifier method,
|
|
|
|
const NPVariant* args, uint32_t argCount, NPVariant* result) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_invoke called from the wrong thread\n"));
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-30 08:00:05 +04:00
|
|
|
if (!npp || !npobj || !npobj->_class || !npobj->_class->invoke) return false;
|
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
PluginDestructionGuard guard(npp);
|
|
|
|
|
2004-07-30 08:00:05 +04:00
|
|
|
NPPExceptionAutoHolder nppExceptionHolder;
|
|
|
|
NPPAutoPusher nppPusher(npp);
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY,
|
|
|
|
("NPN_Invoke(npp %p, npobj %p, method %p, args %d\n", npp,
|
|
|
|
npobj, method, argCount));
|
|
|
|
|
2004-07-12 19:53:22 +04:00
|
|
|
return npobj->_class->invoke(npobj, method, args, argCount, result);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool _invokeDefault(NPP npp, NPObject* npobj, const NPVariant* args,
|
|
|
|
uint32_t argCount, NPVariant* result) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_invokedefault called from the wrong thread\n"));
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-30 08:31:16 +04:00
|
|
|
if (!npp || !npobj || !npobj->_class || !npobj->_class->invokeDefault)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
NPPExceptionAutoHolder nppExceptionHolder;
|
|
|
|
NPPAutoPusher nppPusher(npp);
|
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
NPN_PLUGIN_LOG(
|
|
|
|
PLUGIN_LOG_NOISY,
|
|
|
|
("NPN_InvokeDefault(npp %p, npobj %p, args %d\n", npp, npobj, argCount));
|
|
|
|
|
2004-08-30 08:31:16 +04:00
|
|
|
return npobj->_class->invokeDefault(npobj, args, argCount, result);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool _evaluate(NPP npp, NPObject* npobj, NPString* script, NPVariant* result) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_evaluate called from the wrong thread\n"));
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-30 08:00:05 +04:00
|
|
|
if (!npp) return false;
|
|
|
|
|
|
|
|
NPPAutoPusher nppPusher(npp);
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
Document* doc = GetDocumentFromNPP(npp);
|
2008-01-15 03:51:29 +03:00
|
|
|
NS_ENSURE_TRUE(doc, false);
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(doc->GetInnerWindow());
|
2019-05-03 13:08:07 +03:00
|
|
|
if (NS_WARN_IF(!win || !win->HasJSGlobal())) {
|
2014-03-09 22:35:52 +04:00
|
|
|
return false;
|
|
|
|
}
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2015-07-09 09:41:43 +03:00
|
|
|
nsAutoMicroTask mt;
|
2015-04-09 04:23:48 +03:00
|
|
|
dom::AutoEntryScript aes(win, "NPAPI NPN_evaluate");
|
2019-05-01 11:47:10 +03:00
|
|
|
JSContext* cx = aes.cx();
|
2009-12-23 00:54:06 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
JS::Rooted<JSObject*> obj(cx, nsNPObjWrapper::GetNewOrUsed(npp, cx, npobj));
|
2004-07-12 19:53:22 +04:00
|
|
|
|
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-06 21:03:51 +03:00
|
|
|
obj = js::ToWindowIfWindowProxy(obj);
|
|
|
|
MOZ_ASSERT(obj, "ToWindowIfWindowProxy should never return null");
|
2010-08-11 03:11:32 +04:00
|
|
|
|
2004-07-12 19:53:22 +04:00
|
|
|
if (result) {
|
|
|
|
// Initialize the out param to void
|
|
|
|
VOID_TO_NPVARIANT(*result);
|
|
|
|
}
|
|
|
|
|
2008-12-17 07:48:42 +03:00
|
|
|
if (!script || !script->UTF8Length || !script->UTF8Characters) {
|
2004-07-12 19:53:22 +04:00
|
|
|
// Nothing to evaluate.
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-12-17 07:48:42 +03:00
|
|
|
NS_ConvertUTF8toUTF16 utf16script(script->UTF8Characters, script->UTF8Length);
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIPrincipal* principal = doc->NodePrincipal();
|
2008-01-15 03:51:29 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString specStr;
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* spec;
|
2008-01-15 03:51:29 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
principal->GetURI(getter_AddRefs(uri));
|
|
|
|
|
|
|
|
if (uri) {
|
|
|
|
uri->GetSpec(specStr);
|
|
|
|
spec = specStr.get();
|
|
|
|
} else {
|
|
|
|
// No URI in a principal means it's the system principal. If the
|
|
|
|
// document URI is a chrome:// URI, pass that in as the URI of the
|
|
|
|
// script, else pass in null for the filename as there's no way to
|
|
|
|
// know where this document really came from. Passing in null here
|
|
|
|
// also means that the script gets treated by XPConnect as if it
|
|
|
|
// needs additional protection, which is what we want for unknown
|
|
|
|
// chrome code anyways.
|
|
|
|
|
|
|
|
uri = doc->GetDocumentURI();
|
2019-08-02 11:54:18 +03:00
|
|
|
if (uri && uri->SchemeIs("chrome")) {
|
2008-01-15 03:51:29 +03:00
|
|
|
uri->GetSpec(specStr);
|
|
|
|
spec = specStr.get();
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
spec = nullptr;
|
2008-01-15 03:51:29 +03:00
|
|
|
}
|
|
|
|
}
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY,
|
|
|
|
("NPN_Evaluate(npp %p, npobj %p, script <<<%s>>>) called\n",
|
2008-12-17 07:48:42 +03:00
|
|
|
npp, npobj, script->UTF8Characters));
|
2008-02-29 05:06:00 +03:00
|
|
|
|
2013-01-17 06:50:26 +04:00
|
|
|
JS::CompileOptions options(cx);
|
2017-11-17 14:12:39 +03:00
|
|
|
options.setFileAndLine(spec, 0);
|
2014-01-23 23:49:40 +04:00
|
|
|
JS::Rooted<JS::Value> rval(cx);
|
2019-05-01 11:47:10 +03:00
|
|
|
JS::RootedVector<JSObject*> scopeChain(cx);
|
2018-07-24 11:00:50 +03:00
|
|
|
if (!JS_IsGlobalObject(obj) && !scopeChain.append(obj)) {
|
2014-11-13 01:04:29 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-24 11:00:50 +03:00
|
|
|
// nsNPObjWrapper::GetNewOrUsed returns an object in the current compartment
|
|
|
|
// of the JSContext (it might be a CCW).
|
|
|
|
MOZ_RELEASE_ASSERT(
|
|
|
|
js::GetObjectCompartment(obj) == js::GetContextCompartment(cx),
|
|
|
|
"nsNPObjWrapper::GetNewOrUsed must wrap its return value");
|
|
|
|
obj = JS::CurrentGlobalOrNull(cx);
|
|
|
|
MOZ_ASSERT(obj);
|
2017-03-22 16:42:27 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
{
|
|
|
|
nsJSUtils::ExecutionContext exec(cx, obj);
|
|
|
|
exec.SetScopeChain(scopeChain);
|
2018-12-07 00:52:16 +03:00
|
|
|
exec.Compile(options, utf16script);
|
|
|
|
rv = exec.ExecScript(&rval);
|
2017-03-22 16:42:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!JS_WrapValue(cx, &rval)) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-08-04 00:39:45 +04:00
|
|
|
|
|
|
|
return NS_SUCCEEDED(rv) &&
|
2014-01-23 23:49:40 +04:00
|
|
|
(!result || JSValToNPVariant(npp, cx, rval, result));
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool _getproperty(NPP npp, NPObject* npobj, NPIdentifier property,
|
|
|
|
NPVariant* result) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_getproperty called from the wrong thread\n"));
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-30 08:00:05 +04:00
|
|
|
if (!npp || !npobj || !npobj->_class || !npobj->_class->getProperty)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
NPPExceptionAutoHolder nppExceptionHolder;
|
|
|
|
NPPAutoPusher nppPusher(npp);
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY,
|
|
|
|
("NPN_GetProperty(npp %p, npobj %p, property %p) called\n",
|
|
|
|
npp, npobj, property));
|
|
|
|
|
2010-11-19 23:58:59 +03:00
|
|
|
if (!npobj->_class->getProperty(npobj, property, result)) return false;
|
|
|
|
|
|
|
|
return true;
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool _setproperty(NPP npp, NPObject* npobj, NPIdentifier property,
|
|
|
|
const NPVariant* value) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_setproperty called from the wrong thread\n"));
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-30 08:00:05 +04:00
|
|
|
if (!npp || !npobj || !npobj->_class || !npobj->_class->setProperty)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
NPPExceptionAutoHolder nppExceptionHolder;
|
|
|
|
NPPAutoPusher nppPusher(npp);
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY,
|
|
|
|
("NPN_SetProperty(npp %p, npobj %p, property %p) called\n",
|
|
|
|
npp, npobj, property));
|
|
|
|
|
2004-07-12 19:53:22 +04:00
|
|
|
return npobj->_class->setProperty(npobj, property, value);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool _removeproperty(NPP npp, NPObject* npobj, NPIdentifier property) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_removeproperty called from the wrong thread\n"));
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-30 08:00:05 +04:00
|
|
|
if (!npp || !npobj || !npobj->_class || !npobj->_class->removeProperty)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
NPPExceptionAutoHolder nppExceptionHolder;
|
|
|
|
NPPAutoPusher nppPusher(npp);
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY,
|
|
|
|
("NPN_RemoveProperty(npp %p, npobj %p, property %p) called\n",
|
|
|
|
npp, npobj, property));
|
|
|
|
|
2004-07-12 19:53:22 +04:00
|
|
|
return npobj->_class->removeProperty(npobj, property);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool _hasproperty(NPP npp, NPObject* npobj, NPIdentifier propertyName) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_hasproperty called from the wrong thread\n"));
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-30 08:00:05 +04:00
|
|
|
if (!npp || !npobj || !npobj->_class || !npobj->_class->hasProperty)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
NPPExceptionAutoHolder nppExceptionHolder;
|
|
|
|
NPPAutoPusher nppPusher(npp);
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY,
|
|
|
|
("NPN_HasProperty(npp %p, npobj %p, property %p) called\n",
|
|
|
|
npp, npobj, propertyName));
|
|
|
|
|
2004-07-12 19:53:22 +04:00
|
|
|
return npobj->_class->hasProperty(npobj, propertyName);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool _hasmethod(NPP npp, NPObject* npobj, NPIdentifier methodName) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_hasmethod called from the wrong thread\n"));
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-30 08:00:05 +04:00
|
|
|
if (!npp || !npobj || !npobj->_class || !npobj->_class->hasMethod)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
NPPExceptionAutoHolder nppExceptionHolder;
|
|
|
|
NPPAutoPusher nppPusher(npp);
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY,
|
|
|
|
("NPN_HasMethod(npp %p, npobj %p, property %p) called\n", npp,
|
|
|
|
npobj, methodName));
|
|
|
|
|
2009-01-15 23:20:10 +03:00
|
|
|
return npobj->_class->hasMethod(npobj, methodName);
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool _enumerate(NPP npp, NPObject* npobj, NPIdentifier** identifier,
|
|
|
|
uint32_t* count) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_enumerate called from the wrong thread\n"));
|
|
|
|
return false;
|
|
|
|
}
|
2006-03-01 03:13:38 +03:00
|
|
|
if (!npp || !npobj || !npobj->_class) return false;
|
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY,
|
|
|
|
("NPN_Enumerate(npp %p, npobj %p) called\n", npp, npobj));
|
|
|
|
|
2006-03-01 03:13:38 +03:00
|
|
|
if (!NP_CLASS_STRUCT_VERSION_HAS_ENUM(npobj->_class) ||
|
|
|
|
!npobj->_class->enumerate) {
|
|
|
|
*identifier = 0;
|
|
|
|
*count = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NPPExceptionAutoHolder nppExceptionHolder;
|
|
|
|
NPPAutoPusher nppPusher(npp);
|
|
|
|
|
|
|
|
return npobj->_class->enumerate(npobj, identifier, count);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool _construct(NPP npp, NPObject* npobj, const NPVariant* args,
|
|
|
|
uint32_t argCount, NPVariant* result) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_construct called from the wrong thread\n"));
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-10 05:24:28 +04:00
|
|
|
if (!npp || !npobj || !npobj->_class ||
|
|
|
|
!NP_CLASS_STRUCT_VERSION_HAS_CTOR(npobj->_class) ||
|
|
|
|
!npobj->_class->construct) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NPPExceptionAutoHolder nppExceptionHolder;
|
|
|
|
NPPAutoPusher nppPusher(npp);
|
|
|
|
|
|
|
|
return npobj->_class->construct(npobj, args, argCount, result);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void _releasevariantvalue(NPVariant* variant) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_releasevariantvalue called from the wrong thread\n"));
|
|
|
|
}
|
2004-07-12 19:53:22 +04:00
|
|
|
switch (variant->type) {
|
|
|
|
case NPVariantType_Void:
|
|
|
|
case NPVariantType_Null:
|
|
|
|
case NPVariantType_Bool:
|
|
|
|
case NPVariantType_Int32:
|
|
|
|
case NPVariantType_Double:
|
|
|
|
break;
|
|
|
|
case NPVariantType_String: {
|
2019-05-01 11:47:10 +03:00
|
|
|
const NPString* s = &NPVARIANT_TO_STRING(*variant);
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2008-12-17 07:48:42 +03:00
|
|
|
if (s->UTF8Characters) {
|
2017-08-30 10:53:10 +03:00
|
|
|
#if defined(MOZ_MEMORY) && defined(XP_WIN)
|
2019-05-01 11:47:10 +03:00
|
|
|
if (malloc_usable_size((void*)s->UTF8Characters) != 0) {
|
|
|
|
free((void*)s->UTF8Characters);
|
2008-05-01 04:17:54 +04:00
|
|
|
} else {
|
2019-05-01 11:47:10 +03:00
|
|
|
void* p = (void*)s->UTF8Characters;
|
2008-05-01 04:17:54 +04:00
|
|
|
DWORD nheaps = 0;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<HANDLE, 50> heaps;
|
2008-05-01 04:17:54 +04:00
|
|
|
nheaps = GetProcessHeaps(0, heaps.Elements());
|
|
|
|
heaps.AppendElements(nheaps);
|
|
|
|
GetProcessHeaps(nheaps, heaps.Elements());
|
|
|
|
for (DWORD i = 0; i < nheaps; i++) {
|
|
|
|
if (InHeap(heaps[i], p)) {
|
|
|
|
HeapFree(heaps[i], 0, p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2019-05-01 11:47:10 +03:00
|
|
|
free((void*)s->UTF8Characters);
|
2008-05-01 04:17:54 +04:00
|
|
|
#endif
|
|
|
|
}
|
2004-07-12 19:53:22 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NPVariantType_Object: {
|
2019-05-01 11:47:10 +03:00
|
|
|
NPObject* npobj = NPVARIANT_TO_OBJECT(*variant);
|
2004-07-12 19:53:22 +04:00
|
|
|
|
|
|
|
if (npobj) _releaseobject(npobj);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unknown NPVariant type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID_TO_NPVARIANT(*variant);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void _setexception(NPObject* npobj, const NPUTF8* message) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_setexception called from the wrong thread\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-30 23:15:22 +03:00
|
|
|
if (!message) return;
|
|
|
|
|
2004-07-30 08:00:05 +04:00
|
|
|
if (gNPPException) {
|
|
|
|
// If a plugin throws multiple exceptions, we'll only report the
|
|
|
|
// last one for now.
|
|
|
|
free(gNPPException);
|
|
|
|
}
|
|
|
|
|
|
|
|
gNPPException = strdup(message);
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError _getvalue(NPP npp, NPNVariable variable, void* result) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_getvalue called from the wrong thread\n"));
|
|
|
|
return NPERR_INVALID_PARAM;
|
|
|
|
}
|
2019-05-01 11:47:10 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
|
|
|
|
("NPN_GetValue: npp=%p, var=%d\n", (void*)npp, (int)variable));
|
2001-08-16 06:59:03 +04:00
|
|
|
|
2000-05-27 02:14:39 +04:00
|
|
|
nsresult res;
|
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
PluginDestructionGuard guard(npp);
|
|
|
|
|
2014-10-09 08:28:00 +04:00
|
|
|
// Cast NPNVariable enum to int to avoid warnings about including switch
|
|
|
|
// cases for android_npapi.h's non-standard ANPInterface values.
|
|
|
|
switch (static_cast<int>(variable)) {
|
2002-11-06 04:24:57 +03:00
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
2001-09-22 04:18:55 +04:00
|
|
|
case NPNVxDisplay: {
|
2011-08-24 20:15:58 +04:00
|
|
|
# if defined(MOZ_X11)
|
2005-03-23 03:34:39 +03:00
|
|
|
if (npp) {
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)npp->ndata;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool windowless = false;
|
2009-09-17 05:30:26 +04:00
|
|
|
inst->IsWindowless(&windowless);
|
2012-03-02 10:17:26 +04:00
|
|
|
// The documentation on the types for many variables in NP(N|P)_GetValue
|
|
|
|
// is vague. Often boolean values are NPBool (1 byte), but
|
|
|
|
// https://developer.mozilla.org/en/XEmbed_Extension_for_Mozilla_Plugins
|
|
|
|
// treats NPPVpluginNeedsXEmbed as PRBool (int), and
|
|
|
|
// on x86/32-bit, flash stores to this using |movl 0x1,&needsXEmbed|.
|
|
|
|
// thus we can't use NPBool for needsXEmbed, or the three bytes above
|
|
|
|
// it on the stack would get clobbered. so protect with the larger bool.
|
|
|
|
int needsXEmbed = 0;
|
2008-07-17 05:19:54 +04:00
|
|
|
if (!windowless) {
|
2012-03-02 10:17:26 +04:00
|
|
|
res = inst->GetValueFromPlugin(NPPVpluginNeedsXEmbed, &needsXEmbed);
|
2011-03-23 21:46:09 +03:00
|
|
|
// If the call returned an error code make sure we still use our
|
|
|
|
// default value.
|
|
|
|
if (NS_FAILED(res)) {
|
2012-03-02 10:17:26 +04:00
|
|
|
needsXEmbed = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2012-03-02 10:17:26 +04:00
|
|
|
if (windowless || needsXEmbed) {
|
2019-05-01 11:47:10 +03:00
|
|
|
(*(Display**)result) = mozilla::DefaultXDisplay();
|
2003-09-16 05:44:41 +04:00
|
|
|
return NPERR_NO_ERROR;
|
2011-03-23 21:46:09 +03:00
|
|
|
}
|
2008-07-17 05:19:54 +04:00
|
|
|
}
|
2001-09-22 04:18:55 +04:00
|
|
|
# endif
|
2001-09-08 05:04:03 +04:00
|
|
|
return NPERR_GENERIC_ERROR;
|
2001-09-22 04:18:55 +04:00
|
|
|
}
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2005-03-23 03:37:58 +03:00
|
|
|
case NPNVxtAppContext:
|
2001-09-08 05:04:03 +04:00
|
|
|
return NPERR_GENERIC_ERROR;
|
1999-07-08 00:18:27 +04:00
|
|
|
#endif
|
|
|
|
|
2016-07-13 03:28:31 +03:00
|
|
|
#if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
|
2001-09-08 05:04:03 +04:00
|
|
|
case NPNVnetscapeWindow: {
|
2001-09-22 04:18:55 +04:00
|
|
|
if (!npp || !npp->ndata) return NPERR_INVALID_INSTANCE_ERROR;
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)npp->ndata;
|
2001-09-08 05:04:03 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPluginInstanceOwner> owner = inst->GetOwner();
|
2012-07-20 15:16:17 +04:00
|
|
|
NS_ENSURE_TRUE(owner, NPERR_NO_ERROR);
|
2009-06-29 22:53:52 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(owner->GetNetscapeWindow(result))) {
|
2002-09-19 00:21:47 +04:00
|
|
|
return NPERR_NO_ERROR;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2001-09-08 05:04:03 +04:00
|
|
|
return NPERR_GENERIC_ERROR;
|
2001-08-16 06:59:03 +04:00
|
|
|
}
|
1999-07-08 00:18:27 +04:00
|
|
|
#endif
|
|
|
|
|
2001-09-08 05:04:03 +04:00
|
|
|
case NPNVjavascriptEnabledBool: {
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = false;
|
2012-04-04 08:09:20 +04:00
|
|
|
bool js = false;
|
|
|
|
res = Preferences::GetBool("javascript.enabled", &js);
|
|
|
|
if (NS_SUCCEEDED(res)) {
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = js;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-09-16 05:44:41 +04:00
|
|
|
return NPERR_NO_ERROR;
|
2000-05-27 02:14:39 +04:00
|
|
|
}
|
|
|
|
|
2005-03-23 03:37:58 +03:00
|
|
|
case NPNVasdEnabledBool:
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = false;
|
2000-05-27 02:14:39 +04:00
|
|
|
return NPERR_NO_ERROR;
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2004-08-30 17:25:28 +04:00
|
|
|
case NPNVisOfflineBool: {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool offline = false;
|
2005-03-23 03:34:39 +03:00
|
|
|
nsCOMPtr<nsIIOService> ioservice =
|
|
|
|
do_GetService(NS_IOSERVICE_CONTRACTID, &res);
|
2004-08-30 17:25:28 +04:00
|
|
|
if (NS_SUCCEEDED(res)) res = ioservice->GetOffline(&offline);
|
|
|
|
if (NS_FAILED(res)) return NPERR_GENERIC_ERROR;
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = offline;
|
2000-05-27 02:14:39 +04:00
|
|
|
return NPERR_NO_ERROR;
|
2004-08-30 17:25:28 +04:00
|
|
|
}
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2003-09-16 05:44:41 +04:00
|
|
|
case NPNVToolkit: {
|
2012-06-28 04:15:32 +04:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2019-05-01 11:47:10 +03:00
|
|
|
*((NPNToolkitType*)result) = NPNVGtk2;
|
2003-09-16 05:44:41 +04:00
|
|
|
#endif
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
if (*(NPNToolkitType*)result) return NPERR_NO_ERROR;
|
2003-09-16 05:44:41 +04:00
|
|
|
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NPNVSupportsXEmbedBool: {
|
2012-06-28 04:15:32 +04:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = true;
|
2003-09-16 05:44:41 +04:00
|
|
|
#else
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = false;
|
2003-09-16 05:44:41 +04:00
|
|
|
#endif
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2004-07-12 19:53:22 +04:00
|
|
|
|
|
|
|
case NPNVWindowNPObject: {
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPObject**)result = _getwindowobject(npp);
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
return *(NPObject**)result ? NPERR_NO_ERROR : NPERR_GENERIC_ERROR;
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case NPNVPluginElementNPObject: {
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPObject**)result = _getpluginelement(npp);
|
2004-07-12 19:53:22 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
return *(NPObject**)result ? NPERR_NO_ERROR : NPERR_GENERIC_ERROR;
|
2004-07-12 19:53:22 +04:00
|
|
|
}
|
|
|
|
|
2007-09-06 05:45:08 +04:00
|
|
|
case NPNVSupportsWindowless: {
|
2010-04-20 22:49:34 +04:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX) || \
|
2016-07-13 03:28:31 +03:00
|
|
|
(defined(MOZ_X11) && defined(MOZ_WIDGET_GTK))
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = true;
|
2007-09-06 05:45:08 +04:00
|
|
|
#else
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = false;
|
2007-09-06 05:45:08 +04:00
|
|
|
#endif
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2013-03-04 22:18:20 +04:00
|
|
|
|
|
|
|
case NPNVprivateModeBool: {
|
|
|
|
bool privacy;
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst =
|
|
|
|
static_cast<nsNPAPIPluginInstance*>(npp->ndata);
|
2012-10-30 00:20:03 +04:00
|
|
|
if (!inst) return NPERR_GENERIC_ERROR;
|
2009-01-31 00:40:14 +03:00
|
|
|
|
2011-09-14 20:22:27 +04:00
|
|
|
nsresult rv = inst->IsPrivateBrowsing(&privacy);
|
|
|
|
if (NS_FAILED(rv)) return NPERR_GENERIC_ERROR;
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = (NPBool)privacy;
|
2003-09-16 05:44:41 +04:00
|
|
|
return NPERR_NO_ERROR;
|
2011-09-14 20:22:27 +04:00
|
|
|
}
|
|
|
|
|
2018-04-27 06:37:34 +03:00
|
|
|
case NPNVdocumentOrigin: {
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)npp->ndata;
|
2011-09-14 20:22:27 +04:00
|
|
|
if (!inst) {
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
2018-04-27 06:37:34 +03:00
|
|
|
RefPtr<dom::Element> element;
|
|
|
|
inst->GetDOMElement(getter_AddRefs(element));
|
|
|
|
if (!element) {
|
|
|
|
return NPERR_GENERIC_ERROR;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-09-14 20:22:27 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIPrincipal* principal = element->NodePrincipal();
|
2011-09-14 20:22:27 +04:00
|
|
|
|
2016-10-03 15:43:47 +03:00
|
|
|
nsAutoString utf16Origin;
|
|
|
|
res = nsContentUtils::GetUTFOrigin(principal, utf16Origin);
|
|
|
|
if (NS_FAILED(res)) {
|
2011-09-14 20:22:27 +04:00
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-10-03 15:43:47 +03:00
|
|
|
nsCOMPtr<nsIIDNService> idnService =
|
|
|
|
do_GetService(NS_IDNSERVICE_CONTRACTID);
|
2011-09-14 20:22:27 +04:00
|
|
|
if (!idnService) {
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-10-03 15:43:47 +03:00
|
|
|
// This is a bit messy: we convert to UTF-8 here, but then
|
|
|
|
// nsIDNService::Normalize will convert back to UTF-16 for processing,
|
|
|
|
// and back to UTF-8 again to return the result.
|
|
|
|
// Alternative: perhaps we should add a NormalizeUTF16 version of the API,
|
|
|
|
// and just convert to UTF-8 for the final return (resulting in one
|
|
|
|
// encoding form conversion instead of three).
|
|
|
|
NS_ConvertUTF16toUTF8 utf8Origin(utf16Origin);
|
|
|
|
nsAutoCString normalizedUTF8Origin;
|
|
|
|
res = idnService->Normalize(utf8Origin, normalizedUTF8Origin);
|
2011-09-14 20:22:27 +04:00
|
|
|
if (NS_FAILED(res)) {
|
2001-09-08 05:04:03 +04:00
|
|
|
return NPERR_GENERIC_ERROR;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
*(char**)result = ToNewCString(normalizedUTF8Origin);
|
|
|
|
return *(char**)result ? NPERR_NO_ERROR : NPERR_GENERIC_ERROR;
|
2011-09-14 20:22:27 +04:00
|
|
|
}
|
|
|
|
|
2007-03-27 05:07:57 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case NPNVpluginDrawingModel: {
|
|
|
|
if (npp) {
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)npp->ndata;
|
2007-03-27 05:07:57 +04:00
|
|
|
if (inst) {
|
2009-09-17 05:30:26 +04:00
|
|
|
NPDrawingModel drawingModel;
|
2019-05-01 11:47:10 +03:00
|
|
|
inst->GetDrawingModel((int32_t*)&drawingModel);
|
|
|
|
*(NPDrawingModel*)result = drawingModel;
|
2007-03-27 05:07:57 +04:00
|
|
|
return NPERR_NO_ERROR;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2007-03-27 05:07:57 +04:00
|
|
|
}
|
2013-03-04 22:18:20 +04:00
|
|
|
return NPERR_GENERIC_ERROR;
|
2007-03-27 05:07:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# ifndef NP_NO_QUICKDRAW
|
|
|
|
case NPNVsupportsQuickDrawBool: {
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = false;
|
2014-09-03 22:25:56 +04:00
|
|
|
|
2007-03-27 05:07:57 +04:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
case NPNVsupportsCoreGraphicsBool: {
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = true;
|
2014-09-03 22:25:56 +04:00
|
|
|
|
2009-08-27 04:29:47 +04:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-07-31 21:37:06 +04:00
|
|
|
case NPNVsupportsCoreAnimationBool: {
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = true;
|
2010-03-24 03:51:11 +03:00
|
|
|
|
2011-07-31 21:37:06 +04:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2010-03-24 03:51:11 +03:00
|
|
|
|
2011-07-31 21:37:06 +04:00
|
|
|
case NPNVsupportsInvalidatingCoreAnimationBool: {
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = true;
|
2010-06-09 08:11:48 +04:00
|
|
|
|
2011-07-31 21:37:06 +04:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2010-06-09 08:11:48 +04:00
|
|
|
|
2011-07-31 21:37:06 +04:00
|
|
|
case NPNVsupportsCompositingCoreAnimationPluginsBool: {
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = PR_TRUE;
|
2011-07-31 21:37:06 +04:00
|
|
|
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2010-03-24 03:51:11 +03:00
|
|
|
|
2009-08-27 04:29:47 +04:00
|
|
|
# ifndef NP_NO_CARBON
|
|
|
|
case NPNVsupportsCarbonBool: {
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = false;
|
2009-08-27 04:29:47 +04:00
|
|
|
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
case NPNVsupportsCocoaBool: {
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = true;
|
2009-08-27 04:29:47 +04:00
|
|
|
|
2007-03-27 05:07:57 +04:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2011-01-21 04:08:11 +03:00
|
|
|
|
|
|
|
case NPNVsupportsUpdatedCocoaTextInputBool: {
|
2019-05-01 11:47:10 +03:00
|
|
|
*(NPBool*)result = true;
|
2011-01-21 04:08:11 +03:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2015-09-17 23:31:34 +03:00
|
|
|
#endif
|
2012-10-02 23:48:05 +04:00
|
|
|
|
2015-09-17 23:31:34 +03:00
|
|
|
#if defined(XP_MACOSX) || defined(XP_WIN)
|
2012-10-02 23:48:05 +04:00
|
|
|
case NPNVcontentsScaleFactor: {
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst =
|
|
|
|
(nsNPAPIPluginInstance*)(npp ? npp->ndata : nullptr);
|
2012-10-02 23:48:05 +04:00
|
|
|
double scaleFactor = inst ? inst->GetContentsScaleFactor() : 1.0;
|
2019-05-01 11:47:10 +03:00
|
|
|
*(double*)result = scaleFactor;
|
2012-10-02 23:48:05 +04:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2007-03-27 05:07:57 +04:00
|
|
|
#endif
|
|
|
|
|
2016-03-17 22:00:59 +03:00
|
|
|
case NPNVCSSZoomFactor: {
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst =
|
|
|
|
(nsNPAPIPluginInstance*)(npp ? npp->ndata : nullptr);
|
2016-03-17 22:00:59 +03:00
|
|
|
double scaleFactor = inst ? inst->GetCSSZoomFactor() : 1.0;
|
2019-05-01 11:47:10 +03:00
|
|
|
*(double*)result = scaleFactor;
|
2016-03-17 22:00:59 +03:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-05-08 21:45:56 +04:00
|
|
|
// we no longer hand out any XPCOM objects
|
2009-11-30 13:11:20 +03:00
|
|
|
case NPNVDOMElement:
|
|
|
|
case NPNVDOMWindow:
|
|
|
|
case NPNVserviceManager:
|
|
|
|
// old XPCOM objects, no longer supported, but null out the out
|
|
|
|
// param to avoid crashing plugins that still try to use this.
|
2019-05-01 11:47:10 +03:00
|
|
|
*(nsISupports**)result = nullptr;
|
2015-10-07 07:20:20 +03:00
|
|
|
MOZ_FALLTHROUGH;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-08-14 16:47:04 +04:00
|
|
|
default:
|
2011-09-17 01:34:31 +04:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
|
|
|
|
("NPN_getvalue unhandled get value: %d\n", variable));
|
2008-08-14 16:47:04 +04:00
|
|
|
return NPERR_GENERIC_ERROR;
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError _setvalue(NPP npp, NPPVariable variable, void* result) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_setvalue called from the wrong thread\n"));
|
|
|
|
return NPERR_INVALID_PARAM;
|
|
|
|
}
|
2019-05-01 11:47:10 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
|
|
|
|
("NPN_SetValue: npp=%p, var=%d\n", (void*)npp, (int)variable));
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2001-08-16 06:59:03 +04:00
|
|
|
if (!npp) return NPERR_INVALID_INSTANCE_ERROR;
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)npp->ndata;
|
2005-03-23 03:37:58 +03:00
|
|
|
|
2008-11-03 22:23:07 +03:00
|
|
|
NS_ASSERTION(inst, "null instance");
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2001-08-16 06:59:03 +04:00
|
|
|
if (!inst) return NPERR_INVALID_INSTANCE_ERROR;
|
1999-07-08 00:18:27 +04:00
|
|
|
|
2008-02-29 05:06:00 +03:00
|
|
|
PluginDestructionGuard guard(inst);
|
|
|
|
|
2014-10-09 08:28:00 +04:00
|
|
|
// Cast NPNVariable enum to int to avoid warnings about including switch
|
|
|
|
// cases for android_npapi.h's non-standard ANPInterface values.
|
|
|
|
switch (static_cast<int>(variable)) {
|
2008-09-15 16:45:01 +04:00
|
|
|
// we should keep backward compatibility with NPAPI where the
|
2001-11-07 02:45:01 +03:00
|
|
|
// actual pointer value is checked rather than its content
|
2007-03-20 05:35:56 +03:00
|
|
|
// when passing booleans
|
2001-09-08 05:04:03 +04:00
|
|
|
case NPPVpluginWindowBool: {
|
2008-12-09 20:22:51 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// This setting doesn't apply to OS X (only to Windows and Unix/Linux).
|
|
|
|
// See https://developer.mozilla.org/En/NPN_SetValue#section_5. Return
|
|
|
|
// NPERR_NO_ERROR here to conform to other browsers' behavior on OS X
|
|
|
|
// (e.g. Safari and Opera).
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
#else
|
2012-07-30 18:20:58 +04:00
|
|
|
NPBool bWindowless = (result == nullptr);
|
2001-08-16 06:59:03 +04:00
|
|
|
return inst->SetWindowless(bWindowless);
|
2008-12-09 20:22:51 +03:00
|
|
|
#endif
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
2001-11-07 02:45:01 +03:00
|
|
|
case NPPVpluginTransparentBool: {
|
2012-07-30 18:20:58 +04:00
|
|
|
NPBool bTransparent = (result != nullptr);
|
2001-11-07 02:45:01 +03:00
|
|
|
return inst->SetTransparent(bTransparent);
|
2002-01-31 04:32:43 +03:00
|
|
|
}
|
2005-03-23 03:37:58 +03:00
|
|
|
|
2013-04-11 15:48:10 +04:00
|
|
|
case NPPVjavascriptPushCallerBool: {
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2005-03-23 03:37:58 +03:00
|
|
|
|
2002-03-26 02:42:32 +03:00
|
|
|
case NPPVpluginKeepLibraryInMemory: {
|
2012-07-30 18:20:58 +04:00
|
|
|
NPBool bCached = (result != nullptr);
|
2012-08-14 13:10:42 +04:00
|
|
|
inst->SetCached(bCached);
|
|
|
|
return NPERR_NO_ERROR;
|
2002-03-26 02:42:32 +03:00
|
|
|
}
|
2008-08-05 01:17:55 +04:00
|
|
|
|
2011-04-08 23:58:04 +04:00
|
|
|
case NPPVpluginUsesDOMForCursorBool: {
|
2012-07-30 18:20:58 +04:00
|
|
|
bool useDOMForCursor = (result != nullptr);
|
2011-04-08 23:58:04 +04:00
|
|
|
return inst->SetUsesDOMForCursor(useDOMForCursor);
|
|
|
|
}
|
|
|
|
|
2015-07-28 23:59:26 +03:00
|
|
|
case NPPVpluginIsPlayingAudio: {
|
2017-03-30 09:27:42 +03:00
|
|
|
const bool isPlaying = result;
|
2015-07-29 00:09:48 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)npp->ndata;
|
2015-07-29 00:09:48 +03:00
|
|
|
MOZ_ASSERT(inst);
|
|
|
|
|
2017-03-30 09:27:42 +03:00
|
|
|
if (!isPlaying && !inst->HasAudioChannelAgent()) {
|
2015-07-29 00:09:48 +03:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-03-30 09:27:42 +03:00
|
|
|
if (isPlaying) {
|
|
|
|
inst->NotifyStartedPlaying();
|
2015-07-29 00:09:48 +03:00
|
|
|
} else {
|
2017-03-30 09:27:42 +03:00
|
|
|
inst->NotifyStoppedPlaying();
|
2015-07-28 23:59:26 +03:00
|
|
|
}
|
2015-07-29 00:09:48 +03:00
|
|
|
|
2015-07-28 23:59:26 +03:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-11-13 23:02:03 +03:00
|
|
|
case NPPVpluginDrawingModel: {
|
2007-03-27 05:07:57 +04:00
|
|
|
if (inst) {
|
2009-08-13 02:32:41 +04:00
|
|
|
inst->SetDrawingModel((NPDrawingModel)NS_PTR_TO_INT32(result));
|
2007-03-27 05:07:57 +04:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
2017-02-09 12:33:57 +03:00
|
|
|
return NPERR_GENERIC_ERROR;
|
2007-03-27 05:07:57 +04:00
|
|
|
}
|
2009-08-27 04:29:47 +04:00
|
|
|
|
2012-02-16 07:24:38 +04:00
|
|
|
#ifdef XP_MACOSX
|
2009-08-27 04:29:47 +04:00
|
|
|
case NPPVpluginEventModel: {
|
|
|
|
if (inst) {
|
|
|
|
inst->SetEventModel((NPEventModel)NS_PTR_TO_INT32(result));
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
} else {
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2011-09-17 01:34:31 +04:00
|
|
|
#endif
|
2001-09-08 05:04:03 +04:00
|
|
|
default:
|
2009-03-18 00:20:24 +03:00
|
|
|
return NPERR_GENERIC_ERROR;
|
2001-08-16 06:59:03 +04:00
|
|
|
}
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError _requestread(NPStream* pstream, NPByteRange* rangeList) {
|
2017-10-02 22:51:35 +03:00
|
|
|
return NPERR_STREAM_NOT_SEEKABLE;
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2018-06-20 22:42:39 +03:00
|
|
|
// Deprecated, only stubbed out
|
2019-05-01 11:47:10 +03:00
|
|
|
void* /* OJI type: JRIEnv* */
|
2018-06-20 22:42:39 +03:00
|
|
|
_getJavaEnv() {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPN_GetJavaEnv\n"));
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* _useragent(NPP npp) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_useragent called from the wrong thread\n"));
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-03-30 19:23:21 +04:00
|
|
|
}
|
2019-05-01 11:47:10 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPN_UserAgent: npp=%p\n", (void*)npp));
|
2001-08-16 06:59:03 +04:00
|
|
|
|
2011-05-21 17:28:54 +04:00
|
|
|
nsCOMPtr<nsIPluginHost> pluginHostCOM(
|
|
|
|
do_GetService(MOZ_PLUGIN_HOST_CONTRACTID));
|
2019-05-01 11:47:10 +03:00
|
|
|
nsPluginHost* pluginHost = static_cast<nsPluginHost*>(pluginHostCOM.get());
|
2011-05-21 17:28:54 +04:00
|
|
|
if (!pluginHost) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-05-21 17:28:54 +04:00
|
|
|
}
|
2004-04-11 09:33:17 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* retstr;
|
2009-06-26 01:06:54 +04:00
|
|
|
nsresult rv = pluginHost->UserAgent(&retstr);
|
2008-03-30 19:23:21 +04:00
|
|
|
if (NS_FAILED(rv)) return nullptr;
|
2004-04-11 09:33:17 +04:00
|
|
|
|
2000-06-14 03:16:05 +04:00
|
|
|
return retstr;
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void* _memalloc(uint32_t size) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
|
|
|
|
("NPN_memalloc called from the wrong thread\n"));
|
|
|
|
}
|
2001-08-16 06:59:03 +04:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY, ("NPN_MemAlloc: size=%d\n", size));
|
2015-03-27 03:01:12 +03:00
|
|
|
return moz_xmalloc(size);
|
1999-07-08 00:18:27 +04:00
|
|
|
}
|
|
|
|
|
2018-06-20 22:42:39 +03:00
|
|
|
// Deprecated, only stubbed out
|
2019-05-01 11:47:10 +03:00
|
|
|
void* /* OJI type: jref */
|
2018-06-20 22:42:39 +03:00
|
|
|
_getJavaPeer(NPP npp) {
|
2019-05-01 11:47:10 +03:00
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPN_GetJavaPeer: npp=%p\n", (void*)npp));
|
2018-06-20 22:42:39 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2005-06-18 10:06:45 +04:00
|
|
|
void _pushpopupsenabledstate(NPP npp, NPBool enabled) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(
|
|
|
|
PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_pushpopupsenabledstate called from the wrong thread\n"));
|
|
|
|
return;
|
|
|
|
}
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst =
|
|
|
|
npp ? (nsNPAPIPluginInstance*)npp->ndata : nullptr;
|
2005-06-18 10:06:45 +04:00
|
|
|
if (!inst) return;
|
|
|
|
|
|
|
|
inst->PushPopupsEnabledState(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _poppopupsenabledstate(NPP npp) {
|
2008-03-30 19:23:21 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(
|
|
|
|
PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_poppopupsenabledstate called from the wrong thread\n"));
|
|
|
|
return;
|
|
|
|
}
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst =
|
|
|
|
npp ? (nsNPAPIPluginInstance*)npp->ndata : nullptr;
|
2005-06-18 10:06:45 +04:00
|
|
|
if (!inst) return;
|
|
|
|
|
|
|
|
inst->PopPopupsEnabledState();
|
|
|
|
}
|
2004-07-30 08:00:05 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError _getvalueforurl(NPP instance, NPNURLVariable variable, const char* url,
|
|
|
|
char** value, uint32_t* len) {
|
2015-07-17 10:17:09 +03:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_getvalueforurl called from the wrong thread\n"));
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-01-13 03:55:52 +03:00
|
|
|
if (!instance) {
|
|
|
|
return NPERR_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!url || !*url || !len) {
|
|
|
|
return NPERR_INVALID_URL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*len = 0;
|
|
|
|
|
|
|
|
switch (variable) {
|
|
|
|
case NPNURLVProxy:
|
2017-02-04 02:32:04 +03:00
|
|
|
// NPNURLVProxy is no longer supported.
|
|
|
|
*value = nullptr;
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
|
2009-01-13 03:55:52 +03:00
|
|
|
case NPNURLVCookie:
|
2017-01-27 19:03:41 +03:00
|
|
|
// NPNURLVCookie is no longer supported.
|
|
|
|
*value = nullptr;
|
|
|
|
return NPERR_GENERIC_ERROR;
|
2009-01-13 03:55:52 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
// Fall through and return an error...
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError _setvalueforurl(NPP instance, NPNURLVariable variable, const char* url,
|
|
|
|
const char* value, uint32_t len) {
|
2015-07-17 10:17:09 +03:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_setvalueforurl called from the wrong thread\n"));
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-01-13 03:55:52 +03:00
|
|
|
if (!instance) {
|
|
|
|
return NPERR_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!url || !*url) {
|
|
|
|
return NPERR_INVALID_URL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (variable) {
|
|
|
|
case NPNURLVCookie:
|
2017-01-27 19:03:41 +03:00
|
|
|
// NPNURLVCookie is no longer supported.
|
|
|
|
return NPERR_GENERIC_ERROR;
|
2009-01-13 03:55:52 +03:00
|
|
|
|
|
|
|
case NPNURLVProxy:
|
|
|
|
// We don't support setting proxy values, fall through...
|
|
|
|
default:
|
|
|
|
// Fall through and return an error...
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-12-02 00:27:13 +03:00
|
|
|
uint32_t _scheduletimer(NPP instance, uint32_t interval, NPBool repeat,
|
|
|
|
PluginTimerFunc timerFunc) {
|
2015-07-17 10:17:09 +03:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_scheduletimer called from the wrong thread\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
|
2009-07-01 19:09:49 +04:00
|
|
|
if (!inst) return 0;
|
|
|
|
|
|
|
|
return inst->ScheduleTimer(interval, repeat, timerFunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _unscheduletimer(NPP instance, uint32_t timerID) {
|
2015-07-17 10:17:09 +03:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_unscheduletimer called from the wrong thread\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
|
2009-07-01 19:09:49 +04:00
|
|
|
if (!inst) return;
|
|
|
|
|
|
|
|
inst->UnscheduleTimer(timerID);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError _popupcontextmenu(NPP instance, NPMenu* menu) {
|
2015-07-17 10:17:09 +03:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_popupcontextmenu called from the wrong thread\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-11 17:44:07 +03:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
|
2014-12-11 17:44:07 +03:00
|
|
|
|
|
|
|
double pluginX, pluginY;
|
|
|
|
double screenX, screenY;
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
const NPCocoaEvent* currentEvent =
|
|
|
|
static_cast<NPCocoaEvent*>(inst->GetCurrentEvent());
|
2014-12-11 17:44:07 +03:00
|
|
|
if (!currentEvent) {
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that the events has an x/y value.
|
|
|
|
if (currentEvent->type != NPCocoaEventMouseDown &&
|
|
|
|
currentEvent->type != NPCocoaEventMouseUp &&
|
|
|
|
currentEvent->type != NPCocoaEventMouseMoved &&
|
|
|
|
currentEvent->type != NPCocoaEventMouseEntered &&
|
|
|
|
currentEvent->type != NPCocoaEventMouseExited &&
|
|
|
|
currentEvent->type != NPCocoaEventMouseDragged) {
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
pluginX = currentEvent->data.mouse.pluginX;
|
|
|
|
pluginY = currentEvent->data.mouse.pluginY;
|
|
|
|
|
|
|
|
if ((pluginX < 0.0) || (pluginY < 0.0)) return NPERR_GENERIC_ERROR;
|
2009-08-27 04:29:47 +04:00
|
|
|
|
2014-12-11 17:44:07 +03:00
|
|
|
NPBool success =
|
|
|
|
_convertpoint(instance, pluginX, pluginY, NPCoordinateSpacePlugin,
|
|
|
|
&screenX, &screenY, NPCoordinateSpaceScreen);
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
return mozilla::plugins::PluginUtilsOSX::ShowCocoaContextMenu(
|
|
|
|
menu, screenX, screenY, nullptr, nullptr);
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Convertpoint failed, could not created contextmenu.");
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
NS_WARNING("Not supported on this platform!");
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
#endif
|
2009-08-27 04:29:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NPBool _convertpoint(NPP instance, double sourceX, double sourceY,
|
2019-05-01 11:47:10 +03:00
|
|
|
NPCoordinateSpace sourceSpace, double* destX,
|
|
|
|
double* destY, NPCoordinateSpace destSpace) {
|
2015-07-17 10:17:09 +03:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_convertpoint called from the wrong thread\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
|
2011-09-30 10:02:59 +04:00
|
|
|
if (!inst) return false;
|
2009-08-27 04:29:47 +04:00
|
|
|
|
|
|
|
return inst->ConvertPoint(sourceX, sourceY, sourceSpace, destX, destY,
|
|
|
|
destSpace);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void _urlredirectresponse(NPP instance, void* notifyData, NPBool allow) {
|
2015-07-17 10:17:09 +03:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,
|
|
|
|
("NPN_convertpoint called from the wrong thread\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
|
2011-01-05 22:44:21 +03:00
|
|
|
if (!inst) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inst->URLRedirectResponse(notifyData, allow);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError _initasyncsurface(NPP instance, NPSize* size, NPImageFormat format,
|
|
|
|
void* initData, NPAsyncSurface* surface) {
|
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
|
2015-12-02 22:31:16 +03:00
|
|
|
if (!inst) {
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return inst->InitAsyncSurface(size, format, initData, surface);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NPError _finalizeasyncsurface(NPP instance, NPAsyncSurface* surface) {
|
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
|
2015-12-02 22:31:16 +03:00
|
|
|
if (!inst) {
|
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return inst->FinalizeAsyncSurface(surface);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void _setcurrentasyncsurface(NPP instance, NPAsyncSurface* surface,
|
|
|
|
NPRect* changed) {
|
|
|
|
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
|
2015-12-02 22:31:16 +03:00
|
|
|
if (!inst) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inst->SetCurrentAsyncSurface(surface, changed);
|
|
|
|
}
|
|
|
|
|
2009-12-02 00:27:13 +03:00
|
|
|
} /* namespace parent */
|
|
|
|
} /* namespace plugins */
|
|
|
|
} /* namespace mozilla */
|