home *** CD-ROM | disk | FTP | other *** search
- ////////////////////////////////////////////////////////////////////////////////
- //
- // uBrowser - a program that illustrates one way of embedding the
- // Mozilla Gecko (tm) Rendering Engine in an application, grabbing the
- // rendered output and displaying it on the surface of a 3D polygon as
- // texture in an OpenGL (tm) application.
- //
- // uBrowser is free software; you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation; either version 2 of the License, or
- // (at your option) any later version.
- //
- // uBrowser 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 General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with uBrowser; if not, write to the Free Software
- // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- //
- // Original code: Copyright 2005 Linden Research Inc.
- // http://www.lindenlab.com
- //
- // Primary author and site maintainer: Callum Prentice (callum@ubrowser.com)
- //
- // See contributors.txt or http://ubrowser.com for a list of contributors
- // without whose generous donation of time and effort, this application
- // would not have been possible.
- //
- ////////////////////////////////////////////////////////////////////////////////
- #ifndef EMBEDDEDBROWSERWINDOW_H
- #define EMBEDDEDBROWSERWINDOW_H
-
- #include "nsIBaseWindow.h"
- #include "nsIInterfaceRequestor.h"
- #include "nsIWebBrowserChrome.h"
- #include "nsIWebNavigation.h"
- #include "nsIWebProgressListener.h"
- #include "nsWeakReference.h"
- #include "nsIWebBrowser.h"
-
- #include <algorithm>
- #include <typeinfo>
- #include <list>
-
- // annoying, harmless warning we can't get rid of in MSVC.net
- // (no matching operator delete found; memory will not be freed if initialization throws an exception)
- #pragma warning ( disable : 4291 )
-
- ///////////////////////////////////////////////////////////////////////////////
- // manages the process of sotring and emitting events that the consumer
- // of the embedding class can observe
- template < class T >
- class embeddedBrowserWindowEmitter
- {
- public:
- embeddedBrowserWindowEmitter() { };
- ~embeddedBrowserWindowEmitter() { };
-
- typedef typename T::EventType EventType;
- typedef std::list< T* > ObserverContainer;
- typedef void ( T::*observerMethod )( const EventType& );
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- bool addObserver( T* observerIn )
- {
- if( ! observerIn )
- return false;
-
- if( std::find( observers.begin(), observers.end(), observerIn ) != observers.end() )
- return false;
-
- observers.push_back( observerIn );
-
- return true;
- };
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- bool remObserver( T* observerIn )
- {
- if( ! observerIn )
- return false;
-
- observers.remove( observerIn );
-
- return true;
- };
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- void update( observerMethod method, const EventType& msgIn )
- {
- typename std::list< T* >::iterator iter = observers.begin();
-
- while( iter != observers.end() )
- {
- ( ( *iter )->*method )( msgIn );
-
- ++iter;
- };
- };
-
- protected:
- ObserverContainer observers;
- };
-
- class embeddedBrowserWindow;
-
- ////////////////////////////////////////////////////////////////////////////////
- // data class that is passed with an event - used in this case merely to
- // access the instance of the emitting class
- class embeddedBrowserWindowEvent
- {
- public:
- embeddedBrowserWindowEvent( embeddedBrowserWindow* payloadIn ):
- payload( payloadIn )
- {
- };
-
- virtual ~embeddedBrowserWindowEvent()
- {
- };
-
- embeddedBrowserWindow* getPayload() const
- {
- return payload;
- };
-
- private:
- embeddedBrowserWindow* payload;
- };
-
- ////////////////////////////////////////////////////////////////////////////////
- // the app class derrives from this and overrrides the events it wishes to observe
- class embeddedBrowserWindowObserver
- {
- public:
- typedef embeddedBrowserWindowEvent EventType;
- virtual void onNavigateBegin( const EventType& eventIn ) { }
- virtual void onNavigateComplete( const EventType& eventIn ) { }
- virtual void onUpdateProgress( const EventType& eventIn ) { }
- virtual void onStatusTextChange( const EventType& eventIn ) { }
- virtual void onLocationChange( const EventType& eventIn ) { }
- };
-
- class embeddedBrowser;
-
- ////////////////////////////////////////////////////////////////////////////////
- // class for a "window" that holds a browser - eventually there will be lots of these
- class embeddedBrowserWindow :
- public nsIInterfaceRequestor,
- public nsIWebBrowserChrome,
- public nsIWebProgressListener,
- public nsSupportsWeakReference
- {
- public:
- embeddedBrowserWindow();
- ~embeddedBrowserWindow();
-
- NS_DECL_ISUPPORTS
- NS_DECL_NSIINTERFACEREQUESTOR
- NS_DECL_NSIWEBBROWSERCHROME
- NS_DECL_NSIWEBPROGRESSLISTENER
-
- NS_METHOD Init( embeddedBrowser* browserIn, nsIWebBrowser* webBrowserIn );
-
- const PRInt16 getPercentComplete();
- const std::string& getStatusMsg();
- const std::string& getCurrentUri();
-
- bool addObserver( embeddedBrowserWindowObserver* observerIn );
- bool remObserver( embeddedBrowserWindowObserver* observerIn );
-
- private:
- nsCOMPtr< nsIWebBrowser > mWebBrowser;
- embeddedBrowser* mEmbedBrowser;
- embeddedBrowserWindowEmitter< embeddedBrowserWindowObserver > mEventEmitter;
- PRInt16 mPercentComplete;
- std::string mStatusText;
- std::string mCurrentUri;
- };
-
- #endif // EMBEDEDDBROWSERWINDOW_H