// WEBMOBSV.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#if !defined(__WEBMOBSV_H__)
#define __WEBMOBSV_H__

#if !defined(__E32BASE_H__)
#include <e32base.h>
#endif

#define KNoMessageSubType 0

class MWebModelObserver;
class TWebModelMessage;
class TWebModelRequestReturn;
class TDataType;

// A mixin class to allow the user interface to be given messages from the engine
class MWebModelObserver
	{
public:
	
	// Message types
	enum TWebEngineMessageType
		{
		EWebObserverStatusMessage = 1,		// there is a change in document loading status
		EWebObserverMessage,					// there is a general message from the engine
		EWebEngineGeneralError,					// there is a general error in the engine or plug in
		EWebEngineGeneralErrorNoLeave,		// there is a general error in the engine or plug in - the recipient of this message should not leave
		EWebObserverFocusChange				// the engine wants the UI to change the focus
		};
	
	//Request types
	enum TWebEngineRequestType
		{
		EWebEngineCookieRequest,					// cookie acceptance query
		EWebEngineSecureSpaceRequest,		// enter / leave secure space query
		EWebEnginePostRedirectionRequest,	// allow form submission to redirect query
		EWebEngineDisplaySizeRequest	
		};

	//Request responses
	enum TWebModelRequestResponse
		{
		EWebModelYes = ETrue,			// user said yes
		EWebModelNo = EFalse			// user said no
		};

	// status codes - these are essentially messages from WebTL
	enum TWebModelObserverStatus
		{
		EWebModelOpeningDocument,	// opening a document
		EWebModelSelectingISP,			// Choosing the ISP
		EWebModelStarting,			// preparing to connect
		EWebModelDialling,			// dialling ISP
		EWebModelLoggingIn,			// logging in to ISP
		EWebModelConnected,				// connected to ISP
		EWebModelLookingUpHost,		// looking up host address
		EWebModelConnectingToHost,	// connecting to host
		EWebModelAwaitingReply,		// waiting for reply from host
		EWebModelReceivingData,		// receiving data
		EWebModelSendingData,		// sending data
		EWebModelDisconnected,		// disconnected
		EWebModelCancel,				// operation cancelled
		EWebModelHTTPRedirecting	//A HTTP redirection is underway
		};

	// engine messages - these indicate activity in the engine which the UI needs to know about
	enum TWebModelObserverMessage
		{
		EWebModelNewPage,			// the page has changed
		EWebModelNewPageFrameset,	// page has changed and its a frameset
		EWebModelSize,				// the size of the main document is now known
		EWebModelTitle,				// the title has arrived or changed
		EWebModelData,				// new data has arrived - update the progress bar if any
		EWebModelFramePageComplete,	// all data has arrived for a frame/page including data for embedded objects
		EWebModelFramesetComplete,	// all data has arrived for a frame set
		EWebModelScroll,			// the scroll bar needs to be updated
		EWebModelUrl,				// the URL may have changed after parsing, redirection, etc.
		EWebModelProgressiveDraw,	// the engine is ready to do a progressive draw
		EWebModelReplacePage,		// A page has been replaced
		EWebModelFormattingComplete,	// Formatting of the page is complete
		EWebModelLocalLinkActivated, // User has selected a local link - que for the UI to update the history list
		EWebModelFrameDeleted		 // A frame is being deleted - Observer must not leave 
		};

	// Error codes for errors other than EPOC32 or STNC ones (numbered from 1 upward)
	enum TWebEngineGeneralError
		{
		EAuthenticationCancelledError,		// the user was asked for authentication and cancelled the dialog
		EWebPlugInNotAvailableForTag,	// a plug in was not registered for the requested tag
		EWebPlugInNotAvailableForMime,	// a plug in was not registered for the requested mime type
		EWebPlugInMarkupLanguageNotSupported,		// the browser does not support the incoming markup language
		EWebPlugInScriptingLanguageNotSupported,	// the browser does not support the required scripting language
		EWebPlugInNotFound,						// a plugin was required but couldn't be found (i.e. the plug in was supposed to be there but wasn't (CF Card removed ???)
		EWebPlugInUnrecognisedMime		// a mime type was not supplied for an incoming document, so no PI can be loaded
		};

	enum TWebObserverFocusChange
		{
		EFocusNext,
		EFocusPrev,
		EFocusThisFrame
		};

	// sources of status information and error codes
	enum TWebModelObserverSource
		{
		EWebModelSourceNotAvailable,	// no source information available (not appropriate for this message)
		EWebModelFromMainPage,		// the main web page which is currently on screen
		EWebModelFromNewPage,		// the new page that is being loaded (not yet on screen)
		EWebModelFromFile,				// a document being fetched in raw mode and saved somewhere
		EWebModelFromNifMonitor		// the NIF monitor
		};

	// document levels
	enum TWebModelObserverLevel
		{
		EWebModelLevelNotAvailable,		// no Level information available (not appropriate for this message)
		EWebModelOuter,				// the outermost document
		EWebModelInner				// an embedded document - usually a picture, embedded mime object etc
		};


	// New generic message handling
	virtual void HandleWebModelMessageL(TInt aFrameID, MWebModelObserver::TWebEngineMessageType aMessageType,
										const TWebModelMessage& aMessage) =0;
	
	// Generic request handling.  Return false if cancelled or not handled.
	virtual TBool HandleWebModelRequestL(TInt aFrameID, MWebModelObserver::TWebEngineRequestType aRequestType, 
										const TWebModelMessage& aMessage, TWebModelRequestReturn& aReturn) =0;

	// Handle an authentication request, supplying a user name and password. Return false if the user cancels.
	virtual TBool HandleWebModelAuthenticationL(TDes& aName,TDes& aPassword, TInt aFrameID=0) = 0;
	IMPORT_C virtual void MWebModelObserver_Reserved1();
	IMPORT_C virtual void MWebModelObserver_Reserved2();
};


