aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llwebbrowserctrl.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/llwebbrowserctrl.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/newview/llwebbrowserctrl.cpp')
-rw-r--r--linden/indra/newview/llwebbrowserctrl.cpp385
1 files changed, 253 insertions, 132 deletions
diff --git a/linden/indra/newview/llwebbrowserctrl.cpp b/linden/indra/newview/llwebbrowserctrl.cpp
index 858c88c..763f73d 100644
--- a/linden/indra/newview/llwebbrowserctrl.cpp
+++ b/linden/indra/newview/llwebbrowserctrl.cpp
@@ -31,7 +31,6 @@
31 31
32#include "llviewerprecompiledheaders.h" 32#include "llviewerprecompiledheaders.h"
33 33
34#if LL_LIBXUL_ENABLED
35 34
36#include "llwebbrowserctrl.h" 35#include "llwebbrowserctrl.h"
37 36
@@ -45,6 +44,7 @@
45#include "llviewercontrol.h" 44#include "llviewercontrol.h"
46#include "llviewerwindow.h" 45#include "llviewerwindow.h"
47#include "llweb.h" 46#include "llweb.h"
47#include "llglimmediate.h"
48 48
49// linden library includes 49// linden library includes
50#include "llfocusmgr.h" 50#include "llfocusmgr.h"
@@ -57,44 +57,50 @@ const S32 MAX_TEXTURE_DIMENSION = 2048;
57LLWebBrowserCtrl::LLWebBrowserCtrl( const std::string& name, const LLRect& rect ) : 57LLWebBrowserCtrl::LLWebBrowserCtrl( const std::string& name, const LLRect& rect ) :
58 LLUICtrl( name, rect, FALSE, NULL, NULL ), 58 LLUICtrl( name, rect, FALSE, NULL, NULL ),
59 mTextureDepthBytes( 4 ), 59 mTextureDepthBytes( 4 ),
60 mWebBrowserImage( 0 ),
60 mEmbeddedBrowserWindowId( 0 ), 61 mEmbeddedBrowserWindowId( 0 ),
61 mBorder(NULL), 62 mBorder(NULL),
62 mFrequentUpdates( true ), 63 mFrequentUpdates( true ),
64 mForceUpdate( false ),
63 mOpenLinksInExternalBrowser( false ), 65 mOpenLinksInExternalBrowser( false ),
64 mOpenLinksInInternalBrowser( false ), 66 mOpenLinksInInternalBrowser( false ),
65 mOpenAppSLURLs( false ), 67 mOpenAppSLURLs( false ),
66 mHomePageUrl( "" ), 68 mHomePageUrl( "" ),
67 mIgnoreUIScale( true ), 69 mIgnoreUIScale( true ),
68 mAlwaysRefresh( false ) 70 mAlwaysRefresh( false ),
69{ 71 mMediaSource( 0 )
70 S32 screen_width = mIgnoreUIScale ? llround((F32)mRect.getWidth() * LLUI::sGLScaleFactor.mV[VX]) : llround((F32)mRect.getWidth() * gViewerWindow->getDisplayScale().mV[VX]); 72{
71 S32 screen_height = mIgnoreUIScale ? llround((F32)mRect.getHeight() * LLUI::sGLScaleFactor.mV[VY]) : llround((F32)mRect.getHeight() * gViewerWindow->getDisplayScale().mV[VY]); 73 S32 screen_width = mIgnoreUIScale ?
72 74 llround((F32)getRect().getWidth() * LLUI::sGLScaleFactor.mV[VX]) : getRect().getWidth();
73 // create a new browser window 75 S32 screen_height = mIgnoreUIScale ?
74 { 76 llround((F32)getRect().getHeight() * LLUI::sGLScaleFactor.mV[VY]) : getRect().getHeight();
75#if LL_LINUX 77
76 // Yuck, Mozilla init plays with the locale - push/pop 78
77 // the locale to protect it, as exotic/non-C locales 79 LLMediaManager *mgr = LLMediaManager::getInstance();
78 // causes our code lots of general critical weirdness 80
79 // and crashness. (SL-35450) 81 if (!mgr)
80 std::string saved_locale = setlocale(LC_ALL, NULL); 82 {
81#endif // LL_LINUX 83 llwarns << "cannot get media manager" << llendl;
82 mEmbeddedBrowserWindowId = LLMozLib::getInstance()->createBrowserWindow( gViewerWindow->getPlatformWindow(), screen_width, screen_height ); 84 return;
83#if LL_LINUX 85 }
84 setlocale(LC_ALL, saved_locale.c_str() ); 86
85#endif // LL_LINUX 87 mMediaSource = mgr->createSourceFromMimeType("http", "text/html" );
88 if ( !mMediaSource )
89 {
90 llwarns << "media source create failed " << llendl;
91 return;
86 } 92 }
87 93
88 // change color to black so transisitons aren't so noticable (this should be in XML eventually) 94 // mMediaSource->init();
89 LLMozLib::getInstance()->setBackgroundColor( mEmbeddedBrowserWindowId, 0x00, 0x00, 0x00 ); 95 mMediaSource->addCommand( LLMediaBase::COMMAND_START );
90 96
91 // observe the browser so we can trap HREF events) 97 // observe the browser so we can trap HREF events)
92 LLMozLib::getInstance()->addObserver( mEmbeddedBrowserWindowId, this ); 98 mMediaSource->addObserver(this);
93 99
94 // create a new texture (based on LLDynamic texture) that will be used to display the output 100 // create a new texture (based on LLDynamic texture) that will be used to display the output
95 mWebBrowserImage = new LLWebBrowserTexture( screen_width, screen_height, this, mEmbeddedBrowserWindowId ); 101 mWebBrowserImage = new LLWebBrowserTexture( screen_width, screen_height, this, mMediaSource );
96 102
97 LLRect border_rect( 0, mRect.getHeight() + 2, mRect.getWidth() + 2, 0 ); 103 LLRect border_rect( 0, getRect().getHeight() + 2, getRect().getWidth() + 2, 0 );
98 mBorder = new LLViewBorder( "web control border", border_rect, LLViewBorder::BEVEL_IN ); 104 mBorder = new LLViewBorder( "web control border", border_rect, LLViewBorder::BEVEL_IN );
99 addChild( mBorder ); 105 addChild( mBorder );
100} 106}
@@ -103,9 +109,19 @@ LLWebBrowserCtrl::LLWebBrowserCtrl( const std::string& name, const LLRect& rect
103// note: this is now a singleton and destruction happens via initClass() now 109// note: this is now a singleton and destruction happens via initClass() now
104LLWebBrowserCtrl::~LLWebBrowserCtrl() 110LLWebBrowserCtrl::~LLWebBrowserCtrl()
105{ 111{
106 LLMozLib::getInstance()->remObserver( mEmbeddedBrowserWindowId, this ); 112 LLMediaManager *mgr = LLMediaManager::getInstance();
107 113
108 LLMozLib::getInstance()->destroyBrowserWindow( mEmbeddedBrowserWindowId ); 114 if (!mgr)
115 {
116 llwarns << "cannot get media manager" << llendl;
117 return;
118 }
119
120 if (mMediaSource)
121 {
122 mgr->destroySource(mMediaSource);
123 mMediaSource = NULL;
124 }
109 125
110 if ( mWebBrowserImage ) 126 if ( mWebBrowserImage )
111 { 127 {
@@ -163,7 +179,9 @@ void LLWebBrowserCtrl::setOpenAppSLURLs( bool valIn )
163BOOL LLWebBrowserCtrl::handleHover( S32 x, S32 y, MASK mask ) 179BOOL LLWebBrowserCtrl::handleHover( S32 x, S32 y, MASK mask )
164{ 180{
165 convertInputCoords(x, y); 181 convertInputCoords(x, y);
166 LLMozLib::getInstance()->mouseMove( mEmbeddedBrowserWindowId, x, y ); 182
183 if (mMediaSource)
184 mMediaSource->mouseMove(x, y);
167 185
168 return TRUE; 186 return TRUE;
169} 187}
@@ -172,12 +190,8 @@ BOOL LLWebBrowserCtrl::handleHover( S32 x, S32 y, MASK mask )
172// 190//
173BOOL LLWebBrowserCtrl::handleScrollWheel( S32 x, S32 y, S32 clicks ) 191BOOL LLWebBrowserCtrl::handleScrollWheel( S32 x, S32 y, S32 clicks )
174{ 192{
175 LLMozLib::getInstance()->scrollByLines( mEmbeddedBrowserWindowId, clicks ); 193 if (mMediaSource)
176 194 mMediaSource->scrollByLines(clicks);
177 // note: this isn't really necessary right now since the page is updated
178 // on a timer but if that becomes too burdensome and the page is only updated
179 // once after load then this will be necessary
180 LLMozLib::getInstance()->grabBrowserWindow( mEmbeddedBrowserWindowId );
181 195
182 return TRUE; 196 return TRUE;
183} 197}
@@ -187,8 +201,10 @@ BOOL LLWebBrowserCtrl::handleScrollWheel( S32 x, S32 y, S32 clicks )
187BOOL LLWebBrowserCtrl::handleMouseUp( S32 x, S32 y, MASK mask ) 201BOOL LLWebBrowserCtrl::handleMouseUp( S32 x, S32 y, MASK mask )
188{ 202{
189 convertInputCoords(x, y); 203 convertInputCoords(x, y);
190 LLMozLib::getInstance()->mouseUp( mEmbeddedBrowserWindowId, x, y );
191 204
205 if (mMediaSource)
206 mMediaSource->mouseUp(x, y);
207
192 gViewerWindow->setMouseCapture( NULL ); 208 gViewerWindow->setMouseCapture( NULL );
193 209
194 return TRUE; 210 return TRUE;
@@ -199,8 +215,10 @@ BOOL LLWebBrowserCtrl::handleMouseUp( S32 x, S32 y, MASK mask )
199BOOL LLWebBrowserCtrl::handleMouseDown( S32 x, S32 y, MASK mask ) 215BOOL LLWebBrowserCtrl::handleMouseDown( S32 x, S32 y, MASK mask )
200{ 216{
201 convertInputCoords(x, y); 217 convertInputCoords(x, y);
202 LLMozLib::getInstance()->mouseDown( mEmbeddedBrowserWindowId, x, y );
203 218
219 if (mMediaSource)
220 mMediaSource->mouseDown(x, y);
221
204 gViewerWindow->setMouseCapture( this ); 222 gViewerWindow->setMouseCapture( this );
205 223
206 setFocus( TRUE ); 224 setFocus( TRUE );
@@ -213,7 +231,9 @@ BOOL LLWebBrowserCtrl::handleMouseDown( S32 x, S32 y, MASK mask )
213BOOL LLWebBrowserCtrl::handleDoubleClick( S32 x, S32 y, MASK mask ) 231BOOL LLWebBrowserCtrl::handleDoubleClick( S32 x, S32 y, MASK mask )
214{ 232{
215 convertInputCoords(x, y); 233 convertInputCoords(x, y);
216 LLMozLib::getInstance()->mouseLeftDoubleClick( mEmbeddedBrowserWindowId, x, y ); 234
235 if (mMediaSource)
236 mMediaSource->mouseLeftDoubleClick( x, y );
217 237
218 gViewerWindow->setMouseCapture( this ); 238 gViewerWindow->setMouseCapture( this );
219 239
@@ -226,7 +246,9 @@ BOOL LLWebBrowserCtrl::handleDoubleClick( S32 x, S32 y, MASK mask )
226// 246//
227void LLWebBrowserCtrl::onFocusReceived() 247void LLWebBrowserCtrl::onFocusReceived()
228{ 248{
229 LLMozLib::getInstance()->focusBrowser( mEmbeddedBrowserWindowId, true ); 249 if (mMediaSource)
250 mMediaSource->focus(true);
251
230 252
231 LLUICtrl::onFocusReceived(); 253 LLUICtrl::onFocusReceived();
232} 254}
@@ -235,7 +257,8 @@ void LLWebBrowserCtrl::onFocusReceived()
235// 257//
236void LLWebBrowserCtrl::onFocusLost() 258void LLWebBrowserCtrl::onFocusLost()
237{ 259{
238 LLMozLib::getInstance()->focusBrowser( mEmbeddedBrowserWindowId, false ); 260 if (mMediaSource)
261 mMediaSource->focus(false);
239 262
240 gViewerWindow->focusClient(); 263 gViewerWindow->focusClient();
241 264
@@ -246,7 +269,7 @@ void LLWebBrowserCtrl::onFocusLost()
246// 269//
247BOOL LLWebBrowserCtrl::handleKey( KEY key, MASK mask, BOOL called_from_parent ) 270BOOL LLWebBrowserCtrl::handleKey( KEY key, MASK mask, BOOL called_from_parent )
248{ 271{
249 unsigned long nskey; 272 unsigned long media_key;
250 273
251 // First, turn SL internal keycode enum into Mozilla keycode enum 274 // First, turn SL internal keycode enum into Mozilla keycode enum
252 275
@@ -254,46 +277,48 @@ BOOL LLWebBrowserCtrl::handleKey( KEY key, MASK mask, BOOL called_from_parent )
254 // go through handleUnicodeChar(). This table could be more complete 277 // go through handleUnicodeChar(). This table could be more complete
255 // than it is, but I think this covers all of the important 278 // than it is, but I think this covers all of the important
256 // non-printables. 279 // non-printables.
280
257 switch (key) 281 switch (key)
258 { 282 {
259 case KEY_BACKSPACE: 283 case KEY_BACKSPACE:
260 nskey = LL_DOM_VK_BACK_SPACE; break; 284 media_key = LL_MEDIA_KEY_BACKSPACE; break;
261 case KEY_TAB: 285 case KEY_TAB:
262 nskey = LL_DOM_VK_TAB; break; 286 media_key = LL_MEDIA_KEY_TAB; break;
263 case KEY_RETURN: 287 case KEY_RETURN:
264 nskey = LL_DOM_VK_RETURN; break; 288 media_key = LL_MEDIA_KEY_RETURN; break;
265 case KEY_PAD_RETURN: 289 case KEY_PAD_RETURN:
266 nskey = LL_DOM_VK_ENTER; break; 290 media_key = LL_MEDIA_KEY_PAD_RETURN; break;
267 case KEY_ESCAPE: 291 case KEY_ESCAPE:
268 nskey = LL_DOM_VK_ESCAPE; break; 292 media_key = LL_MEDIA_KEY_ESCAPE; break;
269 case KEY_PAGE_UP: 293 case KEY_PAGE_UP:
270 nskey = LL_DOM_VK_PAGE_UP; break; 294 media_key = LL_MEDIA_KEY_PAGE_UP; break;
271 case KEY_PAGE_DOWN: 295 case KEY_PAGE_DOWN:
272 nskey = LL_DOM_VK_PAGE_DOWN; break; 296 media_key = LL_MEDIA_KEY_PAGE_DOWN; break;
273 case KEY_END: 297 case KEY_END:
274 nskey = LL_DOM_VK_END; break; 298 media_key = LL_MEDIA_KEY_END; break;
275 case KEY_HOME: 299 case KEY_HOME:
276 nskey = LL_DOM_VK_HOME; break; 300 media_key = LL_MEDIA_KEY_HOME; break;
277 case KEY_LEFT: 301 case KEY_LEFT:
278 nskey = LL_DOM_VK_LEFT; break; 302 media_key = LL_MEDIA_KEY_LEFT; break;
279 case KEY_UP: 303 case KEY_UP:
280 nskey = LL_DOM_VK_UP; break; 304 media_key = LL_MEDIA_KEY_UP; break;
281 case KEY_RIGHT: 305 case KEY_RIGHT:
282 nskey = LL_DOM_VK_RIGHT; break; 306 media_key = LL_MEDIA_KEY_RIGHT; break;
283 case KEY_DOWN: 307 case KEY_DOWN:
284 nskey = LL_DOM_VK_DOWN; break; 308 media_key = LL_MEDIA_KEY_DOWN; break;
285 case KEY_INSERT: 309 case KEY_INSERT:
286 nskey = LL_DOM_VK_INSERT; break; 310 media_key = LL_MEDIA_KEY_INSERT; break;
287 case KEY_DELETE: 311 case KEY_DELETE:
288 nskey = LL_DOM_VK_DELETE; break; 312 media_key = LL_MEDIA_KEY_DELETE; break;
289 default: 313 default:
290 llinfos << "Don't know how to map LL keycode " << U32(key) 314 llinfos << "Don't know how to map LL keycode " << U32(key)
291 << " to DOM key. Ignoring." << llendl; 315 << " to DOM key. Ignoring." << llendl;
292 return FALSE; // don't know how to map this key. 316 return FALSE; // don't know how to map this key.
293 } 317 }
294 318
295 LLMozLib::getInstance()->keyPress( mEmbeddedBrowserWindowId, nskey ); 319 if (mMediaSource)
296 320 mMediaSource->keyPress(media_key);
321
297 return TRUE; 322 return TRUE;
298} 323}
299 324
@@ -303,7 +328,8 @@ BOOL LLWebBrowserCtrl::handleUnicodeChar(llwchar uni_char, BOOL called_from_pare
303 if (uni_char >= 32 // discard 'control' characters 328 if (uni_char >= 32 // discard 'control' characters
304 && uni_char != 127) // SDL thinks this is 'delete' - yuck. 329 && uni_char != 127) // SDL thinks this is 'delete' - yuck.
305 { 330 {
306 LLMozLib::getInstance()->unicodeInput( mEmbeddedBrowserWindowId, uni_char ); 331 if (mMediaSource)
332 mMediaSource->unicodeInput(uni_char);
307 } 333 }
308 334
309 return TRUE; 335 return TRUE;
@@ -329,13 +355,14 @@ void LLWebBrowserCtrl::onVisibilityChange ( BOOL new_visibility )
329// 355//
330void LLWebBrowserCtrl::reshape( S32 width, S32 height, BOOL called_from_parent ) 356void LLWebBrowserCtrl::reshape( S32 width, S32 height, BOOL called_from_parent )
331{ 357{
332 S32 screen_width = mIgnoreUIScale ? llround((F32)width * LLUI::sGLScaleFactor.mV[VX]) : llround((F32)width * gViewerWindow->getDisplayScale().mV[VX]); 358 S32 screen_width = mIgnoreUIScale ? llround((F32)width * LLUI::sGLScaleFactor.mV[VX]) : width;
333 S32 screen_height = mIgnoreUIScale ? llround((F32)height * LLUI::sGLScaleFactor.mV[VY]) : llround((F32)height * gViewerWindow->getDisplayScale().mV[VY]); 359 S32 screen_height = mIgnoreUIScale ? llround((F32)height * LLUI::sGLScaleFactor.mV[VY]) : height;
334 360
335 // when floater is minimized, these sizes are negative 361 // when floater is minimized, these sizes are negative
336 if ( screen_height > 0 && screen_width > 0 ) 362 if ( mWebBrowserImage && screen_height > 0 && screen_width > 0 )
337 { 363 {
338 mWebBrowserImage->resize( screen_width, screen_height ); 364 mWebBrowserImage->resize( screen_width, screen_height );
365 mForceUpdate = true;
339 } 366 }
340 367
341 LLUICtrl::reshape( width, height, called_from_parent ); 368 LLUICtrl::reshape( width, height, called_from_parent );
@@ -345,42 +372,51 @@ void LLWebBrowserCtrl::reshape( S32 width, S32 height, BOOL called_from_parent )
345// 372//
346void LLWebBrowserCtrl::navigateBack() 373void LLWebBrowserCtrl::navigateBack()
347{ 374{
348 LLMozLib::getInstance()->navigateBack( mEmbeddedBrowserWindowId ); 375 if (mMediaSource)
376 mMediaSource->navigateBack();
349} 377}
350 378
351//////////////////////////////////////////////////////////////////////////////// 379////////////////////////////////////////////////////////////////////////////////
352// 380//
353void LLWebBrowserCtrl::navigateForward() 381void LLWebBrowserCtrl::navigateForward()
354{ 382{
355 LLMozLib::getInstance()->navigateForward( mEmbeddedBrowserWindowId ); 383 if (mMediaSource)
384 mMediaSource->navigateForward();
356} 385}
357 386
358//////////////////////////////////////////////////////////////////////////////// 387////////////////////////////////////////////////////////////////////////////////
359// 388//
360bool LLWebBrowserCtrl::canNavigateBack() 389bool LLWebBrowserCtrl::canNavigateBack()
361{ 390{
362 return LLMozLib::getInstance()->canNavigateBack( mEmbeddedBrowserWindowId ); 391 if (mMediaSource)
392 return mMediaSource->canNavigateBack();
393 else
394 return false;
363} 395}
364 396
365//////////////////////////////////////////////////////////////////////////////// 397////////////////////////////////////////////////////////////////////////////////
366// 398//
367bool LLWebBrowserCtrl::canNavigateForward() 399bool LLWebBrowserCtrl::canNavigateForward()
368{ 400{
369 return LLMozLib::getInstance()->canNavigateForward( mEmbeddedBrowserWindowId ); 401 if (mMediaSource)
402 return mMediaSource->canNavigateForward();
403 else
404 return false;
370} 405}
371 406
372//////////////////////////////////////////////////////////////////////////////// 407////////////////////////////////////////////////////////////////////////////////
373// 408//
409
374bool LLWebBrowserCtrl::set404RedirectUrl( std::string redirect_url ) 410bool LLWebBrowserCtrl::set404RedirectUrl( std::string redirect_url )
375{ 411{
376 return LLMozLib::getInstance()->set404RedirectUrl( mEmbeddedBrowserWindowId, redirect_url ); 412 return mMediaSource->set404RedirectUrl( redirect_url );
377} 413}
378 414
379//////////////////////////////////////////////////////////////////////////////// 415////////////////////////////////////////////////////////////////////////////////
380// 416//
381bool LLWebBrowserCtrl::clr404RedirectUrl() 417bool LLWebBrowserCtrl::clr404RedirectUrl()
382{ 418{
383 return LLMozLib::getInstance()->clr404RedirectUrl( mEmbeddedBrowserWindowId ); 419 return mMediaSource->clr404RedirectUrl();
384} 420}
385 421
386//////////////////////////////////////////////////////////////////////////////// 422////////////////////////////////////////////////////////////////////////////////
@@ -395,19 +431,22 @@ void LLWebBrowserCtrl::navigateTo( std::string urlIn )
395 { 431 {
396 if ( LLString::compareInsensitive( urlIn.substr( 0, protocol.length() ).c_str(), protocol.c_str() ) != 0 ) 432 if ( LLString::compareInsensitive( urlIn.substr( 0, protocol.length() ).c_str(), protocol.c_str() ) != 0 )
397 { 433 {
398 LLMozLib::getInstance()->navigateTo( mEmbeddedBrowserWindowId, urlIn ); 434 if (mMediaSource)
435 mMediaSource->navigateTo(urlIn);
399 } 436 }
400 } 437 }
401 else if ( urlIn.length() >= protocol2.length() ) 438 else if ( urlIn.length() >= protocol2.length() )
402 { 439 {
403 if ( LLString::compareInsensitive( urlIn.substr( 0, protocol2.length() ).c_str(), protocol2.c_str() ) != 0 ) 440 if ( LLString::compareInsensitive( urlIn.substr( 0, protocol2.length() ).c_str(), protocol2.c_str() ) != 0 )
404 { 441 {
405 LLMozLib::getInstance()->navigateTo( mEmbeddedBrowserWindowId, urlIn ); 442 if (mMediaSource)
443 mMediaSource->navigateTo(urlIn);
406 } 444 }
407 } 445 }
408 else 446 else
409 { 447 {
410 LLMozLib::getInstance()->navigateTo( mEmbeddedBrowserWindowId, urlIn ); 448 if (mMediaSource)
449 mMediaSource->navigateTo(urlIn);
411 } 450 }
412} 451}
413 452
@@ -455,7 +494,8 @@ void LLWebBrowserCtrl::navigateHome()
455{ 494{
456 if( mHomePageUrl.length() ) 495 if( mHomePageUrl.length() )
457 { 496 {
458 LLMozLib::getInstance()->navigateTo( mEmbeddedBrowserWindowId, mHomePageUrl ); 497 if (mMediaSource)
498 mMediaSource->navigateTo(mHomePageUrl);
459 }; 499 };
460} 500}
461 501
@@ -468,6 +508,15 @@ void LLWebBrowserCtrl::setHomePageUrl( const std::string urlIn )
468 508
469//////////////////////////////////////////////////////////////////////////////// 509////////////////////////////////////////////////////////////////////////////////
470// 510//
511bool LLWebBrowserCtrl::setCaretColor(unsigned int red, unsigned int green, unsigned int blue)
512{
513 if (mMediaSource)
514 return mMediaSource->setCaretColor(red, green, blue);
515 else
516 return false;
517}
518////////////////////////////////////////////////////////////////////////////////
519//
471std::string LLWebBrowserCtrl::getHomePageUrl() 520std::string LLWebBrowserCtrl::getHomePageUrl()
472{ 521{
473 return mHomePageUrl; 522 return mHomePageUrl;
@@ -480,9 +529,12 @@ void LLWebBrowserCtrl::draw()
480 if ( ! getVisible() ) 529 if ( ! getVisible() )
481 return; 530 return;
482 531
532 if ( ! mWebBrowserImage )
533 return;
534
483 // NOTE: optimization needed here - probably only need to do this once 535 // NOTE: optimization needed here - probably only need to do this once
484 // unless tearoffs change the parent which they probably do. 536 // unless tearoffs change the parent which they probably do.
485 LLUICtrl* ptr = (LLUICtrl*)findRootMostFocusRoot(); 537 const LLUICtrl* ptr = findRootMostFocusRoot();
486 if ( ptr && ptr->hasFocus() ) 538 if ( ptr && ptr->hasFocus() )
487 { 539 {
488 setFrequentUpdates( true ); 540 setFrequentUpdates( true );
@@ -510,29 +562,29 @@ void LLWebBrowserCtrl::draw()
510 562
511 // scale texture to fit the space using texture coords 563 // scale texture to fit the space using texture coords
512 mWebBrowserImage->bindTexture(); 564 mWebBrowserImage->bindTexture();
513 glColor4fv( LLColor4::white.mV ); 565 gGL.color4fv( LLColor4::white.mV );
514 F32 max_u = ( F32 )mWebBrowserImage->getBrowserWidth() / ( F32 )mWebBrowserImage->getWidth(); 566 F32 max_u = ( F32 )mWebBrowserImage->getBrowserWidth() / ( F32 )mWebBrowserImage->getWidth();
515 F32 max_v = ( F32 )mWebBrowserImage->getBrowserHeight() / ( F32 )mWebBrowserImage->getHeight(); 567 F32 max_v = ( F32 )mWebBrowserImage->getBrowserHeight() / ( F32 )mWebBrowserImage->getHeight();
516 568
517 // draw the browser 569 // draw the browser
518 glBlendFunc( GL_ONE, GL_ZERO ); 570 gGL.blendFunc( GL_ONE, GL_ZERO );
519 glBegin( GL_QUADS ); 571 gGL.begin( GL_QUADS );
520 { 572 {
521 // render using web browser reported width and height, instead of trying to invert GL scale 573 // render using web browser reported width and height, instead of trying to invert GL scale
522 glTexCoord2f( max_u, 0.f ); 574 gGL.texCoord2f( max_u, max_v );
523 glVertex2i( mWebBrowserImage->getBrowserWidth(), mWebBrowserImage->getBrowserHeight() ); 575 gGL.vertex2i( mWebBrowserImage->getBrowserWidth(), mWebBrowserImage->getBrowserHeight() );
524 576
525 glTexCoord2f( 0.f, 0.f ); 577 gGL.texCoord2f( 0.f, max_v );
526 glVertex2i( 0, mWebBrowserImage->getBrowserHeight() ); 578 gGL.vertex2i( 0, mWebBrowserImage->getBrowserHeight() );
527 579
528 glTexCoord2f( 0.f, max_v ); 580 gGL.texCoord2f( 0.f, 0.f );
529 glVertex2i( 0, 0 ); 581 gGL.vertex2i( 0, 0 );
530 582
531 glTexCoord2f( max_u, max_v ); 583 gGL.texCoord2f( max_u, 0.f );
532 glVertex2i( mWebBrowserImage->getBrowserWidth(), 0 ); 584 gGL.vertex2i( mWebBrowserImage->getBrowserWidth(), 0 );
533 } 585 }
534 glEnd(); 586 gGL.end();
535 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); 587 gGL.blendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
536 } 588 }
537 glPopMatrix(); 589 glPopMatrix();
538 590
@@ -546,15 +598,15 @@ void LLWebBrowserCtrl::draw()
546 598
547void LLWebBrowserCtrl::convertInputCoords(S32& x, S32& y) 599void LLWebBrowserCtrl::convertInputCoords(S32& x, S32& y)
548{ 600{
549 x = mIgnoreUIScale ? llround((F32)x * LLUI::sGLScaleFactor.mV[VX]) : llround((F32)x * gViewerWindow->getDisplayScale().mV[VX]); 601 x = mIgnoreUIScale ? llround((F32)x * LLUI::sGLScaleFactor.mV[VX]) : x;
550 y = mIgnoreUIScale ? llround((F32)(mRect.getHeight() - y) * LLUI::sGLScaleFactor.mV[VY]) : llround((F32)(mRect.getHeight() - y) * gViewerWindow->getDisplayScale().mV[VY]); 602 y = mIgnoreUIScale ? llround((F32)(getRect().getHeight() - y) * LLUI::sGLScaleFactor.mV[VY]) : getRect().getHeight() - y;
551} 603}
552 604
553//////////////////////////////////////////////////////////////////////////////// 605////////////////////////////////////////////////////////////////////////////////
554// virtual 606// virtual
555void LLWebBrowserCtrl::onNavigateBegin( const EventType& eventIn ) 607void LLWebBrowserCtrl::onNavigateBegin( const EventType& eventIn )
556{ 608{
557 LLWebBrowserCtrlEvent event; 609 LLWebBrowserCtrlEvent event( eventIn.getStringValue() );
558 mEventEmitter.update( &LLWebBrowserCtrlObserver::onNavigateBegin, event ); 610 mEventEmitter.update( &LLWebBrowserCtrlObserver::onNavigateBegin, event );
559} 611}
560 612
@@ -563,7 +615,7 @@ void LLWebBrowserCtrl::onNavigateBegin( const EventType& eventIn )
563void LLWebBrowserCtrl::onNavigateComplete( const EventType& eventIn ) 615void LLWebBrowserCtrl::onNavigateComplete( const EventType& eventIn )
564{ 616{
565 // chain this event on to observers of an instance of LLWebBrowserCtrl 617 // chain this event on to observers of an instance of LLWebBrowserCtrl
566 LLWebBrowserCtrlEvent event; 618 LLWebBrowserCtrlEvent event( eventIn.getStringValue() );
567 mEventEmitter.update( &LLWebBrowserCtrlObserver::onNavigateComplete, event ); 619 mEventEmitter.update( &LLWebBrowserCtrlObserver::onNavigateComplete, event );
568} 620}
569 621
@@ -606,16 +658,29 @@ void LLWebBrowserCtrl::onLocationChange( const EventType& eventIn )
606 658
607//////////////////////////////////////////////////////////////////////////////// 659////////////////////////////////////////////////////////////////////////////////
608// virtual 660// virtual
661void LLWebBrowserCtrl::onMediaContentsChange( const EventType& event_in )
662{
663 if ( mWebBrowserImage )
664 {
665 mWebBrowserImage->setNeedsUpdate();
666 mForceUpdate = true;
667 }
668}
669
670////////////////////////////////////////////////////////////////////////////////
671// virtual
609void LLWebBrowserCtrl::onClickLinkHref( const EventType& eventIn ) 672void LLWebBrowserCtrl::onClickLinkHref( const EventType& eventIn )
610{ 673{
611 const std::string protocol( "http://" ); 674 const std::string protocol1( "http://" );
675 const std::string protocol2( "https://" );
612 if( mOpenLinksInExternalBrowser ) 676 if( mOpenLinksInExternalBrowser )
613 { 677 {
614 if ( eventIn.getStringValue().length() ) 678 if ( eventIn.getStringValue().length() )
615 { 679 {
616 if ( LLString::compareInsensitive( eventIn.getStringValue().substr( 0, protocol.length() ).c_str(), protocol.c_str() ) == 0 ) 680 if ( LLString::compareInsensitive( eventIn.getStringValue().substr( 0, protocol1.length() ).c_str(), protocol1.c_str() ) == 0 ||
681 LLString::compareInsensitive( eventIn.getStringValue().substr( 0, protocol2.length() ).c_str(), protocol2.c_str() ) == 0 )
617 { 682 {
618 LLWeb::loadURL( eventIn.getStringValue() ); 683 LLWeb::loadURLExternal( eventIn.getStringValue() );
619 }; 684 };
620 }; 685 };
621 } 686 }
@@ -624,15 +689,14 @@ void LLWebBrowserCtrl::onClickLinkHref( const EventType& eventIn )
624 { 689 {
625 if ( eventIn.getStringValue().length() ) 690 if ( eventIn.getStringValue().length() )
626 { 691 {
627 if ( LLString::compareInsensitive( eventIn.getStringValue().substr( 0, protocol.length() ).c_str(), protocol.c_str() ) == 0 ) 692 if ( LLString::compareInsensitive( eventIn.getStringValue().substr( 0, protocol1.length() ).c_str(), protocol1.c_str() ) == 0 ||
693 LLString::compareInsensitive( eventIn.getStringValue().substr( 0, protocol2.length() ).c_str(), protocol2.c_str() ) == 0 )
628 { 694 {
629 // If we spawn a new LLFloaterHTML, assume we want it to 695 // If we spawn a new LLFloaterHTML, assume we want it to
630 // follow this LLWebBrowserCtrl's setting for whether or 696 // follow this LLWebBrowserCtrl's setting for whether or
631 // not to open secondlife:///app/ links. JC. 697 // not to open secondlife:///app/ links. JC.
632 LLFloaterHtml::getInstance()->show( 698 bool open_links_externally = false;
633 eventIn.getStringValue(), 699 LLFloaterHtml::getInstance()->show( eventIn.getStringValue(), "Second Life Browser", mOpenAppSLURLs, open_links_externally);
634 "Second Life Browser",
635 mOpenAppSLURLs);
636 }; 700 };
637 }; 701 };
638 }; 702 };
@@ -644,7 +708,7 @@ void LLWebBrowserCtrl::onClickLinkHref( const EventType& eventIn )
644 708
645//////////////////////////////////////////////////////////////////////////////// 709////////////////////////////////////////////////////////////////////////////////
646// virtual 710// virtual
647void LLWebBrowserCtrl::onClickLinkSecondLife( const EventType& eventIn ) 711void LLWebBrowserCtrl::onClickLinkNoFollow( const EventType& eventIn )
648{ 712{
649 std::string url = eventIn.getStringValue(); 713 std::string url = eventIn.getStringValue();
650 if (LLURLDispatcher::isSLURLCommand(url) 714 if (LLURLDispatcher::isSLURLCommand(url)
@@ -659,17 +723,18 @@ void LLWebBrowserCtrl::onClickLinkSecondLife( const EventType& eventIn )
659 723
660 // chain this event on to observers of an instance of LLWebBrowserCtrl 724 // chain this event on to observers of an instance of LLWebBrowserCtrl
661 LLWebBrowserCtrlEvent event( eventIn.getStringValue() ); 725 LLWebBrowserCtrlEvent event( eventIn.getStringValue() );
662 mEventEmitter.update( &LLWebBrowserCtrlObserver::onClickLinkSecondLife, event ); 726 mEventEmitter.update( &LLWebBrowserCtrlObserver::onClickLinkNoFollow, event );
663} 727}
664 728
665 729
666//////////////////////////////////////////////////////////////////////////////// 730////////////////////////////////////////////////////////////////////////////////
667// 731//
668LLWebBrowserTexture::LLWebBrowserTexture( S32 width, S32 height, LLWebBrowserCtrl* browserCtrl, int browserWindowId ) : 732LLWebBrowserTexture::LLWebBrowserTexture( S32 width, S32 height, LLWebBrowserCtrl* browserCtrl, LLMediaBase *media_source ) :
669 LLDynamicTexture( 512, 512, 4, ORDER_FIRST, TRUE ), 733 LLDynamicTexture( 512, 512, 4, ORDER_FIRST, TRUE ),
670 mLastBrowserDepth( 0 ), 734 mLastBrowserDepth( 0 ),
735 mNeedsUpdate( true ),
671 mWebBrowserCtrl( browserCtrl ), 736 mWebBrowserCtrl( browserCtrl ),
672 mEmbeddedBrowserWindowId( browserWindowId ) 737 mMediaSource(media_source)
673{ 738{
674 mElapsedTime.start(); 739 mElapsedTime.start();
675 740
@@ -685,35 +750,71 @@ LLWebBrowserTexture::~LLWebBrowserTexture()
685 750
686//////////////////////////////////////////////////////////////////////////////// 751////////////////////////////////////////////////////////////////////////////////
687// 752//
688BOOL LLWebBrowserTexture::render() 753BOOL LLWebBrowserTexture::needsRender()
689{ 754{
690 // frequent updates turned on? 755 if ( mWebBrowserCtrl->getFrequentUpdates() ||
691 if ( mWebBrowserCtrl->getFrequentUpdates() || mWebBrowserCtrl->getAlwaysRefresh() ) 756 mWebBrowserCtrl->getAlwaysRefresh() ||
757 mWebBrowserCtrl->getForceUpdate() )
692 { 758 {
693 // only update mozilla/texture occasionally 759 // only update mozilla/texture occasionally
694 if ( mElapsedTime.getElapsedTimeF32() > ( 1.0f / 15.0f ) ) 760 if ( mElapsedTime.getElapsedTimeF32() > ( 1.0f / 15.0f ) )
695 { 761 {
696 mElapsedTime.reset(); 762 return TRUE;
763 }
764 }
765
766 return FALSE;
767}
697 768
698 const unsigned char* pixels = LLMozLib::getInstance()->grabBrowserWindow( mEmbeddedBrowserWindowId ); 769////////////////////////////////////////////////////////////////////////////////
770//
771BOOL LLWebBrowserTexture::render()
772{
773 if (!mMediaSource)
774 return FALSE;
775
776 // frequent updates turned on?
777 if ( mWebBrowserCtrl->getFrequentUpdates() ||
778 mWebBrowserCtrl->getAlwaysRefresh() ||
779 mWebBrowserCtrl->getForceUpdate() )
780 {
699 781
700 S32 actual_rowspan = LLMozLib::getInstance()->getBrowserRowSpan( mEmbeddedBrowserWindowId ); 782 if ( mNeedsUpdate )
701 S32 browser_depth = LLMozLib::getInstance()->getBrowserDepth( mEmbeddedBrowserWindowId ); 783 {
702 784
785 const unsigned char* pixels = mMediaSource->getMediaData();
786 if ( ! pixels )
787 return FALSE;
788
789 mNeedsUpdate = false;
790 mWebBrowserCtrl->setForceUpdate(false);
791
792 S32 media_depth = mMediaSource->getMediaDepth();
793 S32 media_width = mMediaSource->getMediaWidth();
794 S32 media_height = mMediaSource->getMediaHeight();
795
703 // these are both invalid conditions and should never happen but SL-27583 indicates it does 796 // these are both invalid conditions and should never happen but SL-27583 indicates it does
704 if ( actual_rowspan < 1 || browser_depth < 2 ) 797 if ((media_width < 1) || (media_depth < 2))
705 return FALSE; 798 return FALSE;
706 799
707 // width can change after it's rendered - (Mozilla bug# 24721)
708 S32 pagebuffer_width = actual_rowspan / browser_depth;
709
710 // Browser depth hasn't changed. 800 // Browser depth hasn't changed.
711 if(mLastBrowserDepth == browser_depth) 801 if(mLastBrowserDepth == media_depth)
712 { 802 {
803 S32 width = llmin(media_width, mBrowserWidth);
804 S32 height = llmin(media_height, mBrowserHeight);
805
806 S32 media_data_width = mMediaSource->getMediaDataWidth();
807 S32 media_data_height = mMediaSource->getMediaDataHeight();
808
713 // Just grab the pixels. 809 // Just grab the pixels.
714 mTexture->setSubImage( pixels, 810 if ( media_data_width > 0 && media_data_height > 0 &&
715 pagebuffer_width, mBrowserHeight, 811 media_data_width < MAX_DIMENSION && media_data_height < MAX_DIMENSION )
716 0, 0, pagebuffer_width, mBrowserHeight ); 812 {
813 mTexture->setSubImage( pixels,
814 media_data_width, media_data_height,
815 0, 0,
816 width, height );
817 };
717 } 818 }
718 else 819 else
719 { 820 {
@@ -740,11 +841,20 @@ S32 LLWebBrowserTexture::getBrowserHeight()
740 return mBrowserHeight; 841 return mBrowserHeight;
741} 842}
742 843
844////////////////////////////////////////////////////////////////////////////////
845//
846void LLWebBrowserTexture::setNeedsUpdate()
847{
848 mNeedsUpdate = true;
849}
743 850
744//////////////////////////////////////////////////////////////////////////////// 851////////////////////////////////////////////////////////////////////////////////
745// 852//
746void LLWebBrowserTexture::resize( S32 new_width, S32 new_height ) 853void LLWebBrowserTexture::resize( S32 new_width, S32 new_height )
747{ 854{
855 if (!mMediaSource)
856 return;
857
748 F32 scale_ratio = 1.f; 858 F32 scale_ratio = 1.f;
749 if (new_width > MAX_DIMENSION) 859 if (new_width > MAX_DIMENSION)
750 { 860 {
@@ -758,23 +868,25 @@ void LLWebBrowserTexture::resize( S32 new_width, S32 new_height )
758 mBrowserWidth = llround(scale_ratio * (F32)new_width); 868 mBrowserWidth = llround(scale_ratio * (F32)new_width);
759 mBrowserHeight = llround(scale_ratio * (F32)new_height); 869 mBrowserHeight = llround(scale_ratio * (F32)new_height);
760 870
761 LLMozLib::getInstance()->setSize( mEmbeddedBrowserWindowId, mBrowserWidth, mBrowserHeight ); 871 mMediaSource->setRequestedMediaSize(mBrowserWidth, mBrowserHeight);
762 872
763 const unsigned char* pixels = LLMozLib::getInstance()->grabBrowserWindow( mEmbeddedBrowserWindowId ); 873 // HACK - this code is executing a render - resize should call render() instead
874 // (and render() should be refactored so it doesn't call resize())
875
876 const unsigned char* pixels = mMediaSource->getMediaData();
764 877
765 S32 actual_rowspan = LLMozLib::getInstance()->getBrowserRowSpan( mEmbeddedBrowserWindowId ); 878 S32 media_width = mMediaSource->getMediaWidth();
766 S32 browser_depth = LLMozLib::getInstance()->getBrowserDepth( mEmbeddedBrowserWindowId ); 879 S32 media_height = mMediaSource->getMediaHeight();
880 S32 media_depth = mMediaSource->getMediaDepth();
767 881
768 // these are both invalid conditions and should never happen but SL-27583 indicates it does 882 // these are both invalid conditions and should never happen but SL-27583 indicates it does
769 if ( actual_rowspan < 1 || browser_depth < 2 ) 883 if ( media_width < 1 || media_depth < 2 )
770 return; 884 return;
771
772 releaseGLTexture();
773 885
774 S32 pagebuffer_width = actual_rowspan / browser_depth; 886 releaseGLTexture();
775 887
776 // calculate the next power of 2 bigger than reqquested size for width and height 888 // calculate the next power of 2 bigger than reqquested size for width and height
777 for ( mWidth = 1; mWidth < pagebuffer_width; mWidth <<= 1 ) 889 for ( mWidth = 1; mWidth < mBrowserWidth; mWidth <<= 1 )
778 { 890 {
779 if ( mWidth >= MAX_TEXTURE_DIMENSION ) 891 if ( mWidth >= MAX_TEXTURE_DIMENSION )
780 { 892 {
@@ -795,7 +907,7 @@ void LLWebBrowserTexture::resize( S32 new_width, S32 new_height )
795 LLGLenum type_format; 907 LLGLenum type_format;
796 BOOL swap_bytes = FALSE; 908 BOOL swap_bytes = FALSE;
797 909
798 switch(browser_depth) 910 switch(media_depth)
799 { 911 {
800 default: 912 default:
801 case 4: 913 case 4:
@@ -831,12 +943,21 @@ void LLWebBrowserTexture::resize( S32 new_width, S32 new_height )
831 943
832 // will create mWidth * mHeight sized texture, using BGR ordering 944 // will create mWidth * mHeight sized texture, using BGR ordering
833 LLDynamicTexture::generateGLTexture(internal_format, primary_format, type_format, swap_bytes); 945 LLDynamicTexture::generateGLTexture(internal_format, primary_format, type_format, swap_bytes);
946
947
948 S32 width = llmin(media_width, mBrowserWidth);
949 S32 height = llmin(media_height, mBrowserHeight);
950
951 S32 media_data_width = mMediaSource->getMediaDataWidth();
952 S32 media_data_height = mMediaSource->getMediaDataHeight();
953
954 if (pixels)
955 {
956 mTexture->setSubImage( pixels, media_data_width, media_data_height,
957 0, 0, width, height );
958 }
834 959
835 mTexture->setSubImage( pixels, 960 mLastBrowserDepth = media_depth;
836 pagebuffer_width, mBrowserHeight,
837 0, 0, pagebuffer_width, mBrowserHeight );
838
839 mLastBrowserDepth = browser_depth;
840} 961}
841 962
842LLView* LLWebBrowserCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) 963LLView* LLWebBrowserCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
@@ -860,7 +981,7 @@ LLView* LLWebBrowserCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFac
860 LLColor4 color; 981 LLColor4 color;
861 LLUICtrlFactory::getAttributeColor(node, "caret_color", color); 982 LLUICtrlFactory::getAttributeColor(node, "caret_color", color);
862 LLColor4U colorU = LLColor4U(color); 983 LLColor4U colorU = LLColor4U(color);
863 LLMozLib::getInstance()->setCaretColor( web_browser->mEmbeddedBrowserWindowId, colorU.mV[0], colorU.mV[1], colorU.mV[2] ); 984 web_browser->setCaretColor( colorU.mV[0], colorU.mV[1], colorU.mV[2] );
864 } 985 }
865 986
866 BOOL ignore_ui_scale = web_browser->getIgnoreUIScale(); 987 BOOL ignore_ui_scale = web_browser->getIgnoreUIScale();
@@ -878,4 +999,4 @@ LLView* LLWebBrowserCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFac
878 return web_browser; 999 return web_browser;
879} 1000}
880 1001
881#endif // LL_LIBXUL_ENABLED 1002