// WEBSVMOD.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#if !defined(__WEBSVMOD_H__)
#define __WEBSVMOD_H__

#if !defined(__E32STD_H__)
#include <e32std.h>
#endif
#if !defined(__E32BASE_H__)
#include <e32base.h>
#endif
#if !defined(__GDI_H__)
#include <gdi.h>
#endif
#if !defined(__ES_SOCK_H__)
#include <es_sock.h>
#endif
#if !defined(__BADESCA_H__)
#include <badesca.h>
#endif
#if !defined(__WEBDEF_H__)
#include "webdef.h"
#endif
#if !defined(__APADEF_H__)
#include <apadef.h>
#endif
#if !defined(__APGCLI_H__)
#include <apgcli.h>
#endif


class THistoryListDetails;
class THistoryListFrameId;

class CAuthenticationData;
class CBookmarkControl;
class CBookmarkModel;
class CHistoryListModel;
class CNifMonitor;
class CWtlDocument;
class CWtlSession;
class MWebModelObserver;
class CWebLogger;
class RWriteStream;
class CWebSchemes;
class RResourceFile;
class TDataType;

class MBkmkModelObserver;


class CWebServicesModel: public CBase
// The Web Services Model
// This stores all the per session state information that is not local to an individual page
	{
public:
// configuration items
	enum TBoolConfigurationItem
		{
		EBoolConfigEnableApplet,
		EBoolConfigEnableFrames,
		EBoolConfigEnableScript,
		EBoolConfigOffline,
		EBoolConfigPersistHistoryList,
		EBoolConfigPersistCache
		};

	enum TNumericConfigurationItem
		{
		ENumericConfigCacheSize,
		ENumericConfigImageColorDepth,
		ENumericConfigImageBrightness,
		ENumericConfigImageContrast,
		ENumericConfigCookiesEnabled
		};

	enum THBufConfigurationItem
		{
		EHBufConfigFileDirText,
		EHBufConfigFileDateFormat,
		EHBufConfigFileParentDirText,
		EHBufConfigMsgTelLine,
		EHBufConfigMsgTelModule
		};

	enum THttpConfigurationItem
		{
		EConfigHttpAcceptHeader,
		EConfigHttpAcceptCharset,
		EConfigHttpAcceptLanguage,
		EConfigHttpUserAgentString,
		EConfigHttpFromHeader
		};

	enum TPtrConfigurationItem
		{
		EPtrConfigHomeUrl,
		EPtrConfigSearchUrl
		};

// network settings flags
	enum TWebNetworkSettings
		{
		ENoLocations = 1,
		ENoModems = 2,
		ENoServices = 4
		};

// simulated failure heaps
	enum TWebHeapType	
		{
		EKernalHeap,
		EServerUserHeap,
		EClientUserHeap
		};

// Cookie values mapped in CWebServicesModel to WebTL constant integers
	enum TWebServicesCookieConfigValue
		{
		ECookieAccept,
		ECookieReject,
		ECookieAskUser
		};

// exported public functions
	IMPORT_C static CWebServicesModel* NewL(TInt aHistoryListSize);
	IMPORT_C ~CWebServicesModel();
	IMPORT_C void StartCommsL(TUint32& aNetworkSettings);
	IMPORT_C TBool IsConnected();
	IMPORT_C CWtlSession* Session();
	IMPORT_C RFs& FsSession() const;
	IMPORT_C void OpenResourceFileL(RResourceFile& aResFile, const TDesC& aResFileName,const TDesC& aResFileLocation, const TDesC& aDrive);
	IMPORT_C void FindAndOpenResourceFileL(RResourceFile& aResFile,const TDesC& aResFileName, const TDesC& aResFileLocation);
	IMPORT_C HBufC* ReadResourceHBufCL(TInt aResID,RResourceFile& aResFile);
//version information
	IMPORT_C TVersion Version() const;
	IMPORT_C TVersion WebTlVersion() const;
//stream awareness
	IMPORT_C void  StoreL(CDictionaryStore* aIniFile) const;
	IMPORT_C void  RestoreL(CDictionaryStore* aIniFile);
// web authentication settings
	IMPORT_C TBool GetAuthenticationL(CWtlDocument* aDocument,
														TDes& aName,TDes& aPassword,TInt aFrameId) const;
	IMPORT_C void CommitAuthenticationL();
// bookmarks
	IMPORT_C void UseBookmarkFileL(const TDesC& aFilename);
	IMPORT_C CBookmarkModel* CreateBookmarkModelL(TBool aReadOnly, MBkmkModelObserver* aObserver=NULL);
	IMPORT_C void AddToBookmarkFileL(const TDesC& aTitle, const TDesC& aUrl);

// history list functions	
	IMPORT_C void AddToHistoryListL(const THistoryListDetails& aEntryDetails);
	IMPORT_C void AddFrameToHistoryListL(const THistoryListDetails& aFrameDetails);
	IMPORT_C void UpdateHistoryListTitleL(const TDesC& aTitle);
	IMPORT_C void UpdateHistoryListDocPos(const THistoryListFrameId& aFrameId,TInt aDocPos);
	IMPORT_C void UpdateHistoryListFormData(const THistoryListFrameId& aFrameId,CBufBase* aFormData);
	IMPORT_C MDesCArray* GetHistoryListTopPageTitles();
	IMPORT_C TBool GetHistoryListItemUrl(TInt aHistoryListIndex,TPtrC& aUrl);
	IMPORT_C void SetHistoryListCurrentPosition(TInt aHistoryListNewCurrentPosition);
	IMPORT_C TBool SetHistoryListRequestedPosition(TInt aHistoryListRequestedPosition);
	IMPORT_C void GetHistoryListDetails(TInt aHistoryListIndex, const THistoryListFrameId& aFrameId, THistoryListDetails& aDetails);  
	IMPORT_C void GetHistoryListDocPos(TInt aHistoryListIndex, const THistoryListFrameId& aFrameId, TInt& aDocPos);  
	IMPORT_C void GetHistoryListFormData(TInt aHistoryListIndex, const THistoryListFrameId& aFrameId, CBufBase*& aFormData);	
	IMPORT_C TInt CurrentHistoryListPosition() const;	
	IMPORT_C TInt RequestedHistoryListPosition() const;
	IMPORT_C TBool IsStartOfHistoryList();
	IMPORT_C TBool IsEndOfHistoryList();
	IMPORT_C TInt HistoryListPositionNumFrames(TInt aHistoryListIndex) const;	
	IMPORT_C THistoryListFrameId HistoryListPositionFrameId(TInt aHistoryListIndex,TInt aIndex);

// web services config settings
	IMPORT_C TBool ConfigItemL(TBoolConfigurationItem aItem) const;
	IMPORT_C void SetConfigItemL(TBoolConfigurationItem aItem,TBool aValue);
	IMPORT_C TInt ConfigItemL(TNumericConfigurationItem aItem) const;
	IMPORT_C void SetConfigItemL(TNumericConfigurationItem aItem,TInt aValue);
	IMPORT_C HBufC* ConfigItemL(THBufConfigurationItem aItem) const;
	IMPORT_C void SetConfigItemL(THBufConfigurationItem aItem,const TDesC& aValue);
	IMPORT_C TPtrC ConfigItemL(TPtrConfigurationItem aItem) const;
	IMPORT_C void SetConfigItemL(TPtrConfigurationItem aItem,const TDesC& aValue);
	IMPORT_C HBufC8* HttpConfigItemL(THttpConfigurationItem aItem) const;
	IMPORT_C void SetHttpConfigItemL(THttpConfigurationItem aItem, const TDesC8& aValue);
	IMPORT_C void SetImageColorDepthL(TDisplayMode aDisplayType);
	IMPORT_C TDisplayMode ImageColorDepthL() const;
	IMPORT_C TInt EmptyCache(TBool aDeleteSubscriptions = EFalse);
// url functions
	IMPORT_C HBufC* AutoCorrectUrlLC(const TDesC& aUrl);
// observer functions
	IMPORT_C void SetObserver(MWebModelObserver* aObserver);
	IMPORT_C MWebModelObserver* Observer() const;
	IMPORT_C CWebLogger* LogPtr();
// simulated failure 
	IMPORT_C void __DbgSetAllocFail(TWebHeapType aHeap, RHeap::TAllocFail aType, TInt aValue);
	IMPORT_C void __DbgSetHttpFailL(TInt aErrorCode, TInt aNetworkCall);
	IMPORT_C void __DbgSetFileFailL(TInt aErrorCode, TInt aCount);

	IMPORT_C CWebSchemes* Schemes();

// query current proxy settings
	IMPORT_C TInt GetProxy(const TDesC& aScheme,HBufC*& aHost,TUint& aPort) const;
	IMPORT_C TBool IsExcluded(const TDesC& aHost) const;

// apply proxy settings for current ISP
	IMPORT_C void ApplyProxiesForCurrentIspL();

private:
	CWebServicesModel();
	void ConstructL(TInt aHistoryListSize);

	TBool ConfigL(TBoolConfigurationItem aItem) const;
	void SetConfigL(TBoolConfigurationItem aItem,TBool aValue);
	TInt ConfigL(TNumericConfigurationItem aItem) const;
	void SetConfigL(TNumericConfigurationItem aItem,TInt aValue);	
	void EnableWebtlLoggingL();

	void ExternalizeL(RWriteStream& aStream) const;
	void InternalizeL(RReadStream& aStream);

	TPtrC RemoveLeadingAndTrailingSpaces(const TDesC& aStr);

private:
	CWtlSession* iSession;						// the current internet session
	HBufC* iHomeUrl;						
	HBufC* iSearchUrl;						

	MWebModelObserver *iObserver;				// if non-null, observer of changes
	TBool iOffline;								// offline status
	TBool iDoPersistHistoryList;
	TBool iDoPersistCache;

	CHistoryListModel* iHistoryList;			
	CBookmarkControl* iBookmarkControl;			
		
	CAuthenticationData* iAuthentication;		// authentication database
	CNifMonitor* iNetworkMonitor;				// active object for reporting progress info from network interface

	__DECLARE_LOG;								// the logging object
	CWebSchemes* iSchemes;
	RFs iFsSession;
	RSocketServ iSocketServer;                  // socket server to maintain network connection
	};


#endif