// A class to pass a message payload to an observer of the web engine
class TWebModelMessage
	{
public:
	IMPORT_C TWebModelMessage(	TInt aMessageSubType, MWebModelObserver::TWebModelObserverSource aSource,
											MWebModelObserver::TWebModelObserverLevel aLevel,
											const TDesC& aURL, const TDesC& aDescriptor, TDataType* aMimeType, TAny* aAdditionalData  );

	IMPORT_C TWebModelMessage(const TWebModelMessage& aMessage);
	IMPORT_C TWebModelMessage();
	IMPORT_C TInt MessageSubType() const;
	IMPORT_C MWebModelObserver::TWebModelObserverSource Source() const;
	IMPORT_C MWebModelObserver::TWebModelObserverLevel Level() const;
	IMPORT_C const TDesC& URL() const;		
	IMPORT_C const TDesC& Descriptor() const;		
	IMPORT_C TDataType* MimeType() const;	
	IMPORT_C TAny* AdditionalData() const;	
	
private:
	TInt iMessageSubType;			//The subtype of the message
	MWebModelObserver::TWebModelObserverSource iSource;	//Source of the message
	MWebModelObserver::TWebModelObserverLevel iLevel;	//Level of the message
	const TDesC& iURL;									//URL related to the message
	const TDesC& iDescriptor;							//A descriptor holding text relevant to the message (eg a tag name)
	TDataType* iMimeType;						//Mime type related to the message

	TAny* iAdditionalData;						//Additional data related to the message
	};

// A class for an observer to pass back to the engine following a request
class TWebModelRequestReturn
	{
public:
	IMPORT_C TWebModelRequestReturn(  TInt aRequestSubType, TInt aRequestResponse, TAny* aAdditionalData );
	IMPORT_C TWebModelRequestReturn( const TWebModelRequestReturn& aRetVal );
	IMPORT_C TWebModelRequestReturn();
	IMPORT_C TInt RequestSubType() const;
	IMPORT_C TInt RequestResponse() const;
	IMPORT_C void SetRequestResponse(TInt aValue);
	IMPORT_C TAny* AdditionalData() const;
	IMPORT_C void SetAdditionalData(TAny* aValue);

private:
	TInt iRequestSubType;				//The subtype of the request
	TInt iRequestResponse;				//Return value from the observer
	
	TAny* iAdditionalData;		//Additional data from the observer
	};

#endif 
