dom/plugins/ipc/PluginMessageUtils.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8; -*- */
     2 /* vim: set sw=2 ts=8 et tw=80 : */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "PluginMessageUtils.h"
     8 #include "nsIRunnable.h"
     9 #include "nsThreadUtils.h"
    11 #include "PluginInstanceParent.h"
    12 #include "PluginInstanceChild.h"
    13 #include "PluginScriptableObjectParent.h"
    14 #include "PluginScriptableObjectChild.h"
    16 using std::string;
    18 using mozilla::ipc::MessageChannel;
    20 namespace {
    22 class DeferNPObjectReleaseRunnable : public nsRunnable
    23 {
    24 public:
    25   DeferNPObjectReleaseRunnable(const NPNetscapeFuncs* f, NPObject* o)
    26     : mFuncs(f)
    27     , mObject(o)
    28   {
    29     NS_ASSERTION(o, "no release null objects");
    30   }
    32   NS_IMETHOD Run();
    34 private:
    35   const NPNetscapeFuncs* mFuncs;
    36   NPObject* mObject;
    37 };
    39 NS_IMETHODIMP
    40 DeferNPObjectReleaseRunnable::Run()
    41 {
    42   mFuncs->releaseobject(mObject);
    43   return NS_OK;
    44 }
    46 } // anonymous namespace
    48 namespace mozilla {
    49 namespace plugins {
    51 NPRemoteWindow::NPRemoteWindow() :
    52   window(0), x(0), y(0), width(0), height(0), type(NPWindowTypeDrawable)
    53 #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
    54   , visualID(0)
    55   , colormap(0)
    56 #endif /* XP_UNIX */
    57 #if defined(XP_WIN)
    58   ,surfaceHandle(0)
    59 #endif
    60 #if defined(XP_MACOSX)
    61   ,contentsScaleFactor(1.0)
    62 #endif
    63 {
    64   clipRect.top = 0;
    65   clipRect.left = 0;
    66   clipRect.bottom = 0;
    67   clipRect.right = 0;
    68 }
    70 ipc::RacyInterruptPolicy
    71 MediateRace(const MessageChannel::Message& parent,
    72             const MessageChannel::Message& child)
    73 {
    74   switch (parent.type()) {
    75   case PPluginInstance::Msg_Paint__ID:
    76   case PPluginInstance::Msg_NPP_SetWindow__ID:
    77   case PPluginInstance::Msg_NPP_HandleEvent_Shmem__ID:
    78   case PPluginInstance::Msg_NPP_HandleEvent_IOSurface__ID:
    79     // our code relies on the frame list not changing during paints and
    80     // reflows
    81     return ipc::RIPParentWins;
    83   default:
    84     return ipc::RIPChildWins;
    85   }
    86 }
    88 #if defined(OS_LINUX)
    89 static string
    90 ReplaceAll(const string& haystack, const string& needle, const string& with)
    91 {
    92   string munged = haystack;
    93   string::size_type i = 0;
    95   while (string::npos != (i = munged.find(needle, i))) {
    96     munged.replace(i, needle.length(), with);
    97     i += with.length();
    98   }
   100   return munged;
   101 }
   102 #endif
   104 string
   105 MungePluginDsoPath(const string& path)
   106 {
   107 #if defined(OS_LINUX)
   108   // https://bugzilla.mozilla.org/show_bug.cgi?id=519601
   109   return ReplaceAll(path, "netscape", "netsc@pe");
   110 #else
   111   return path;
   112 #endif
   113 }
   115 string
   116 UnmungePluginDsoPath(const string& munged)
   117 {
   118 #if defined(OS_LINUX)
   119   return ReplaceAll(munged, "netsc@pe", "netscape");
   120 #else
   121   return munged;
   122 #endif
   123 }
   126 PRLogModuleInfo*
   127 GetPluginLog()
   128 {
   129   static PRLogModuleInfo *sLog;
   130   if (!sLog)
   131     sLog = PR_NewLogModule("IPCPlugins");
   132   return sLog;
   133 }
   135 void
   136 DeferNPObjectLastRelease(const NPNetscapeFuncs* f, NPObject* o)
   137 {
   138   if (!o)
   139     return;
   141   if (o->referenceCount > 1) {
   142     f->releaseobject(o);
   143     return;
   144   }
   146   NS_DispatchToCurrentThread(new DeferNPObjectReleaseRunnable(f, o));
   147 }
   149 void DeferNPVariantLastRelease(const NPNetscapeFuncs* f, NPVariant* v)
   150 {
   151   if (!NPVARIANT_IS_OBJECT(*v)) {
   152     f->releasevariantvalue(v);
   153     return;
   154   }
   155   DeferNPObjectLastRelease(f, v->value.objectValue);
   156   VOID_TO_NPVARIANT(*v);
   157 }
   159 #ifdef XP_WIN
   161 // The private event used for double-pass widgetless plugin rendering.
   162 UINT DoublePassRenderingEvent()
   163 {
   164   static UINT gEventID = 0;
   165   if (!gEventID)
   166     gEventID = ::RegisterWindowMessage(L"MozDoublePassMsg");
   167   return gEventID;
   168 }
   170 #endif
   172 } // namespace plugins
   173 } // namespace mozilla

mercurial