aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmedia/llmediaimplllmozlib.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llmedia/llmediaimplllmozlib.cpp')
-rw-r--r--linden/indra/llmedia/llmediaimplllmozlib.cpp590
1 files changed, 590 insertions, 0 deletions
diff --git a/linden/indra/llmedia/llmediaimplllmozlib.cpp b/linden/indra/llmedia/llmediaimplllmozlib.cpp
new file mode 100644
index 0000000..06250f7
--- /dev/null
+++ b/linden/indra/llmedia/llmediaimplllmozlib.cpp
@@ -0,0 +1,590 @@
1/**
2 * @file llmediaimplllmozlib.cpp
3 * @brief Example 2 of a media impl concrete class
4 *
5 * $LicenseInfo:firstyear=2007&license=viewergpl$
6 *
7 * Copyright (c) 2007-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#include "llmediaimplllmozlib.h"
33
34#if LL_LLMOZLIB_ENABLED
35
36#include "llmediaimplregister.h"
37#include "llmediamanager.h"
38
39#ifdef WIN32
40 // platform specific includes needed before OpenGL header
41 #include <windows.h>
42 #include <GL/gl.h>
43#elif defined(__APPLE__)
44 // framework-style include path when building on the Mac.
45 #include <OpenGL/gl.h>
46#else // Assume this is linux
47 // Linux, MESA headers, but not necessarily assuming MESA runtime.
48 // quotes so we get libraries/.../GL/ version
49 #include "GL/gl.h"
50#endif
51
52#include <iostream>
53
54// register this impl with media manager factory
55static LLMediaImplRegister sLLMediaImplLLMozLibReg( "LLMediaImplLLMozLib", new LLMediaImplLLMozLibMaker() );
56
57///////////////////////////////////////////////////////////////////////////////
58//
59LLMediaImplLLMozLibMaker::LLMediaImplLLMozLibMaker()
60{
61 // Register to handle the scheme
62 mMimeTypeCategories.push_back( "text" );
63#if !LL_QUICKTIME_ENABLED
64 mMimeTypeCategories.push_back( "image" );
65#endif
66}
67
68///////////////////////////////////////////////////////////////////////////////
69//
70LLMediaImplLLMozLib::LLMediaImplLLMozLib() :
71 mBrowserWindowWidth( 800 ),
72 mBrowserWindowHeight( 600 ),
73 mMediaDataWidth( 0 ),
74 mMediaDataHeight( 0 ),
75 mWindowId( 0 ),
76 mNeedsUpdate( false )
77{
78 setRequestedMediaSize( mBrowserWindowWidth, mBrowserWindowHeight );
79
80 setMediaDepth( 4 );
81}
82
83////////////////////////////////////////////////////////////////////////////////
84// (static) super-initialization - called once at application startup
85bool LLMediaImplLLMozLib::startup( LLMediaManagerData* init_data )
86{
87 bool result = LLMozLib::getInstance()->init( init_data->getBrowserApplicationDir(),
88 init_data->getBrowserComponentDir(),
89 init_data->getBrowserProfileDir(),
90 init_data->getBrowserParentWindow() );
91
92 // append special string to the embedded browser user agent string
93 LLMozLib::getInstance()->setBrowserAgentId( init_data->getBrowserUserAgentId() );
94
95 return result;
96}
97
98////////////////////////////////////////////////////////////////////////////////
99// (static) super-uninitialization - called once at application closedown
100bool LLMediaImplLLMozLib::closedown()
101{
102 // name discrepancy - this reset actually shuts down LLMozLib
103 LLMozLib::getInstance()->reset();
104
105 return true;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109// virtual
110bool LLMediaImplLLMozLib::init()
111{
112 // if mWindowId is non-0, it's we already called init() and shouldn't call it again
113 // (::reset() will zero this value)
114 if ( mWindowId )
115 return false;
116
117 mWindowId = LLMozLib::getInstance()->createBrowserWindow( mBrowserWindowWidth, mBrowserWindowHeight );
118
119 LLMozLib::getInstance()->setSize( mWindowId, mBrowserWindowWidth, mBrowserWindowHeight );
120
121 LLMozLib::getInstance()->setBackgroundColor( mWindowId, 0x00, 0x00, 0x00 );
122
123 LLMozLib::getInstance()->addObserver( mWindowId, this );
124
125 // plugins only work with some client-side hackery and they cause
126 // exception handling issues (DEV-10020) so we turn them off
127 LLMozLib::getInstance()->enablePlugins( false );
128
129 // second life client needs the bitmap flipped
130 LLMozLib::getInstance()->flipWindow( mWindowId, true );
131
132 // set media depth now we have created a browser window and know what it is
133 setMediaDepth( LLMozLib::getInstance()->getBrowserDepth( mWindowId ) );
134
135 return true;
136}
137
138////////////////////////////////////////////////////////////////////////////////
139// virtual
140std::string LLMediaImplLLMozLib::getVersion()
141{
142 std::string version_string = "[" + sLLMediaImplLLMozLibReg.getImplName() + "] - " + LLMozLib::getInstance()->getVersion();
143
144 return version_string;
145}
146
147////////////////////////////////////////////////////////////////////////////////
148// virtual
149bool LLMediaImplLLMozLib::set404RedirectUrl( std::string redirect_url )
150{
151 return LLMozLib::getInstance()->set404RedirectUrl( mWindowId, redirect_url );
152}
153
154////////////////////////////////////////////////////////////////////////////////
155// virtual
156
157bool LLMediaImplLLMozLib::clr404RedirectUrl()
158{
159 return LLMozLib::getInstance()->clr404RedirectUrl( mWindowId );
160}
161
162////////////////////////////////////////////////////////////////////////////////
163// virtual
164bool LLMediaImplLLMozLib::setBackgroundColor( unsigned int red, unsigned int green, unsigned int blue ) const
165{
166 return LLMozLib::getInstance()->setBackgroundColor( mWindowId, red, green, blue );
167}
168
169////////////////////////////////////////////////////////////////////////////////
170// virtual
171bool LLMediaImplLLMozLib::setCaretColor( unsigned int red, unsigned int green, unsigned int blue ) const
172{
173 return LLMozLib::getInstance()->setCaretColor( mWindowId, red, green, blue );
174}
175
176////////////////////////////////////////////////////////////////////////////////
177// virtual
178bool LLMediaImplLLMozLib::navigateTo( const std::string url )
179{
180 // pass url to llmozlib
181 LLMozLib::getInstance()->navigateTo( mWindowId, url );
182
183 // emit event with size change to kick things off
184 LLMediaEvent event( this );
185 mEventEmitter.update( &LLMediaObserver::onMediaSizeChange, event );
186
187 // not that useful right now but maybe later
188 return true;
189}
190
191////////////////////////////////////////////////////////////////////////////////
192// virtual
193bool LLMediaImplLLMozLib::updateMedia()
194{
195 if ( getStatus() == LLMediaBase::STATUS_STARTED )
196 {
197 // if flag set, the page changed and we need to update
198 if ( mNeedsUpdate )
199 {
200 // snap browser pixels
201 LLMozLib::getInstance()->grabBrowserWindow( mWindowId );
202
203 // update media width - rendering the page can change it
204 mMediaDataWidth = LLMozLib::getInstance()->getBrowserRowSpan( mWindowId ) / getMediaDepth();
205 mMediaDataHeight = LLMozLib::getInstance()->getBrowserHeight( mWindowId );
206
207 // emit an event to say that something in the media stream changed
208 LLMediaEvent event( this );
209 mEventEmitter.update( &LLMediaObserver::onMediaContentsChange, event );
210
211 // flag that we've done the update and one isn't needed next frame
212 mNeedsUpdate = false;
213 };
214 };
215
216 // update the state (e.g. transport controls) state
217 updateState();
218
219 return false;
220}
221
222////////////////////////////////////////////////////////////////////////////////
223//
224bool LLMediaImplLLMozLib::updateState()
225{
226 if ( nextCommand() == LLMediaBase::COMMAND_START )
227 {
228 setStatus( LLMediaBase::STATUS_STARTED );
229 clearCommand();
230 };
231
232 if ( nextCommand() == LLMediaBase::COMMAND_STOP )
233 {
234 setStatus( LLMediaBase::STATUS_STOPPED );
235 clearCommand();
236 };
237
238 if ( nextCommand() == LLMediaBase::COMMAND_BACK )
239 {
240 setStatus( LLMediaBase::STATUS_STARTED );
241 LLMozLib::getInstance()->navigateBack( mWindowId );
242 clearCommand();
243 };
244
245 if ( nextCommand() == LLMediaBase::COMMAND_FORWARD )
246 {
247 setStatus( LLMediaBase::STATUS_STARTED );
248 LLMozLib::getInstance()->navigateForward( mWindowId );
249 clearCommand();
250 };
251
252 return true;
253}
254
255////////////////////////////////////////////////////////////////////////////////
256// virtual
257void LLMediaImplLLMozLib::onPageChanged( const EventType& eventIn )
258{
259 // force an update when the contents of the page changes
260 mNeedsUpdate = true;
261}
262
263////////////////////////////////////////////////////////////////////////////////
264// virtual
265void LLMediaImplLLMozLib::onClickLinkHref( const EventType& eventIn )
266{
267 LLMediaEvent event( this, eventIn.getStringValue() );
268 mEventEmitter.update( &LLMediaObserver::onClickLinkHref, event );
269}
270
271////////////////////////////////////////////////////////////////////////////////
272// virtual
273void LLMediaImplLLMozLib::onClickLinkNoFollow( const EventType& eventIn )
274{
275 LLMediaEvent event( this, eventIn.getStringValue() );
276 mEventEmitter.update( &LLMediaObserver::onClickLinkNoFollow, event );
277}
278
279////////////////////////////////////////////////////////////////////////////////
280// virtual
281void LLMediaImplLLMozLib::onUpdateProgress( const EventType& eventIn )
282{
283 LLMediaEvent event( this, eventIn.getIntValue() );
284 mEventEmitter.update( &LLMediaObserver::onUpdateProgress, event );
285}
286
287////////////////////////////////////////////////////////////////////////////////
288// virtual
289void LLMediaImplLLMozLib::onStatusTextChange( const EventType& eventIn )
290{
291 LLMediaEvent event( this, eventIn.getStringValue() );
292 mEventEmitter.update( &LLMediaObserver::onStatusTextChange, event );
293}
294
295////////////////////////////////////////////////////////////////////////////////
296// virtual
297void LLMediaImplLLMozLib::onLocationChange( const EventType& eventIn )
298{
299 LLMediaEvent event( this, eventIn.getEventUri() );
300 mEventEmitter.update( &LLMediaObserver::onLocationChange, event );
301}
302
303////////////////////////////////////////////////////////////////////////////////
304// virtual
305void LLMediaImplLLMozLib::onNavigateBegin( const EventType& eventIn )
306{
307 LLMediaEvent event( this, eventIn.getEventUri() );
308 mEventEmitter.update( &LLMediaObserver::onNavigateBegin, event );
309}
310
311////////////////////////////////////////////////////////////////////////////////
312// virtual
313void LLMediaImplLLMozLib::onNavigateComplete( const EventType& eventIn )
314{
315 // force an update when the page is finished
316 mNeedsUpdate = true;
317
318 // pass in url and HTML response code (200/404 etc.)
319 LLMediaEvent event( this, eventIn.getEventUri(), eventIn.getIntValue() );
320 mEventEmitter.update( &LLMediaObserver::onNavigateComplete, event );
321}
322
323////////////////////////////////////////////////////////////////////////////////
324// virtual
325unsigned char* LLMediaImplLLMozLib::getMediaData()
326{
327 return (unsigned char*)LLMozLib::getInstance()->getBrowserWindowPixels( mWindowId );
328}
329
330// helper func to compute size of media data
331bool LLMediaImplLLMozLib::recomputeSizes()
332{
333 int new_width = mMediaRequestedWidth;
334 int new_height = mMediaRequestedHeight;
335
336 if (new_width < 0)
337 new_width = 512;
338
339 if (new_height < 0)
340 new_height = 512;
341
342 if (mAutoScaled)
343 {
344 new_width = LLMediaManager::textureWidthFromMediaWidth( new_width );
345 new_height = LLMediaManager::textureHeightFromMediaHeight( new_height );
346 }
347
348 bool status = LLMozLib::getInstance()->setSize( mWindowId, new_width, new_height );
349
350 if (status)
351 setMediaSize(new_width, new_height);
352
353 return status;
354}
355
356
357////////////////////////////////////////////////////////////////////////////////
358// virtual
359int LLMediaImplLLMozLib::getMediaDataWidth() const
360{
361 return mMediaDataWidth;
362}
363
364////////////////////////////////////////////////////////////////////////////////
365// virtual
366int LLMediaImplLLMozLib::getMediaDataHeight() const
367{
368 return mMediaDataHeight;
369}
370
371////////////////////////////////////////////////////////////////////////////////
372// virtual
373bool LLMediaImplLLMozLib::setRequestedMediaSize(int width, int height)
374{
375 LLMediaImplCommon::setRequestedMediaSize(width, height);
376
377 return recomputeSizes();
378}
379
380////////////////////////////////////////////////////////////////////////////////
381// virtual
382bool LLMediaImplLLMozLib::setAutoScaled( bool auto_scaled )
383{
384 LLMediaImplCommon::setAutoScaled(auto_scaled);
385
386 return recomputeSizes();
387}
388
389
390////////////////////////////////////////////////////////////////////////////////
391// virtual
392int LLMediaImplLLMozLib::getTextureFormatPrimary() const
393{
394#if defined(__APPLE__) || defined(MACOSX)
395 return GL_BGRA_EXT;
396#else
397 return LLMozLib::getInstance()->getBrowserDepth( mWindowId ) == 3 ? GL_BGR_EXT : GL_BGRA_EXT;
398#endif
399}
400
401////////////////////////////////////////////////////////////////////////////////
402// virtual
403int LLMediaImplLLMozLib::getTextureFormatType() const
404{
405#if defined(__APPLE__) || defined(MACOSX)
406 #ifdef __BIG_ENDIAN__
407 return GL_UNSIGNED_INT_8_8_8_8_REV;
408 #else
409 return GL_UNSIGNED_INT_8_8_8_8;
410 #endif
411#else
412 return GL_UNSIGNED_BYTE;
413#endif
414}
415
416////////////////////////////////////////////////////////////////////////////////
417// virtual
418bool LLMediaImplLLMozLib::mouseDown( int x_pos, int y_pos )
419{
420 return LLMozLib::getInstance()->mouseDown( mWindowId, x_pos, y_pos );
421}
422
423////////////////////////////////////////////////////////////////////////////////
424// virtual
425bool LLMediaImplLLMozLib::mouseUp( int x_pos, int y_pos )
426{
427 LLMozLib::getInstance()->mouseUp( mWindowId, x_pos, y_pos );
428
429 // this seems better than sending focus on mouse down (still need to improve this)
430 LLMozLib::getInstance()->focusBrowser( mWindowId, true );
431
432 return true;
433}
434
435////////////////////////////////////////////////////////////////////////////////
436// virtual
437bool LLMediaImplLLMozLib::mouseMove( int x_pos, int y_pos )
438{
439 return LLMozLib::getInstance()->mouseMove( mWindowId, x_pos, y_pos );
440}
441
442////////////////////////////////////////////////////////////////////////////////
443// virtual
444bool LLMediaImplLLMozLib::keyPress( int key_code )
445{
446 // We don't have to deal with printable characters here - they should
447 // go through handleUnicodeChar(). This table could be more complete
448 // than it is, but I think this covers all of the important
449 // non-printables.
450
451 unsigned long moz_key;
452
453 switch(key_code)
454 {
455 case LL_MEDIA_KEY_BACKSPACE:
456 moz_key = LL_DOM_VK_BACK_SPACE; break;
457 case LL_MEDIA_KEY_TAB:
458 moz_key = LL_DOM_VK_TAB; break;
459 case LL_MEDIA_KEY_RETURN:
460 moz_key = LL_DOM_VK_RETURN; break;
461 case LL_MEDIA_KEY_PAD_RETURN:
462 moz_key = LL_DOM_VK_ENTER; break;
463 case LL_MEDIA_KEY_ESCAPE:
464 moz_key = LL_DOM_VK_ESCAPE; break;
465 case LL_MEDIA_KEY_PAGE_UP:
466 moz_key = LL_DOM_VK_PAGE_UP; break;
467 case LL_MEDIA_KEY_PAGE_DOWN:
468 moz_key = LL_DOM_VK_PAGE_DOWN; break;
469 case LL_MEDIA_KEY_END:
470 moz_key = LL_DOM_VK_END; break;
471 case LL_MEDIA_KEY_HOME:
472 moz_key = LL_DOM_VK_HOME; break;
473 case LL_MEDIA_KEY_LEFT:
474 moz_key = LL_DOM_VK_LEFT; break;
475 case LL_MEDIA_KEY_UP:
476 moz_key = LL_DOM_VK_UP; break;
477 case LL_MEDIA_KEY_RIGHT:
478 moz_key = LL_DOM_VK_RIGHT; break;
479 case LL_MEDIA_KEY_DOWN:
480 moz_key = LL_DOM_VK_DOWN; break;
481 case LL_MEDIA_KEY_INSERT:
482 moz_key = LL_DOM_VK_INSERT; break;
483 case LL_MEDIA_KEY_DELETE:
484 moz_key = LL_DOM_VK_DELETE; break;
485
486 default:
487 return false; // don't know how to map this key.
488 }
489
490 return LLMozLib::getInstance()->keyPress( mWindowId, moz_key );
491}
492
493////////////////////////////////////////////////////////////////////////////////
494// virtual
495bool LLMediaImplLLMozLib::scrollByLines( int lines )
496{
497 return LLMozLib::getInstance()->scrollByLines(mWindowId, lines);
498}
499
500////////////////////////////////////////////////////////////////////////////////
501// virtual
502bool LLMediaImplLLMozLib::focus( bool focus )
503{
504 return LLMozLib::getInstance()->focusBrowser(mWindowId, focus);
505}
506
507////////////////////////////////////////////////////////////////////////////////
508// virtual
509bool LLMediaImplLLMozLib::unicodeInput( unsigned long uni_char )
510{
511 return LLMozLib::getInstance()->unicodeInput(mWindowId, uni_char);
512}
513
514////////////////////////////////////////////////////////////////////////////////
515// virtual
516bool LLMediaImplLLMozLib::mouseLeftDoubleClick( int x_pos, int y_pos )
517{
518 return LLMozLib::getInstance()->mouseLeftDoubleClick( mWindowId, x_pos, y_pos );
519}
520
521////////////////////////////////////////////////////////////////////////////////
522// virtual
523bool LLMediaImplLLMozLib::navigateForward()
524{
525 return LLMozLib::getInstance()->navigateForward(mWindowId);
526}
527
528////////////////////////////////////////////////////////////////////////////////
529// virtual
530bool LLMediaImplLLMozLib::navigateBack()
531{
532 return LLMozLib::getInstance()->navigateBack(mWindowId);
533}
534
535////////////////////////////////////////////////////////////////////////////////
536// virtual
537bool LLMediaImplLLMozLib::canNavigateForward()
538{
539 return LLMozLib::getInstance()->canNavigateForward(mWindowId);
540}
541
542////////////////////////////////////////////////////////////////////////////////
543// virtual
544bool LLMediaImplLLMozLib::canNavigateBack()
545{
546 return LLMozLib::getInstance()->canNavigateBack(mWindowId);
547}
548
549////////////////////////////////////////////////////////////////////////////////
550// virtual
551bool LLMediaImplLLMozLib::enableCookies(bool enable)
552{
553 return LLMozLib::getInstance()->enableCookies(enable);
554}
555
556////////////////////////////////////////////////////////////////////////////////
557// virtual
558bool LLMediaImplLLMozLib::enableProxy(bool enable, std::string proxy_host_name, int proxy_port)
559{
560 return LLMozLib::getInstance()->enableProxy(enable, proxy_host_name, proxy_port);
561}
562
563////////////////////////////////////////////////////////////////////////////////
564// virtual
565bool LLMediaImplLLMozLib::clearCache()
566{
567 return LLMozLib::getInstance()->clearCache();
568}
569
570////////////////////////////////////////////////////////////////////////////////
571// virtual
572bool LLMediaImplLLMozLib::clearCookies()
573{
574 return LLMozLib::getInstance()->clearAllCookies();
575}
576
577////////////////////////////////////////////////////////////////////////////////
578// virtual
579bool LLMediaImplLLMozLib::reset()
580{
581 LLMozLib::getInstance()->remObserver( mWindowId, this );
582
583 LLMozLib::getInstance()->destroyBrowserWindow( mWindowId );
584
585 mWindowId = 0;
586
587 return true;
588}
589
590#endif // LL_LLMOZLIB_ENABLED