-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathllpluginclassmedia.cpp
More file actions
1718 lines (1470 loc) · 53.8 KB
/
Copy pathllpluginclassmedia.cpp
File metadata and controls
1718 lines (1470 loc) · 53.8 KB
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
/**
* @file llpluginclassmedia.cpp
* @brief LLPluginClassMedia handles a plugin which knows about the "media" message class.
*
* @cond
* $LicenseInfo:firstyear=2008&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
* @endcond
*/
#include "linden_common.h"
#include "indra_constants.h"
#include "llpluginclassmedia.h"
#include "llpluginmessageclasses.h"
#include "llcontrol.h"
#if LL_WINDOWS
#include <process.h> // _getpid (host pid for accelerated-paint handle dup)
#else
#include <unistd.h> // getpid
#endif
extern LLControlGroup gSavedSettings;
#if LL_DARWIN || LL_LINUX
extern bool gHiDPISupport;
#endif
static int LOW_PRIORITY_TEXTURE_SIZE_DEFAULT = 256;
static int nextPowerOf2( int value )
{
int next_power_of_2 = 1;
while ( next_power_of_2 < value )
{
next_power_of_2 <<= 1;
}
return next_power_of_2;
}
LLPluginClassMedia::LLPluginClassMedia(LLPluginClassMediaOwner *owner)
{
mOwner = owner;
reset();
// Unique per-media id for the macOS accelerated-paint mach-port demux. Media
// sources are created on the main thread, so a plain counter is fine.
static int sNextAccelId = 1;
mAccelId = sNextAccelId++;
//debug use
mDeleteOK = true ;
}
LLPluginClassMedia::~LLPluginClassMedia()
{
llassert_always(mDeleteOK) ;
reset();
}
bool LLPluginClassMedia::init(const std::string &launcher_filename, const std::string &plugin_dir, const std::string &plugin_filename, bool debug)
{
LL_DEBUGS("Plugin") << "launcher: " << launcher_filename << LL_ENDL;
LL_DEBUGS("Plugin") << "dir: " << plugin_dir << LL_ENDL;
LL_DEBUGS("Plugin") << "plugin: " << plugin_filename << LL_ENDL;
mPlugin = LLPluginProcessParent::create(this);
mPlugin->setSleepTime(mSleepTime);
mPlugin->setUseDaemon(mUseDaemon, mDaemonRendezvous);
// Queue up the media init message -- it will be sent after all the currently queued messages.
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "init");
message.setValue("target", mTarget);
message.setValueReal("factor", mZoomFactor);
// Zero-copy paint: ask for GPU shared-texture handles, and hand the plugin
// this (viewer) process id so it can DuplicateHandle the shared texture into
// us across the process boundary.
message.setValueBoolean("accelerated_paint", mUseAcceleratedPaint);
// macOS shares the accelerated-paint IOSurface over a mach channel; the plugin
// rendezvous via the bootstrap name derived from host_pid, and tags each frame
// with accel_id so the viewer demuxes it back to this media.
message.setValueS32("accel_id", mAccelId);
#if LL_WINDOWS
message.setValueS32("host_pid", (S32)_getpid());
#else
message.setValueS32("host_pid", (S32)getpid());
#endif
// Linux: which windowing backend the viewer chose, so the CEF plugin can pin
// its Ozone platform (X11 vs Wayland) to match. Empty on other platforms.
message.setValue("display_server", mDisplayServer);
sendMessage(message);
mPlugin->init(launcher_filename, plugin_dir, plugin_filename, debug);
return true;
}
void LLPluginClassMedia::reset()
{
if(mPlugin)
{
mPlugin->requestShutdown();
mPlugin.reset();
}
mTextureParamsReceived = false;
mRequestedTextureDepth = 0;
mRequestedTextureInternalFormat = 0;
mRequestedTextureFormat = 0;
mRequestedTextureType = 0;
mRequestedTextureSwapBytes = false;
mRequestedTextureCoordsOpenGL = false;
mTextureSharedMemorySize = 0;
mTextureSharedMemoryName.clear();
mDefaultMediaWidth = 0;
mDefaultMediaHeight = 0;
mNaturalMediaWidth = 0;
mNaturalMediaHeight = 0;
mSetMediaWidth = -1;
mSetMediaHeight = -1;
mRequestedMediaWidth = 0;
mRequestedMediaHeight = 0;
mRequestedTextureWidth = 0;
mRequestedTextureHeight = 0;
mFullMediaWidth = 0;
mFullMediaHeight = 0;
mTextureWidth = 0;
mTextureHeight = 0;
mMediaWidth = 0;
mMediaHeight = 0;
mDirtyRect = LLRect::null;
mAutoScaleMedia = false;
mRequestedVolume = 0.0f;
mPriority = PRIORITY_NORMAL;
mLowPrioritySizeLimit = LOW_PRIORITY_TEXTURE_SIZE_DEFAULT;
mAllowDownsample = false;
mPadding = 0;
mLastMouseX = 0;
mLastMouseY = 0;
mStatus = LLPluginClassMediaOwner::MEDIA_NONE;
mSleepTime = 1.0f / 100.0f;
mCanUndo = false;
mCanRedo = false;
mCanCut = false;
mCanCopy = false;
mCanPaste = false;
mCanDoDelete = false;
mCanSelectAll = false;
mContextMenuX = 0;
mContextMenuY = 0;
mMediaName.clear();
mMediaDescription.clear();
mBackgroundColor = LLColor4(1.0f, 1.0f, 1.0f, 1.0f);
// media_browser class
mNavigateURI.clear();
mNavigateResultCode = -1;
mNavigateResultString.clear();
mHistoryBackAvailable = false;
mHistoryForwardAvailable = false;
mStatusText.clear();
mProgressPercent = 0;
mClickURL.clear();
mClickNavType.clear();
mClickTarget.clear();
mClickUUID.clear();
mStatusCode = 0;
mClickEnforceTarget = false;
// media_time class
mCurrentTime = 0.0f;
mDuration = 0.0f;
mCurrentRate = 0.0f;
mLoadedDuration = 0.0f;
}
void LLPluginClassMedia::idle(void)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_MEDIA;
if(mPlugin)
{
mPlugin->idle();
}
if((mMediaWidth == -1) || (!mTextureParamsReceived) || (mPlugin == NULL) || (mPlugin->isBlocked()) || (mOwner == NULL))
{
// Can't process a size change at this time
}
else if((mRequestedMediaWidth != mMediaWidth) || (mRequestedMediaHeight != mMediaHeight))
{
// Calculate the correct size for the media texture
mRequestedTextureHeight = mRequestedMediaHeight;
if(mPadding < 0)
{
// negative values indicate the plugin wants a power of 2
mRequestedTextureWidth = nextPowerOf2(mRequestedMediaWidth);
}
else
{
mRequestedTextureWidth = mRequestedMediaWidth;
if(mPadding > 1)
{
// Pad up to a multiple of the specified number of bytes per row
int rowbytes = mRequestedTextureWidth * mRequestedTextureDepth;
int pad = rowbytes % mPadding;
if(pad != 0)
{
rowbytes += mPadding - pad;
}
if(rowbytes % mRequestedTextureDepth == 0)
{
mRequestedTextureWidth = rowbytes / mRequestedTextureDepth;
}
else
{
LL_WARNS("Plugin") << "Unable to pad texture width, padding size " << mPadding << "is not a multiple of pixel size " << mRequestedTextureDepth << LL_ENDL;
}
}
}
// Size change has been requested but not initiated yet.
size_t newsize = mRequestedTextureWidth * mRequestedTextureHeight * mRequestedTextureDepth;
// Add an extra line for padding, just in case.
newsize += mRequestedTextureWidth * mRequestedTextureDepth;
if(newsize != mTextureSharedMemorySize)
{
if(!mTextureSharedMemoryName.empty())
{
// Tell the plugin to remove the old memory segment
mPlugin->removeSharedMemory(mTextureSharedMemoryName);
mTextureSharedMemoryName.clear();
}
mTextureSharedMemorySize = newsize;
mTextureSharedMemoryName = mPlugin->addSharedMemory(mTextureSharedMemorySize);
if(!mTextureSharedMemoryName.empty())
{
void *addr = mPlugin->getSharedMemoryAddress(mTextureSharedMemoryName);
// clear texture memory to avoid random screen visual fuzz from uninitialized texture data
if (addr)
{
memset( addr, 0x00, newsize );
}
else
{
LL_WARNS("Plugin") << "Failed to get previously created shared memory address: " << mTextureSharedMemoryName << " size: " << mTextureSharedMemorySize << LL_ENDL;
}
// We could do this to force an update, but textureValid() will still be returning false until the first roundtrip to the plugin,
// so it may not be worthwhile.
// mDirtyRect.setOriginAndSize(0, 0, mRequestedMediaWidth, mRequestedMediaHeight);
}
}
// This is our local indicator that a change is in progress.
mTextureWidth = -1;
mTextureHeight = -1;
mMediaWidth = -1;
mMediaHeight = -1;
// This invalidates any existing dirty rect.
resetDirty();
// Send a size change message to the plugin
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "size_change");
message.setValue("name", mTextureSharedMemoryName);
message.setValueS32("width", mRequestedMediaWidth);
message.setValueS32("height", mRequestedMediaHeight);
message.setValueS32("texture_width", mRequestedTextureWidth);
message.setValueS32("texture_height", mRequestedTextureHeight);
message.setValueReal("background_r", mBackgroundColor.mV[VRED]);
message.setValueReal("background_g", mBackgroundColor.mV[VGREEN]);
message.setValueReal("background_b", mBackgroundColor.mV[VBLUE]);
message.setValueReal("background_a", mBackgroundColor.mV[VALPHA]);
mPlugin->sendMessage(message); // DO NOT just use sendMessage() here -- we want this to jump ahead of the queue.
LL_DEBUGS("Plugin") << "Sending size_change" << LL_ENDL;
}
}
if(mPlugin && mPlugin->isRunning())
{
// Send queued messages
while(!mSendQueue.empty())
{
LLPluginMessage message = mSendQueue.front();
mSendQueue.pop();
mPlugin->sendMessage(message);
}
}
}
int LLPluginClassMedia::getTextureWidth() const
{
return nextPowerOf2(mTextureWidth);
}
int LLPluginClassMedia::getTextureHeight() const
{
return nextPowerOf2(mTextureHeight);
}
unsigned char* LLPluginClassMedia::getBitsData()
{
unsigned char *result = NULL;
if((mPlugin != NULL) && !mTextureSharedMemoryName.empty())
{
result = (unsigned char*)mPlugin->getSharedMemoryAddress(mTextureSharedMemoryName);
}
return result;
}
void LLPluginClassMedia::setSize(int width, int height)
{
if((width > 0) && (height > 0))
{
mSetMediaWidth = width;
mSetMediaHeight = height;
}
else
{
mSetMediaWidth = -1;
mSetMediaHeight = -1;
}
setSizeInternal();
}
void LLPluginClassMedia::setSizeInternal(void)
{
if((mSetMediaWidth > 0) && (mSetMediaHeight > 0))
{
mRequestedMediaWidth = mSetMediaWidth;
mRequestedMediaHeight = mSetMediaHeight;
}
else if((mNaturalMediaWidth > 0) && (mNaturalMediaHeight > 0))
{
mRequestedMediaWidth = mNaturalMediaWidth;
mRequestedMediaHeight = mNaturalMediaHeight;
}
else
{
mRequestedMediaWidth = mDefaultMediaWidth;
mRequestedMediaHeight = mDefaultMediaHeight;
}
// Save these for size/interest calculations
mFullMediaWidth = mRequestedMediaWidth;
mFullMediaHeight = mRequestedMediaHeight;
if(mAllowDownsample)
{
switch(mPriority)
{
case PRIORITY_SLIDESHOW:
case PRIORITY_LOW:
// Reduce maximum texture dimension to (or below) mLowPrioritySizeLimit
while((mRequestedMediaWidth > mLowPrioritySizeLimit) || (mRequestedMediaHeight > mLowPrioritySizeLimit))
{
mRequestedMediaWidth /= 2;
mRequestedMediaHeight /= 2;
}
break;
default:
// Don't adjust texture size
break;
}
}
if(mAutoScaleMedia)
{
mRequestedMediaWidth = nextPowerOf2(mRequestedMediaWidth);
mRequestedMediaHeight = nextPowerOf2(mRequestedMediaHeight);
}
}
void LLPluginClassMedia::setAutoScale(bool auto_scale)
{
if(auto_scale != mAutoScaleMedia)
{
mAutoScaleMedia = auto_scale;
setSizeInternal();
}
}
bool LLPluginClassMedia::textureValid(void)
{
if(
!mTextureParamsReceived ||
mTextureWidth <= 0 ||
mTextureHeight <= 0 ||
mMediaWidth <= 0 ||
mMediaHeight <= 0 ||
mRequestedMediaWidth != mMediaWidth ||
mRequestedMediaHeight != mMediaHeight ||
getBitsData() == NULL
)
return false;
return true;
}
bool LLPluginClassMedia::getDirty(LLRect *dirty_rect)
{
bool result = !mDirtyRect.isEmpty();
if(dirty_rect != NULL)
{
*dirty_rect = mDirtyRect;
}
return result;
}
void LLPluginClassMedia::resetDirty(void)
{
mDirtyRect = LLRect::null;
}
std::string LLPluginClassMedia::translateModifiers(MASK modifiers)
{
std::string result;
if(modifiers & MASK_CONTROL)
{
result += "control|";
}
if(modifiers & MASK_ALT)
{
result += "alt|";
}
if(modifiers & MASK_SHIFT)
{
result += "shift|";
}
// TODO: should I deal with platform differences here or in callers?
// TODO: how do we deal with the Mac "command" key?
/*
if(modifiers & MASK_SOMETHING)
{
result += "meta|";
}
*/
return result;
}
void LLPluginClassMedia::jsEnableObject( bool enable )
{
if( ! mPlugin || !mPlugin->isRunning() || mPlugin->isBlocked() )
{
return;
}
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "js_enable_object");
message.setValueBoolean( "enable", enable );
sendMessage( message );
}
void LLPluginClassMedia::jsAgentLocationEvent( double x, double y, double z )
{
if( ! mPlugin || !mPlugin->isRunning() || mPlugin->isBlocked() )
{
return;
}
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "js_agent_location");
message.setValueReal( "x", x );
message.setValueReal( "y", y );
message.setValueReal( "z", z );
sendMessage( message );
}
void LLPluginClassMedia::jsAgentGlobalLocationEvent( double x, double y, double z )
{
if( ! mPlugin || !mPlugin->isRunning() || mPlugin->isBlocked() )
{
return;
}
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "js_agent_global_location");
message.setValueReal( "x", x );
message.setValueReal( "y", y );
message.setValueReal( "z", z );
sendMessage( message );
}
void LLPluginClassMedia::jsAgentOrientationEvent( double angle )
{
if( ! mPlugin || !mPlugin->isRunning() || mPlugin->isBlocked() )
{
return;
}
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "js_agent_orientation");
message.setValueReal( "angle", angle );
sendMessage( message );
}
void LLPluginClassMedia::jsAgentLanguageEvent( const std::string& language )
{
if( ! mPlugin || !mPlugin->isRunning() || mPlugin->isBlocked() )
{
return;
}
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "js_agent_language");
message.setValue( "language", language );
sendMessage( message );
}
void LLPluginClassMedia::jsAgentRegionEvent( const std::string& region )
{
if( ! mPlugin || !mPlugin->isRunning() || mPlugin->isBlocked() )
{
return;
}
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "js_agent_region");
message.setValue( "region", region );
sendMessage( message );
}
void LLPluginClassMedia::jsAgentMaturityEvent( const std::string& maturity )
{
if( ! mPlugin || !mPlugin->isRunning() || mPlugin->isBlocked() )
{
return;
}
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "js_agent_maturity");
message.setValue( "maturity", maturity );
sendMessage( message );
}
void LLPluginClassMedia::mouseEvent(EMouseEventType type, int button, int x, int y, MASK modifiers)
{
if(type == MOUSE_EVENT_MOVE)
{
if(!mPlugin || !mPlugin->isRunning() || mPlugin->isBlocked())
{
// Don't queue up mouse move events that can't be delivered.
return;
}
if((x == mLastMouseX) && (y == mLastMouseY))
{
// Don't spam unnecessary mouse move events.
return;
}
mLastMouseX = x;
mLastMouseY = y;
}
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "mouse_event");
std::string temp;
switch(type)
{
case MOUSE_EVENT_DOWN: temp = "down"; break;
case MOUSE_EVENT_UP: temp = "up"; break;
case MOUSE_EVENT_MOVE: temp = "move"; break;
case MOUSE_EVENT_DOUBLE_CLICK: temp = "double_click"; break;
}
message.setValue("event", temp);
message.setValueS32("button", button);
message.setValueS32("x", x);
// Incoming coordinates are OpenGL-style ((0,0) = lower left), so flip them here if the plugin has requested it.
if(!mRequestedTextureCoordsOpenGL)
{
// TODO: Should I use mMediaHeight or mRequestedMediaHeight here?
y = mMediaHeight - y;
}
message.setValueS32("y", y);
message.setValue("modifiers", translateModifiers(modifiers));
sendMessage(message);
}
bool LLPluginClassMedia::keyEvent(EKeyEventType type, int key_code, MASK modifiers, LLSD native_key_data)
{
bool result = true;
// FIXME:
// HACK: we don't have an easy way to tell if the plugin is going to handle a particular keycode.
// For now, return false for the ones the webkit plugin won't handle properly.
switch(key_code)
{
case KEY_BACKSPACE:
case KEY_TAB:
case KEY_RETURN:
case KEY_PAD_RETURN:
case KEY_SHIFT:
case KEY_CONTROL:
case KEY_ALT:
case KEY_CAPSLOCK:
case KEY_ESCAPE:
case KEY_PAGE_UP:
case KEY_PAGE_DOWN:
case KEY_END:
case KEY_HOME:
case KEY_LEFT:
case KEY_UP:
case KEY_RIGHT:
case KEY_DOWN:
case KEY_INSERT:
case KEY_DELETE:
// These will be handled
break;
default:
// regular ASCII characters will also be handled
if(key_code >= KEY_SPECIAL)
{
// Other "special" codes will not work properly.
result = false;
}
break;
}
#if LL_DARWIN
if(modifiers & MASK_ALT)
{
// Option-key modified characters should be handled by the unicode input path instead of this one.
result = false;
}
#endif
if(result)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "key_event");
std::string temp;
switch(type)
{
case KEY_EVENT_DOWN: temp = "down"; break;
case KEY_EVENT_UP: temp = "up"; break;
case KEY_EVENT_REPEAT: temp = "repeat"; break;
}
message.setValue("event", temp);
message.setValueS32("key", key_code);
message.setValue("modifiers", translateModifiers(modifiers));
message.setValueLLSD("native_key_data", native_key_data);
sendMessage(message);
}
return result;
}
void LLPluginClassMedia::scrollEvent(int x, int y, int clicks_x, int clicks_y, MASK modifiers)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "scroll_event");
message.setValueS32("x", x);
message.setValueS32("y", y);
message.setValueS32("clicks_x", clicks_x);
message.setValueS32("clicks_y", clicks_y);
message.setValue("modifiers", translateModifiers(modifiers));
sendMessage(message);
}
bool LLPluginClassMedia::textInput(const std::string &text, MASK modifiers, LLSD native_key_data)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "text_event");
message.setValue("text", text);
message.setValue("modifiers", translateModifiers(modifiers));
message.setValueLLSD("native_key_data", native_key_data);
sendMessage(message);
return true;
}
// This function injects a previously stored OpenID cookie into
// each new media instance - see SL-15867 for details. It appears
// that the way we use the cache, shared between multiple CEF
// instances means that sometimes the OpenID cookie cannot be read
// even though it appears to be there. The long term solution to
// this is to create a separate cache directory for each instance
// but that has its own set of problems. This short term approach
// "forces" each new media instance to have a copy of the cookie
// so that a page that needs it - e.g. Profiles - finds it and
// can log in successfully.
void LLPluginClassMedia::injectOpenIDCookie()
{
// can be called before we know who the user is at login
// and there is no OpenID cookie at that point so no
// need to try to set it (these values will all be empty)
if (sOIDcookieName.length() && sOIDcookieValue.length())
{
setCookie(sOIDcookieUrl, sOIDcookieName,
sOIDcookieValue, sOIDcookieHost, sOIDcookiePath, sOIDcookieHttpOnly, sOIDcookieSecure);
}
}
// We store each component of the OpenI cookie individuality here
// because previously, there was some significant parsing to
// break up the raw string into these components and we do not
// want to have to do that again here. Stored as statics because
// we want to share their value between all instances of this
// class - the ones that receive it at login and any others
// that open afterwards (e.g. the Profiles floater)
std::string LLPluginClassMedia::sOIDcookieUrl = std::string();
std::string LLPluginClassMedia::sOIDcookieName = std::string();
std::string LLPluginClassMedia::sOIDcookieValue = std::string();
std::string LLPluginClassMedia::sOIDcookieHost = std::string();
std::string LLPluginClassMedia::sOIDcookiePath = std::string();
bool LLPluginClassMedia::sOIDcookieHttpOnly = false;
bool LLPluginClassMedia::sOIDcookieSecure = false;
// Once we receive the OpenID cookie, it is parsed/processed
// in llViewerMedia::parseRawCookie() and then the component
// values are stored here so that next time a new media
// instance is created, we can use injectOpenIDCookie()
// to "insist" that the cookie store remember its value.
// One might ask why we need to go via LLViewerMedia (which
// makes this call) - this is because the raw cookie arrives
// here in this file but undergoes non-trivial processing
// in LLViewerMedia.
void LLPluginClassMedia::storeOpenIDCookie(const std::string url,
const std::string name, const std::string value,
const std::string host, const std::string path,
bool httponly, bool secure)
{
sOIDcookieUrl = url;
sOIDcookieName = name;
sOIDcookieValue = value;
sOIDcookieHost = host;
sOIDcookiePath = path;
sOIDcookieHttpOnly = httponly;
sOIDcookieSecure = secure;
}
void LLPluginClassMedia::setCookie(std::string uri, std::string name, std::string value, std::string domain, std::string path, bool httponly, bool secure)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "set_cookie");
message.setValue("uri", uri);
message.setValue("name", name);
message.setValue("value", value);
message.setValue("domain", domain);
message.setValue("path", path);
message.setValueBoolean("httponly", httponly);
message.setValueBoolean("secure", secure);
sendMessage(message);
}
void LLPluginClassMedia::loadURI(const std::string &uri)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "load_uri");
message.setValue("uri", uri);
sendMessage(message);
}
void LLPluginClassMedia::executeJavaScript(const std::string &code)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "execute_javascript");
message.setValue("code", code);
sendMessage(message);
}
const char* LLPluginClassMedia::priorityToString(EPriority priority)
{
const char* result = "UNKNOWN";
switch(priority)
{
case PRIORITY_UNLOADED: result = "unloaded"; break;
case PRIORITY_STOPPED: result = "stopped"; break;
case PRIORITY_HIDDEN: result = "hidden"; break;
case PRIORITY_SLIDESHOW: result = "slideshow"; break;
case PRIORITY_LOW: result = "low"; break;
case PRIORITY_NORMAL: result = "normal"; break;
case PRIORITY_HIGH: result = "high"; break;
}
return result;
}
void LLPluginClassMedia::setPriority(EPriority priority)
{
if(mPriority != priority)
{
mPriority = priority;
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "set_priority");
std::string priority_string = priorityToString(priority);
switch(priority)
{
case PRIORITY_UNLOADED:
mSleepTime = 1.0f;
break;
case PRIORITY_STOPPED:
mSleepTime = 1.0f;
break;
case PRIORITY_HIDDEN:
mSleepTime = 1.0f;
break;
case PRIORITY_SLIDESHOW:
mSleepTime = 1.0f;
break;
case PRIORITY_LOW:
mSleepTime = 1.0f / 25.0f;
break;
case PRIORITY_NORMAL:
mSleepTime = 1.0f / 50.0f;
break;
case PRIORITY_HIGH:
mSleepTime = 1.0f / 100.0f;
break;
}
message.setValue("priority", priority_string);
sendMessage(message);
if(mPlugin)
{
mPlugin->setSleepTime(mSleepTime);
}
LL_DEBUGS("PluginPriority") << this << ": setting priority to " << priority_string << LL_ENDL;
// This may affect the calculated size, so recalculate it here.
setSizeInternal();
}
}
void LLPluginClassMedia::setLowPrioritySizeLimit(int size)
{
int power = nextPowerOf2(size);
if(mLowPrioritySizeLimit != power)
{
mLowPrioritySizeLimit = power;
// This may affect the calculated size, so recalculate it here.
setSizeInternal();
}
}
F64 LLPluginClassMedia::getCPUUsage()
{
F64 result = 0.0f;
if(mPlugin)
{
result = mPlugin->getCPUUsage();
}
return result;
}
void LLPluginClassMedia::sendPickFileResponse(const std::vector<std::string> files)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "pick_file_response");
if(mPlugin && mPlugin->isBlocked())
{
// If the plugin sent a blocking pick-file request, the response should unblock it.
message.setValueBoolean("blocking_response", true);
}
LLSD file_list = LLSD::emptyArray();
for (std::vector<std::string>::const_iterator in_iter = files.begin(); in_iter != files.end(); ++in_iter)
{
file_list.append(LLSD::String(*in_iter));
}
message.setValueLLSD("file_list", file_list);
sendMessage(message);
}
void LLPluginClassMedia::sendAuthResponse(bool ok, const std::string &username, const std::string &password)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "auth_response");
message.setValueBoolean("ok", ok);
message.setValue("username", username);
message.setValue("password", password);
if(mPlugin && mPlugin->isBlocked())
{
// If the plugin sent a blocking pick-file request, the response should unblock it.
message.setValueBoolean("blocking_response", true);
}
sendMessage(message);
}
void LLPluginClassMedia::undo()
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "edit_undo");
sendMessage(message);
}
void LLPluginClassMedia::redo()
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "edit_redo");
sendMessage(message);
}
void LLPluginClassMedia::cut()
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "edit_cut");
sendMessage(message);
}
void LLPluginClassMedia::copy()
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "edit_copy");
sendMessage(message);
}
void LLPluginClassMedia::paste()
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "edit_paste");
sendMessage(message);
}
void LLPluginClassMedia::doDelete()
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "edit_delete");
sendMessage(message);
}
void LLPluginClassMedia::selectAll()
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "edit_select_all");
sendMessage(message);
}
void LLPluginClassMedia::showPageSource()
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "edit_show_source");
sendMessage(message);
}
void LLPluginClassMedia::setUserDataPath(const std::string &user_data_path_cache,
const std::string &username,
const std::string &user_data_path_cef_log)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "set_user_data_path");
message.setValue("cache_path", user_data_path_cache);
message.setValue("username", username); // cef shares cache between users but creates user-based contexts
message.setValue("cef_log_file", user_data_path_cef_log);
bool cef_verbose_log = gSavedSettings.getBOOL("CefVerboseLog");
message.setValueBoolean("cef_verbose_log", cef_verbose_log);
sendMessage(message);
}
void LLPluginClassMedia::setLanguageCode(const std::string &language_code)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "set_language_code");
message.setValue("language", language_code);
sendMessage(message);