dom/plugins/ipc/PluginMessageUtils.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/ipc/PluginMessageUtils.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,173 @@
     1.4 +/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8; -*- */
     1.5 +/* vim: set sw=2 ts=8 et tw=80 : */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "PluginMessageUtils.h"
    1.11 +#include "nsIRunnable.h"
    1.12 +#include "nsThreadUtils.h"
    1.13 +
    1.14 +#include "PluginInstanceParent.h"
    1.15 +#include "PluginInstanceChild.h"
    1.16 +#include "PluginScriptableObjectParent.h"
    1.17 +#include "PluginScriptableObjectChild.h"
    1.18 +
    1.19 +using std::string;
    1.20 +
    1.21 +using mozilla::ipc::MessageChannel;
    1.22 +
    1.23 +namespace {
    1.24 +
    1.25 +class DeferNPObjectReleaseRunnable : public nsRunnable
    1.26 +{
    1.27 +public:
    1.28 +  DeferNPObjectReleaseRunnable(const NPNetscapeFuncs* f, NPObject* o)
    1.29 +    : mFuncs(f)
    1.30 +    , mObject(o)
    1.31 +  {
    1.32 +    NS_ASSERTION(o, "no release null objects");
    1.33 +  }
    1.34 +
    1.35 +  NS_IMETHOD Run();
    1.36 +
    1.37 +private:
    1.38 +  const NPNetscapeFuncs* mFuncs;
    1.39 +  NPObject* mObject;
    1.40 +};
    1.41 +
    1.42 +NS_IMETHODIMP
    1.43 +DeferNPObjectReleaseRunnable::Run()
    1.44 +{
    1.45 +  mFuncs->releaseobject(mObject);
    1.46 +  return NS_OK;
    1.47 +}
    1.48 +
    1.49 +} // anonymous namespace
    1.50 +
    1.51 +namespace mozilla {
    1.52 +namespace plugins {
    1.53 +
    1.54 +NPRemoteWindow::NPRemoteWindow() :
    1.55 +  window(0), x(0), y(0), width(0), height(0), type(NPWindowTypeDrawable)
    1.56 +#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
    1.57 +  , visualID(0)
    1.58 +  , colormap(0)
    1.59 +#endif /* XP_UNIX */
    1.60 +#if defined(XP_WIN)
    1.61 +  ,surfaceHandle(0)
    1.62 +#endif
    1.63 +#if defined(XP_MACOSX)
    1.64 +  ,contentsScaleFactor(1.0)
    1.65 +#endif
    1.66 +{
    1.67 +  clipRect.top = 0;
    1.68 +  clipRect.left = 0;
    1.69 +  clipRect.bottom = 0;
    1.70 +  clipRect.right = 0;
    1.71 +}
    1.72 +
    1.73 +ipc::RacyInterruptPolicy
    1.74 +MediateRace(const MessageChannel::Message& parent,
    1.75 +            const MessageChannel::Message& child)
    1.76 +{
    1.77 +  switch (parent.type()) {
    1.78 +  case PPluginInstance::Msg_Paint__ID:
    1.79 +  case PPluginInstance::Msg_NPP_SetWindow__ID:
    1.80 +  case PPluginInstance::Msg_NPP_HandleEvent_Shmem__ID:
    1.81 +  case PPluginInstance::Msg_NPP_HandleEvent_IOSurface__ID:
    1.82 +    // our code relies on the frame list not changing during paints and
    1.83 +    // reflows
    1.84 +    return ipc::RIPParentWins;
    1.85 +
    1.86 +  default:
    1.87 +    return ipc::RIPChildWins;
    1.88 +  }
    1.89 +}
    1.90 +
    1.91 +#if defined(OS_LINUX)
    1.92 +static string
    1.93 +ReplaceAll(const string& haystack, const string& needle, const string& with)
    1.94 +{
    1.95 +  string munged = haystack;
    1.96 +  string::size_type i = 0;
    1.97 +
    1.98 +  while (string::npos != (i = munged.find(needle, i))) {
    1.99 +    munged.replace(i, needle.length(), with);
   1.100 +    i += with.length();
   1.101 +  }
   1.102 +
   1.103 +  return munged;
   1.104 +}
   1.105 +#endif
   1.106 +
   1.107 +string
   1.108 +MungePluginDsoPath(const string& path)
   1.109 +{
   1.110 +#if defined(OS_LINUX)
   1.111 +  // https://bugzilla.mozilla.org/show_bug.cgi?id=519601
   1.112 +  return ReplaceAll(path, "netscape", "netsc@pe");
   1.113 +#else
   1.114 +  return path;
   1.115 +#endif
   1.116 +}
   1.117 +
   1.118 +string
   1.119 +UnmungePluginDsoPath(const string& munged)
   1.120 +{
   1.121 +#if defined(OS_LINUX)
   1.122 +  return ReplaceAll(munged, "netsc@pe", "netscape");
   1.123 +#else
   1.124 +  return munged;
   1.125 +#endif
   1.126 +}
   1.127 +
   1.128 +
   1.129 +PRLogModuleInfo*
   1.130 +GetPluginLog()
   1.131 +{
   1.132 +  static PRLogModuleInfo *sLog;
   1.133 +  if (!sLog)
   1.134 +    sLog = PR_NewLogModule("IPCPlugins");
   1.135 +  return sLog;
   1.136 +}
   1.137 +
   1.138 +void
   1.139 +DeferNPObjectLastRelease(const NPNetscapeFuncs* f, NPObject* o)
   1.140 +{
   1.141 +  if (!o)
   1.142 +    return;
   1.143 +
   1.144 +  if (o->referenceCount > 1) {
   1.145 +    f->releaseobject(o);
   1.146 +    return;
   1.147 +  }
   1.148 +
   1.149 +  NS_DispatchToCurrentThread(new DeferNPObjectReleaseRunnable(f, o));
   1.150 +}
   1.151 +
   1.152 +void DeferNPVariantLastRelease(const NPNetscapeFuncs* f, NPVariant* v)
   1.153 +{
   1.154 +  if (!NPVARIANT_IS_OBJECT(*v)) {
   1.155 +    f->releasevariantvalue(v);
   1.156 +    return;
   1.157 +  }
   1.158 +  DeferNPObjectLastRelease(f, v->value.objectValue);
   1.159 +  VOID_TO_NPVARIANT(*v);
   1.160 +}
   1.161 +
   1.162 +#ifdef XP_WIN
   1.163 +
   1.164 +// The private event used for double-pass widgetless plugin rendering.
   1.165 +UINT DoublePassRenderingEvent()
   1.166 +{
   1.167 +  static UINT gEventID = 0;
   1.168 +  if (!gEventID)
   1.169 +    gEventID = ::RegisterWindowMessage(L"MozDoublePassMsg");
   1.170 +  return gEventID;
   1.171 +}
   1.172 +
   1.173 +#endif
   1.174 +
   1.175 +} // namespace plugins
   1.176 +} // namespace mozilla

mercurial