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 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Content App.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * The Mozilla Foundation.
20 : * Portions created by the Initial Developer are Copyright (C) 2009
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "PluginMessageUtils.h"
40 : #include "nsIRunnable.h"
41 : #include "nsThreadUtils.h"
42 :
43 : #include "PluginInstanceParent.h"
44 : #include "PluginInstanceChild.h"
45 : #include "PluginScriptableObjectParent.h"
46 : #include "PluginScriptableObjectChild.h"
47 :
48 : using std::string;
49 :
50 : using mozilla::ipc::RPCChannel;
51 :
52 : namespace {
53 :
54 : class DeferNPObjectReleaseRunnable : public nsRunnable
55 0 : {
56 : public:
57 0 : DeferNPObjectReleaseRunnable(const NPNetscapeFuncs* f, NPObject* o)
58 : : mFuncs(f)
59 0 : , mObject(o)
60 : {
61 0 : NS_ASSERTION(o, "no release null objects");
62 0 : }
63 :
64 : NS_IMETHOD Run();
65 :
66 : private:
67 : const NPNetscapeFuncs* mFuncs;
68 : NPObject* mObject;
69 : };
70 :
71 : NS_IMETHODIMP
72 0 : DeferNPObjectReleaseRunnable::Run()
73 : {
74 0 : mFuncs->releaseobject(mObject);
75 0 : return NS_OK;
76 : }
77 :
78 : } // anonymous namespace
79 :
80 : namespace mozilla {
81 : namespace plugins {
82 :
83 0 : NPRemoteWindow::NPRemoteWindow() :
84 : window(0), x(0), y(0), width(0), height(0), type(NPWindowTypeDrawable)
85 : #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
86 : , visualID(0)
87 0 : , colormap(0)
88 : #endif /* XP_UNIX */
89 : #if defined(XP_WIN)
90 : ,surfaceHandle(0)
91 : #endif
92 : {
93 0 : clipRect.top = 0;
94 0 : clipRect.left = 0;
95 0 : clipRect.bottom = 0;
96 0 : clipRect.right = 0;
97 0 : }
98 :
99 : RPCChannel::RacyRPCPolicy
100 0 : MediateRace(const RPCChannel::Message& parent,
101 : const RPCChannel::Message& child)
102 : {
103 0 : switch (parent.type()) {
104 : case PPluginInstance::Msg_Paint__ID:
105 : case PPluginInstance::Msg_NPP_SetWindow__ID:
106 : case PPluginInstance::Msg_NPP_HandleEvent_Shmem__ID:
107 : case PPluginInstance::Msg_NPP_HandleEvent_IOSurface__ID:
108 : // our code relies on the frame list not changing during paints and
109 : // reflows
110 0 : return RPCChannel::RRPParentWins;
111 :
112 : default:
113 0 : return RPCChannel::RRPChildWins;
114 : }
115 : }
116 :
117 : #if defined(OS_LINUX)
118 : static string
119 0 : ReplaceAll(const string& haystack, const string& needle, const string& with)
120 : {
121 0 : string munged = haystack;
122 0 : string::size_type i = 0;
123 :
124 0 : while (string::npos != (i = munged.find(needle, i))) {
125 0 : munged.replace(i, needle.length(), with);
126 0 : i += with.length();
127 : }
128 :
129 : return munged;
130 : }
131 : #endif
132 :
133 : string
134 0 : MungePluginDsoPath(const string& path)
135 : {
136 : #if defined(OS_LINUX)
137 : // https://bugzilla.mozilla.org/show_bug.cgi?id=519601
138 0 : return ReplaceAll(path, "netscape", "netsc@pe");
139 : #else
140 : return path;
141 : #endif
142 : }
143 :
144 : string
145 0 : UnmungePluginDsoPath(const string& munged)
146 : {
147 : #if defined(OS_LINUX)
148 0 : return ReplaceAll(munged, "netsc@pe", "netscape");
149 : #else
150 : return munged;
151 : #endif
152 : }
153 :
154 :
155 1464 : PRLogModuleInfo* gPluginLog = PR_NewLogModule("IPCPlugins");
156 :
157 : void
158 0 : DeferNPObjectLastRelease(const NPNetscapeFuncs* f, NPObject* o)
159 : {
160 0 : if (!o)
161 0 : return;
162 :
163 0 : if (o->referenceCount > 1) {
164 0 : f->releaseobject(o);
165 0 : return;
166 : }
167 :
168 0 : NS_DispatchToCurrentThread(new DeferNPObjectReleaseRunnable(f, o));
169 : }
170 :
171 0 : void DeferNPVariantLastRelease(const NPNetscapeFuncs* f, NPVariant* v)
172 : {
173 0 : if (!NPVARIANT_IS_OBJECT(*v)) {
174 0 : f->releasevariantvalue(v);
175 0 : return;
176 : }
177 0 : DeferNPObjectLastRelease(f, v->value.objectValue);
178 0 : VOID_TO_NPVARIANT(*v);
179 : }
180 :
181 : #ifdef XP_WIN
182 :
183 : // The private event used for double-pass widgetless plugin rendering.
184 : UINT DoublePassRenderingEvent()
185 : {
186 : static UINT gEventID = 0;
187 : if (!gEventID)
188 : gEventID = ::RegisterWindowMessage(L"MozDoublePassMsg");
189 : return gEventID;
190 : }
191 :
192 : #endif
193 :
194 : } // namespace plugins
195 4392 : } // namespace mozilla
|