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