/src/mozilla-central/dom/plugins/ipc/PluginMessageUtils.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "PluginMessageUtils.h" |
8 | | #include "nsIRunnable.h" |
9 | | #include "nsThreadUtils.h" |
10 | | |
11 | | #include "PluginInstanceParent.h" |
12 | | #include "PluginInstanceChild.h" |
13 | | #include "PluginScriptableObjectParent.h" |
14 | | #include "PluginScriptableObjectChild.h" |
15 | | |
16 | | using std::string; |
17 | | |
18 | | using mozilla::ipc::MessageChannel; |
19 | | |
20 | | namespace { |
21 | | |
22 | | class DeferNPObjectReleaseRunnable : public mozilla::Runnable |
23 | | { |
24 | | public: |
25 | | DeferNPObjectReleaseRunnable(const NPNetscapeFuncs* f, NPObject* o) |
26 | | : Runnable("DeferNPObjectReleaseRunnable") |
27 | | , mFuncs(f) |
28 | | , mObject(o) |
29 | 0 | { |
30 | 0 | NS_ASSERTION(o, "no release null objects"); |
31 | 0 | } |
32 | | |
33 | | NS_IMETHOD Run() override; |
34 | | |
35 | | private: |
36 | | const NPNetscapeFuncs* mFuncs; |
37 | | NPObject* mObject; |
38 | | }; |
39 | | |
40 | | NS_IMETHODIMP |
41 | | DeferNPObjectReleaseRunnable::Run() |
42 | 0 | { |
43 | 0 | mFuncs->releaseobject(mObject); |
44 | 0 | return NS_OK; |
45 | 0 | } |
46 | | |
47 | | } // namespace |
48 | | |
49 | | namespace mozilla { |
50 | | namespace plugins { |
51 | | |
52 | | NPRemoteWindow::NPRemoteWindow() : |
53 | | window(0), x(0), y(0), width(0), height(0), type(NPWindowTypeDrawable) |
54 | | #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX) |
55 | | , visualID(0) |
56 | | , colormap(0) |
57 | | #endif /* XP_UNIX */ |
58 | | #if defined(XP_MACOSX) |
59 | | ,contentsScaleFactor(1.0) |
60 | | #endif |
61 | 0 | { |
62 | 0 | clipRect.top = 0; |
63 | 0 | clipRect.left = 0; |
64 | 0 | clipRect.bottom = 0; |
65 | 0 | clipRect.right = 0; |
66 | 0 | } |
67 | | |
68 | | ipc::RacyInterruptPolicy |
69 | | MediateRace(const MessageChannel::MessageInfo& parent, |
70 | | const MessageChannel::MessageInfo& child) |
71 | | { |
72 | | switch (parent.type()) { |
73 | | case PPluginInstance::Msg_Paint__ID: |
74 | | case PPluginInstance::Msg_NPP_SetWindow__ID: |
75 | | case PPluginInstance::Msg_NPP_HandleEvent_Shmem__ID: |
76 | | case PPluginInstance::Msg_NPP_HandleEvent_IOSurface__ID: |
77 | | // our code relies on the frame list not changing during paints and |
78 | | // reflows |
79 | | return ipc::RIPParentWins; |
80 | | |
81 | | default: |
82 | | return ipc::RIPChildWins; |
83 | | } |
84 | | } |
85 | | |
86 | | #if defined(OS_LINUX) || defined(OS_SOLARIS) |
87 | | static string |
88 | | ReplaceAll(const string& haystack, const string& needle, const string& with) |
89 | 0 | { |
90 | 0 | string munged = haystack; |
91 | 0 | string::size_type i = 0; |
92 | 0 |
|
93 | 0 | while (string::npos != (i = munged.find(needle, i))) { |
94 | 0 | munged.replace(i, needle.length(), with); |
95 | 0 | i += with.length(); |
96 | 0 | } |
97 | 0 |
|
98 | 0 | return munged; |
99 | 0 | } |
100 | | #endif |
101 | | |
102 | | string |
103 | | MungePluginDsoPath(const string& path) |
104 | 0 | { |
105 | 0 | #if defined(OS_LINUX) || defined(OS_SOLARIS) |
106 | 0 | // https://bugzilla.mozilla.org/show_bug.cgi?id=519601 |
107 | 0 | return ReplaceAll(path, "netscape", "netsc@pe"); |
108 | | #else |
109 | | return path; |
110 | | #endif |
111 | | } |
112 | | |
113 | | string |
114 | | UnmungePluginDsoPath(const string& munged) |
115 | 0 | { |
116 | 0 | #if defined(OS_LINUX) || defined(OS_SOLARIS) |
117 | 0 | return ReplaceAll(munged, "netsc@pe", "netscape"); |
118 | | #else |
119 | | return munged; |
120 | | #endif |
121 | | } |
122 | | |
123 | | |
124 | | LogModule* |
125 | | GetPluginLog() |
126 | 0 | { |
127 | 0 | static LazyLogModule sLog("IPCPlugins"); |
128 | 0 | return sLog; |
129 | 0 | } |
130 | | |
131 | | void |
132 | | DeferNPObjectLastRelease(const NPNetscapeFuncs* f, NPObject* o) |
133 | 0 | { |
134 | 0 | if (!o) |
135 | 0 | return; |
136 | 0 | |
137 | 0 | if (o->referenceCount > 1) { |
138 | 0 | f->releaseobject(o); |
139 | 0 | return; |
140 | 0 | } |
141 | 0 | |
142 | 0 | NS_DispatchToCurrentThread(new DeferNPObjectReleaseRunnable(f, o)); |
143 | 0 | } |
144 | | |
145 | | void DeferNPVariantLastRelease(const NPNetscapeFuncs* f, NPVariant* v) |
146 | 0 | { |
147 | 0 | if (!NPVARIANT_IS_OBJECT(*v)) { |
148 | 0 | f->releasevariantvalue(v); |
149 | 0 | return; |
150 | 0 | } |
151 | 0 | DeferNPObjectLastRelease(f, v->value.objectValue); |
152 | 0 | VOID_TO_NPVARIANT(*v); |
153 | 0 | } |
154 | | |
155 | | } // namespace plugins |
156 | | } // namespace mozilla |