This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
/
PluginInstanceChild.cpp
3015 lines (2617 loc) · 95.8 KB
/
PluginInstanceChild.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
* Chris Jones <jones.chris.g@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jim Mathies <jmathies@mozilla.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 ***** */
#include "PluginInstanceChild.h"
#include "PluginModuleChild.h"
#include "BrowserStreamChild.h"
#include "PluginStreamChild.h"
#include "StreamNotifyChild.h"
#include "PluginProcessChild.h"
#include "gfxASurface.h"
#include "gfxContext.h"
#ifdef MOZ_X11
#include "gfxXlibSurface.h"
#endif
#ifdef XP_WIN
#include "mozilla/gfx/SharedDIBSurface.h"
using mozilla::gfx::SharedDIBSurface;
#endif
#include "gfxSharedImageSurface.h"
#include "gfxUtils.h"
#include "gfxAlphaRecovery.h"
#include "mozilla/ipc/SyncChannel.h"
using mozilla::ipc::ProcessChild;
using namespace mozilla::plugins;
#ifdef MOZ_WIDGET_GTK2
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdk.h>
#include "gtk2xtbin.h"
#elif defined(MOZ_WIDGET_QT)
#include <QX11Info>
#elif defined(OS_WIN)
#ifndef WM_MOUSEHWHEEL
#define WM_MOUSEHWHEEL 0x020E
#endif
#include "nsWindowsDllInterceptor.h"
typedef BOOL (WINAPI *User32TrackPopupMenu)(HMENU hMenu,
UINT uFlags,
int x,
int y,
int nReserved,
HWND hWnd,
CONST RECT *prcRect);
static WindowsDllInterceptor sUser32Intercept;
static HWND sWinlessPopupSurrogateHWND = NULL;
static User32TrackPopupMenu sUser32TrackPopupMenuStub = NULL;
using mozilla::gfx::SharedDIB;
#include <windows.h>
#include <windowsx.h>
// Flash WM_USER message delay time for PostDelayedTask. Borrowed
// from Chromium's web plugin delegate src. See 'flash msg throttling
// helpers' section for details.
const int kFlashWMUSERMessageThrottleDelayMs = 5;
static const TCHAR kPluginIgnoreSubclassProperty[] = TEXT("PluginIgnoreSubclassProperty");
#elif defined(XP_MACOSX)
#include <ApplicationServices/ApplicationServices.h>
#endif // defined(XP_MACOSX)
template<>
struct RunnableMethodTraits<PluginInstanceChild>
{
static void RetainCallee(PluginInstanceChild* obj) { }
static void ReleaseCallee(PluginInstanceChild* obj) { }
};
PluginInstanceChild::PluginInstanceChild(const NPPluginFuncs* aPluginIface)
: mPluginIface(aPluginIface)
, mCachedWindowActor(nsnull)
, mCachedElementActor(nsnull)
#if defined(OS_WIN)
, mPluginWindowHWND(0)
, mPluginWndProc(0)
, mPluginParentHWND(0)
, mCachedWinlessPluginHWND(0)
, mWinlessPopupSurrogateHWND(0)
, mWinlessThrottleOldWndProc(0)
, mWinlessHiddenMsgHWND(0)
#endif // OS_WIN
, mAsyncCallMutex("PluginInstanceChild::mAsyncCallMutex")
#if defined(OS_MACOSX)
#if defined(__i386__)
, mEventModel(NPEventModelCarbon)
#endif
, mShColorSpace(nsnull)
, mShContext(nsnull)
, mDrawingModel(NPDrawingModelCoreGraphics)
, mCurrentEvent(nsnull)
#endif
, mLayersRendering(false)
, mAccumulatedInvalidRect(0,0,0,0)
, mIsTransparent(false)
, mSurfaceType(gfxASurface::SurfaceTypeMax)
, mCurrentInvalidateTask(nsnull)
, mCurrentAsyncSetWindowTask(nsnull)
, mPendingPluginCall(false)
, mDoAlphaExtraction(false)
, mSurfaceDifferenceRect(0,0,0,0)
#if (MOZ_PLATFORM_MAEMO == 5) || (MOZ_PLATFORM_MAEMO == 6)
, mMaemoImageRendering(PR_FALSE)
#endif
{
memset(&mWindow, 0, sizeof(mWindow));
mData.ndata = (void*) this;
mData.pdata = nsnull;
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
mWindow.ws_info = &mWsInfo;
memset(&mWsInfo, 0, sizeof(mWsInfo));
mWsInfo.display = DefaultXDisplay();
#endif // MOZ_X11 && XP_UNIX && !XP_MACOSX
#if defined(OS_WIN)
memset(&mAlphaExtract, 0, sizeof(mAlphaExtract));
#endif // OS_WIN
#if defined(OS_WIN)
InitPopupMenuHook();
#endif // OS_WIN
#ifdef MOZ_X11
const char *description = NULL;
mPluginIface->getvalue(GetNPP(), NPPVpluginDescriptionString,
&description);
if (description) {
NS_NAMED_LITERAL_CSTRING(flash10Head, "Shockwave Flash 10.");
if (StringBeginsWith(nsDependentCString(description), flash10Head)) {
PluginModuleChild::current()->AddQuirk(PluginModuleChild::QUIRK_FLASH_EXPOSE_COORD_TRANSLATION);
}
}
#endif
}
PluginInstanceChild::~PluginInstanceChild()
{
#if defined(OS_WIN)
NS_ASSERTION(!mPluginWindowHWND, "Destroying PluginInstanceChild without NPP_Destroy?");
#endif
#if defined(OS_MACOSX)
if (mShColorSpace) {
::CGColorSpaceRelease(mShColorSpace);
}
if (mShContext) {
::CGContextRelease(mShContext);
}
#endif
}
int
PluginInstanceChild::GetQuirks()
{
return PluginModuleChild::current()->GetQuirks();
}
NPError
PluginInstanceChild::InternalGetNPObjectForValue(NPNVariable aValue,
NPObject** aObject)
{
PluginScriptableObjectChild* actor;
NPError result = NPERR_NO_ERROR;
switch (aValue) {
case NPNVWindowNPObject:
if (!(actor = mCachedWindowActor)) {
PPluginScriptableObjectChild* actorProtocol;
CallNPN_GetValue_NPNVWindowNPObject(&actorProtocol, &result);
if (result == NPERR_NO_ERROR) {
actor = mCachedWindowActor =
static_cast<PluginScriptableObjectChild*>(actorProtocol);
NS_ASSERTION(actor, "Null actor!");
PluginModuleChild::sBrowserFuncs.retainobject(
actor->GetObject(false));
}
}
break;
case NPNVPluginElementNPObject:
if (!(actor = mCachedElementActor)) {
PPluginScriptableObjectChild* actorProtocol;
CallNPN_GetValue_NPNVPluginElementNPObject(&actorProtocol,
&result);
if (result == NPERR_NO_ERROR) {
actor = mCachedElementActor =
static_cast<PluginScriptableObjectChild*>(actorProtocol);
NS_ASSERTION(actor, "Null actor!");
PluginModuleChild::sBrowserFuncs.retainobject(
actor->GetObject(false));
}
}
break;
default:
NS_NOTREACHED("Don't know what to do with this value type!");
}
#ifdef DEBUG
{
NPError currentResult;
PPluginScriptableObjectChild* currentActor;
switch (aValue) {
case NPNVWindowNPObject:
CallNPN_GetValue_NPNVWindowNPObject(¤tActor,
¤tResult);
break;
case NPNVPluginElementNPObject:
CallNPN_GetValue_NPNVPluginElementNPObject(¤tActor,
¤tResult);
break;
default:
NS_NOTREACHED("Don't know what to do with this value type!");
}
// Make sure that the current actor returned by the parent matches our
// cached actor!
NS_ASSERTION(static_cast<PluginScriptableObjectChild*>(currentActor) ==
actor, "Cached actor is out of date!");
NS_ASSERTION(currentResult == result, "Results don't match?!");
}
#endif
if (result != NPERR_NO_ERROR) {
return result;
}
NPObject* object = actor->GetObject(false);
NS_ASSERTION(object, "Null object?!");
*aObject = PluginModuleChild::sBrowserFuncs.retainobject(object);
return NPERR_NO_ERROR;
}
NPError
PluginInstanceChild::NPN_GetValue(NPNVariable aVar,
void* aValue)
{
PLUGIN_LOG_DEBUG(("%s (aVar=%i)", FULLFUNCTION, (int) aVar));
AssertPluginThread();
switch(aVar) {
case NPNVSupportsWindowless:
#if defined(OS_LINUX) || defined(OS_WIN)
*((NPBool*)aValue) = true;
#else
*((NPBool*)aValue) = false;
#endif
return NPERR_NO_ERROR;
#if (MOZ_PLATFORM_MAEMO == 5) || (MOZ_PLATFORM_MAEMO == 6)
case NPNVSupportsWindowlessLocal: {
#ifdef MOZ_WIDGET_QT
const char *graphicsSystem = PR_GetEnv("MOZ_QT_GRAPHICSSYSTEM");
// we should set local rendering to false in order to render X-Plugin
// there is no possibility to change it later on maemo5 platform
mMaemoImageRendering = (!(graphicsSystem && !strcmp(graphicsSystem, "native")));
#endif
*((NPBool*)aValue) = mMaemoImageRendering;
return NPERR_NO_ERROR;
}
#endif
#if defined(OS_LINUX)
case NPNVSupportsXEmbedBool:
*((NPBool*)aValue) = true;
return NPERR_NO_ERROR;
case NPNVToolkit:
*((NPNToolkitType*)aValue) = NPNVGtk2;
return NPERR_NO_ERROR;
#elif defined(OS_WIN)
case NPNVToolkit:
return NPERR_GENERIC_ERROR;
#endif
case NPNVjavascriptEnabledBool: {
bool v = false;
NPError result;
if (!CallNPN_GetValue_NPNVjavascriptEnabledBool(&v, &result)) {
return NPERR_GENERIC_ERROR;
}
*static_cast<NPBool*>(aValue) = v;
return result;
}
case NPNVisOfflineBool: {
bool v = false;
NPError result;
if (!CallNPN_GetValue_NPNVisOfflineBool(&v, &result)) {
return NPERR_GENERIC_ERROR;
}
*static_cast<NPBool*>(aValue) = v;
return result;
}
case NPNVprivateModeBool: {
bool v = false;
NPError result;
if (!CallNPN_GetValue_NPNVprivateModeBool(&v, &result)) {
return NPERR_GENERIC_ERROR;
}
*static_cast<NPBool*>(aValue) = v;
return result;
}
case NPNVWindowNPObject: // Intentional fall-through
case NPNVPluginElementNPObject: {
NPObject* object;
NPError result = InternalGetNPObjectForValue(aVar, &object);
if (result == NPERR_NO_ERROR) {
*((NPObject**)aValue) = object;
}
return result;
}
case NPNVnetscapeWindow: {
#ifdef XP_WIN
if (mWindow.type == NPWindowTypeDrawable) {
if (mCachedWinlessPluginHWND) {
*static_cast<HWND*>(aValue) = mCachedWinlessPluginHWND;
return NPERR_NO_ERROR;
}
NPError result;
if (!CallNPN_GetValue_NPNVnetscapeWindow(&mCachedWinlessPluginHWND, &result)) {
return NPERR_GENERIC_ERROR;
}
*static_cast<HWND*>(aValue) = mCachedWinlessPluginHWND;
return result;
}
else {
*static_cast<HWND*>(aValue) = mPluginWindowHWND;
return NPERR_NO_ERROR;
}
#elif defined(MOZ_X11)
NPError result;
CallNPN_GetValue_NPNVnetscapeWindow(static_cast<XID*>(aValue), &result);
return result;
#else
return NPERR_GENERIC_ERROR;
#endif
}
#ifdef XP_MACOSX
case NPNVsupportsCoreGraphicsBool: {
*((NPBool*)aValue) = true;
return NPERR_NO_ERROR;
}
case NPNVsupportsCoreAnimationBool: {
*((NPBool*)aValue) = true;
return NPERR_NO_ERROR;
}
case NPNVsupportsInvalidatingCoreAnimationBool: {
*((NPBool*)aValue) = true;
return NPERR_NO_ERROR;
}
case NPNVsupportsCocoaBool: {
*((NPBool*)aValue) = true;
return NPERR_NO_ERROR;
}
#ifndef NP_NO_QUICKDRAW
case NPNVsupportsQuickDrawBool: {
*((NPBool*)aValue) = false;
return NPERR_NO_ERROR;
}
#endif /* NP_NO_QUICKDRAW */
#endif /* XP_MACOSX */
default:
PR_LOG(gPluginLog, PR_LOG_WARNING,
("In PluginInstanceChild::NPN_GetValue: Unhandled NPNVariable %i (%s)",
(int) aVar, NPNVariableToString(aVar)));
return NPERR_GENERIC_ERROR;
}
}
NPError
PluginInstanceChild::NPN_SetValue(NPPVariable aVar, void* aValue)
{
PR_LOG(gPluginLog, PR_LOG_DEBUG, ("%s (aVar=%i, aValue=%p)",
FULLFUNCTION, (int) aVar, aValue));
AssertPluginThread();
switch (aVar) {
case NPPVpluginWindowBool: {
NPError rv;
bool windowed = (NPBool) (intptr_t) aValue;
if (!CallNPN_SetValue_NPPVpluginWindow(windowed, &rv))
return NPERR_GENERIC_ERROR;
return rv;
}
case NPPVpluginTransparentBool: {
NPError rv;
mIsTransparent = (!!aValue);
if (!CallNPN_SetValue_NPPVpluginTransparent(mIsTransparent, &rv))
return NPERR_GENERIC_ERROR;
return rv;
}
#ifdef XP_MACOSX
case NPPVpluginDrawingModel: {
NPError rv;
int drawingModel = (int16) (intptr_t) aValue;
if (!CallNPN_SetValue_NPPVpluginDrawingModel(drawingModel, &rv))
return NPERR_GENERIC_ERROR;
mDrawingModel = drawingModel;
return rv;
}
case NPPVpluginEventModel: {
NPError rv;
int eventModel = (int16) (intptr_t) aValue;
if (!CallNPN_SetValue_NPPVpluginEventModel(eventModel, &rv))
return NPERR_GENERIC_ERROR;
#if defined(__i386__)
mEventModel = static_cast<NPEventModel>(eventModel);
#endif
return rv;
}
#endif
default:
PR_LOG(gPluginLog, PR_LOG_WARNING,
("In PluginInstanceChild::NPN_SetValue: Unhandled NPPVariable %i (%s)",
(int) aVar, NPPVariableToString(aVar)));
return NPERR_GENERIC_ERROR;
}
}
bool
PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginNeedsXEmbed(
bool* needs, NPError* rv)
{
AssertPluginThread();
#ifdef MOZ_X11
// The documentation on the types for many variables in NP(N|P)_GetValue
// is vague. Often boolean values are NPBool (1 byte), but
// https://developer.mozilla.org/en/XEmbed_Extension_for_Mozilla_Plugins
// treats NPPVpluginNeedsXEmbed as PRBool (int), and
// on x86/32-bit, flash stores to this using |movl 0x1,&needsXEmbed|.
// thus we can't use NPBool for needsXEmbed, or the three bytes above
// it on the stack would get clobbered. so protect with the larger PRBool.
PRBool needsXEmbed = 0;
if (!mPluginIface->getvalue) {
*rv = NPERR_GENERIC_ERROR;
}
else {
*rv = mPluginIface->getvalue(GetNPP(), NPPVpluginNeedsXEmbed,
&needsXEmbed);
}
*needs = needsXEmbed;
return true;
#else
NS_RUNTIMEABORT("shouldn't be called on non-X11 platforms");
return false; // not reached
#endif
}
bool
PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginScriptableNPObject(
PPluginScriptableObjectChild** aValue,
NPError* aResult)
{
AssertPluginThread();
NPObject* object = nsnull;
NPError result = NPERR_GENERIC_ERROR;
if (mPluginIface->getvalue) {
result = mPluginIface->getvalue(GetNPP(), NPPVpluginScriptableNPObject,
&object);
}
if (result == NPERR_NO_ERROR && object) {
PluginScriptableObjectChild* actor = GetActorForNPObject(object);
// If we get an actor then it has retained. Otherwise we don't need it
// any longer.
PluginModuleChild::sBrowserFuncs.releaseobject(object);
if (actor) {
*aValue = actor;
*aResult = NPERR_NO_ERROR;
return true;
}
NS_ERROR("Failed to get actor!");
result = NPERR_GENERIC_ERROR;
}
else {
result = NPERR_GENERIC_ERROR;
}
*aValue = nsnull;
*aResult = result;
return true;
}
bool
PluginInstanceChild::AnswerNPP_SetValue_NPNVprivateModeBool(const bool& value,
NPError* result)
{
if (!mPluginIface->setvalue) {
*result = NPERR_GENERIC_ERROR;
return true;
}
NPBool v = value;
*result = mPluginIface->setvalue(GetNPP(), NPNVprivateModeBool, &v);
return true;
}
bool
PluginInstanceChild::AnswerNPP_HandleEvent(const NPRemoteEvent& event,
int16_t* handled)
{
PLUGIN_LOG_DEBUG_FUNCTION;
AssertPluginThread();
#if defined(MOZ_X11) && defined(DEBUG)
if (GraphicsExpose == event.event.type)
PLUGIN_LOG_DEBUG((" received drawable 0x%lx\n",
event.event.xgraphicsexpose.drawable));
#endif
#ifdef XP_MACOSX
// Mac OS X does not define an NPEvent structure. It defines more specific types.
NPCocoaEvent evcopy = event.event;
// Make sure we reset mCurrentEvent in case of an exception
AutoRestore<const NPCocoaEvent*> savePreviousEvent(mCurrentEvent);
// Track the current event for NPN_PopUpContextMenu.
mCurrentEvent = &event.event;
#else
// Make a copy since we may modify values.
NPEvent evcopy = event.event;
#endif
#ifdef OS_WIN
// FIXME/bug 567645: temporarily drop the "dummy event" on the floor
if (WM_NULL == evcopy.event)
return true;
// Painting for win32. SharedSurfacePaint handles everything.
if (mWindow.type == NPWindowTypeDrawable) {
if (evcopy.event == WM_PAINT) {
*handled = SharedSurfacePaint(evcopy);
return true;
}
else if (DoublePassRenderingEvent() == evcopy.event) {
// We'll render to mSharedSurfaceDib first, then render to a cached bitmap
// we store locally. The two passes are for alpha extraction, so the second
// pass must be to a flat white surface in order for things to work.
mAlphaExtract.doublePass = RENDER_BACK_ONE;
*handled = true;
return true;
}
}
*handled = WinlessHandleEvent(evcopy);
return true;
#endif
if (!mPluginIface->event)
*handled = false;
else
*handled = mPluginIface->event(&mData, reinterpret_cast<void*>(&evcopy));
#ifdef XP_MACOSX
// Release any reference counted objects created in the child process.
if (evcopy.type == NPCocoaEventKeyDown ||
evcopy.type == NPCocoaEventKeyUp) {
::CFRelease((CFStringRef)evcopy.data.key.characters);
::CFRelease((CFStringRef)evcopy.data.key.charactersIgnoringModifiers);
}
else if (evcopy.type == NPCocoaEventTextInput) {
::CFRelease((CFStringRef)evcopy.data.text.text);
}
#endif
#ifdef MOZ_X11
if (GraphicsExpose == event.event.type) {
// Make sure the X server completes the drawing before the parent
// draws on top and destroys the Drawable.
//
// XSync() waits for the X server to complete. Really this child
// process does not need to wait; the parent is the process that needs
// to wait. A possibly-slightly-better alternative would be to send
// an X event to the parent that the parent would wait for.
XSync(mWsInfo.display, False);
}
#endif
return true;
}
#ifdef XP_MACOSX
bool
PluginInstanceChild::AnswerNPP_HandleEvent_Shmem(const NPRemoteEvent& event,
Shmem& mem,
int16_t* handled,
Shmem* rtnmem)
{
PLUGIN_LOG_DEBUG_FUNCTION;
AssertPluginThread();
PaintTracker pt;
NPCocoaEvent evcopy = event.event;
if (evcopy.type == NPCocoaEventDrawRect) {
if (!mShColorSpace) {
mShColorSpace = CreateSystemColorSpace();
if (!mShColorSpace) {
PLUGIN_LOG_DEBUG(("Could not allocate ColorSpace."));
*handled = false;
*rtnmem = mem;
return true;
}
}
if (!mShContext) {
void* cgContextByte = mem.get<char>();
mShContext = ::CGBitmapContextCreate(cgContextByte,
mWindow.width, mWindow.height, 8,
mWindow.width * 4, mShColorSpace,
kCGImageAlphaPremultipliedFirst |
kCGBitmapByteOrder32Host);
if (!mShContext) {
PLUGIN_LOG_DEBUG(("Could not allocate CGBitmapContext."));
*handled = false;
*rtnmem = mem;
return true;
}
}
CGRect clearRect = ::CGRectMake(0, 0, mWindow.width, mWindow.height);
::CGContextClearRect(mShContext, clearRect);
evcopy.data.draw.context = mShContext;
} else {
PLUGIN_LOG_DEBUG(("Invalid event type for AnswerNNP_HandleEvent_Shmem."));
*handled = false;
*rtnmem = mem;
return true;
}
if (!mPluginIface->event) {
*handled = false;
} else {
::CGContextSaveGState(evcopy.data.draw.context);
*handled = mPluginIface->event(&mData, reinterpret_cast<void*>(&evcopy));
::CGContextRestoreGState(evcopy.data.draw.context);
}
*rtnmem = mem;
return true;
}
#else
bool
PluginInstanceChild::AnswerNPP_HandleEvent_Shmem(const NPRemoteEvent& event,
Shmem& mem,
int16_t* handled,
Shmem* rtnmem)
{
NS_RUNTIMEABORT("not reached.");
*rtnmem = mem;
return true;
}
#endif
#ifdef XP_MACOSX
bool
PluginInstanceChild::AnswerNPP_HandleEvent_IOSurface(const NPRemoteEvent& event,
const uint32_t &surfaceid,
int16_t* handled)
{
PLUGIN_LOG_DEBUG_FUNCTION;
AssertPluginThread();
PaintTracker pt;
NPCocoaEvent evcopy = event.event;
nsIOSurface* surf = nsIOSurface::LookupSurface(surfaceid);
if (!surf) {
NS_ERROR("Invalid IOSurface.");
*handled = false;
return false;
}
if (evcopy.type == NPCocoaEventDrawRect) {
mCARenderer.AttachIOSurface(surf);
if (!mCARenderer.isInit()) {
void *caLayer = nsnull;
NPError result = mPluginIface->getvalue(GetNPP(),
NPPVpluginCoreAnimationLayer,
&caLayer);
if (result != NPERR_NO_ERROR || !caLayer) {
PLUGIN_LOG_DEBUG(("Plugin requested CoreAnimation but did not "
"provide CALayer."));
*handled = false;
return false;
}
mCARenderer.SetupRenderer(caLayer, mWindow.width, mWindow.height);
// Flash needs to have the window set again after this step
if (mPluginIface->setwindow)
(void) mPluginIface->setwindow(&mData, &mWindow);
}
} else {
PLUGIN_LOG_DEBUG(("Invalid event type for "
"AnswerNNP_HandleEvent_IOSurface."));
*handled = false;
return false;
}
mCARenderer.Render(mWindow.width, mWindow.height, nsnull);
return true;
}
#else
bool
PluginInstanceChild::AnswerNPP_HandleEvent_IOSurface(const NPRemoteEvent& event,
const uint32_t &surfaceid,
int16_t* handled)
{
NS_RUNTIMEABORT("NPP_HandleEvent_IOSurface is a OSX-only message");
return false;
}
#endif
bool
PluginInstanceChild::RecvWindowPosChanged(const NPRemoteEvent& event)
{
NS_ASSERTION(!mLayersRendering && !mPendingPluginCall,
"Shouldn't be receiving WindowPosChanged with layer rendering");
#ifdef OS_WIN
int16_t dontcare;
return AnswerNPP_HandleEvent(event, &dontcare);
#else
NS_RUNTIMEABORT("WindowPosChanged is a windows-only message");
return false;
#endif
}
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
static bool
XVisualIDToInfo(Display* aDisplay, VisualID aVisualID,
Visual** aVisual, unsigned int* aDepth)
{
if (aVisualID == None) {
*aVisual = NULL;
*aDepth = 0;
return true;
}
const Screen* screen = DefaultScreenOfDisplay(aDisplay);
for (int d = 0; d < screen->ndepths; d++) {
Depth *d_info = &screen->depths[d];
for (int v = 0; v < d_info->nvisuals; v++) {
Visual* visual = &d_info->visuals[v];
if (visual->visualid == aVisualID) {
*aVisual = visual;
*aDepth = d_info->depth;
return true;
}
}
}
NS_ERROR("VisualID not on Screen.");
return false;
}
#endif
bool
PluginInstanceChild::AnswerNPP_SetWindow(const NPRemoteWindow& aWindow)
{
PLUGIN_LOG_DEBUG(("%s (aWindow=<window: 0x%lx, x: %d, y: %d, width: %d, height: %d>)",
FULLFUNCTION,
aWindow.window,
aWindow.x, aWindow.y,
aWindow.width, aWindow.height));
NS_ASSERTION(!mLayersRendering && !mPendingPluginCall,
"Shouldn't be receiving NPP_SetWindow with layer rendering");
AssertPluginThread();
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
// The minimum info is sent over IPC to allow this
// code to determine the rest.
mWindow.window = reinterpret_cast<void*>(aWindow.window);
mWindow.x = aWindow.x;
mWindow.y = aWindow.y;
mWindow.width = aWindow.width;
mWindow.height = aWindow.height;
mWindow.clipRect = aWindow.clipRect;
mWindow.type = aWindow.type;
mWsInfo.colormap = aWindow.colormap;
if (!XVisualIDToInfo(mWsInfo.display, aWindow.visualID,
&mWsInfo.visual, &mWsInfo.depth))
return false;
#ifdef MOZ_WIDGET_GTK2
if (gtk_check_version(2,18,7) != NULL) { // older
if (aWindow.type == NPWindowTypeWindow) {
GdkWindow* socket_window = gdk_window_lookup(aWindow.window);
if (socket_window) {
// A GdkWindow for the socket already exists. Need to
// workaround https://bugzilla.gnome.org/show_bug.cgi?id=607061
// See wrap_gtk_plug_embedded in PluginModuleChild.cpp.
g_object_set_data(G_OBJECT(socket_window),
"moz-existed-before-set-window",
GUINT_TO_POINTER(1));
}
}
if (aWindow.visualID != None
&& gtk_check_version(2, 12, 10) != NULL) { // older
// Workaround for a bug in Gtk+ (prior to 2.12.10) where deleting
// a foreign GdkColormap will also free the XColormap.
// http://git.gnome.org/browse/gtk+/log/gdk/x11/gdkcolor-x11.c?id=GTK_2_12_10
GdkVisual *gdkvisual = gdkx_visual_get(aWindow.visualID);
GdkColormap *gdkcolor =
gdk_x11_colormap_foreign_new(gdkvisual, aWindow.colormap);
if (g_object_get_data(G_OBJECT(gdkcolor), "moz-have-extra-ref")) {
// We already have a ref to keep the object alive.
g_object_unref(gdkcolor);
} else {
// leak and mark as already leaked
g_object_set_data(G_OBJECT(gdkcolor),
"moz-have-extra-ref", GUINT_TO_POINTER(1));
}
}
}
#endif
if (mPluginIface->setwindow)
(void) mPluginIface->setwindow(&mData, &mWindow);
#elif defined(OS_WIN)
switch (aWindow.type) {
case NPWindowTypeWindow:
{
if (!CreatePluginWindow())
return false;
ReparentPluginWindow((HWND)aWindow.window);
SizePluginWindow(aWindow.width, aWindow.height);
mWindow.window = (void*)mPluginWindowHWND;
mWindow.x = aWindow.x;
mWindow.y = aWindow.y;
mWindow.width = aWindow.width;
mWindow.height = aWindow.height;
mWindow.type = aWindow.type;
if (mPluginIface->setwindow) {
SetProp(mPluginWindowHWND, kPluginIgnoreSubclassProperty, (HANDLE)1);
(void) mPluginIface->setwindow(&mData, &mWindow);
WNDPROC wndProc = reinterpret_cast<WNDPROC>(
GetWindowLongPtr(mPluginWindowHWND, GWLP_WNDPROC));
if (wndProc != PluginWindowProc) {
mPluginWndProc = reinterpret_cast<WNDPROC>(
SetWindowLongPtr(mPluginWindowHWND, GWLP_WNDPROC,
reinterpret_cast<LONG_PTR>(PluginWindowProc)));
}
RemoveProp(mPluginWindowHWND, kPluginIgnoreSubclassProperty);
HookSetWindowLongPtr();
}
}
break;
case NPWindowTypeDrawable:
mWindow.type = aWindow.type;
if (GetQuirks() & PluginModuleChild::QUIRK_WINLESS_TRACKPOPUP_HOOK)
CreateWinlessPopupSurrogate();
if (GetQuirks() & PluginModuleChild::QUIRK_FLASH_THROTTLE_WMUSER_EVENTS)
SetupFlashMsgThrottle();
return SharedSurfaceSetWindow(aWindow);
break;
default:
NS_NOTREACHED("Bad plugin window type.");
return false;
break;
}
#elif defined(XP_MACOSX)
mWindow.x = aWindow.x;
mWindow.y = aWindow.y;
mWindow.width = aWindow.width;
mWindow.height = aWindow.height;
mWindow.clipRect = aWindow.clipRect;
mWindow.type = aWindow.type;
if (mShContext) {
// Release the shared context so that it is reallocated
// with the new size.
::CGContextRelease(mShContext);
mShContext = nsnull;
}
if (mPluginIface->setwindow)
(void) mPluginIface->setwindow(&mData, &mWindow);
#elif defined(ANDROID)
# warning Need Android impl
#else
# error Implement me for your OS
#endif
return true;
}
bool
PluginInstanceChild::Initialize()
{
return true;
}
#if defined(OS_WIN)
static const TCHAR kWindowClassName[] = TEXT("GeckoPluginWindow");
static const TCHAR kPluginInstanceChildProperty[] = TEXT("PluginInstanceChildProperty");
static const TCHAR kFlashThrottleProperty[] = TEXT("MozillaFlashThrottleProperty");
// static
bool
PluginInstanceChild::RegisterWindowClass()
{
static bool alreadyRegistered = false;
if (alreadyRegistered)
return true;