[sldev] Browser in Secondlife Viewer
Matt Kimmel
mattk at electricsheepcompany.com
Wed Nov 7 19:14:12 PST 2007
For those of you who are curious, the attached files illustrate the
basics of how we implemented the in-world browser in the OnRez viewer.
Instances of the browser are created with a simple "new
ESCFloaterHTML(<browser type>)" and are made visible, with content, by
calls to ESCFloaterHTML::show or ::showRawURL.
As you can see, it's pretty straightforward--as Callum says, all the
support is already in the code base; it's just a matter of writing a UI
to go with it. In fact, our code is adapted from an existing class.
-Matt
--
Matt Kimmel, Software Alchemist
The Electric Sheep Company, Inc.
SL: Feep Larsson
Callum Prentice wrote:
> First off, thanks for the spirited discussion that's taking place around
> what to do with the embedded browser - it's useful to get a sense of
> what people think is important and what isn't.
>
> It's trivial to create a regular browser in in the client UI - you can
> *almost* to it all using XUI (but not quite). One reason we haven't done
> it already is that there are still some issues with LLMozLib and not all
> sites render correctly. Along with the inevitable bump in support calls
> this would lead to, the lack of bookmarks, access to password protected
> sites etc. meant it wasn't very high on the list and we figured
> residents would rather use their system browser.
>
> Maybe that should change.
>
>>> In the OnRez viewer, how they brought up a web page in a SL window.
>>> I would like to know the functionality they used for it.
>>> Suggestions are welcome, and I request you all to guide me in this
>
> _______________________________________________
> Click here to unsubscribe or manage your list subscription:
> /index.html
>
-------------- next part --------------
/**
* @file escfloaterhtml.cpp
* @brief In-world HTML dialog
*
* Copyright (c) 2007, The Electric Sheep Company, Inc
* Copyright (c) 2005-2007, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at http://secondlife.com/developers/opensource/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
*/
#include "llviewerprecompiledheaders.h"
#include "llvieweruictrlfactory.h"
#include "llviewerwindow.h"
#include "llviewercontrol.h"
#include "escfloaterhtml.h"
#include "llfloaterhtmlhelp.h"
#include "llweb.h"
#include <curl/curl.h>
ESCFloaterHtml* gFloaterHTMLGreeting = NULL;
ESCFloaterHtml* gFloaterHTMLBrowser = NULL;
ESCFloaterHtml::ESCFloaterHtml( BrowserType type )
: LLFloater( "ESC Browser" )
#if LL_LIBXUL_ENABLED
,
mWebBrowser( 0 )
#endif // LL_LIBXUL_ENABLED
{
// create floater from its XML definition
gUICtrlFactory->buildFloater( this, "floater_html_esc.xml" );
#if LL_LIBXUL_ENABLED
mWebBrowser = LLViewerUICtrlFactory::getWebBrowserByName(this, "html_floater_browser_esc" );
if ( mWebBrowser )
{
// observe browser events
mWebBrowser->addObserver( this );
// make links open in external browser
mWebBrowser->setOpenInExternalBrowser( false );
// don't automatically open secondlife links since we want to catch
// special ones that do other stuff (like open F1 Help)
mWebBrowser->setOpenSecondLifeLinksInMap( false );
}
#endif // LL_LIBXUL_ENABLED
childSetAction("close_btn", onClickClose, this);
childSetAction("forward_btn", onClickForward, this);
childSetAction("back_btn", onClickBack, this);
childSetAction("go_btn", onClickGo, this);
childSetAction("home_btn", onClickHome, this);
childSetAction("reload_btn", onClickReload, this);
childSetAction("external_browser_btn", onClickExternal, this);
childSetText("browser_progress_text", "");
// Set up some defaults based on the browser type
// ESCTODO: This should eventually be data-driven
switch (type)
{
case GREETING:
setControlsVisible(FALSE);
mRectSettingName = "ESCHtmlFloaterRect";
#if LL_LIBXUL_ENABLED
mWebBrowser->setAlwaysRefresh(true); // Work around black-window bug
#endif
break;
case ARBITRARY:
setControlsVisible(TRUE);
mRectSettingName = "ESCArbitraryHtmlFloaterRect";
setTitle( childGetValue( "browser_title" ).asString() );
setDefaultBtn("go_btn");
break;
}
// reposition floater from saved settings
LLRect rect = gSavedSettings.getRect( mRectSettingName );
reshape( rect.getWidth(), rect.getHeight(), FALSE );
setRect( rect );
}
ESCFloaterHtml::~ESCFloaterHtml()
{
#if LL_LIBXUL_ENABLED
// stop observing browser events
if ( mWebBrowser )
mWebBrowser->remObserver( this );
#endif // LL_LIBXUL_ENABLED
// save position of floater
gSavedSettings.setRect( mRectSettingName, mRect );
}
void ESCFloaterHtml::show( LLString content_id )
{
// calculate the XML labels we'll need (if only XML folders worked)
LLString title_str = content_id + "_title";
LLString url_str = content_id + "_url";
// set the title
setTitle( childGetValue( title_str ).asString() );
#if LL_LIBXUL_ENABLED
// navigate to the URL
if ( mWebBrowser )
mWebBrowser->navigateTo( childGetValue( url_str ).asString() );
#endif // LL_LIBXUL_ENABLED
// make floater appear
setVisibleAndFrontmost();
}
void ESCFloaterHtml::showRawURL( LLString url )
{
// TODO: Set title?
#if LL_LIBXUL_ENABLED
// navigate to the URL
if ( mWebBrowser )
mWebBrowser->navigateTo( url.c_str() );
#endif // LL_LIBXUL_ENABLED
// make floater appear
setVisibleAndFrontmost();
}
void ESCFloaterHtml::setControlsVisible( BOOL is_visible /*= TRUE */ )
{
childSetVisible( "forward_btn", is_visible );
childSetVisible( "back_btn", is_visible );
childSetVisible( "web_text", is_visible );
childSetVisible( "url_bar", is_visible );
childSetVisible( "go_btn", is_visible );
childSetVisible( "reload_btn", is_visible );
childSetVisible( "external_browser_btn", is_visible );
// If hiding, extend the web browser to cover the button area.
// If showing, move the web browser out of the button area.
if ( is_visible )
{
LLRect r = mWebBrowser->getRect();
LLRect buttonRect;
if ( childGetRect( "forward_btn", buttonRect ) )
{
r.mTop = buttonRect.mBottom - 10;
mWebBrowser->reshape( r.getWidth(), r.getHeight(), TRUE );
mWebBrowser->setRect( r );
}
}
else
{
LLRect r = mWebBrowser->getRect();
LLRect buttonRect;
if ( childGetRect( "forward_btn", buttonRect ) )
{
r.mTop = buttonRect.mTop;
mWebBrowser->reshape( r.getWidth(), r.getHeight(), TRUE );
mWebBrowser->setRect( r );
}
}
}
void ESCFloaterHtml::onClose( bool app_quitting )
{
#if LL_LIBXUL_ENABLED
// stop any streaming media
if ( mWebBrowser )
mWebBrowser->navigateTo( "about:blank" );
#endif // LL_LIBXUL_ENABLED
setVisible( false );
}
void ESCFloaterHtml::onClickClose( void* data )
{
ESCFloaterHtml* self = ( ESCFloaterHtml* )data;
self->setVisible( false );
}
// virtual
BOOL ESCFloaterHtml::handleKeyHere( KEY key, MASK mask, BOOL called_from_parent )
{
BOOL handled = FALSE;
if( getVisible() && getEnabled() && !called_from_parent )
{
if( (KEY_RETURN == key) && (MASK_NONE == mask) )
{
LLString new_url = childGetValue( "url_bar" ).asString();
if ( !new_url.empty() )
{
showRawURL( new_url );
childSetFocus( "url_bar", FALSE );
childSetFocus( "html_floater_browser_esc", TRUE );
handled = TRUE;
}
}
}
return handled;
}
void ESCFloaterHtml::onClickLinkSecondLife( const EventType& eventIn )
{
#if LL_LIBXUL_ENABLED
const std::string protocol( "secondlife://app." );
// special 'app' secondlife link (using a different protocol - one that isn't registered in the browser) causes bad
// things to happen and Mozilla stops responding because it can't display the "invalid protocol dialog)
if ( LLString::compareInsensitive( eventIn.getStringValue().substr( 0, protocol.length() ).c_str(), protocol.c_str() ) == 0 )
{
// extract the command string
LLString cmd = eventIn.getStringValue().substr( protocol.length() );
// command is open the F1 Help floater
if ( LLString::compareInsensitive( cmd.c_str() , "floater.html.help" ) == 0 )
{
gViewerHtmlHelp.show();
}
}
else
// regular secondlife link - just open the map as normal
{
mWebBrowser->openMapAtlocation( eventIn.getStringValue() );
}
#endif // LL_LIBXUL_ENABLED
};
// virtual
void ESCFloaterHtml::onLocationChange( const EventType& eventIn )
{
// Set URL bar to match new location
LLString new_url = eventIn.getStringValue();
childSetText( "url_bar", new_url );
childSetFocus( "url_bar", FALSE );
childSetFocus( "html_floater_browser_esc", TRUE );
mCurrentLocation = new_url;
}
void ESCFloaterHtml::onClickBack( void* data )
{
ESCFloaterHtml* self = ( ESCFloaterHtml* )data;
#if LL_LIBXUL_ENABLED
if (self && self->mWebBrowser)
{
self->mWebBrowser->navigateBack();
}
#endif
}
// virtual
void ESCFloaterHtml::onStatusTextChange( const EventType& eventIn )
{
LLString progress_text = eventIn.getStringValue();
childSetText( "browser_progress_text", progress_text );
}
void ESCFloaterHtml::onClickForward( void* data )
{
ESCFloaterHtml* self = ( ESCFloaterHtml* )data;
#if LL_LIBXUL_ENABLED
if (self && self->mWebBrowser)
{
self->mWebBrowser->navigateForward();
}
#endif
}
void ESCFloaterHtml::onClickGo( void* data )
{
ESCFloaterHtml* self = ( ESCFloaterHtml* )data;
if ( self )
{
LLString new_url = self->childGetValue( "url_bar" ).asString();
if ( !new_url.empty() )
{
self->showRawURL( new_url );
self->childSetFocus( "html_floater_browser_esc", TRUE );
}
}
}
void ESCFloaterHtml::onClickHome( void* data )
{
ESCFloaterHtml* self = ( ESCFloaterHtml* )data;
if ( self )
{
self->showRawURL( gSavedSettings.getString( "BrowserHomePage" ) );
}
}
void ESCFloaterHtml::onClickLinkHref( const EventType& eventIn )
{
const std::string protocol( "http://" );
if ( eventIn.getStringValue().length() )
{
if ( LLString::compareInsensitive( eventIn.getStringValue().substr( 0, protocol.length() ).c_str(), protocol.c_str() ) == 0 )
{
// HACK: Show this in main window, in case it was an href
// with a target other than the main window.
showRawURL( eventIn.getStringValue() );
}
}
}
// static
void ESCFloaterHtml::onClickReload( void* data )
{
ESCFloaterHtml* self = ( ESCFloaterHtml* )data;
if ( self )
{
self->showRawURL( self->mCurrentLocation );
}
}
// static
void ESCFloaterHtml::onClickExternal( void* data )
{
ESCFloaterHtml* self = ( ESCFloaterHtml* )data;
if (self)
{
if (!self->mCurrentLocation.empty())
{
LLWeb::loadURLExternal(self->mCurrentLocation);
}
}
}
-------------- next part --------------
/**
* @file escfloaterhtml.h
* @brief In-world browser floater
*
* Copyright (c) 2007, The Electric Sheep Company, Inc.
* Copyright (c) 2005-2007, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at http://secondlife.com/developers/opensource/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
*/
#ifndef ESC_FLOATERHTML_H
#define ESC_FLOATERHTML_H
#include "llwebbrowserctrl.h"
#include "llfloater.h"
class ESCFloaterHtml :
public LLFloater,
public LLWebBrowserCtrlObserver
{
public:
/**
* This enum specifies different browser types, each of which
* has its own defaults, including visibility of buttons,
* settings names, and so on.
*/
enum BrowserType
{
GREETING, // The "greeting" browser that pops up when a user logs in
ARBITRARY // The "arbitrary" browser that opens on llLoadURL or when the user clicks on a URL in chat history
};
public:
ESCFloaterHtml(BrowserType type);
virtual ~ESCFloaterHtml();
virtual void onClose( bool app_quitting );
virtual BOOL handleKeyHere( KEY key, MASK mask, BOOL called_from_parent );
void show( LLString content_id );
void showRawURL( LLString url );
void setControlsVisible( BOOL is_visible = TRUE );
static void onClickClose( void* data );
static void onClickBack( void* data );
static void onClickForward( void* data );
static void onClickGo( void* data );
static void onClickHome( void* data );
static void onClickReload( void* data );
static void onClickExternal( void* data );
// observable browser events
virtual void onClickLinkSecondLife( const EventType& eventIn );
virtual void onLocationChange( const EventType& eventIn );
virtual void onClickLinkHref( const EventType& eventIn );
virtual void onStatusTextChange( const EventType& eventIn );
private:
#if LL_LIBXUL_ENABLED
LLWebBrowserCtrl* mWebBrowser;
#endif // LL_LIBXUL_ENABLED
LLButton* mCloseButton;
BrowserType mBrowserType;
LLString mRectSettingName;
LLString mCurrentLocation;
private:
// Default constructor not available
ESCFloaterHtml();
};
extern ESCFloaterHtml* gFloaterHTMLGreeting;
extern ESCFloaterHtml* gFloaterHTMLBrowser;
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: floater_html_esc.xml
Type: text/xml
Size: 2315 bytes
Desc: not available
Url : http://lists.secondlife.com/pipermail/sldev/attachments/20071107/96453682/floater_html_esc-0001.bin
More information about the SLDev
mailing list