This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 305
/
PluginModuleChild.cpp
2288 lines (1917 loc) · 64.9 KB
/
PluginModuleChild.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: sw=4 ts=4 et : */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Jones <jones.chris.g@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifdef MOZ_WIDGET_QT
#include <QtCore/QTimer>
#include "nsQAppInstance.h"
#include "NestedLoopTimer.h"
#endif
#include "mozilla/plugins/PluginModuleChild.h"
#ifdef MOZ_WIDGET_GTK2
#include <gtk/gtk.h>
#endif
#include "nsILocalFile.h"
#include "pratom.h"
#include "nsDebug.h"
#include "nsCOMPtr.h"
#include "nsPluginsDir.h"
#include "nsXULAppAPI.h"
#ifdef MOZ_X11
# include "mozilla/X11Util.h"
#endif
#include "mozilla/plugins/PluginInstanceChild.h"
#include "mozilla/plugins/StreamNotifyChild.h"
#include "mozilla/plugins/BrowserStreamChild.h"
#include "mozilla/plugins/PluginStreamChild.h"
#include "PluginIdentifierChild.h"
#include "nsNPAPIPlugin.h"
#ifdef XP_WIN
#include "COMMessageFilter.h"
#include "nsWindowsDllInterceptor.h"
#endif
#ifdef OS_MACOSX
#include "PluginInterposeOSX.h"
#include "PluginUtilsOSX.h"
#endif
using namespace mozilla::plugins;
#if defined(XP_WIN)
const PRUnichar * kFlashFullscreenClass = L"ShockwaveFlashFullScreen";
const PRUnichar * kMozillaWindowClass = L"MozillaWindowClass";
#endif
namespace {
PluginModuleChild* gInstance = nsnull;
}
#ifdef MOZ_WIDGET_QT
typedef void (*_gtk_init_fn)(int argc, char **argv);
static _gtk_init_fn s_gtk_init = nsnull;
static PRLibrary *sGtkLib = nsnull;
#endif
#ifdef XP_WIN
// Used with fix for flash fullscreen window loosing focus.
static bool gDelayFlashFocusReplyUntilEval = false;
// Used to fix GetWindowInfo problems with internal flash settings dialogs
static WindowsDllInterceptor sUser32Intercept;
typedef BOOL (WINAPI *GetWindowInfoPtr)(HWND hwnd, PWINDOWINFO pwi);
static GetWindowInfoPtr sGetWindowInfoPtrStub = NULL;
static HWND sBrowserHwnd = NULL;
#endif
PluginModuleChild::PluginModuleChild()
: mLibrary(0)
, mPluginFilename("")
, mQuirks(QUIRKS_NOT_INITIALIZED)
, mShutdownFunc(0)
, mInitializeFunc(0)
#if defined(OS_WIN) || defined(OS_MACOSX)
, mGetEntryPointsFunc(0)
#elif defined(MOZ_WIDGET_GTK2)
, mNestedLoopTimerId(0)
#elif defined(MOZ_WIDGET_QT)
, mNestedLoopTimerObject(0)
#endif
#ifdef OS_WIN
, mNestedEventHook(NULL)
, mGlobalCallWndProcHook(NULL)
#endif
{
NS_ASSERTION(!gInstance, "Something terribly wrong here!");
memset(&mFunctions, 0, sizeof(mFunctions));
memset(&mSavedData, 0, sizeof(mSavedData));
gInstance = this;
#ifdef XP_MACOSX
mac_plugin_interposing::child::SetUpCocoaInterposing();
#endif
}
PluginModuleChild::~PluginModuleChild()
{
NS_ASSERTION(gInstance == this, "Something terribly wrong here!");
if (mLibrary) {
PR_UnloadLibrary(mLibrary);
}
DeinitGraphics();
gInstance = nsnull;
}
// static
PluginModuleChild*
PluginModuleChild::current()
{
NS_ASSERTION(gInstance, "Null instance!");
return gInstance;
}
bool
PluginModuleChild::Init(const std::string& aPluginFilename,
base::ProcessHandle aParentProcessHandle,
MessageLoop* aIOLoop,
IPC::Channel* aChannel)
{
PLUGIN_LOG_DEBUG_METHOD;
#ifdef XP_WIN
COMMessageFilter::Initialize(this);
#endif
NS_ASSERTION(aChannel, "need a channel");
if (!mObjectMap.Init()) {
NS_WARNING("Failed to initialize object hashtable!");
return false;
}
if (!mStringIdentifiers.Init()) {
NS_ERROR("Failed to initialize string identifier hashtable!");
return false;
}
if (!mIntIdentifiers.Init()) {
NS_ERROR("Failed to initialize int identifier hashtable!");
return false;
}
if (!InitGraphics())
return false;
mPluginFilename = aPluginFilename.c_str();
nsCOMPtr<nsILocalFile> pluginFile;
NS_NewLocalFile(NS_ConvertUTF8toUTF16(mPluginFilename),
PR_TRUE,
getter_AddRefs(pluginFile));
PRBool exists;
pluginFile->Exists(&exists);
NS_ASSERTION(exists, "plugin file ain't there");
nsCOMPtr<nsIFile> pluginIfile;
pluginIfile = do_QueryInterface(pluginFile);
nsPluginFile lib(pluginIfile);
nsresult rv = lib.LoadPlugin(&mLibrary);
NS_ASSERTION(NS_OK == rv, "trouble with mPluginFile");
NS_ASSERTION(mLibrary, "couldn't open shared object");
if (!Open(aChannel, aParentProcessHandle, aIOLoop))
return false;
memset((void*) &mFunctions, 0, sizeof(mFunctions));
mFunctions.size = sizeof(mFunctions);
mFunctions.version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
// TODO: use PluginPRLibrary here
#if defined(OS_LINUX)
mShutdownFunc =
(NP_PLUGINSHUTDOWN) PR_FindFunctionSymbol(mLibrary, "NP_Shutdown");
// create the new plugin handler
mInitializeFunc =
(NP_PLUGINUNIXINIT) PR_FindFunctionSymbol(mLibrary, "NP_Initialize");
NS_ASSERTION(mInitializeFunc, "couldn't find NP_Initialize()");
#elif defined(OS_WIN) || defined(OS_MACOSX)
mShutdownFunc =
(NP_PLUGINSHUTDOWN)PR_FindFunctionSymbol(mLibrary, "NP_Shutdown");
mGetEntryPointsFunc =
(NP_GETENTRYPOINTS)PR_FindSymbol(mLibrary, "NP_GetEntryPoints");
NS_ENSURE_TRUE(mGetEntryPointsFunc, false);
mInitializeFunc =
(NP_PLUGININIT)PR_FindFunctionSymbol(mLibrary, "NP_Initialize");
NS_ENSURE_TRUE(mInitializeFunc, false);
#else
# error Please copy the initialization code from nsNPAPIPlugin.cpp
#endif
return true;
}
#if defined(MOZ_WIDGET_GTK2)
typedef void (*GObjectDisposeFn)(GObject*);
typedef gboolean (*GtkWidgetScrollEventFn)(GtkWidget*, GdkEventScroll*);
typedef void (*GtkPlugEmbeddedFn)(GtkPlug*);
static GObjectDisposeFn real_gtk_plug_dispose;
static GtkPlugEmbeddedFn real_gtk_plug_embedded;
static void
undo_bogus_unref(gpointer data, GObject* object, gboolean is_last_ref) {
if (!is_last_ref) // recursion in g_object_ref
return;
g_object_ref(object);
}
static void
wrap_gtk_plug_dispose(GObject* object) {
// Work around Flash Player bug described in bug 538914.
//
// This function is called during gtk_widget_destroy and/or before
// the object's last reference is removed. A reference to the
// object is held during the call so the ref count should not drop
// to zero. However, Flash Player tries to destroy the GtkPlug
// using g_object_unref instead of gtk_widget_destroy. The
// reference that Flash is removing actually belongs to the
// GtkPlug. During real_gtk_plug_dispose, the GtkPlug removes its
// reference.
//
// A toggle ref is added to prevent premature deletion of the object
// caused by Flash Player's extra unref, and to detect when there are
// unexpectedly no other references.
g_object_add_toggle_ref(object, undo_bogus_unref, NULL);
(*real_gtk_plug_dispose)(object);
g_object_remove_toggle_ref(object, undo_bogus_unref, NULL);
}
static gboolean
gtk_plug_scroll_event(GtkWidget *widget, GdkEventScroll *gdk_event)
{
if (!GTK_WIDGET_TOPLEVEL(widget)) // in same process as its GtkSocket
return FALSE; // event not handled; propagate to GtkSocket
GdkWindow* socket_window = GTK_PLUG(widget)->socket_window;
if (!socket_window)
return FALSE;
// Propagate the event to the embedder.
GdkScreen* screen = gdk_drawable_get_screen(socket_window);
GdkWindow* plug_window = widget->window;
GdkWindow* event_window = gdk_event->window;
gint x = gdk_event->x;
gint y = gdk_event->y;
unsigned int button;
unsigned int button_mask = 0;
XEvent xevent;
Display* dpy = GDK_WINDOW_XDISPLAY(socket_window);
/* Translate the event coordinates to the plug window,
* which should be aligned with the socket window.
*/
while (event_window != plug_window)
{
gint dx, dy;
gdk_window_get_position(event_window, &dx, &dy);
x += dx;
y += dy;
event_window = gdk_window_get_parent(event_window);
if (!event_window)
return FALSE;
}
switch (gdk_event->direction) {
case GDK_SCROLL_UP:
button = 4;
button_mask = Button4Mask;
break;
case GDK_SCROLL_DOWN:
button = 5;
button_mask = Button5Mask;
break;
case GDK_SCROLL_LEFT:
button = 6;
break;
case GDK_SCROLL_RIGHT:
button = 7;
break;
default:
return FALSE; // unknown GdkScrollDirection
}
memset(&xevent, 0, sizeof(xevent));
xevent.xbutton.type = ButtonPress;
xevent.xbutton.window = GDK_WINDOW_XWINDOW(socket_window);
xevent.xbutton.root = GDK_WINDOW_XWINDOW(gdk_screen_get_root_window(screen));
xevent.xbutton.subwindow = GDK_WINDOW_XWINDOW(plug_window);
xevent.xbutton.time = gdk_event->time;
xevent.xbutton.x = x;
xevent.xbutton.y = y;
xevent.xbutton.x_root = gdk_event->x_root;
xevent.xbutton.y_root = gdk_event->y_root;
xevent.xbutton.state = gdk_event->state;
xevent.xbutton.button = button;
xevent.xbutton.same_screen = True;
gdk_error_trap_push();
XSendEvent(dpy, xevent.xbutton.window,
True, ButtonPressMask, &xevent);
xevent.xbutton.type = ButtonRelease;
xevent.xbutton.state |= button_mask;
XSendEvent(dpy, xevent.xbutton.window,
True, ButtonReleaseMask, &xevent);
gdk_display_sync(gdk_screen_get_display(screen));
gdk_error_trap_pop();
return TRUE; // event handled
}
static void
wrap_gtk_plug_embedded(GtkPlug* plug) {
GdkWindow* socket_window = plug->socket_window;
if (socket_window) {
if (gtk_check_version(2,18,7) != NULL // older
&& g_object_get_data(G_OBJECT(socket_window),
"moz-existed-before-set-window")) {
// Add missing reference for
// https://bugzilla.gnome.org/show_bug.cgi?id=607061
g_object_ref(socket_window);
}
// Ensure the window exists to make this GtkPlug behave like an
// in-process GtkPlug for Flash Player. (Bugs 561308 and 539138).
gtk_widget_realize(GTK_WIDGET(plug));
}
if (*real_gtk_plug_embedded) {
(*real_gtk_plug_embedded)(plug);
}
}
//
// The next four constants are knobs that can be tuned. They trade
// off potential UI lag from delayed event processing with CPU time.
//
static const gint kNestedLoopDetectorPriority = G_PRIORITY_HIGH_IDLE;
// 90ms so that we can hopefully break livelocks before the user
// notices UI lag (100ms)
static const guint kNestedLoopDetectorIntervalMs = 90;
static const gint kBrowserEventPriority = G_PRIORITY_HIGH_IDLE;
static const guint kBrowserEventIntervalMs = 10;
// static
gboolean
PluginModuleChild::DetectNestedEventLoop(gpointer data)
{
PluginModuleChild* pmc = static_cast<PluginModuleChild*>(data);
NS_ABORT_IF_FALSE(0 != pmc->mNestedLoopTimerId,
"callback after descheduling");
NS_ABORT_IF_FALSE(pmc->mTopLoopDepth < g_main_depth(),
"not canceled before returning to main event loop!");
PLUGIN_LOG_DEBUG(("Detected nested glib event loop"));
// just detected a nested loop; start a timer that will
// periodically rpc-call back into the browser and process some
// events
pmc->mNestedLoopTimerId =
g_timeout_add_full(kBrowserEventPriority,
kBrowserEventIntervalMs,
PluginModuleChild::ProcessBrowserEvents,
data,
NULL);
// cancel the nested-loop detection timer
return FALSE;
}
// static
gboolean
PluginModuleChild::ProcessBrowserEvents(gpointer data)
{
PluginModuleChild* pmc = static_cast<PluginModuleChild*>(data);
NS_ABORT_IF_FALSE(pmc->mTopLoopDepth < g_main_depth(),
"not canceled before returning to main event loop!");
pmc->CallProcessSomeEvents();
return TRUE;
}
void
PluginModuleChild::EnteredCxxStack()
{
NS_ABORT_IF_FALSE(0 == mNestedLoopTimerId,
"previous timer not descheduled");
mNestedLoopTimerId =
g_timeout_add_full(kNestedLoopDetectorPriority,
kNestedLoopDetectorIntervalMs,
PluginModuleChild::DetectNestedEventLoop,
this,
NULL);
#ifdef DEBUG
mTopLoopDepth = g_main_depth();
#endif
}
void
PluginModuleChild::ExitedCxxStack()
{
NS_ABORT_IF_FALSE(0 < mNestedLoopTimerId,
"nested loop timeout not scheduled");
g_source_remove(mNestedLoopTimerId);
mNestedLoopTimerId = 0;
}
#elif defined (MOZ_WIDGET_QT)
void
PluginModuleChild::EnteredCxxStack()
{
NS_ABORT_IF_FALSE(mNestedLoopTimerObject == NULL,
"previous timer not descheduled");
mNestedLoopTimerObject = new NestedLoopTimer(this);
QTimer::singleShot(kNestedLoopDetectorIntervalMs,
mNestedLoopTimerObject, SLOT(timeOut()));
}
void
PluginModuleChild::ExitedCxxStack()
{
NS_ABORT_IF_FALSE(mNestedLoopTimerObject != NULL,
"nested loop timeout not scheduled");
delete mNestedLoopTimerObject;
mNestedLoopTimerObject = NULL;
}
#endif
bool
PluginModuleChild::InitGraphics()
{
#if defined(MOZ_WIDGET_GTK2)
// Work around plugins that don't interact well with GDK
// client-side windows.
PR_SetEnv("GDK_NATIVE_WINDOWS=1");
gtk_init(0, 0);
// GtkPlug is a static class so will leak anyway but this ref makes sure.
gpointer gtk_plug_class = g_type_class_ref(GTK_TYPE_PLUG);
// The dispose method is a good place to hook into the destruction process
// because the reference count should be 1 the last time dispose is
// called. (Toggle references wouldn't detect if the reference count
// might be higher.)
GObjectDisposeFn* dispose = &G_OBJECT_CLASS(gtk_plug_class)->dispose;
NS_ABORT_IF_FALSE(*dispose != wrap_gtk_plug_dispose,
"InitGraphics called twice");
real_gtk_plug_dispose = *dispose;
*dispose = wrap_gtk_plug_dispose;
// If we ever stop setting GDK_NATIVE_WINDOWS, we'll also need to
// gtk_widget_add_events GDK_SCROLL_MASK or GDK client-side windows will
// not tell us about the scroll events that it intercepts. With native
// windows, this is called when GDK intercepts the events; if GDK doesn't
// intercept the events, then the X server will instead send them directly
// to an ancestor (embedder) window.
GtkWidgetScrollEventFn* scroll_event =
>K_WIDGET_CLASS(gtk_plug_class)->scroll_event;
if (!*scroll_event) {
*scroll_event = gtk_plug_scroll_event;
}
GtkPlugEmbeddedFn* embedded = >K_PLUG_CLASS(gtk_plug_class)->embedded;
real_gtk_plug_embedded = *embedded;
*embedded = wrap_gtk_plug_embedded;
#elif defined(MOZ_WIDGET_QT)
nsQAppInstance::AddRef();
// Work around plugins that don't interact well without gtk initialized
// see bug 566845
#if defined(MOZ_X11)
if (!sGtkLib)
sGtkLib = PR_LoadLibrary("libgtk-x11-2.0.so.0");
#elif defined(MOZ_DFB)
if (!sGtkLib)
sGtkLib = PR_LoadLibrary("libgtk-directfb-2.0.so.0");
#endif
if (sGtkLib) {
s_gtk_init = (_gtk_init_fn)PR_FindFunctionSymbol(sGtkLib, "gtk_init");
if (s_gtk_init)
s_gtk_init(0, 0);
}
#else
// may not be necessary on all platforms
#endif
#ifdef MOZ_X11
// Do this after initializing GDK, or GDK will install its own handler.
XRE_InstallX11ErrorHandler();
#endif
return true;
}
void
PluginModuleChild::DeinitGraphics()
{
#ifdef MOZ_WIDGET_QT
nsQAppInstance::Release();
if (sGtkLib) {
PR_UnloadLibrary(sGtkLib);
sGtkLib = nsnull;
s_gtk_init = nsnull;
}
#endif
#if defined(MOZ_X11) && defined(NS_FREE_PERMANENT_DATA)
// We free some data off of XDisplay close hooks, ensure they're
// run. Closing the display is pretty scary, so we only do it to
// silence leak checkers.
XCloseDisplay(DefaultXDisplay());
#endif
}
bool
PluginModuleChild::AnswerNP_Shutdown(NPError *rv)
{
AssertPluginThread();
// the PluginModuleParent shuts down this process after this RPC
// call pops off its stack
*rv = mShutdownFunc ? mShutdownFunc() : NPERR_NO_ERROR;
// weakly guard against re-entry after NP_Shutdown
memset(&mFunctions, 0, sizeof(mFunctions));
#ifdef OS_WIN
ResetEventHooks();
#endif
return true;
}
bool
PluginModuleChild::AnswerOptionalFunctionsSupported(bool *aURLRedirectNotify,
bool *aClearSiteData,
bool *aGetSitesWithData)
{
*aURLRedirectNotify = !!mFunctions.urlredirectnotify;
*aClearSiteData = !!mFunctions.clearsitedata;
*aGetSitesWithData = !!mFunctions.getsiteswithdata;
return true;
}
bool
PluginModuleChild::AnswerNPP_ClearSiteData(const nsCString& aSite,
const uint64_t& aFlags,
const uint64_t& aMaxAge,
NPError* aResult)
{
*aResult =
mFunctions.clearsitedata(NullableStringGet(aSite), aFlags, aMaxAge);
return true;
}
bool
PluginModuleChild::AnswerNPP_GetSitesWithData(InfallibleTArray<nsCString>* aResult)
{
char** result = mFunctions.getsiteswithdata();
if (!result)
return true;
char** iterator = result;
while (*iterator) {
aResult->AppendElement(*iterator);
NS_Free(*iterator);
++iterator;
}
NS_Free(result);
return true;
}
void
PluginModuleChild::QuickExit()
{
NS_WARNING("plugin process _exit()ing");
_exit(0);
}
void
PluginModuleChild::ActorDestroy(ActorDestroyReason why)
{
if (AbnormalShutdown == why) {
NS_WARNING("shutting down early because of crash!");
QuickExit();
}
// doesn't matter why we're being destroyed; it's up to us to
// initiate (clean) shutdown
XRE_ShutdownChildProcess();
}
void
PluginModuleChild::CleanUp()
{
}
const char*
PluginModuleChild::GetUserAgent()
{
if (!CallNPN_UserAgent(&mUserAgent))
return NULL;
return NullableStringGet(mUserAgent);
}
bool
PluginModuleChild::RegisterActorForNPObject(NPObject* aObject,
PluginScriptableObjectChild* aActor)
{
AssertPluginThread();
NS_ASSERTION(mObjectMap.IsInitialized(), "Not initialized!");
NS_ASSERTION(aObject && aActor, "Null pointer!");
NPObjectData* d = mObjectMap.GetEntry(aObject);
if (!d) {
NS_ERROR("NPObject not in object table");
return false;
}
d->actor = aActor;
return true;
}
void
PluginModuleChild::UnregisterActorForNPObject(NPObject* aObject)
{
AssertPluginThread();
NS_ASSERTION(mObjectMap.IsInitialized(), "Not initialized!");
NS_ASSERTION(aObject, "Null pointer!");
mObjectMap.GetEntry(aObject)->actor = NULL;
}
PluginScriptableObjectChild*
PluginModuleChild::GetActorForNPObject(NPObject* aObject)
{
AssertPluginThread();
NS_ASSERTION(mObjectMap.IsInitialized(), "Not initialized!");
NS_ASSERTION(aObject, "Null pointer!");
NPObjectData* d = mObjectMap.GetEntry(aObject);
if (!d) {
NS_ERROR("Plugin using object not created with NPN_CreateObject?");
return NULL;
}
return d->actor;
}
#ifdef DEBUG
bool
PluginModuleChild::NPObjectIsRegistered(NPObject* aObject)
{
return !!mObjectMap.GetEntry(aObject);
}
#endif
//-----------------------------------------------------------------------------
// FIXME/cjones: just getting this out of the way for the moment ...
namespace mozilla {
namespace plugins {
namespace child {
static NPError NP_CALLBACK
_requestread(NPStream *pstream, NPByteRange *rangeList);
static NPError NP_CALLBACK
_geturlnotify(NPP aNPP, const char* relativeURL, const char* target,
void* notifyData);
static NPError NP_CALLBACK
_getvalue(NPP aNPP, NPNVariable variable, void *r_value);
static NPError NP_CALLBACK
_setvalue(NPP aNPP, NPPVariable variable, void *r_value);
static NPError NP_CALLBACK
_geturl(NPP aNPP, const char* relativeURL, const char* target);
static NPError NP_CALLBACK
_posturlnotify(NPP aNPP, const char* relativeURL, const char *target,
uint32_t len, const char *buf, NPBool file, void* notifyData);
static NPError NP_CALLBACK
_posturl(NPP aNPP, const char* relativeURL, const char *target, uint32_t len,
const char *buf, NPBool file);
static NPError NP_CALLBACK
_newstream(NPP aNPP, NPMIMEType type, const char* window, NPStream** pstream);
static int32_t NP_CALLBACK
_write(NPP aNPP, NPStream *pstream, int32_t len, void *buffer);
static NPError NP_CALLBACK
_destroystream(NPP aNPP, NPStream *pstream, NPError reason);
static void NP_CALLBACK
_status(NPP aNPP, const char *message);
static void NP_CALLBACK
_memfree (void *ptr);
static uint32_t NP_CALLBACK
_memflush(uint32_t size);
static void NP_CALLBACK
_reloadplugins(NPBool reloadPages);
static void NP_CALLBACK
_invalidaterect(NPP aNPP, NPRect *invalidRect);
static void NP_CALLBACK
_invalidateregion(NPP aNPP, NPRegion invalidRegion);
static void NP_CALLBACK
_forceredraw(NPP aNPP);
static const char* NP_CALLBACK
_useragent(NPP aNPP);
static void* NP_CALLBACK
_memalloc (uint32_t size);
// Deprecated entry points for the old Java plugin.
static void* NP_CALLBACK /* OJI type: JRIEnv* */
_getjavaenv(void);
// Deprecated entry points for the old Java plugin.
static void* NP_CALLBACK /* OJI type: jref */
_getjavapeer(NPP aNPP);
static bool NP_CALLBACK
_invoke(NPP aNPP, NPObject* npobj, NPIdentifier method, const NPVariant *args,
uint32_t argCount, NPVariant *result);
static bool NP_CALLBACK
_invokedefault(NPP aNPP, NPObject* npobj, const NPVariant *args,
uint32_t argCount, NPVariant *result);
static bool NP_CALLBACK
_evaluate(NPP aNPP, NPObject* npobj, NPString *script, NPVariant *result);
static bool NP_CALLBACK
_getproperty(NPP aNPP, NPObject* npobj, NPIdentifier property,
NPVariant *result);
static bool NP_CALLBACK
_setproperty(NPP aNPP, NPObject* npobj, NPIdentifier property,
const NPVariant *value);
static bool NP_CALLBACK
_removeproperty(NPP aNPP, NPObject* npobj, NPIdentifier property);
static bool NP_CALLBACK
_hasproperty(NPP aNPP, NPObject* npobj, NPIdentifier propertyName);
static bool NP_CALLBACK
_hasmethod(NPP aNPP, NPObject* npobj, NPIdentifier methodName);
static bool NP_CALLBACK
_enumerate(NPP aNPP, NPObject *npobj, NPIdentifier **identifier,
uint32_t *count);
static bool NP_CALLBACK
_construct(NPP aNPP, NPObject* npobj, const NPVariant *args,
uint32_t argCount, NPVariant *result);
static void NP_CALLBACK
_releasevariantvalue(NPVariant *variant);
static void NP_CALLBACK
_setexception(NPObject* npobj, const NPUTF8 *message);
static void NP_CALLBACK
_pushpopupsenabledstate(NPP aNPP, NPBool enabled);
static void NP_CALLBACK
_poppopupsenabledstate(NPP aNPP);
static void NP_CALLBACK
_pluginthreadasynccall(NPP instance, PluginThreadCallback func,
void *userData);
static NPError NP_CALLBACK
_getvalueforurl(NPP npp, NPNURLVariable variable, const char *url,
char **value, uint32_t *len);
static NPError NP_CALLBACK
_setvalueforurl(NPP npp, NPNURLVariable variable, const char *url,
const char *value, uint32_t len);
static NPError NP_CALLBACK
_getauthenticationinfo(NPP npp, const char *protocol,
const char *host, int32_t port,
const char *scheme, const char *realm,
char **username, uint32_t *ulen,
char **password, uint32_t *plen);
static uint32_t NP_CALLBACK
_scheduletimer(NPP instance, uint32_t interval, NPBool repeat,
void (*timerFunc)(NPP npp, uint32_t timerID));
static void NP_CALLBACK
_unscheduletimer(NPP instance, uint32_t timerID);
static NPError NP_CALLBACK
_popupcontextmenu(NPP instance, NPMenu* menu);
static NPBool NP_CALLBACK
_convertpoint(NPP instance,
double sourceX, double sourceY, NPCoordinateSpace sourceSpace,
double *destX, double *destY, NPCoordinateSpace destSpace);
static void NP_CALLBACK
_urlredirectresponse(NPP instance, void* notifyData, NPBool allow);
} /* namespace child */
} /* namespace plugins */
} /* namespace mozilla */
const NPNetscapeFuncs PluginModuleChild::sBrowserFuncs = {
sizeof(sBrowserFuncs),
(NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR,
mozilla::plugins::child::_geturl,
mozilla::plugins::child::_posturl,
mozilla::plugins::child::_requestread,
mozilla::plugins::child::_newstream,
mozilla::plugins::child::_write,
mozilla::plugins::child::_destroystream,
mozilla::plugins::child::_status,
mozilla::plugins::child::_useragent,
mozilla::plugins::child::_memalloc,
mozilla::plugins::child::_memfree,
mozilla::plugins::child::_memflush,
mozilla::plugins::child::_reloadplugins,
mozilla::plugins::child::_getjavaenv,
mozilla::plugins::child::_getjavapeer,
mozilla::plugins::child::_geturlnotify,
mozilla::plugins::child::_posturlnotify,
mozilla::plugins::child::_getvalue,
mozilla::plugins::child::_setvalue,
mozilla::plugins::child::_invalidaterect,
mozilla::plugins::child::_invalidateregion,
mozilla::plugins::child::_forceredraw,
PluginModuleChild::NPN_GetStringIdentifier,
PluginModuleChild::NPN_GetStringIdentifiers,
PluginModuleChild::NPN_GetIntIdentifier,
PluginModuleChild::NPN_IdentifierIsString,
PluginModuleChild::NPN_UTF8FromIdentifier,
PluginModuleChild::NPN_IntFromIdentifier,
PluginModuleChild::NPN_CreateObject,
PluginModuleChild::NPN_RetainObject,
PluginModuleChild::NPN_ReleaseObject,
mozilla::plugins::child::_invoke,
mozilla::plugins::child::_invokedefault,
mozilla::plugins::child::_evaluate,
mozilla::plugins::child::_getproperty,
mozilla::plugins::child::_setproperty,
mozilla::plugins::child::_removeproperty,
mozilla::plugins::child::_hasproperty,
mozilla::plugins::child::_hasmethod,
mozilla::plugins::child::_releasevariantvalue,
mozilla::plugins::child::_setexception,
mozilla::plugins::child::_pushpopupsenabledstate,
mozilla::plugins::child::_poppopupsenabledstate,
mozilla::plugins::child::_enumerate,
mozilla::plugins::child::_pluginthreadasynccall,
mozilla::plugins::child::_construct,
mozilla::plugins::child::_getvalueforurl,
mozilla::plugins::child::_setvalueforurl,
mozilla::plugins::child::_getauthenticationinfo,
mozilla::plugins::child::_scheduletimer,
mozilla::plugins::child::_unscheduletimer,
mozilla::plugins::child::_popupcontextmenu,
mozilla::plugins::child::_convertpoint,
NULL, // handleevent, unimplemented
NULL, // unfocusinstance, unimplemented
mozilla::plugins::child::_urlredirectresponse
};
PluginInstanceChild*
InstCast(NPP aNPP)
{
NS_ABORT_IF_FALSE(!!(aNPP->ndata), "nil instance");
return static_cast<PluginInstanceChild*>(aNPP->ndata);
}
namespace mozilla {
namespace plugins {
namespace child {
NPError NP_CALLBACK
_requestread(NPStream* aStream,
NPByteRange* aRangeList)
{
PLUGIN_LOG_DEBUG_FUNCTION;
ENSURE_PLUGIN_THREAD(NPERR_INVALID_PARAM);
BrowserStreamChild* bs =
static_cast<BrowserStreamChild*>(static_cast<AStream*>(aStream->ndata));
bs->EnsureCorrectStream(aStream);
return bs->NPN_RequestRead(aRangeList);
}
NPError NP_CALLBACK
_geturlnotify(NPP aNPP,
const char* aRelativeURL,
const char* aTarget,
void* aNotifyData)
{
PLUGIN_LOG_DEBUG_FUNCTION;
ENSURE_PLUGIN_THREAD(NPERR_INVALID_PARAM);
if (!aNPP) // NULL check for nspluginwrapper (bug 561690)
return NPERR_INVALID_INSTANCE_ERROR;
nsCString url = NullableString(aRelativeURL);
StreamNotifyChild* sn = new StreamNotifyChild(url);
NPError err;
InstCast(aNPP)->CallPStreamNotifyConstructor(
sn, url, NullableString(aTarget), false, nsCString(), false, &err);
if (NPERR_NO_ERROR == err) {
// If NPN_PostURLNotify fails, the parent will immediately send us
// a PStreamNotifyDestructor, which should not call NPP_URLNotify.
sn->SetValid(aNotifyData);
}
return err;
}
NPError NP_CALLBACK
_getvalue(NPP aNPP,